Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/view/DiffusionHistoryTableView.php
<?php | <?php | ||||
final class DiffusionHistoryTableView extends DiffusionView { | final class DiffusionHistoryTableView extends DiffusionView { | ||||
private $history; | private $history; | ||||
private $revisions = array(); | private $revisions = array(); | ||||
private $handles = array(); | private $handles = array(); | ||||
private $isHead; | private $isHead; | ||||
private $parents; | private $parents; | ||||
private $buildCache; | |||||
public function setHistory(array $history) { | public function setHistory(array $history) { | ||||
assert_instances_of($history, 'DiffusionPathChange'); | assert_instances_of($history, 'DiffusionPathChange'); | ||||
$this->history = $history; | $this->history = $history; | ||||
$this->buildCache = null; | |||||
return $this; | return $this; | ||||
} | } | ||||
public function loadRevisions() { | public function loadRevisions() { | ||||
$commit_phids = array(); | $commit_phids = array(); | ||||
foreach ($this->history as $item) { | foreach ($this->history as $item) { | ||||
if ($item->getCommit()) { | if ($item->getCommit()) { | ||||
$commit_phids[] = $item->getCommit()->getPHID(); | $commit_phids[] = $item->getCommit()->getPHID(); | ||||
Show All 33 Lines | public function setParents(array $parents) { | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setIsHead($is_head) { | public function setIsHead($is_head) { | ||||
$this->isHead = $is_head; | $this->isHead = $is_head; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function loadBuildablesOnDemand() { | |||||
if ($this->buildCache !== null) { | |||||
return $this->buildCache; | |||||
} | |||||
$commits_to_builds = array(); | |||||
$commits = mpull($this->history, 'getCommit'); | |||||
$commit_phids = mpull($commits, 'getPHID'); | |||||
$buildables = id(new HarbormasterBuildableQuery()) | |||||
->setViewer($this->getUser()) | |||||
->withBuildablePHIDs($commit_phids) | |||||
->withManualBuildables(false) | |||||
->execute(); | |||||
$this->buildCache = mpull($buildables, null, 'getBuildablePHID'); | |||||
return $this->buildCache; | |||||
} | |||||
public function render() { | public function render() { | ||||
$drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
$viewer = $this->getUser(); | $viewer = $this->getUser(); | ||||
$buildables = $this->loadBuildables(mpull($this->history, 'getCommit')); | |||||
$has_any_build = false; | |||||
$show_revisions = PhabricatorApplication::isClassInstalledForViewer( | $show_revisions = PhabricatorApplication::isClassInstalledForViewer( | ||||
'PhabricatorDifferentialApplication', | 'PhabricatorDifferentialApplication', | ||||
$viewer); | $viewer); | ||||
$handles = $viewer->loadHandles($this->getRequiredHandlePHIDs()); | $handles = $viewer->loadHandles($this->getRequiredHandlePHIDs()); | ||||
$graph = null; | $graph = null; | ||||
if ($this->parents) { | if ($this->parents) { | ||||
$graph = $this->renderGraph(); | $graph = $this->renderGraph(); | ||||
} | } | ||||
$show_builds = PhabricatorApplication::isClassInstalledForViewer( | $show_builds = PhabricatorApplication::isClassInstalledForViewer( | ||||
'PhabricatorHarbormasterApplication', | 'PhabricatorHarbormasterApplication', | ||||
$this->getUser()); | $this->getUser()); | ||||
$rows = array(); | $rows = array(); | ||||
$ii = 0; | $ii = 0; | ||||
foreach ($this->history as $history) { | foreach ($this->history as $history) { | ||||
$epoch = $history->getEpoch(); | $epoch = $history->getEpoch(); | ||||
if ($epoch) { | if ($epoch) { | ||||
$date = phabricator_date($epoch, $this->user); | $committed = phabricator_datetime($epoch, $viewer); | ||||
$time = phabricator_time($epoch, $this->user); | |||||
} else { | } else { | ||||
$date = null; | $committed = null; | ||||
$time = null; | |||||
} | } | ||||
$data = $history->getCommitData(); | $data = $history->getCommitData(); | ||||
$author_phid = $committer = $committer_phid = null; | $author_phid = $committer = $committer_phid = null; | ||||
if ($data) { | if ($data) { | ||||
$author_phid = $data->getCommitDetail('authorPHID'); | $author_phid = $data->getCommitDetail('authorPHID'); | ||||
$committer_phid = $data->getCommitDetail('committerPHID'); | $committer_phid = $data->getCommitDetail('committerPHID'); | ||||
$committer = $data->getCommitDetail('committer'); | $committer = $data->getCommitDetail('committer'); | ||||
Show All 29 Lines | foreach ($this->history as $history) { | ||||
$summary = AphrontTableView::renderSingleDisplayLine( | $summary = AphrontTableView::renderSingleDisplayLine( | ||||
$history->getSummary()); | $history->getSummary()); | ||||
} else { | } else { | ||||
$summary = phutil_tag('em', array(), pht("Importing\xE2\x80\xA6")); | $summary = phutil_tag('em', array(), pht("Importing\xE2\x80\xA6")); | ||||
} | } | ||||
$build = null; | $build = null; | ||||
if ($show_builds) { | if ($show_builds) { | ||||
$buildable_lookup = $this->loadBuildablesOnDemand(); | $buildable = idx($buildables, $commit->getPHID()); | ||||
$buildable = idx($buildable_lookup, $commit->getPHID()); | |||||
if ($buildable !== null) { | if ($buildable !== null) { | ||||
$icon = HarbormasterBuildable::getBuildableStatusIcon( | $build = $this->renderBuildable($buildable); | ||||
$buildable->getBuildableStatus()); | |||||
$color = HarbormasterBuildable::getBuildableStatusColor( | |||||
$buildable->getBuildableStatus()); | |||||
$name = HarbormasterBuildable::getBuildableStatusName( | |||||
$buildable->getBuildableStatus()); | |||||
$icon_view = id(new PHUIIconView()) | |||||
->setIconFont($icon.' '.$color); | |||||
$tooltip_view = javelin_tag( | |||||
'span', | |||||
array( | |||||
'sigil' => 'has-tooltip', | |||||
'meta' => array('tip' => $name), | |||||
), | |||||
$icon_view); | |||||
Javelin::initBehavior('phabricator-tooltips'); | |||||
$href_view = phutil_tag( | |||||
'a', | |||||
array('href' => '/'.$buildable->getMonogram()), | |||||
$tooltip_view); | |||||
$build = $href_view; | |||||
$has_any_build = true; | $has_any_build = true; | ||||
} | } | ||||
} | } | ||||
$browse = $this->linkBrowse( | $browse = $this->linkBrowse( | ||||
$history->getPath(), | $history->getPath(), | ||||
array( | array( | ||||
'commit' => $history->getCommitIdentifier(), | 'commit' => $history->getCommitIdentifier(), | ||||
'branch' => $drequest->getBranch(), | 'branch' => $drequest->getBranch(), | ||||
'type' => $history->getFileType(), | 'type' => $history->getFileType(), | ||||
)); | )); | ||||
$rows[] = array( | $rows[] = array( | ||||
$graph ? $graph[$ii++] : null, | $graph ? $graph[$ii++] : null, | ||||
$browse, | $browse, | ||||
self::linkCommit( | self::linkCommit( | ||||
$drequest->getRepository(), | $drequest->getRepository(), | ||||
$history->getCommitIdentifier()), | $history->getCommitIdentifier()), | ||||
$build, | $build, | ||||
($commit ? | ($commit ? | ||||
self::linkRevision(idx($this->revisions, $commit->getPHID())) : | self::linkRevision(idx($this->revisions, $commit->getPHID())) : | ||||
null), | null), | ||||
$author, | $author, | ||||
$summary, | $summary, | ||||
$date, | $committed, | ||||
$time, | |||||
); | ); | ||||
} | } | ||||
$view = new AphrontTableView($rows); | $view = new AphrontTableView($rows); | ||||
$view->setHeaders( | $view->setHeaders( | ||||
array( | array( | ||||
null, | null, | ||||
null, | null, | ||||
pht('Commit'), | pht('Commit'), | ||||
null, | null, | ||||
pht('Revision'), | null, | ||||
pht('Author/Committer'), | pht('Author/Committer'), | ||||
pht('Details'), | pht('Details'), | ||||
pht('Date'), | pht('Committed'), | ||||
pht('Time'), | |||||
)); | )); | ||||
$view->setColumnClasses( | $view->setColumnClasses( | ||||
array( | array( | ||||
'threads', | 'threads', | ||||
'nudgeright', | 'nudgeright', | ||||
'n', | '', | ||||
'icon', | 'icon', | ||||
'n', | '', | ||||
'', | '', | ||||
'wide', | 'wide', | ||||
'', | '', | ||||
'right', | |||||
)); | )); | ||||
$view->setColumnVisibility( | $view->setColumnVisibility( | ||||
array( | array( | ||||
$graph ? true : false, | $graph ? true : false, | ||||
true, | true, | ||||
true, | true, | ||||
true, | $has_any_build, | ||||
$show_revisions, | $show_revisions, | ||||
)); | )); | ||||
$view->setDeviceVisibility( | $view->setDeviceVisibility( | ||||
array( | array( | ||||
$graph ? true : false, | $graph ? true : false, | ||||
true, | true, | ||||
true, | true, | ||||
true, | true, | ||||
true, | true, | ||||
false, | false, | ||||
true, | true, | ||||
false, | false, | ||||
false, | |||||
)); | )); | ||||
return $view->render(); | return $view->render(); | ||||
} | } | ||||
/** | /** | ||||
* Draw a merge/branch graph from the parent revision data. We're basically | * Draw a merge/branch graph from the parent revision data. We're basically | ||||
* building up a bunch of strings like this: | * building up a bunch of strings like this: | ||||
* | * | ||||
▲ Show 20 Lines • Show All 149 Lines • Show Last 20 Lines |