[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/differential/view/ -> DifferentialChangesetDetailView.php (source)

   1  <?php
   2  
   3  final class DifferentialChangesetDetailView extends AphrontView {
   4  
   5    private $changeset;
   6    private $buttons = array();
   7    private $editable;
   8    private $symbolIndex;
   9    private $id;
  10    private $vsChangesetID;
  11    private $renderURI;
  12    private $whitespace;
  13    private $renderingRef;
  14    private $autoload;
  15  
  16    public function setAutoload($autoload) {
  17      $this->autoload = $autoload;
  18      return $this;
  19    }
  20  
  21    public function getAutoload() {
  22      return $this->autoload;
  23    }
  24  
  25    public function setRenderingRef($rendering_ref) {
  26      $this->renderingRef = $rendering_ref;
  27      return $this;
  28    }
  29  
  30    public function getRenderingRef() {
  31      return $this->renderingRef;
  32    }
  33  
  34    public function setWhitespace($whitespace) {
  35      $this->whitespace = $whitespace;
  36      return $this;
  37    }
  38  
  39    public function getWhitespace() {
  40      return $this->whitespace;
  41    }
  42  
  43    public function setRenderURI($render_uri) {
  44      $this->renderURI = $render_uri;
  45      return $this;
  46    }
  47  
  48    public function getRenderURI() {
  49      return $this->renderURI;
  50    }
  51  
  52    public function setChangeset($changeset) {
  53      $this->changeset = $changeset;
  54      return $this;
  55    }
  56  
  57    public function addButton($button) {
  58      $this->buttons[] = $button;
  59      return $this;
  60    }
  61  
  62    public function setEditable($editable) {
  63      $this->editable = $editable;
  64      return $this;
  65    }
  66  
  67    public function setSymbolIndex($symbol_index) {
  68      $this->symbolIndex = $symbol_index;
  69      return $this;
  70    }
  71  
  72    public function getID() {
  73      if (!$this->id) {
  74        $this->id = celerity_generate_unique_node_id();
  75      }
  76      return $this->id;
  77    }
  78  
  79    public function setID($id) {
  80      $this->id = $id;
  81      return $this;
  82    }
  83  
  84    public function setVsChangesetID($vs_changeset_id) {
  85      $this->vsChangesetID = $vs_changeset_id;
  86      return $this;
  87    }
  88  
  89    public function getVsChangesetID() {
  90      return $this->vsChangesetID;
  91    }
  92  
  93    public function getFileIcon($filename) {
  94      $path_info = pathinfo($filename);
  95      $extension = idx($path_info, 'extension');
  96      switch ($extension) {
  97        case 'psd':
  98        case 'ai':
  99          $icon = 'fa-eye';
 100          break;
 101        case 'conf':
 102          $icon = 'fa-wrench';
 103          break;
 104        case 'wav':
 105        case 'mp3':
 106        case 'aiff':
 107          $icon = 'fa-file-sound-o';
 108          break;
 109        case 'm4v':
 110        case 'mov':
 111          $icon = 'fa-file-movie-o';
 112          break;
 113        case 'sql':
 114        case 'db':
 115          $icon = 'fa-database';
 116          break;
 117        case 'xls':
 118        case 'csv':
 119          $icon = 'fa-file-excel-o';
 120          break;
 121        case 'ics':
 122          $icon = 'fa-calendar';
 123          break;
 124        case 'zip':
 125        case 'tar':
 126        case 'bz':
 127        case 'tgz':
 128        case 'gz':
 129          $icon = 'fa-file-archive-o';
 130          break;
 131        case 'png':
 132        case 'jpg':
 133        case 'bmp':
 134        case 'gif':
 135          $icon = 'fa-file-picture-o';
 136          break;
 137        case 'txt':
 138          $icon = 'fa-file-text-o';
 139          break;
 140        case 'doc':
 141        case 'docx':
 142          $icon = 'fa-file-word-o';
 143          break;
 144        case 'pdf':
 145          $icon = 'fa-file-pdf-o';
 146          break;
 147        default:
 148          $icon = 'fa-file-code-o';
 149          break;
 150      }
 151      return $icon;
 152    }
 153  
 154    public function render() {
 155      $this->requireResource('differential-changeset-view-css');
 156      $this->requireResource('syntax-highlighting-css');
 157  
 158      Javelin::initBehavior('phabricator-oncopy', array());
 159  
 160      $changeset = $this->changeset;
 161      $class = 'differential-changeset';
 162      if (!$this->editable) {
 163        $class .= ' differential-changeset-immutable';
 164      }
 165  
 166      $buttons = null;
 167      if ($this->buttons) {
 168        $buttons = phutil_tag(
 169          'div',
 170          array(
 171            'class' => 'differential-changeset-buttons',
 172          ),
 173          $this->buttons);
 174      }
 175  
 176      $id = $this->getID();
 177  
 178      if ($this->symbolIndex) {
 179        Javelin::initBehavior(
 180          'repository-crossreference',
 181          array(
 182            'container' => $id,
 183          ) + $this->symbolIndex);
 184      }
 185  
 186      $display_filename = $changeset->getDisplayFilename();
 187      $display_icon = $this->getFileIcon($display_filename);
 188      $icon = id(new PHUIIconView())
 189        ->setIconFont($display_icon);
 190  
 191      return javelin_tag(
 192        'div',
 193        array(
 194          'sigil' => 'differential-changeset',
 195          'meta'  => array(
 196            'left'  => nonempty(
 197              $this->getVsChangesetID(),
 198              $this->changeset->getID()),
 199            'right' => $this->changeset->getID(),
 200            'renderURI' => $this->getRenderURI(),
 201            'whitespace' => $this->getWhitespace(),
 202            'highlight' => null,
 203            'renderer' => null,
 204            'ref' => $this->getRenderingRef(),
 205            'autoload' => $this->getAutoload(),
 206          ),
 207          'class' => $class,
 208          'id'    => $id,
 209        ),
 210        array(
 211          id(new PhabricatorAnchorView())
 212            ->setAnchorName($changeset->getAnchorName())
 213            ->setNavigationMarker(true)
 214            ->render(),
 215          $buttons,
 216          phutil_tag('h1',
 217            array(
 218              'class' => 'differential-file-icon-header',
 219            ),
 220            array(
 221              $icon,
 222              $display_filename,
 223            )),
 224          javelin_tag(
 225            'div',
 226            array(
 227              'class' => 'changeset-view-content',
 228              'sigil' => 'changeset-view-content',
 229            ),
 230            $this->renderChildren()),
 231        ));
 232    }
 233  
 234  }


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