@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<?php
2
3final class DrydockLogListView extends AphrontView {
4
5 private $logs;
6 private $hideBlueprints;
7 private $hideResources;
8 private $hideLeases;
9 private $hideOperations;
10
11 public function setHideBlueprints($hide_blueprints) {
12 $this->hideBlueprints = $hide_blueprints;
13 return $this;
14 }
15
16 public function getHideBlueprints() {
17 return $this->hideBlueprints;
18 }
19
20 public function setHideResources($hide_resources) {
21 $this->hideResources = $hide_resources;
22 return $this;
23 }
24
25 public function getHideResources() {
26 return $this->hideResources;
27 }
28
29 public function setHideLeases($hide_leases) {
30 $this->hideLeases = $hide_leases;
31 return $this;
32 }
33
34 public function getHideLeases() {
35 return $this->hideLeases;
36 }
37
38 public function setHideOperations($hide_operations) {
39 $this->hideOperations = $hide_operations;
40 return $this;
41 }
42
43 public function getHideOperations() {
44 return $this->hideOperations;
45 }
46
47 /**
48 * @param array<DrydockLog> $logs
49 */
50 public function setLogs(array $logs) {
51 assert_instances_of($logs, DrydockLog::class);
52 $this->logs = $logs;
53 return $this;
54 }
55
56 public function render() {
57 $logs = $this->logs;
58 $viewer = $this->getUser();
59
60 $view = new PHUIObjectItemListView();
61
62 $types = DrydockLogType::getAllLogTypes();
63
64 $rows = array();
65 foreach ($logs as $log) {
66 $blueprint_phid = $log->getBlueprintPHID();
67 if ($blueprint_phid) {
68 $blueprint = $viewer->renderHandle($blueprint_phid);
69 } else {
70 $blueprint = null;
71 }
72
73 $resource_phid = $log->getResourcePHID();
74 if ($resource_phid) {
75 $resource = $viewer->renderHandle($resource_phid);
76 } else {
77 $resource = null;
78 }
79
80 $lease_phid = $log->getLeasePHID();
81 if ($lease_phid) {
82 $lease = $viewer->renderHandle($lease_phid);
83 } else {
84 $lease = null;
85 }
86
87 $operation_phid = $log->getOperationPHID();
88 if ($operation_phid) {
89 $operation = $viewer->renderHandle($operation_phid);
90 } else {
91 $operation = null;
92 }
93
94 if ($log->isComplete()) {
95 $type_key = $log->getType();
96 if (isset($types[$type_key])) {
97 $type_object = id(clone $types[$type_key])
98 ->setLog($log)
99 ->setViewer($viewer);
100
101 $log_data = $log->getData();
102
103 $type = $type_object->getLogTypeName();
104 $icon = $type_object->getLogTypeIcon($log_data);
105 $data = $type_object->renderLogForHTML($log_data);
106 $data = phutil_escape_html_newlines($data);
107 } else {
108 $type = pht('<Unknown: %s>', $type_key);
109 $data = null;
110 $icon = 'fa-question-circle red';
111 }
112 } else {
113 $type = phutil_tag('em', array(), pht('Restricted'));
114 $data = phutil_tag(
115 'em',
116 array(),
117 pht('You do not have permission to view this log event.'));
118 $icon = 'fa-lock grey';
119 }
120
121 $rows[] = array(
122 $blueprint,
123 $resource,
124 $lease,
125 $operation,
126 id(new PHUIIconView())->setIcon($icon),
127 $type,
128 $data,
129 phabricator_datetime($log->getEpoch(), $viewer),
130 );
131 }
132
133 $table = id(new AphrontTableView($rows))
134 ->setDeviceReadyTable(true)
135 ->setHeaders(
136 array(
137 pht('Blueprint'),
138 pht('Resource'),
139 pht('Lease'),
140 pht('Operation'),
141 null,
142 pht('Type'),
143 pht('Data'),
144 pht('Date'),
145 ))
146 ->setColumnVisibility(
147 array(
148 !$this->getHideBlueprints(),
149 !$this->getHideResources(),
150 !$this->getHideLeases(),
151 !$this->getHideOperations(),
152 ))
153 ->setColumnClasses(
154 array(
155 '',
156 '',
157 '',
158 '',
159 'icon',
160 '',
161 'wide',
162 '',
163 ));
164
165 return $table;
166 }
167
168}