[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class DifferentialLocalCommitsView extends AphrontView { 4 5 private $localCommits; 6 private $commitsForLinks = array(); 7 8 public function setLocalCommits($local_commits) { 9 $this->localCommits = $local_commits; 10 return $this; 11 } 12 13 public function setCommitsForLinks(array $commits) { 14 assert_instances_of($commits, 'PhabricatorRepositoryCommit'); 15 $this->commitsForLinks = $commits; 16 return $this; 17 } 18 19 public function render() { 20 $user = $this->user; 21 if (!$user) { 22 throw new Exception('Call setUser() before render()-ing this view.'); 23 } 24 25 $local = $this->localCommits; 26 if (!$local) { 27 return null; 28 } 29 30 $has_tree = false; 31 $has_local = false; 32 33 foreach ($local as $commit) { 34 if (idx($commit, 'tree')) { 35 $has_tree = true; 36 } 37 if (idx($commit, 'local')) { 38 $has_local = true; 39 } 40 } 41 42 $rows = array(); 43 foreach ($local as $commit) { 44 $row = array(); 45 if (idx($commit, 'commit')) { 46 $commit_link = $this->buildCommitLink($commit['commit']); 47 } else if (isset($commit['rev'])) { 48 $commit_link = $this->buildCommitLink($commit['rev']); 49 } else { 50 $commit_link = null; 51 } 52 $row[] = $commit_link; 53 54 if ($has_tree) { 55 $row[] = $this->buildCommitLink($commit['tree']); 56 } 57 58 if ($has_local) { 59 $row[] = $this->buildCommitLink($commit['local']); 60 } 61 62 $parents = idx($commit, 'parents', array()); 63 foreach ($parents as $k => $parent) { 64 if (is_array($parent)) { 65 $parent = idx($parent, 'rev'); 66 } 67 $parents[$k] = $this->buildCommitLink($parent); 68 } 69 $parents = phutil_implode_html(phutil_tag('br'), $parents); 70 $row[] = $parents; 71 72 $author = nonempty( 73 idx($commit, 'user'), 74 idx($commit, 'author')); 75 $row[] = $author; 76 77 $message = idx($commit, 'message'); 78 79 $summary = idx($commit, 'summary'); 80 $summary = id(new PhutilUTF8StringTruncator()) 81 ->setMaximumGlyphs(80) 82 ->truncateString($summary); 83 84 $view = new AphrontMoreView(); 85 $view->setSome($summary); 86 87 if ($message && (trim($summary) != trim($message))) { 88 $view->setMore(phutil_escape_html_newlines($message)); 89 } 90 91 $row[] = $view->render(); 92 93 $date = nonempty( 94 idx($commit, 'date'), 95 idx($commit, 'time')); 96 if ($date) { 97 $date = phabricator_datetime($date, $user); 98 } 99 $row[] = $date; 100 101 $rows[] = $row; 102 } 103 104 $column_classes = array(''); 105 if ($has_tree) { 106 $column_classes[] = ''; 107 } 108 if ($has_local) { 109 $column_classes[] = ''; 110 } 111 $column_classes[] = ''; 112 $column_classes[] = ''; 113 $column_classes[] = 'wide'; 114 $column_classes[] = 'date'; 115 $table = id(new AphrontTableView($rows)) 116 ->setColumnClasses($column_classes); 117 $headers = array(); 118 $headers[] = pht('Commit'); 119 if ($has_tree) { 120 $headers[] = pht('Tree'); 121 } 122 if ($has_local) { 123 $headers[] = pht('Local'); 124 } 125 $headers[] = pht('Parents'); 126 $headers[] = pht('Author'); 127 $headers[] = pht('Summary'); 128 $headers[] = pht('Date'); 129 $table->setHeaders($headers); 130 131 return id(new PHUIObjectBoxView()) 132 ->setHeaderText(pht('Local Commits')) 133 ->appendChild($table); 134 } 135 136 private static function formatCommit($commit) { 137 return substr($commit, 0, 12); 138 } 139 140 private function buildCommitLink($hash) { 141 $commit_for_link = idx($this->commitsForLinks, $hash); 142 $commit_hash = self::formatCommit($hash); 143 if ($commit_for_link) { 144 $link = phutil_tag( 145 'a', 146 array( 147 'href' => $commit_for_link->getURI(), 148 ), 149 $commit_hash); 150 } else { 151 $link = $commit_hash; 152 } 153 return $link; 154 } 155 156 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |