@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.

Modularize Herald task status/priority fields

Summary: Ref T8726. These are a bit involved because they have custom rendering and editor values.

Test Plan: Created new rule using these fields, edited tasks to trigger them, viewed transcripts.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: eadler, joshuaspence, epriestley

Maniphest Tasks: T8726

Differential Revision: https://secure.phabricator.com/D13500

+218 -69
+7 -1
src/__phutil_library_map__.php
··· 950 950 'HeraldInvalidActionException' => 'applications/herald/engine/exception/HeraldInvalidActionException.php', 951 951 'HeraldInvalidConditionException' => 'applications/herald/engine/exception/HeraldInvalidConditionException.php', 952 952 'HeraldManageGlobalRulesCapability' => 'applications/herald/capability/HeraldManageGlobalRulesCapability.php', 953 - 'HeraldManiphestTaskAdapter' => 'applications/herald/adapter/HeraldManiphestTaskAdapter.php', 953 + 'HeraldManiphestTaskAdapter' => 'applications/maniphest/herald/HeraldManiphestTaskAdapter.php', 954 954 'HeraldNewController' => 'applications/herald/controller/HeraldNewController.php', 955 955 'HeraldNewObjectField' => 'applications/herald/field/HeraldNewObjectField.php', 956 956 'HeraldObjectTranscript' => 'applications/herald/storage/transcript/HeraldObjectTranscript.php', ··· 1072 1072 'ManiphestExcelFormatTestCase' => 'applications/maniphest/export/__tests__/ManiphestExcelFormatTestCase.php', 1073 1073 'ManiphestExportController' => 'applications/maniphest/controller/ManiphestExportController.php', 1074 1074 'ManiphestGetTaskTransactionsConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestGetTaskTransactionsConduitAPIMethod.php', 1075 + 'ManiphestHeraldField' => 'applications/maniphest/herald/ManiphestHeraldField.php', 1075 1076 'ManiphestHovercardEventListener' => 'applications/maniphest/event/ManiphestHovercardEventListener.php', 1076 1077 'ManiphestInfoConduitAPIMethod' => 'applications/maniphest/conduit/ManiphestInfoConduitAPIMethod.php', 1077 1078 'ManiphestNameIndex' => 'applications/maniphest/storage/ManiphestNameIndex.php', ··· 1105 1106 'ManiphestTaskPHIDType' => 'applications/maniphest/phid/ManiphestTaskPHIDType.php', 1106 1107 'ManiphestTaskPriority' => 'applications/maniphest/constants/ManiphestTaskPriority.php', 1107 1108 'ManiphestTaskPriorityDatasource' => 'applications/maniphest/typeahead/ManiphestTaskPriorityDatasource.php', 1109 + 'ManiphestTaskPriorityHeraldField' => 'applications/maniphest/herald/ManiphestTaskPriorityHeraldField.php', 1108 1110 'ManiphestTaskQuery' => 'applications/maniphest/query/ManiphestTaskQuery.php', 1109 1111 'ManiphestTaskResultListView' => 'applications/maniphest/view/ManiphestTaskResultListView.php', 1110 1112 'ManiphestTaskSearchEngine' => 'applications/maniphest/query/ManiphestTaskSearchEngine.php', 1111 1113 'ManiphestTaskStatus' => 'applications/maniphest/constants/ManiphestTaskStatus.php', 1112 1114 'ManiphestTaskStatusDatasource' => 'applications/maniphest/typeahead/ManiphestTaskStatusDatasource.php', 1113 1115 'ManiphestTaskStatusFunctionDatasource' => 'applications/maniphest/typeahead/ManiphestTaskStatusFunctionDatasource.php', 1116 + 'ManiphestTaskStatusHeraldField' => 'applications/maniphest/herald/ManiphestTaskStatusHeraldField.php', 1114 1117 'ManiphestTaskStatusTestCase' => 'applications/maniphest/constants/__tests__/ManiphestTaskStatusTestCase.php', 1115 1118 'ManiphestTaskTestCase' => 'applications/maniphest/__tests__/ManiphestTaskTestCase.php', 1116 1119 'ManiphestTransaction' => 'applications/maniphest/storage/ManiphestTransaction.php', ··· 4602 4605 'ManiphestExcelFormatTestCase' => 'PhabricatorTestCase', 4603 4606 'ManiphestExportController' => 'ManiphestController', 4604 4607 'ManiphestGetTaskTransactionsConduitAPIMethod' => 'ManiphestConduitAPIMethod', 4608 + 'ManiphestHeraldField' => 'HeraldField', 4605 4609 'ManiphestHovercardEventListener' => 'PhabricatorEventListener', 4606 4610 'ManiphestInfoConduitAPIMethod' => 'ManiphestConduitAPIMethod', 4607 4611 'ManiphestNameIndex' => 'ManiphestDAO', ··· 4649 4653 'ManiphestTaskPHIDType' => 'PhabricatorPHIDType', 4650 4654 'ManiphestTaskPriority' => 'ManiphestConstants', 4651 4655 'ManiphestTaskPriorityDatasource' => 'PhabricatorTypeaheadDatasource', 4656 + 'ManiphestTaskPriorityHeraldField' => 'ManiphestHeraldField', 4652 4657 'ManiphestTaskQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4653 4658 'ManiphestTaskResultListView' => 'ManiphestView', 4654 4659 'ManiphestTaskSearchEngine' => 'PhabricatorApplicationSearchEngine', 4655 4660 'ManiphestTaskStatus' => 'ManiphestConstants', 4656 4661 'ManiphestTaskStatusDatasource' => 'PhabricatorTypeaheadDatasource', 4657 4662 'ManiphestTaskStatusFunctionDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 4663 + 'ManiphestTaskStatusHeraldField' => 'ManiphestHeraldField', 4658 4664 'ManiphestTaskStatusTestCase' => 'PhabricatorTestCase', 4659 4665 'ManiphestTaskTestCase' => 'PhabricatorTestCase', 4660 4666 'ManiphestTransaction' => 'PhabricatorApplicationTransaction',
+40 -33
src/applications/herald/adapter/HeraldAdapter.php
··· 29 29 const FIELD_BRANCHES = 'branches'; 30 30 const FIELD_AUTHOR_RAW = 'author-raw'; 31 31 const FIELD_COMMITTER_RAW = 'committer-raw'; 32 - const FIELD_TASK_PRIORITY = 'taskpriority'; 33 - const FIELD_TASK_STATUS = 'taskstatus'; 34 32 const FIELD_PUSHER_IS_COMMITTER = 'pusher-is-committer'; 35 33 const FIELD_PATH = 'path'; 36 34 ··· 383 381 self::FIELD_BRANCHES => pht('Commit\'s branches'), 384 382 self::FIELD_AUTHOR_RAW => pht('Raw author name'), 385 383 self::FIELD_COMMITTER_RAW => pht('Raw committer name'), 386 - self::FIELD_TASK_PRIORITY => pht('Task priority'), 387 - self::FIELD_TASK_STATUS => pht('Task status'), 388 384 self::FIELD_PUSHER_IS_COMMITTER => pht('Pusher same as committer'), 389 385 self::FIELD_PATH => pht('Path'), 390 386 ); ··· 443 439 ); 444 440 case self::FIELD_REVIEWER: 445 441 case self::FIELD_PUSHER: 446 - case self::FIELD_TASK_PRIORITY: 447 - case self::FIELD_TASK_STATUS: 448 442 return array( 449 443 self::CONDITION_IS_ANY, 450 444 self::CONDITION_IS_NOT_ANY, ··· 906 900 switch ($field) { 907 901 case self::FIELD_REPOSITORY: 908 902 return self::VALUE_REPOSITORY; 909 - case self::FIELD_TASK_PRIORITY: 910 - return self::VALUE_TASK_PRIORITY; 911 - case self::FIELD_TASK_STATUS: 912 - return self::VALUE_TASK_STATUS; 913 903 default: 914 904 return self::VALUE_USER; 915 905 } ··· 1070 1060 return $map; 1071 1061 } 1072 1062 1063 + public function getEditorValueForCondition( 1064 + PhabricatorUser $viewer, 1065 + HeraldCondition $condition, 1066 + array $handles) { 1067 + 1068 + $impl = $this->getFieldImplementation($condition->getFieldName()); 1069 + if ($impl) { 1070 + return $impl->getEditorValue( 1071 + $viewer, 1072 + $condition->getValue()); 1073 + } 1074 + 1075 + $value = $condition->getValue(); 1076 + if (is_array($value)) { 1077 + $value_map = array(); 1078 + foreach ($value as $k => $phid) { 1079 + $value_map[$phid] = $handles[$phid]->getName(); 1080 + } 1081 + $value = $value_map; 1082 + } 1083 + 1084 + return $value; 1085 + } 1086 + 1073 1087 public function renderRuleAsText( 1074 1088 HeraldRule $rule, 1075 - PhabricatorHandleList $handles) { 1089 + PhabricatorHandleList $handles, 1090 + PhabricatorUser $viewer) { 1076 1091 1077 1092 require_celerity_resource('herald-css'); 1078 1093 ··· 1102 1117 ), 1103 1118 array( 1104 1119 $icon, 1105 - $this->renderConditionAsText($condition, $handles), 1120 + $this->renderConditionAsText($condition, $handles, $viewer), 1106 1121 )); 1107 1122 } 1108 1123 ··· 1147 1162 1148 1163 private function renderConditionAsText( 1149 1164 HeraldCondition $condition, 1150 - PhabricatorHandleList $handles) { 1165 + PhabricatorHandleList $handles, 1166 + PhabricatorUser $viewer) { 1151 1167 1152 1168 $field_type = $condition->getFieldName(); 1153 1169 ··· 1158 1174 $condition_type = $condition->getFieldCondition(); 1159 1175 $condition_name = idx($this->getConditionNameMap(), $condition_type); 1160 1176 1161 - $value = $this->renderConditionValueAsText($condition, $handles); 1177 + $value = $this->renderConditionValueAsText($condition, $handles, $viewer); 1162 1178 1163 1179 return hsprintf(' %s %s %s', $field_name, $condition_name, $value); 1164 1180 } ··· 1184 1200 1185 1201 private function renderConditionValueAsText( 1186 1202 HeraldCondition $condition, 1187 - PhabricatorHandleList $handles) { 1203 + PhabricatorHandleList $handles, 1204 + PhabricatorUser $viewer) { 1205 + 1206 + $impl = $this->getFieldImplementation($condition->getFieldName()); 1207 + if ($impl) { 1208 + return $impl->renderConditionValue( 1209 + $viewer, 1210 + $condition->getValue()); 1211 + } 1188 1212 1189 1213 $value = $condition->getValue(); 1190 1214 if (!is_array($value)) { 1191 1215 $value = array($value); 1192 1216 } 1217 + 1193 1218 switch ($condition->getFieldName()) { 1194 - case self::FIELD_TASK_PRIORITY: 1195 - $priority_map = ManiphestTaskPriority::getTaskPriorityMap(); 1196 - foreach ($value as $index => $val) { 1197 - $name = idx($priority_map, $val); 1198 - if ($name) { 1199 - $value[$index] = $name; 1200 - } 1201 - } 1202 - break; 1203 - case self::FIELD_TASK_STATUS: 1204 - $status_map = ManiphestTaskStatus::getTaskStatusMap(); 1205 - foreach ($value as $index => $val) { 1206 - $name = idx($status_map, $val); 1207 - if ($name) { 1208 - $value[$index] = $name; 1209 - } 1210 - } 1211 - break; 1212 1219 case HeraldPreCommitRefAdapter::FIELD_REF_CHANGE: 1213 1220 $change_map = 1214 1221 PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions();
-6
src/applications/herald/adapter/HeraldManiphestTaskAdapter.php src/applications/maniphest/herald/HeraldManiphestTaskAdapter.php
··· 74 74 self::FIELD_BODY, 75 75 self::FIELD_AUTHOR, 76 76 self::FIELD_ASSIGNEE, 77 - self::FIELD_TASK_PRIORITY, 78 - self::FIELD_TASK_STATUS, 79 77 ), 80 78 parent::getFields()); 81 79 } ··· 124 122 return $this->getTask()->getAuthorPHID(); 125 123 case self::FIELD_ASSIGNEE: 126 124 return $this->getTask()->getOwnerPHID(); 127 - case self::FIELD_TASK_PRIORITY: 128 - return $this->getTask()->getPriority(); 129 - case self::FIELD_TASK_STATUS: 130 - return $this->getTask()->getStatus(); 131 125 } 132 126 133 127 return parent::getHeraldField($field);
+5 -28
src/applications/herald/controller/HeraldRuleController.php
··· 354 354 if ($rule->getConditions()) { 355 355 $serial_conditions = array(); 356 356 foreach ($rule->getConditions() as $condition) { 357 - $value = $condition->getValue(); 358 - switch ($condition->getFieldName()) { 359 - case HeraldAdapter::FIELD_TASK_PRIORITY: 360 - $value_map = array(); 361 - $priority_map = ManiphestTaskPriority::getTaskPriorityMap(); 362 - foreach ($value as $priority) { 363 - $value_map[$priority] = idx($priority_map, $priority); 364 - } 365 - $value = $value_map; 366 - break; 367 - case HeraldAdapter::FIELD_TASK_STATUS: 368 - $value_map = array(); 369 - $status_map = ManiphestTaskStatus::getTaskStatusMap(); 370 - foreach ($value as $status) { 371 - $value_map[$status] = idx($status_map, $status); 372 - } 373 - $value = $value_map; 374 - break; 375 - default: 376 - if (is_array($value)) { 377 - $value_map = array(); 378 - foreach ($value as $k => $fbid) { 379 - $value_map[$fbid] = $handles[$fbid]->getName(); 380 - } 381 - $value = $value_map; 382 - } 383 - break; 384 - } 357 + $value = $adapter->getEditorValueForCondition( 358 + $this->getViewer(), 359 + $condition, 360 + $handles); 361 + 385 362 $serial_conditions[] = array( 386 363 $condition->getFieldName(), 387 364 $condition->getFieldCondition(),
+2 -1
src/applications/herald/controller/HeraldRuleViewController.php
··· 152 152 PHUIPropertyListView::ICON_SUMMARY); 153 153 154 154 $handles = $viewer->loadHandles(HeraldAdapter::getHandlePHIDs($rule)); 155 - $view->addTextContent($adapter->renderRuleAsText($rule, $handles)); 155 + $rule_text = $adapter->renderRuleAsText($rule, $handles, $viewer); 156 + $view->addTextContent($rule_text); 156 157 } 157 158 158 159 return $view;
+45
src/applications/herald/field/HeraldField.php
··· 49 49 return array($this->getFieldConstant() => $this); 50 50 } 51 51 52 + public function renderConditionValue( 53 + PhabricatorUser $viewer, 54 + $value) { 55 + 56 + // TODO: While this is less of a mess than it used to be, it would still 57 + // be nice to push this down into individual fields better eventually and 58 + // stop guessing which values are PHIDs and which aren't. 59 + 60 + if (!is_array($value)) { 61 + return $value; 62 + } 63 + 64 + $type_unknown = PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN; 65 + 66 + foreach ($value as $key => $val) { 67 + if (is_string($val)) { 68 + if (phid_get_type($val) !== $type_unknown) { 69 + $value[$key] = $viewer->renderHandle($val); 70 + } 71 + } 72 + } 73 + 74 + return phutil_implode_html(', ', $value); 75 + } 76 + 77 + public function getEditorValue( 78 + PhabricatorUser $viewer, 79 + $value) { 80 + 81 + // TODO: This should be better structured and pushed down into individual 82 + // fields. As it is used to manually build tokenizer tokens, it can 83 + // probably be removed entirely. 84 + 85 + if (is_array($value)) { 86 + $handles = $viewer->loadHandles($value); 87 + $value_map = array(); 88 + foreach ($value as $k => $phid) { 89 + $value_map[$phid] = $handles[$phid]->getName(); 90 + } 91 + $value = $value_map; 92 + } 93 + 94 + return $value; 95 + } 96 + 52 97 final public function setAdapter(HeraldAdapter $adapter) { 53 98 $this->adapter = $adapter; 54 99 return $this;
+9
src/applications/maniphest/herald/ManiphestHeraldField.php
··· 1 + <?php 2 + 3 + abstract class ManiphestHeraldField extends HeraldField { 4 + 5 + public function supportsObject($object) { 6 + return ($object instanceof ManiphestTask); 7 + } 8 + 9 + }
+55
src/applications/maniphest/herald/ManiphestTaskPriorityHeraldField.php
··· 1 + <?php 2 + 3 + final class ManiphestTaskPriorityHeraldField 4 + extends ManiphestHeraldField { 5 + 6 + const FIELDCONST = 'taskpriority'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Task priority'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $object->getPriority(); 14 + } 15 + 16 + protected function getHeraldFieldStandardConditions() { 17 + return self::STANDARD_PHID; 18 + } 19 + 20 + public function getHeraldFieldValueType($condition) { 21 + return HeraldAdapter::VALUE_TASK_PRIORITY; 22 + } 23 + 24 + public function renderConditionValue( 25 + PhabricatorUser $viewer, 26 + $value) { 27 + 28 + $priority_map = ManiphestTaskPriority::getTaskPriorityMap(); 29 + 30 + $value = (array)$value; 31 + foreach ($value as $index => $val) { 32 + $name = idx($priority_map, $val); 33 + if ($name !== null) { 34 + $value[$index] = $name; 35 + } 36 + } 37 + 38 + return implode(', ', $value); 39 + } 40 + 41 + public function getEditorValue( 42 + PhabricatorUser $viewer, 43 + $value) { 44 + 45 + $priority_map = ManiphestTaskPriority::getTaskPriorityMap(); 46 + 47 + $value_map = array(); 48 + foreach ($value as $priority) { 49 + $value_map[$priority] = idx($priority_map, $priority, $priority); 50 + } 51 + 52 + return $value_map; 53 + } 54 + 55 + }
+55
src/applications/maniphest/herald/ManiphestTaskStatusHeraldField.php
··· 1 + <?php 2 + 3 + final class ManiphestTaskStatusHeraldField 4 + extends ManiphestHeraldField { 5 + 6 + const FIELDCONST = 'taskstatus'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Task status'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $object->getStatus(); 14 + } 15 + 16 + protected function getHeraldFieldStandardConditions() { 17 + return self::STANDARD_PHID; 18 + } 19 + 20 + public function getHeraldFieldValueType($condition) { 21 + return HeraldAdapter::VALUE_TASK_STATUS; 22 + } 23 + 24 + public function renderConditionValue( 25 + PhabricatorUser $viewer, 26 + $value) { 27 + 28 + $status_map = ManiphestTaskStatus::getTaskStatusMap(); 29 + 30 + $value = (array)$value; 31 + foreach ($value as $index => $val) { 32 + $name = idx($status_map, $val); 33 + if ($name !== null) { 34 + $value[$index] = $name; 35 + } 36 + } 37 + 38 + return implode(', ', $value); 39 + } 40 + 41 + public function getEditorValue( 42 + PhabricatorUser $viewer, 43 + $value) { 44 + 45 + $status_map = ManiphestTaskStatus::getTaskStatusMap(); 46 + 47 + $value_map = array(); 48 + foreach ($value as $status) { 49 + $value_map[$status] = idx($status_map, $status, $status); 50 + } 51 + 52 + return $value_map; 53 + } 54 + 55 + }