Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/view/DiffusionCommitGraphView.php
<?php | <?php | ||||
final class DiffusionCommitGraphView | final class DiffusionCommitGraphView | ||||
extends DiffusionView { | extends DiffusionView { | ||||
private $history; | private $history; | ||||
private $commits; | private $commits; | ||||
private $isHead; | private $isHead; | ||||
private $isTail; | private $isTail; | ||||
private $parents; | private $parents; | ||||
private $filterParents; | private $filterParents; | ||||
private $commitMap; | private $commitMap; | ||||
private $buildableMap; | private $buildableMap; | ||||
private $revisionMap; | private $revisionMap; | ||||
private $showAuditors; | |||||
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; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getHistory() { | public function getHistory() { | ||||
return $this->history; | return $this->history; | ||||
} | } | ||||
public function setCommits(array $commits) { | public function setCommits(array $commits) { | ||||
assert_instances_of($commits, 'PhabricatorRepositoryCommit'); | assert_instances_of($commits, 'PhabricatorRepositoryCommit'); | ||||
$this->commits = $commits; | $this->commits = $commits; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getCommits() { | public function getCommits() { | ||||
return $this->commits; | return $this->commits; | ||||
} | } | ||||
public function setShowAuditors($show_auditors) { | |||||
$this->showAuditors = $show_auditors; | |||||
return $this; | |||||
} | |||||
public function getShowAuditors() { | |||||
return $this->showAuditors; | |||||
} | |||||
public function setParents(array $parents) { | public function setParents(array $parents) { | ||||
$this->parents = $parents; | $this->parents = $parents; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getParents() { | public function getParents() { | ||||
return $this->parents; | return $this->parents; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | public function newObjectItemListView() { | ||||
foreach ($item_views as $item_view) { | foreach ($item_views as $item_view) { | ||||
$list_view->addItem($item_view); | $list_view->addItem($item_view); | ||||
} | } | ||||
return $list_view; | return $list_view; | ||||
} | } | ||||
private function newObjectItemViews() { | private function newObjectItemViews() { | ||||
$viewer = $this->getViewer(); | |||||
require_celerity_resource('diffusion-css'); | require_celerity_resource('diffusion-css'); | ||||
$show_builds = $this->shouldShowBuilds(); | $show_builds = $this->shouldShowBuilds(); | ||||
$show_revisions = $this->shouldShowRevisions(); | $show_revisions = $this->shouldShowRevisions(); | ||||
$show_auditors = $this->shouldShowAuditors(); | |||||
$phids = array(); | |||||
if ($show_revisions) { | |||||
$revision_map = $this->getRevisionMap(); | |||||
foreach ($revision_map as $revisions) { | |||||
foreach ($revisions as $revision) { | |||||
$phids[] = $revision->getPHID(); | |||||
} | |||||
} | |||||
} | |||||
if ($show_auditors) { | |||||
$commits = $this->getCommitMap(); | |||||
foreach ($commits as $commit) { | |||||
$audits = $commit->getAudits(); | |||||
foreach ($audits as $auditor) { | |||||
$phids[] = $auditor->getAuditorPHID(); | |||||
} | |||||
} | |||||
} | |||||
$handles = $viewer->loadHandles($phids); | |||||
$views = array(); | $views = array(); | ||||
$items = $this->newHistoryItems(); | $items = $this->newHistoryItems(); | ||||
foreach ($items as $hash => $item) { | foreach ($items as $hash => $item) { | ||||
$content = array(); | $content = array(); | ||||
$commit = $item['commit']; | $commit = $item['commit']; | ||||
$commit_description = $this->getCommitDescription($commit); | $commit_description = $this->getCommitDescription($commit); | ||||
$commit_link = $this->getCommitURI($hash); | $commit_link = $this->getCommitURI($hash); | ||||
$short_hash = $this->getCommitObjectName($hash); | $short_hash = $this->getCommitObjectName($hash); | ||||
$is_disabled = $this->getCommitIsDisabled($commit); | $is_disabled = $this->getCommitIsDisabled($commit); | ||||
$author_view = $this->getCommitAuthorView($commit); | |||||
$item_view = id(new PHUIObjectItemView()) | $item_view = id(new PHUIObjectItemView()) | ||||
->setViewer($viewer) | |||||
->setHeader($commit_description) | ->setHeader($commit_description) | ||||
->setObjectName($short_hash) | ->setObjectName($short_hash) | ||||
->setHref($commit_link) | ->setHref($commit_link) | ||||
->setDisabled($is_disabled); | ->setDisabled($is_disabled); | ||||
if ($author_view !== null) { | $this->addBrowseAction($item_view, $hash); | ||||
$item_view->addAttribute($author_view); | |||||
if ($show_builds) { | |||||
$this->addBuildAction($item_view, $hash); | |||||
} | } | ||||
$browse_button = $this->newBrowseButton($hash); | $this->addAuditAction($item_view, $hash); | ||||
$build_view = null; | if ($show_auditors) { | ||||
if ($show_builds) { | $auditor_list = $item_view->newPropertyList(); | ||||
$build_view = $this->newBuildView($hash); | if ($commit) { | ||||
$auditors = $this->newAuditorList($commit, $handles); | |||||
$auditor_list->addProperty(pht('Auditors'), $auditors); | |||||
} | |||||
} | } | ||||
$item_view->setSideColumn( | $property_list = $item_view->newPropertyList(); | ||||
array( | |||||
$build_view, | |||||
$browse_button, | |||||
)); | |||||
$revision_view = null; | if ($commit) { | ||||
if ($show_revisions) { | $author_view = $this->getCommitAuthorView($commit); | ||||
$revision_view = $this->newRevisionView($hash); | if ($author_view) { | ||||
$property_list->addProperty( | |||||
pht('Author'), | |||||
$this->getCommitAuthorView($commit)); | |||||
} | |||||
} | } | ||||
if ($revision_view !== null) { | if ($show_revisions) { | ||||
$item_view->addAttribute($revision_view); | if ($commit) { | ||||
$revisions = $this->getRevisions($commit); | |||||
if ($revisions) { | |||||
$revision = head($revisions); | |||||
$handle = $handles[$revision->getPHID()]; | |||||
$property_list->addProperty( | |||||
pht('Revision'), | |||||
$handle->renderLink()); | |||||
} | |||||
} | |||||
} | } | ||||
$views[$hash] = $item_view; | $views[$hash] = $item_view; | ||||
} | } | ||||
return $views; | return $views; | ||||
} | } | ||||
Show All 13 Lines | foreach ($items as $hash => $item) { | ||||
$header = $item_date; | $header = $item_date; | ||||
} else { | } else { | ||||
$header = null; | $header = null; | ||||
} | } | ||||
$item_view = $views[$hash]; | $item_view = $views[$hash]; | ||||
$list_view = id(new PHUIObjectItemListView()) | $list_view = id(new PHUIObjectItemListView()) | ||||
->setViewer($viewer) | |||||
->setFlush(true) | ->setFlush(true) | ||||
->addItem($item_view); | ->addItem($item_view); | ||||
if ($header !== null) { | if ($header !== null) { | ||||
$list_view->setHeader($header); | $list_view->setHeader($header); | ||||
} | } | ||||
$rows[] = $list_view; | $rows[] = $list_view; | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | private function shouldShowRevisions() { | ||||
$show_revisions = PhabricatorApplication::isClassInstalledForViewer( | $show_revisions = PhabricatorApplication::isClassInstalledForViewer( | ||||
'PhabricatorDifferentialApplication', | 'PhabricatorDifferentialApplication', | ||||
$viewer); | $viewer); | ||||
return $show_revisions; | return $show_revisions; | ||||
} | } | ||||
private function shouldShowAuditors() { | |||||
return $this->getShowAuditors(); | |||||
} | |||||
private function newHistoryItems() { | private function newHistoryItems() { | ||||
$items = array(); | $items = array(); | ||||
$history = $this->getHistory(); | $history = $this->getHistory(); | ||||
if ($history !== null) { | if ($history !== null) { | ||||
foreach ($history as $history_item) { | foreach ($history as $history_item) { | ||||
$commit_hash = $history_item->getCommitIdentifier(); | $commit_hash = $history_item->getCommitIdentifier(); | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | if (!$commit) { | ||||
return null; | return null; | ||||
} | } | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
return $commit->newCommitAuthorView($viewer); | return $commit->newCommitAuthorView($viewer); | ||||
} | } | ||||
private function newBrowseButton($hash) { | |||||
$repository = $this->getRepository(); | |||||
if ($repository) { | |||||
$drequest = $this->getDiffusionRequest(); | |||||
return $this->linkBrowse( | |||||
$drequest->getPath(), | |||||
array( | |||||
'commit' => $hash, | |||||
'branch' => $drequest->getBranch(), | |||||
), | |||||
$as_button = true); | |||||
} | |||||
return null; | |||||
} | |||||
private function getCommit($hash) { | private function getCommit($hash) { | ||||
$commit_map = $this->getCommitMap(); | $commit_map = $this->getCommitMap(); | ||||
return idx($commit_map, $hash); | return idx($commit_map, $hash); | ||||
} | } | ||||
private function getCommitMap() { | private function getCommitMap() { | ||||
if ($this->commitMap === null) { | if ($this->commitMap === null) { | ||||
$commit_list = $this->newCommitList(); | $commit_list = $this->newCommitList(); | ||||
$this->commitMap = mpull($commit_list, null, 'getCommitIdentifier'); | $this->commitMap = mpull($commit_list, null, 'getCommitIdentifier'); | ||||
} | } | ||||
return $this->commitMap; | return $this->commitMap; | ||||
} | } | ||||
private function newBuildView($hash) { | private function addBrowseAction(PHUIObjectItemView $item, $hash) { | ||||
$repository = $this->getRepository(); | |||||
if (!$repository) { | |||||
return; | |||||
} | |||||
$drequest = $this->getDiffusionRequest(); | |||||
$path = $drequest->getPath(); | |||||
$uri = $drequest->generateURI( | |||||
array( | |||||
'action' => 'browse', | |||||
'path' => $path, | |||||
)); | |||||
$item->newAction() | |||||
->setIcon('fa-folder-open-o bluegrey') | |||||
->setName(pht('Browse Repository')) | |||||
->setHref($uri); | |||||
} | |||||
private function addBuildAction(PHUIObjectItemView $item, $hash) { | |||||
$is_disabled = true; | |||||
$buildable = null; | |||||
$commit = $this->getCommit($hash); | $commit = $this->getCommit($hash); | ||||
if (!$commit) { | if (!$commit) { | ||||
return null; | $buildable = $this->getBuildable($commit); | ||||
} | } | ||||
$buildable = $this->getBuildable($commit); | if ($buildable) { | ||||
if (!$buildable) { | $icon = $buildable->getStatusIcon(); | ||||
return null; | $color = $buildable->getStatusColor(); | ||||
$name = $buildable->getStatusDisplayName(); | |||||
$uri = $buildable->getURI(); | |||||
} else { | |||||
$icon = 'fa-times'; | |||||
$color = 'grey'; | |||||
$name = pht('No Builds'); | |||||
$uri = null; | |||||
} | |||||
$item->newAction() | |||||
->setIcon($icon.' '.$color) | |||||
->setName($name) | |||||
->setHref($uri) | |||||
->setDisabled(($uri === null)); | |||||
} | |||||
private function addAuditAction(PHUIObjectItemView $item_view, $hash) { | |||||
$commit = $this->getCommit($hash); | |||||
if ($commit) { | |||||
$status = $commit->getAuditStatusObject(); | |||||
$text = $status->getName(); | |||||
$color = $status->getColor(); | |||||
$icon = $status->getIcon(); | |||||
$uri = $commit->getURI(); | |||||
$is_disabled = $status->isNoAudit(); | |||||
} else { | |||||
$text = pht('No Audit'); | |||||
$color = 'grey'; | |||||
$icon = 'fa-times'; | |||||
$uri = null; | |||||
$is_disabled = true; | |||||
} | } | ||||
return $this->renderBuildable($buildable, 'button'); | $item_view->newAction() | ||||
->setIcon($icon.' '.$color) | |||||
->setName($text) | |||||
->setHref($uri) | |||||
->setDisabled($is_disabled); | |||||
} | } | ||||
private function getBuildable(PhabricatorRepositoryCommit $commit) { | private function getBuildable(PhabricatorRepositoryCommit $commit) { | ||||
$buildable_map = $this->getBuildableMap(); | $buildable_map = $this->getBuildableMap(); | ||||
return idx($buildable_map, $commit->getPHID()); | return idx($buildable_map, $commit->getPHID()); | ||||
} | } | ||||
private function getBuildableMap() { | private function getBuildableMap() { | ||||
if ($this->buildableMap === null) { | if ($this->buildableMap === null) { | ||||
$commits = $this->getCommitMap(); | $commits = $this->getCommitMap(); | ||||
$buildables = $this->loadBuildables($commits); | $buildables = $this->loadBuildables($commits); | ||||
$this->buildableMap = $buildables; | $this->buildableMap = $buildables; | ||||
} | } | ||||
return $this->buildableMap; | return $this->buildableMap; | ||||
} | } | ||||
private function newRevisionView($hash) { | |||||
$commit = $this->getCommit($hash); | |||||
if (!$commit) { | |||||
return null; | |||||
} | |||||
$revisions = $this->getRevisions($commit); | |||||
if (!$revisions) { | |||||
return null; | |||||
} | |||||
$revision = head($revisions); | |||||
return id(new PHUITagView()) | |||||
->setName($revision->getMonogram()) | |||||
->setType(PHUITagView::TYPE_SHADE) | |||||
->setColor(PHUITagView::COLOR_BLUE) | |||||
->setHref($revision->getURI()) | |||||
->setBorder(PHUITagView::BORDER_NONE) | |||||
->setSlimShady(true); | |||||
} | |||||
private function getRevisions(PhabricatorRepositoryCommit $commit) { | private function getRevisions(PhabricatorRepositoryCommit $commit) { | ||||
$revision_map = $this->getRevisionMap(); | $revision_map = $this->getRevisionMap(); | ||||
return idx($revision_map, $commit->getPHID(), array()); | return idx($revision_map, $commit->getPHID(), array()); | ||||
} | } | ||||
private function getRevisionMap() { | private function getRevisionMap() { | ||||
if ($this->revisionMap === null) { | if ($this->revisionMap === null) { | ||||
$this->revisionMap = $this->newRevisionMap(); | $this->revisionMap = $this->newRevisionMap(); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | $commits = id(new DiffusionCommitQuery()) | ||||
->withIdentifiers($identifiers) | ->withIdentifiers($identifiers) | ||||
->needCommitData(true) | ->needCommitData(true) | ||||
->needIdentities(true) | ->needIdentities(true) | ||||
->execute(); | ->execute(); | ||||
return $commits; | return $commits; | ||||
} | } | ||||
private function newAuditorList( | |||||
PhabricatorRepositoryCommit $commit, | |||||
$handles) { | |||||
$auditors = $commit->getAudits(); | |||||
if (!$auditors) { | |||||
return phutil_tag('em', array(), pht('None')); | |||||
} | |||||
$auditor_phids = mpull($auditors, 'getAuditorPHID'); | |||||
$auditor_list = $handles->newSublist($auditor_phids) | |||||
->renderList() | |||||
->setAsInline(true); | |||||
return $auditor_list; | |||||
} | |||||
} | } |