[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/phui/ -> PHUITimelineView.php (source)

   1  <?php
   2  
   3  final class PHUITimelineView extends AphrontView {
   4  
   5    private $events = array();
   6    private $id;
   7    private $shouldTerminate = false;
   8  
   9    public function setID($id) {
  10      $this->id = $id;
  11      return $this;
  12    }
  13  
  14    public function setShouldTerminate($term) {
  15      $this->shouldTerminate = $term;
  16      return $this;
  17    }
  18  
  19    public function addEvent(PHUITimelineEventView $event) {
  20      $this->events[] = $event;
  21      return $this;
  22    }
  23  
  24    public function render() {
  25      require_celerity_resource('phui-timeline-view-css');
  26  
  27      $spacer = self::renderSpacer();
  28  
  29      $hide = array();
  30      $show = array();
  31  
  32      foreach ($this->events as $event) {
  33        if ($event->getHideByDefault()) {
  34          $hide[] = $event;
  35        } else {
  36          $show[] = $event;
  37        }
  38      }
  39  
  40      $events = array();
  41      if ($hide) {
  42        $hidden = phutil_implode_html($spacer, $hide);
  43        $count = count($hide);
  44  
  45        $show_id = celerity_generate_unique_node_id();
  46        $hide_id = celerity_generate_unique_node_id();
  47        $link_id = celerity_generate_unique_node_id();
  48  
  49        Javelin::initBehavior(
  50          'phabricator-show-all-transactions',
  51          array(
  52            'anchors' => array_filter(mpull($hide, 'getAnchor')),
  53            'linkID' => $link_id,
  54            'hideID' => $hide_id,
  55            'showID' => $show_id,
  56          ));
  57  
  58        $events[] = phutil_tag(
  59          'div',
  60          array(
  61            'id' => $hide_id,
  62            'class' => 'phui-timeline-older-transactions-are-hidden',
  63          ),
  64          array(
  65            pht('%s older changes(s) are hidden.', new PhutilNumber($count)),
  66            ' ',
  67            javelin_tag(
  68              'a',
  69              array(
  70                'href' => '#',
  71                'mustcapture' => true,
  72                'id' => $link_id,
  73              ),
  74              pht('Show all changes.')),
  75          ));
  76  
  77        $events[] = phutil_tag(
  78          'div',
  79          array(
  80            'id' => $show_id,
  81            'style' => 'display: none',
  82          ),
  83          $hidden);
  84      }
  85  
  86      if ($hide && $show) {
  87        $events[] = $spacer;
  88      }
  89  
  90      if ($show) {
  91        $events[] = phutil_implode_html($spacer, $show);
  92      }
  93  
  94      if ($events) {
  95        $events = array($spacer, $events, $spacer);
  96      } else {
  97        $events = array($spacer);
  98      }
  99  
 100      if ($this->shouldTerminate) {
 101        $events[] = self::renderEnder(true);
 102      }
 103  
 104      return phutil_tag(
 105        'div',
 106        array(
 107          'class' => 'phui-timeline-view',
 108          'id' => $this->id,
 109        ),
 110        $events);
 111    }
 112  
 113    public static function renderSpacer() {
 114      return phutil_tag(
 115        'div',
 116        array(
 117          'class' => 'phui-timeline-event-view '.
 118                     'phui-timeline-spacer',
 119        ),
 120        '');
 121    }
 122  
 123    public static function renderEnder() {
 124      return phutil_tag(
 125        'div',
 126        array(
 127          'class' => 'phui-timeline-event-view '.
 128                     'the-worlds-end',
 129        ),
 130        '');
 131    }
 132  
 133  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1