Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / controller / AlmanacController.php
blob918b3a4ad9cc298a975419d8d44c66f26d7d1bbe
1 <?php
3 abstract class AlmanacController
4 extends PhabricatorController {
6 protected function buildAlmanacPropertiesTable(
7 AlmanacPropertyInterface $object) {
9 $viewer = $this->getViewer();
10 $properties = $object->getAlmanacProperties();
12 $this->requireResource('almanac-css');
13 Javelin::initBehavior('phabricator-tooltips', array());
15 $can_edit = PhabricatorPolicyFilter::hasCapability(
16 $viewer,
17 $object,
18 PhabricatorPolicyCapability::CAN_EDIT);
20 $properties = $object->getAlmanacProperties();
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 ));
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 ));
40 $builtins = $object->getAlmanacPropertyFieldSpecifications();
41 $defaults = mpull($builtins, 'getValueForTransaction');
43 // Sort fields so builtin fields appear first, then fields are ordered
44 // alphabetically.
45 $properties = msort($properties, 'getFieldName');
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;
58 $properties = $head + $tail;
60 $delete_base = $this->getApplicationURI('property/delete/');
61 $edit_base = $this->getApplicationURI('property/update/');
63 $rows = array();
64 foreach ($properties as $key => $property) {
65 $value = $property->getFieldValue();
67 $is_builtin = isset($builtins[$key]);
68 $is_persistent = (bool)$property->getID();
70 $params = array(
71 'key' => $key,
72 'objectPHID' => $object->getPHID(),
75 $delete_uri = new PhutilURI($delete_base, $params);
76 $edit_uri = new PhutilURI($edit_base, $params);
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,
87 $is_builtin ? pht('Reset') : pht('Delete'));
89 $default = idx($defaults, $key);
90 $is_default = ($default !== null && $default === $value);
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',
99 $display_value);
102 $display_key = $key;
103 if ($can_edit) {
104 $display_key = javelin_tag(
105 'a',
106 array(
107 'href' => $edit_uri,
108 'sigil' => 'workflow',
110 $display_key);
113 $rows[] = array(
114 ($is_builtin ? $icon_builtin : $icon_custom),
115 $display_key,
116 $display_value,
117 $delete,
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,
130 ->setColumnClasses(
131 array(
132 null,
133 null,
134 'wide',
135 'action',
138 $phid = $object->getPHID();
139 $add_uri = id(new PhutilURI($edit_base))
140 ->replaceQueryParam('objectPHID', $object->getPHID());
142 $can_edit = PhabricatorPolicyFilter::hasCapability(
143 $viewer,
144 $object,
145 PhabricatorPolicyCapability::CAN_EDIT);
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');
155 $header = id(new PHUIHeaderView())
156 ->setHeader(pht('Properties'))
157 ->addActionLink($add_button);
159 return id(new PHUIObjectBoxView())
160 ->setHeader($header)
161 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
162 ->setTable($table);
165 protected function addClusterMessage(
166 $positive,
167 $negative) {
169 $can_manage = $this->hasApplicationCapability(
170 AlmanacManageClusterServicesCapability::CAPABILITY);
172 $doc_link = phutil_tag(
173 'a',
174 array(
175 'href' => PhabricatorEnv::getDoclink(
176 'Clustering Introduction'),
177 'target' => '_blank',
179 pht('Learn More'));
181 if ($can_manage) {
182 $severity = PHUIInfoView::SEVERITY_NOTICE;
183 $message = $positive;
184 } else {
185 $severity = PHUIInfoView::SEVERITY_WARNING;
186 $message = $negative;
189 $icon = id(new PHUIIconView())
190 ->setIcon('fa-sitemap');
192 return id(new PHUIInfoView())
193 ->setSeverity($severity)
194 ->setErrors(
195 array(
196 array($icon, ' ', $message, ' ', $doc_link),
201 protected function getPropertyDeleteURI($object) {
202 return null;
205 protected function getPropertyUpdateURI($object) {
206 return null;