[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class DifferentialRevisionUpdateHistoryView extends AphrontView {
   4  
   5    private $diffs = array();
   6    private $selectedVersusDiffID;
   7    private $selectedDiffID;
   8    private $selectedWhitespace;
   9    private $commitsForLinks = array();
  10  
  11    public function setDiffs(array $diffs) {
  12      assert_instances_of($diffs, 'DifferentialDiff');
  13      $this->diffs = $diffs;
  14      return $this;
  15    }
  16  
  17    public function setSelectedVersusDiffID($id) {
  18      $this->selectedVersusDiffID = $id;
  19      return $this;
  20    }
  21  
  22    public function setSelectedDiffID($id) {
  23      $this->selectedDiffID = $id;
  24      return $this;
  25    }
  26  
  27    public function setSelectedWhitespace($whitespace) {
  28      $this->selectedWhitespace = $whitespace;
  29      return $this;
  30    }
  31  
  32    public function setCommitsForLinks(array $commits) {
  33      assert_instances_of($commits, 'PhabricatorRepositoryCommit');
  34      $this->commitsForLinks = $commits;
  35      return $this;
  36    }
  37  
  38    public function render() {
  39  
  40      $this->requireResource('differential-core-view-css');
  41      $this->requireResource('differential-revision-history-css');
  42  
  43      $data = array(
  44        array(
  45          'name' => 'Base',
  46          'id'   => null,
  47          'desc' => 'Base',
  48          'age'  => null,
  49          'obj'  => null,
  50        ),
  51      );
  52  
  53      $seq = 0;
  54      foreach ($this->diffs as $diff) {
  55        $data[] = array(
  56          'name' => 'Diff '.(++$seq),
  57          'id'   => $diff->getID(),
  58          'desc' => $diff->getDescription(),
  59          'age'  => $diff->getDateCreated(),
  60          'obj'  => $diff,
  61        );
  62      }
  63  
  64      $max_id = $diff->getID();
  65  
  66      $idx = 0;
  67      $rows = array();
  68      $disable = false;
  69      $radios = array();
  70      $last_base = null;
  71      $rowc = array();
  72      foreach ($data as $row) {
  73  
  74        $diff = $row['obj'];
  75        $name = $row['name'];
  76        $id   = $row['id'];
  77  
  78        $old_class = false;
  79        $new_class = false;
  80  
  81        if ($id) {
  82          $new_checked = ($this->selectedDiffID == $id);
  83          $new = javelin_tag(
  84            'input',
  85            array(
  86              'type' => 'radio',
  87              'name' => 'id',
  88              'value' => $id,
  89              'checked' => $new_checked ? 'checked' : null,
  90              'sigil' => 'differential-new-radio',
  91            ));
  92          if ($new_checked) {
  93            $new_class = true;
  94            $disable = true;
  95          }
  96          $new = phutil_tag(
  97            'div',
  98            array(
  99              'class' => 'differential-update-history-radio',
 100            ),
 101            $new);
 102        } else {
 103          $new = null;
 104        }
 105  
 106        if ($max_id != $id) {
 107          $uniq = celerity_generate_unique_node_id();
 108          $old_checked = ($this->selectedVersusDiffID == $id);
 109          $old = phutil_tag(
 110            'input',
 111            array(
 112              'type' => 'radio',
 113              'name' => 'vs',
 114              'value' => $id,
 115              'id' => $uniq,
 116              'checked' => $old_checked ? 'checked' : null,
 117              'disabled' => $disable ? 'disabled' : null,
 118            ));
 119          $radios[] = $uniq;
 120          if ($old_checked) {
 121            $old_class = true;
 122          }
 123          $old = phutil_tag(
 124            'div',
 125            array(
 126              'class' => 'differential-update-history-radio',
 127            ),
 128            $old);
 129        } else {
 130          $old = null;
 131        }
 132  
 133        $desc = $row['desc'];
 134  
 135        if ($row['age']) {
 136          $age = phabricator_datetime($row['age'], $this->getUser());
 137        } else {
 138          $age = null;
 139        }
 140  
 141        if ($diff) {
 142          $lint = self::renderDiffLintStar($row['obj']);
 143          $lint = phutil_tag(
 144            'div',
 145            array(
 146              'class' => 'lintunit-star',
 147              'title' => self::getDiffLintMessage($diff),
 148            ),
 149            $lint);
 150  
 151          $unit = self::renderDiffUnitStar($row['obj']);
 152          $unit = phutil_tag(
 153            'div',
 154            array(
 155              'class' => 'lintunit-star',
 156              'title' => self::getDiffUnitMessage($diff),
 157            ),
 158            $unit);
 159  
 160          $base = $this->renderBaseRevision($diff);
 161        } else {
 162          $lint = null;
 163          $unit = null;
 164          $base = null;
 165        }
 166  
 167        if ($last_base !== null && $base !== $last_base) {
 168          // TODO: Render some kind of notice about rebases.
 169        }
 170        $last_base = $base;
 171  
 172        $id_link = phutil_tag(
 173          'a',
 174          array(
 175            'href' => '/differential/diff/'.$id.'/',
 176          ),
 177          $id);
 178  
 179        $rows[] = array(
 180          $name,
 181          $id_link,
 182          $base,
 183          $desc,
 184          $age,
 185          $lint,
 186          $unit,
 187          $old,
 188          $new,
 189        );
 190  
 191        $classes = array();
 192        if ($old_class) {
 193          $classes[] = 'differential-update-history-old-now';
 194        }
 195        if ($new_class) {
 196          $classes[] = 'differential-update-history-new-now';
 197        }
 198        $rowc[] = nonempty(implode(' ', $classes), null);
 199      }
 200  
 201      Javelin::initBehavior(
 202        'differential-diff-radios',
 203        array(
 204          'radios' => $radios,
 205        ));
 206  
 207      $options = array(
 208        DifferentialChangesetParser::WHITESPACE_IGNORE_FORCE => 'Ignore All',
 209        DifferentialChangesetParser::WHITESPACE_IGNORE_ALL => 'Ignore Most',
 210        DifferentialChangesetParser::WHITESPACE_IGNORE_TRAILING =>
 211          'Ignore Trailing',
 212        DifferentialChangesetParser::WHITESPACE_SHOW_ALL => 'Show All',
 213      );
 214  
 215      foreach ($options as $value => $label) {
 216        $options[$value] = phutil_tag(
 217          'option',
 218          array(
 219            'value' => $value,
 220            'selected' => ($value == $this->selectedWhitespace)
 221            ? 'selected'
 222            : null,
 223          ),
 224          $label);
 225      }
 226      $select = phutil_tag('select', array('name' => 'whitespace'), $options);
 227  
 228  
 229      $table = id(new AphrontTableView($rows));
 230      $table->setHeaders(
 231        array(
 232          pht('Diff'),
 233          pht('ID'),
 234          pht('Base'),
 235          pht('Description'),
 236          pht('Created'),
 237          pht('Lint'),
 238          pht('Unit'),
 239          '',
 240          '',
 241        ));
 242      $table->setColumnClasses(
 243        array(
 244          'pri',
 245          '',
 246          '',
 247          'wide',
 248          'date',
 249          'center',
 250          'center',
 251          'center differential-update-history-old',
 252          'center differential-update-history-new',
 253        ));
 254      $table->setRowClasses($rowc);
 255      $table->setDeviceVisibility(
 256        array(
 257          true,
 258          true,
 259          false,
 260          true,
 261          false,
 262          false,
 263          false,
 264          true,
 265          true,
 266        ));
 267  
 268      $show_diff = phutil_tag(
 269        'div',
 270        array(
 271          'class' => 'differential-update-history-footer',
 272        ),
 273        array(
 274          phutil_tag(
 275            'label',
 276            array(),
 277            array(
 278              pht('Whitespace Changes:'),
 279              $select,
 280            )),
 281          phutil_tag(
 282            'button',
 283            array(),
 284            pht('Show Diff')),
 285        ));
 286  
 287      $content = phabricator_form(
 288        $this->getUser(),
 289        array(
 290          'action' => '#toc',
 291        ),
 292        array(
 293          $table,
 294          $show_diff,
 295        ));
 296  
 297      return id(new PHUIObjectBoxView())
 298        ->setHeaderText(pht('Revision Update History'))
 299        ->setFlush(true)
 300        ->appendChild($content);
 301    }
 302  
 303    const STAR_NONE = 'none';
 304    const STAR_OKAY = 'okay';
 305    const STAR_WARN = 'warn';
 306    const STAR_FAIL = 'fail';
 307    const STAR_SKIP = 'skip';
 308  
 309    public static function renderDiffLintStar(DifferentialDiff $diff) {
 310      static $map = array(
 311        DifferentialLintStatus::LINT_NONE => self::STAR_NONE,
 312        DifferentialLintStatus::LINT_OKAY => self::STAR_OKAY,
 313        DifferentialLintStatus::LINT_WARN => self::STAR_WARN,
 314        DifferentialLintStatus::LINT_FAIL => self::STAR_FAIL,
 315        DifferentialLintStatus::LINT_SKIP => self::STAR_SKIP,
 316        DifferentialLintStatus::LINT_AUTO_SKIP => self::STAR_SKIP,
 317        DifferentialLintStatus::LINT_POSTPONED => self::STAR_SKIP,
 318      );
 319  
 320      $star = idx($map, $diff->getLintStatus(), self::STAR_FAIL);
 321  
 322      return self::renderDiffStar($star);
 323    }
 324  
 325    public static function renderDiffUnitStar(DifferentialDiff $diff) {
 326      static $map = array(
 327        DifferentialUnitStatus::UNIT_NONE => self::STAR_NONE,
 328        DifferentialUnitStatus::UNIT_OKAY => self::STAR_OKAY,
 329        DifferentialUnitStatus::UNIT_WARN => self::STAR_WARN,
 330        DifferentialUnitStatus::UNIT_FAIL => self::STAR_FAIL,
 331        DifferentialUnitStatus::UNIT_SKIP => self::STAR_SKIP,
 332        DifferentialUnitStatus::UNIT_AUTO_SKIP => self::STAR_SKIP,
 333        DifferentialUnitStatus::UNIT_POSTPONED => self::STAR_SKIP,
 334      );
 335  
 336      $star = idx($map, $diff->getUnitStatus(), self::STAR_FAIL);
 337  
 338      return self::renderDiffStar($star);
 339    }
 340  
 341    public static function getDiffLintMessage(DifferentialDiff $diff) {
 342      switch ($diff->getLintStatus()) {
 343        case DifferentialLintStatus::LINT_NONE:
 344          return pht('No Linters Available');
 345        case DifferentialLintStatus::LINT_OKAY:
 346          return pht('Lint OK');
 347        case DifferentialLintStatus::LINT_WARN:
 348          return pht('Lint Warnings');
 349        case DifferentialLintStatus::LINT_FAIL:
 350          return pht('Lint Errors');
 351        case DifferentialLintStatus::LINT_SKIP:
 352          return pht('Lint Skipped');
 353        case DifferentialLintStatus::LINT_AUTO_SKIP:
 354          return pht('Automatic diff as part of commit; lint not applicable.');
 355        case DifferentialLintStatus::LINT_POSTPONED:
 356          return pht('Lint Postponed');
 357      }
 358      return '???';
 359    }
 360  
 361    public static function getDiffUnitMessage(DifferentialDiff $diff) {
 362      switch ($diff->getUnitStatus()) {
 363        case DifferentialUnitStatus::UNIT_NONE:
 364          return pht('No Unit Test Coverage');
 365        case DifferentialUnitStatus::UNIT_OKAY:
 366          return pht('Unit Tests OK');
 367        case DifferentialUnitStatus::UNIT_WARN:
 368          return pht('Unit Test Warnings');
 369        case DifferentialUnitStatus::UNIT_FAIL:
 370          return pht('Unit Test Errors');
 371        case DifferentialUnitStatus::UNIT_SKIP:
 372          return pht('Unit Tests Skipped');
 373        case DifferentialUnitStatus::UNIT_AUTO_SKIP:
 374          return pht(
 375            'Automatic diff as part of commit; unit tests not applicable.');
 376        case DifferentialUnitStatus::UNIT_POSTPONED:
 377          return pht('Unit Tests Postponed');
 378      }
 379      return '???';
 380    }
 381  
 382    private static function renderDiffStar($star) {
 383      $class = 'diff-star-'.$star;
 384      return phutil_tag(
 385        'span',
 386        array('class' => $class),
 387        "\xE2\x98\x85");
 388    }
 389  
 390    private function renderBaseRevision(DifferentialDiff $diff) {
 391      switch ($diff->getSourceControlSystem()) {
 392        case 'git':
 393          $base = $diff->getSourceControlBaseRevision();
 394          if (strpos($base, '@') === false) {
 395            $label = substr($base, 0, 7);
 396          } else {
 397            // The diff is from git-svn
 398            $base = explode('@', $base);
 399            $base = last($base);
 400            $label = $base;
 401          }
 402          break;
 403        case 'svn':
 404          $base = $diff->getSourceControlBaseRevision();
 405          $base = explode('@', $base);
 406          $base = last($base);
 407          $label = $base;
 408          break;
 409        default:
 410          $label = null;
 411          break;
 412      }
 413      $link = null;
 414      if ($label) {
 415        $commit_for_link = idx(
 416          $this->commitsForLinks,
 417          $diff->getSourceControlBaseRevision());
 418        if ($commit_for_link) {
 419          $link = phutil_tag(
 420            'a',
 421            array('href' => $commit_for_link->getURI()),
 422            $label);
 423        } else {
 424          $link = $label;
 425        }
 426      }
 427      return $link;
 428    }
 429  }


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