@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 160 lines 3.6 kB view raw
1<?php 2 3final class HarbormasterUnitPropertyView extends AphrontView { 4 5 private $pathURIMap = array(); 6 private $unitMessages = array(); 7 private $limit; 8 private $fullResultsURI; 9 private $notice; 10 11 public function setPathURIMap(array $map) { 12 $this->pathURIMap = $map; 13 return $this; 14 } 15 16 /** 17 * @param array<HarbormasterBuildUnitMessage> $messages 18 */ 19 public function setUnitMessages(array $messages) { 20 assert_instances_of($messages, HarbormasterBuildUnitMessage::class); 21 $this->unitMessages = $messages; 22 return $this; 23 } 24 25 public function setLimit($limit) { 26 $this->limit = $limit; 27 return $this; 28 } 29 30 public function setFullResultsURI($full_results_uri) { 31 $this->fullResultsURI = $full_results_uri; 32 return $this; 33 } 34 35 public function setNotice($notice) { 36 $this->notice = $notice; 37 return $this; 38 } 39 40 public function render() { 41 $viewer = $this->getViewer(); 42 43 $messages = $this->unitMessages; 44 $messages = msort($messages, 'getSortKey'); 45 46 $limit = $this->limit; 47 48 if ($this->limit) { 49 $display_messages = array_slice($messages, 0, $limit); 50 } else { 51 $display_messages = $messages; 52 } 53 54 $rows = array(); 55 $any_duration = false; 56 foreach ($display_messages as $message) { 57 $status = $message->getResult(); 58 59 $icon_icon = HarbormasterUnitStatus::getUnitStatusIcon($status); 60 $icon_color = HarbormasterUnitStatus::getUnitStatusColor($status); 61 $icon_label = HarbormasterUnitStatus::getUnitStatusLabel($status); 62 63 $result_icon = id(new PHUIIconView()) 64 ->setIcon("{$icon_icon} {$icon_color}") 65 ->addSigil('has-tooltip') 66 ->setMetadata( 67 array( 68 'tip' => $icon_label, 69 )); 70 71 $duration = $message->getDuration(); 72 if ($duration !== null) { 73 $any_duration = true; 74 $duration = pht('%s ms', new PhutilNumber((int)(1000 * $duration))); 75 } 76 77 $name = $message->getUnitMessageDisplayName(); 78 $uri = $message->getURI(); 79 80 if ($uri) { 81 $name = phutil_tag( 82 'a', 83 array( 84 'href' => $uri, 85 ), 86 $name); 87 } 88 89 $name = array( 90 $name, 91 $message->newUnitMessageDetailsView($viewer, true), 92 ); 93 94 $rows[] = array( 95 $result_icon, 96 $duration, 97 $name, 98 ); 99 } 100 101 $full_uri = $this->fullResultsURI; 102 if ($full_uri && (count($messages) > $limit)) { 103 $counts = array(); 104 105 $groups = mgroup($messages, 'getResult'); 106 foreach ($groups as $status => $group) { 107 $counts[] = HarbormasterUnitStatus::getUnitStatusCountLabel( 108 $status, 109 count($group)); 110 } 111 112 $link_text = pht( 113 'View Full Test Results (%s)', 114 implode(" \xC2\xB7 ", $counts)); 115 116 $full_link = phutil_tag( 117 'a', 118 array( 119 'href' => $full_uri, 120 ), 121 $link_text); 122 123 $link_icon = id(new PHUIIconView()) 124 ->setIcon('fa-ellipsis-h lightgreytext'); 125 126 $rows[] = array($link_icon, null, $full_link); 127 } 128 129 $table = id(new AphrontTableView($rows)) 130 ->setHeaders( 131 array( 132 null, 133 pht('Time'), 134 pht('Test'), 135 )) 136 ->setColumnClasses( 137 array( 138 'top center', 139 'top right', 140 'top wide', 141 )) 142 ->setColumnWidths( 143 array( 144 '32px', 145 '64px', 146 )) 147 ->setColumnVisibility( 148 array( 149 true, 150 $any_duration, 151 )); 152 153 if ($this->notice) { 154 $table->setNotice($this->notice); 155 } 156 157 return $table; 158 } 159 160}