Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/controller/AlmanacController.php
12262 views
1
<?php
2
3
abstract class AlmanacController
4
extends PhabricatorController {
5
6
protected function buildAlmanacPropertiesTable(
7
AlmanacPropertyInterface $object) {
8
9
$viewer = $this->getViewer();
10
$properties = $object->getAlmanacProperties();
11
12
$this->requireResource('almanac-css');
13
Javelin::initBehavior('phabricator-tooltips', array());
14
15
$can_edit = PhabricatorPolicyFilter::hasCapability(
16
$viewer,
17
$object,
18
PhabricatorPolicyCapability::CAN_EDIT);
19
20
$properties = $object->getAlmanacProperties();
21
22
$icon_builtin = id(new PHUIIconView())
23
->setIcon('fa-circle')
24
->addSigil('has-tooltip')
25
->setMetadata(
26
array(
27
'tip' => pht('Builtin Property'),
28
'align' => 'E',
29
));
30
31
$icon_custom = id(new PHUIIconView())
32
->setIcon('fa-circle-o grey')
33
->addSigil('has-tooltip')
34
->setMetadata(
35
array(
36
'tip' => pht('Custom Property'),
37
'align' => 'E',
38
));
39
40
$builtins = $object->getAlmanacPropertyFieldSpecifications();
41
$defaults = mpull($builtins, 'getValueForTransaction');
42
43
// Sort fields so builtin fields appear first, then fields are ordered
44
// alphabetically.
45
$properties = msort($properties, 'getFieldName');
46
47
$head = array();
48
$tail = array();
49
foreach ($properties as $property) {
50
$key = $property->getFieldName();
51
if (isset($builtins[$key])) {
52
$head[$key] = $property;
53
} else {
54
$tail[$key] = $property;
55
}
56
}
57
58
$properties = $head + $tail;
59
60
$delete_base = $this->getApplicationURI('property/delete/');
61
$edit_base = $this->getApplicationURI('property/update/');
62
63
$rows = array();
64
foreach ($properties as $key => $property) {
65
$value = $property->getFieldValue();
66
67
$is_builtin = isset($builtins[$key]);
68
$is_persistent = (bool)$property->getID();
69
70
$params = array(
71
'key' => $key,
72
'objectPHID' => $object->getPHID(),
73
);
74
75
$delete_uri = new PhutilURI($delete_base, $params);
76
$edit_uri = new PhutilURI($edit_base, $params);
77
78
$delete = javelin_tag(
79
'a',
80
array(
81
'class' => (($can_edit && $is_persistent)
82
? 'button button-grey small'
83
: 'button button-grey small disabled'),
84
'sigil' => 'workflow',
85
'href' => $delete_uri,
86
),
87
$is_builtin ? pht('Reset') : pht('Delete'));
88
89
$default = idx($defaults, $key);
90
$is_default = ($default !== null && $default === $value);
91
92
$display_value = PhabricatorConfigJSON::prettyPrintJSON($value);
93
if ($is_default) {
94
$display_value = phutil_tag(
95
'span',
96
array(
97
'class' => 'almanac-default-property-value',
98
),
99
$display_value);
100
}
101
102
$display_key = $key;
103
if ($can_edit) {
104
$display_key = javelin_tag(
105
'a',
106
array(
107
'href' => $edit_uri,
108
'sigil' => 'workflow',
109
),
110
$display_key);
111
}
112
113
$rows[] = array(
114
($is_builtin ? $icon_builtin : $icon_custom),
115
$display_key,
116
$display_value,
117
$delete,
118
);
119
}
120
121
$table = id(new AphrontTableView($rows))
122
->setNoDataString(pht('No properties.'))
123
->setHeaders(
124
array(
125
null,
126
pht('Name'),
127
pht('Value'),
128
null,
129
))
130
->setColumnClasses(
131
array(
132
null,
133
null,
134
'wide',
135
'action',
136
));
137
138
$phid = $object->getPHID();
139
$add_uri = id(new PhutilURI($edit_base))
140
->replaceQueryParam('objectPHID', $object->getPHID());
141
142
$can_edit = PhabricatorPolicyFilter::hasCapability(
143
$viewer,
144
$object,
145
PhabricatorPolicyCapability::CAN_EDIT);
146
147
$add_button = id(new PHUIButtonView())
148
->setTag('a')
149
->setHref($add_uri)
150
->setWorkflow(true)
151
->setDisabled(!$can_edit)
152
->setText(pht('Add Property'))
153
->setIcon('fa-plus');
154
155
$header = id(new PHUIHeaderView())
156
->setHeader(pht('Properties'))
157
->addActionLink($add_button);
158
159
return id(new PHUIObjectBoxView())
160
->setHeader($header)
161
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
162
->setTable($table);
163
}
164
165
protected function addClusterMessage(
166
$positive,
167
$negative) {
168
169
$can_manage = $this->hasApplicationCapability(
170
AlmanacManageClusterServicesCapability::CAPABILITY);
171
172
$doc_link = phutil_tag(
173
'a',
174
array(
175
'href' => PhabricatorEnv::getDoclink(
176
'Clustering Introduction'),
177
'target' => '_blank',
178
),
179
pht('Learn More'));
180
181
if ($can_manage) {
182
$severity = PHUIInfoView::SEVERITY_NOTICE;
183
$message = $positive;
184
} else {
185
$severity = PHUIInfoView::SEVERITY_WARNING;
186
$message = $negative;
187
}
188
189
$icon = id(new PHUIIconView())
190
->setIcon('fa-sitemap');
191
192
return id(new PHUIInfoView())
193
->setSeverity($severity)
194
->setErrors(
195
array(
196
array($icon, ' ', $message, ' ', $doc_link),
197
));
198
199
}
200
201
protected function getPropertyDeleteURI($object) {
202
return null;
203
}
204
205
protected function getPropertyUpdateURI($object) {
206
return null;
207
}
208
209
}
210
211