[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class DifferentialChangesetListView extends AphrontView {
   4  
   5    private $changesets = array();
   6    private $visibleChangesets = array();
   7    private $references = array();
   8    private $inlineURI;
   9    private $renderURI = '/differential/changeset/';
  10    private $whitespace;
  11  
  12    private $standaloneURI;
  13    private $leftRawFileURI;
  14    private $rightRawFileURI;
  15  
  16    private $symbolIndexes = array();
  17    private $repository;
  18    private $branch;
  19    private $diff;
  20    private $vsMap = array();
  21  
  22    private $title;
  23  
  24    public function setTitle($title) {
  25      $this->title = $title;
  26      return $this;
  27    }
  28    private function getTitle() {
  29      return $this->title;
  30    }
  31  
  32    public function setBranch($branch) {
  33      $this->branch = $branch;
  34      return $this;
  35    }
  36    private function getBranch() {
  37      return $this->branch;
  38    }
  39  
  40    public function setChangesets($changesets) {
  41      $this->changesets = $changesets;
  42      return $this;
  43    }
  44  
  45    public function setVisibleChangesets($visible_changesets) {
  46      $this->visibleChangesets = $visible_changesets;
  47      return $this;
  48    }
  49  
  50    public function setInlineCommentControllerURI($uri) {
  51      $this->inlineURI = $uri;
  52      return $this;
  53    }
  54  
  55    public function setRepository(PhabricatorRepository $repository) {
  56      $this->repository = $repository;
  57      return $this;
  58    }
  59  
  60    public function setDiff(DifferentialDiff $diff) {
  61      $this->diff = $diff;
  62      return $this;
  63    }
  64  
  65    public function setRenderingReferences(array $references) {
  66      $this->references = $references;
  67      return $this;
  68    }
  69  
  70    public function setSymbolIndexes(array $indexes) {
  71      $this->symbolIndexes = $indexes;
  72      return $this;
  73    }
  74  
  75    public function setRenderURI($render_uri) {
  76      $this->renderURI = $render_uri;
  77      return $this;
  78    }
  79  
  80    public function setWhitespace($whitespace) {
  81      $this->whitespace = $whitespace;
  82      return $this;
  83    }
  84  
  85    public function setVsMap(array $vs_map) {
  86      $this->vsMap = $vs_map;
  87      return $this;
  88    }
  89  
  90    public function getVsMap() {
  91      return $this->vsMap;
  92    }
  93  
  94    public function setStandaloneURI($uri) {
  95      $this->standaloneURI = $uri;
  96      return $this;
  97    }
  98  
  99    public function setRawFileURIs($l, $r) {
 100      $this->leftRawFileURI = $l;
 101      $this->rightRawFileURI = $r;
 102      return $this;
 103    }
 104  
 105    public function render() {
 106      $this->requireResource('differential-changeset-view-css');
 107  
 108      $changesets = $this->changesets;
 109  
 110      Javelin::initBehavior('differential-toggle-files', array(
 111        'pht' => array(
 112          'undo' => pht('Undo'),
 113          'collapsed' => pht('This file content has been collapsed.'),
 114        ),
 115      ));
 116      Javelin::initBehavior(
 117        'differential-dropdown-menus',
 118        array(
 119          'pht' => array(
 120            'Open in Editor' => pht('Open in Editor'),
 121            'Show Entire File' => pht('Show Entire File'),
 122            'Entire File Shown' => pht('Entire File Shown'),
 123            "Can't Toggle Unloaded File" => pht("Can't Toggle Unloaded File"),
 124            'Expand File' => pht('Expand File'),
 125            'Collapse File' => pht('Collapse File'),
 126            'Browse in Diffusion' => pht('Browse in Diffusion'),
 127            'View Standalone' => pht('View Standalone'),
 128            'Show Raw File (Left)' => pht('Show Raw File (Left)'),
 129            'Show Raw File (Right)' => pht('Show Raw File (Right)'),
 130            'Configure Editor' => pht('Configure Editor'),
 131            'Load Changes' => pht('Load Changes'),
 132            'View Side-by-Side' => pht('View Side-by-Side'),
 133            'View Unified' => pht('View Unified (Barely Works!)'),
 134            'Change Text Encoding...' => pht('Change Text Encoding...'),
 135            'Highlight As...' => pht('Highlight As...'),
 136          ),
 137        ));
 138  
 139      $output = array();
 140      $ids = array();
 141      foreach ($changesets as $key => $changeset) {
 142  
 143        $file = $changeset->getFilename();
 144        $class = 'differential-changeset';
 145        if (!$this->inlineURI) {
 146          $class .= ' differential-changeset-noneditable';
 147        }
 148  
 149        $ref = $this->references[$key];
 150  
 151        $detail = new DifferentialChangesetDetailView();
 152  
 153        $uniq_id = 'diff-'.$changeset->getAnchorName();
 154        $detail->setID($uniq_id);
 155  
 156        $view_options = $this->renderViewOptionsDropdown(
 157          $detail,
 158          $ref,
 159          $changeset);
 160  
 161        $detail->setChangeset($changeset);
 162        $detail->addButton($view_options);
 163        $detail->setSymbolIndex(idx($this->symbolIndexes, $key));
 164        $detail->setVsChangesetID(idx($this->vsMap, $changeset->getID()));
 165        $detail->setEditable(true);
 166        $detail->setRenderingRef($ref);
 167        $detail->setAutoload(isset($this->visibleChangesets[$key]));
 168  
 169        $detail->setRenderURI($this->renderURI);
 170        $detail->setWhitespace($this->whitespace);
 171  
 172        if (isset($this->visibleChangesets[$key])) {
 173          $load = 'Loading...';
 174        } else {
 175          $load = javelin_tag(
 176            'a',
 177            array(
 178              'class' => 'button grey',
 179              'href' => '#'.$uniq_id,
 180              'sigil' => 'differential-load',
 181              'meta' => array(
 182                'id' => $detail->getID(),
 183                'kill' => true,
 184              ),
 185              'mustcapture' => true,
 186            ),
 187            pht('Load File'));
 188        }
 189        $detail->appendChild(
 190          phutil_tag(
 191            'div',
 192            array(
 193              'id' => $uniq_id,
 194            ),
 195            phutil_tag('div', array('class' => 'differential-loading'), $load)));
 196        $output[] = $detail->render();
 197  
 198        $ids[] = $detail->getID();
 199      }
 200  
 201      $this->requireResource('aphront-tooltip-css');
 202  
 203      $this->initBehavior('differential-populate', array(
 204        'changesetViewIDs' => $ids,
 205      ));
 206  
 207      $this->initBehavior('differential-show-more', array(
 208        'uri' => $this->renderURI,
 209        'whitespace' => $this->whitespace,
 210      ));
 211  
 212      $this->initBehavior('differential-comment-jump', array());
 213  
 214      if ($this->inlineURI) {
 215        $undo_templates = $this->renderUndoTemplates();
 216  
 217        Javelin::initBehavior('differential-edit-inline-comments', array(
 218          'uri'             => $this->inlineURI,
 219          'undo_templates'  => $undo_templates,
 220          'stage'           => 'differential-review-stage',
 221        ));
 222      }
 223  
 224      $header = id(new PHUIHeaderView())
 225        ->setHeader($this->getTitle());
 226  
 227      $content = phutil_tag(
 228        'div',
 229        array(
 230          'class' => 'differential-review-stage',
 231          'id'    => 'differential-review-stage',
 232        ),
 233        $output);
 234  
 235      $object_box = id(new PHUIObjectBoxView())
 236        ->setHeader($header)
 237        ->appendChild($content);
 238  
 239      return $object_box;
 240    }
 241  
 242    /**
 243     * Render the "Undo" markup for the inline comment undo feature.
 244     */
 245    private function renderUndoTemplates() {
 246      $link = javelin_tag(
 247        'a',
 248        array(
 249          'href'  => '#',
 250          'sigil' => 'differential-inline-comment-undo',
 251        ),
 252        pht('Undo'));
 253  
 254      $div = phutil_tag(
 255        'div',
 256        array(
 257          'class' => 'differential-inline-undo',
 258        ),
 259        array('Changes discarded. ', $link));
 260  
 261      return array(
 262        'l' => phutil_tag('table', array(),
 263          phutil_tag('tr', array(), array(
 264            phutil_tag('th', array()),
 265            phutil_tag('td', array(), $div),
 266            phutil_tag('th', array()),
 267            phutil_tag('td', array('colspan' => 3)),
 268          ))),
 269  
 270        'r' => phutil_tag('table', array(),
 271          phutil_tag('tr', array(), array(
 272            phutil_tag('th', array()),
 273            phutil_tag('td', array()),
 274            phutil_tag('th', array()),
 275            phutil_tag('td', array('colspan' => 3), $div),
 276          ))),
 277      );
 278    }
 279  
 280    private function renderViewOptionsDropdown(
 281      DifferentialChangesetDetailView $detail,
 282      $ref,
 283      DifferentialChangeset $changeset) {
 284  
 285      $meta = array();
 286  
 287      $qparams = array(
 288        'ref'         => $ref,
 289        'whitespace'  => $this->whitespace,
 290      );
 291  
 292      if ($this->standaloneURI) {
 293        $uri = new PhutilURI($this->standaloneURI);
 294        $uri->setQueryParams($uri->getQueryParams() + $qparams);
 295        $meta['standaloneURI'] = (string)$uri;
 296      }
 297  
 298      $repository = $this->repository;
 299      if ($repository) {
 300        try {
 301          $meta['diffusionURI'] =
 302            (string)$repository->getDiffusionBrowseURIForPath(
 303              $this->user,
 304              $changeset->getAbsoluteRepositoryPath($repository, $this->diff),
 305              idx($changeset->getMetadata(), 'line:first'),
 306              $this->getBranch());
 307        } catch (DiffusionSetupException $e) {
 308          // Ignore
 309        }
 310      }
 311  
 312      $change = $changeset->getChangeType();
 313  
 314      if ($this->leftRawFileURI) {
 315        if ($change != DifferentialChangeType::TYPE_ADD) {
 316          $uri = new PhutilURI($this->leftRawFileURI);
 317          $uri->setQueryParams($uri->getQueryParams() + $qparams);
 318          $meta['leftURI'] = (string)$uri;
 319        }
 320      }
 321  
 322      if ($this->rightRawFileURI) {
 323        if ($change != DifferentialChangeType::TYPE_DELETE &&
 324            $change != DifferentialChangeType::TYPE_MULTICOPY) {
 325          $uri = new PhutilURI($this->rightRawFileURI);
 326          $uri->setQueryParams($uri->getQueryParams() + $qparams);
 327          $meta['rightURI'] = (string)$uri;
 328        }
 329      }
 330  
 331      $user = $this->user;
 332      if ($user && $repository) {
 333        $path = ltrim(
 334          $changeset->getAbsoluteRepositoryPath($repository, $this->diff),
 335          '/');
 336        $line = idx($changeset->getMetadata(), 'line:first', 1);
 337        $callsign = $repository->getCallsign();
 338        $editor_link = $user->loadEditorLink($path, $line, $callsign);
 339        if ($editor_link) {
 340          $meta['editor'] = $editor_link;
 341        } else {
 342          $meta['editorConfigure'] = '/settings/panel/display/';
 343        }
 344      }
 345  
 346      $meta['containerID'] = $detail->getID();
 347      $caret = phutil_tag('span', array('class' => 'caret'), '');
 348  
 349      return javelin_tag(
 350        'a',
 351        array(
 352          'class'   => 'button grey small dropdown',
 353          'meta'    => $meta,
 354          'href'    => idx($meta, 'detailURI', '#'),
 355          'target'  => '_blank',
 356          'sigil'   => 'differential-view-options',
 357        ),
 358        array(pht('View Options'), $caret));
 359    }
 360  
 361  }


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