|
| 1 | +<?php |
| 2 | + |
| 3 | +final class DiffusionHistoryListView extends AphrontView { |
| 4 | + |
| 5 | + private $commits = array(); |
| 6 | + private $noDataString; |
| 7 | + |
| 8 | + public function setNoDataString($no_data_string) { |
| 9 | + $this->noDataString = $no_data_string; |
| 10 | + return $this; |
| 11 | + } |
| 12 | + |
| 13 | + public function setHeader($header) { |
| 14 | + $this->header = $header; |
| 15 | + return $this; |
| 16 | + } |
| 17 | + |
| 18 | + public function setCommits(array $commits) { |
| 19 | + assert_instances_of($commits, 'PhabricatorRepositoryCommit'); |
| 20 | + $this->commits = mpull($commits, null, 'getPHID'); |
| 21 | + return $this; |
| 22 | + } |
| 23 | + |
| 24 | + public function getCommits() { |
| 25 | + return $this->commits; |
| 26 | + } |
| 27 | + |
| 28 | + private function getCommitDescription($phid) { |
| 29 | + if ($this->commits === null) { |
| 30 | + return pht('(Unknown Commit)'); |
| 31 | + } |
| 32 | + |
| 33 | + $commit = idx($this->commits, $phid); |
| 34 | + if (!$commit) { |
| 35 | + return pht('(Unknown Commit)'); |
| 36 | + } |
| 37 | + |
| 38 | + $summary = $commit->getCommitData()->getSummary(); |
| 39 | + if (strlen($summary)) { |
| 40 | + return $summary; |
| 41 | + } |
| 42 | + |
| 43 | + // No summary, so either this is still importing or just has an empty |
| 44 | + // commit message. |
| 45 | + |
| 46 | + if (!$commit->isImported()) { |
| 47 | + return pht('(Importing Commit...)'); |
| 48 | + } else { |
| 49 | + return pht('(Untitled Commit)'); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + public function render() { |
| 54 | + require_celerity_resource('diffusion-history-css'); |
| 55 | + return $this->buildList(); |
| 56 | + } |
| 57 | + |
| 58 | + public function buildList() { |
| 59 | + $viewer = $this->getViewer(); |
| 60 | + $rowc = array(); |
| 61 | + |
| 62 | + $phids = array(); |
| 63 | + foreach ($this->getCommits() as $commit) { |
| 64 | + $phids[] = $commit->getPHID(); |
| 65 | + |
| 66 | + $author_phid = $commit->getAuthorPHID(); |
| 67 | + if ($author_phid) { |
| 68 | + $phids[] = $author_phid; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + $handles = $viewer->loadHandles($phids); |
| 73 | + |
| 74 | + $cur_date = 0; |
| 75 | + $list = null; |
| 76 | + $header = null; |
| 77 | + $view = array(); |
| 78 | + foreach ($this->commits as $commit) { |
| 79 | + $new_date = date('Ymd', $commit->getEpoch()); |
| 80 | + if ($cur_date != $new_date) { |
| 81 | + if ($list) { |
| 82 | + $view[] = id(new PHUIObjectBoxView()) |
| 83 | + ->setHeader($header) |
| 84 | + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) |
| 85 | + ->setObjectList($list); |
| 86 | + } |
| 87 | + $date = ucfirst( |
| 88 | + phabricator_relative_date($commit->getEpoch(), $viewer)); |
| 89 | + $header = id(new PHUIHeaderView()) |
| 90 | + ->setHeader($date); |
| 91 | + $list = id(new PHUIObjectItemListView()) |
| 92 | + ->setFlush(true) |
| 93 | + ->addClass('diffusion-history-list'); |
| 94 | + } |
| 95 | + |
| 96 | + $commit_phid = $commit->getPHID(); |
| 97 | + $commit_handle = $handles[$commit_phid]; |
| 98 | + $committed = null; |
| 99 | + |
| 100 | + $commit_name = $commit_handle->getName(); |
| 101 | + $commit_link = $commit_handle->getURI(); |
| 102 | + $commit_desc = $this->getCommitDescription($commit_phid); |
| 103 | + $committed = phabricator_datetime($commit->getEpoch(), $viewer); |
| 104 | + |
| 105 | + $author_phid = $commit->getAuthorPHID(); |
| 106 | + if ($author_phid) { |
| 107 | + $author_name = $handles[$author_phid]->renderLink(); |
| 108 | + $author_image_uri = $handles[$author_phid]->getImageURI(); |
| 109 | + } else { |
| 110 | + $author_name = $commit->getCommitData()->getAuthorName(); |
| 111 | + $author_image_uri = |
| 112 | + celerity_get_resource_uri('/rsrc/image/people/user0.png'); |
| 113 | + } |
| 114 | + |
| 115 | + $commit_tag = id(new PHUITagView()) |
| 116 | + ->setName($commit_name) |
| 117 | + ->setType(PHUITagView::TYPE_SHADE) |
| 118 | + ->setColor(PHUITagView::COLOR_INDIGO) |
| 119 | + ->setSlimShady(true); |
| 120 | + |
| 121 | + $item = id(new PHUIObjectItemView()) |
| 122 | + ->setHeader($commit_desc) |
| 123 | + ->setHref($commit_link) |
| 124 | + ->setDisabled($commit->isUnreachable()) |
| 125 | + ->setImageURI($author_image_uri) |
| 126 | + ->addByline(pht('Author: %s', $author_name)) |
| 127 | + ->addIcon('none', $committed) |
| 128 | + ->addAttribute($commit_tag); |
| 129 | + |
| 130 | + $list->addItem($item); |
| 131 | + $cur_date = $new_date; |
| 132 | + } |
| 133 | + |
| 134 | + if (!$view) { |
| 135 | + $list = id(new PHUIObjectItemListView()) |
| 136 | + ->setFlush(true) |
| 137 | + ->setNoDataString($this->noDataString); |
| 138 | + |
| 139 | + $view = id(new PHUIObjectBoxView()) |
| 140 | + ->setHeaderText(pht('Recent Commits')) |
| 141 | + ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) |
| 142 | + ->setObjectList($list); |
| 143 | + } |
| 144 | + |
| 145 | + return $view; |
| 146 | + } |
| 147 | + |
| 148 | +} |
0 commit comments