@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

Give Drydock Resources more modern status treatment

Summary: Ref T13073. Depends on D19074. Update icons and UI for resource status.

Test Plan: Viewed resources in detail view and list view, saw better status icons.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13073

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

+124 -72
+1 -3
src/__phutil_library_map__.php
··· 1041 1041 'DrydockCommandInterface' => 'applications/drydock/interface/command/DrydockCommandInterface.php', 1042 1042 'DrydockCommandQuery' => 'applications/drydock/query/DrydockCommandQuery.php', 1043 1043 'DrydockConsoleController' => 'applications/drydock/controller/DrydockConsoleController.php', 1044 - 'DrydockConstants' => 'applications/drydock/constants/DrydockConstants.php', 1045 1044 'DrydockController' => 'applications/drydock/controller/DrydockController.php', 1046 1045 'DrydockCreateBlueprintsCapability' => 'applications/drydock/capability/DrydockCreateBlueprintsCapability.php', 1047 1046 'DrydockDAO' => 'applications/drydock/storage/DrydockDAO.php', ··· 6259 6258 'DrydockCommandInterface' => 'DrydockInterface', 6260 6259 'DrydockCommandQuery' => 'DrydockQuery', 6261 6260 'DrydockConsoleController' => 'DrydockController', 6262 - 'DrydockConstants' => 'Phobject', 6263 6261 'DrydockController' => 'PhabricatorController', 6264 6262 'DrydockCreateBlueprintsCapability' => 'PhabricatorPolicyCapability', 6265 6263 'DrydockDAO' => 'PhabricatorLiskDAO', ··· 6347 6345 'DrydockResourceReclaimLogType' => 'DrydockLogType', 6348 6346 'DrydockResourceReleaseController' => 'DrydockResourceController', 6349 6347 'DrydockResourceSearchEngine' => 'PhabricatorApplicationSearchEngine', 6350 - 'DrydockResourceStatus' => 'DrydockConstants', 6348 + 'DrydockResourceStatus' => 'PhabricatorObjectStatus', 6351 6349 'DrydockResourceUpdateWorker' => 'DrydockWorker', 6352 6350 'DrydockResourceViewController' => 'DrydockResourceController', 6353 6351 'DrydockSFTPFilesystemInterface' => 'DrydockFilesystemInterface',
-3
src/applications/drydock/constants/DrydockConstants.php
··· 1 - <?php 2 - 3 - abstract class DrydockConstants extends Phobject {}
+1 -1
src/applications/drydock/constants/DrydockLeaseStatus.php
··· 95 95 'key' => self::STATUS_DESTROYED, 96 96 'name' => pht('Destroyed'), 97 97 'icon' => 'fa-times', 98 - 'color' => 'red', 98 + 'color' => 'grey', 99 99 'isReleasable' => false, 100 100 'isCommandable' => false, 101 101 'isActivating' => false,
+75 -11
src/applications/drydock/constants/DrydockResourceStatus.php
··· 1 1 <?php 2 2 3 - final class DrydockResourceStatus extends DrydockConstants { 3 + final class DrydockResourceStatus 4 + extends PhabricatorObjectStatus { 4 5 5 6 const STATUS_PENDING = 'pending'; 6 7 const STATUS_ACTIVE = 'active'; ··· 8 9 const STATUS_BROKEN = 'broken'; 9 10 const STATUS_DESTROYED = 'destroyed'; 10 11 12 + public static function newStatusObject($key) { 13 + return new self($key, id(new self())->getStatusSpecification($key)); 14 + } 15 + 11 16 public static function getStatusMap() { 12 - return array( 13 - self::STATUS_PENDING => pht('Pending'), 14 - self::STATUS_ACTIVE => pht('Active'), 15 - self::STATUS_RELEASED => pht('Released'), 16 - self::STATUS_BROKEN => pht('Broken'), 17 - self::STATUS_DESTROYED => pht('Destroyed'), 18 - ); 17 + $map = id(new self())->getStatusSpecifications(); 18 + return ipull($map, 'name', 'key'); 19 19 } 20 20 21 21 public static function getNameForStatus($status) { 22 - $map = self::getStatusMap(); 23 - return idx($map, $status, pht('Unknown')); 22 + $map = id(new self())->getStatusSpecification($status); 23 + return $map['name']; 24 24 } 25 25 26 26 public static function getAllStatuses() { 27 - return array_keys(self::getStatusMap()); 27 + return array_keys(id(new self())->getStatusSpecifications()); 28 + } 29 + 30 + public function isActive() { 31 + return ($this->getKey() === self::STATUS_ACTIVE); 32 + } 33 + 34 + public function canRelease() { 35 + return $this->getStatusProperty('isReleasable'); 36 + } 37 + 38 + public function canReceiveCommands() { 39 + return $this->getStatusProperty('isCommandable'); 40 + } 41 + 42 + protected function newStatusSpecifications() { 43 + return array( 44 + array( 45 + 'key' => self::STATUS_PENDING, 46 + 'name' => pht('Pending'), 47 + 'icon' => 'fa-clock-o', 48 + 'color' => 'blue', 49 + 'isReleasable' => true, 50 + 'isCommandable' => true, 51 + ), 52 + array( 53 + 'key' => self::STATUS_ACTIVE, 54 + 'name' => pht('Active'), 55 + 'icon' => 'fa-check', 56 + 'color' => 'green', 57 + 'isReleasable' => true, 58 + 'isCommandable' => true, 59 + ), 60 + array( 61 + 'key' => self::STATUS_RELEASED, 62 + 'name' => pht('Released'), 63 + 'icon' => 'fa-circle-o', 64 + 'color' => 'blue', 65 + 'isReleasable' => false, 66 + 'isCommandable' => false, 67 + ), 68 + array( 69 + 'key' => self::STATUS_BROKEN, 70 + 'name' => pht('Broken'), 71 + 'icon' => 'fa-times', 72 + 'color' => 'indigo', 73 + 'isReleasable' => true, 74 + 'isCommandable' => false, 75 + ), 76 + array( 77 + 'key' => self::STATUS_DESTROYED, 78 + 'name' => pht('Destroyed'), 79 + 'icon' => 'fa-times', 80 + 'color' => 'grey', 81 + 'isReleasable' => false, 82 + 'isCommandable' => false, 83 + ), 84 + ); 85 + } 86 + 87 + protected function newUnknownStatusSpecification($status) { 88 + return array( 89 + 'isReleasable' => false, 90 + 'isCommandable' => false, 91 + ); 28 92 } 29 93 30 94 }
+11 -8
src/applications/drydock/controller/DrydockResourceViewController.php
··· 24 24 ->setUser($viewer) 25 25 ->setPolicyObject($resource) 26 26 ->setHeader($title) 27 - ->setHeaderIcon('fa-map'); 27 + ->setHeaderIcon('fa-map') 28 + ->setStatus( 29 + $resource->getStatusIcon(), 30 + $resource->getStatusColor(), 31 + $resource->getStatusDisplayName()); 28 32 29 33 if ($resource->isReleasing()) { 30 - $header->setStatus('fa-exclamation-triangle', 'red', pht('Releasing')); 34 + $header->addTag( 35 + id(new PHUITagView()) 36 + ->setType(PHUITagView::TYPE_SHADE) 37 + ->setIcon('fa-exclamation-triangle') 38 + ->setColor('red') 39 + ->setName('Releasing')); 31 40 } 32 41 33 42 $curtain = $this->buildCurtain($resource); ··· 127 136 $viewer = $this->getViewer(); 128 137 129 138 $view = new PHUIPropertyListView(); 130 - $status = $resource->getStatus(); 131 - $status = DrydockResourceStatus::getNameForStatus($status); 132 - 133 - $view->addProperty( 134 - pht('Status'), 135 - $status); 136 139 137 140 $until = $resource->getUntil(); 138 141 if ($until) {
+32 -30
src/applications/drydock/storage/DrydockResource.php
··· 235 235 return $this->isActivated; 236 236 } 237 237 238 - public function canRelease() { 239 - switch ($this->getStatus()) { 240 - case DrydockResourceStatus::STATUS_RELEASED: 241 - case DrydockResourceStatus::STATUS_DESTROYED: 242 - return false; 243 - default: 244 - return true; 245 - } 246 - } 247 - 248 238 public function scheduleUpdate($epoch = null) { 249 239 PhabricatorWorker::scheduleTask( 250 240 'DrydockResourceUpdateWorker', ··· 282 272 } 283 273 } 284 274 285 - public function canReceiveCommands() { 286 - switch ($this->getStatus()) { 287 - case DrydockResourceStatus::STATUS_RELEASED: 288 - case DrydockResourceStatus::STATUS_BROKEN: 289 - case DrydockResourceStatus::STATUS_DESTROYED: 290 - return false; 291 - default: 292 - return true; 293 - } 294 - } 295 - 296 - public function isActive() { 297 - switch ($this->getStatus()) { 298 - case DrydockResourceStatus::STATUS_ACTIVE: 299 - return true; 300 - } 301 - 302 - return false; 303 - } 304 - 305 275 public function logEvent($type, array $data = array()) { 306 276 $log = id(new DrydockLog()) 307 277 ->setEpoch(PhabricatorTime::getNow()) ··· 312 282 $log->setBlueprintPHID($this->getBlueprintPHID()); 313 283 314 284 return $log->save(); 285 + } 286 + 287 + 288 + /* -( Status )------------------------------------------------------------- */ 289 + 290 + 291 + public function getStatusObject() { 292 + return DrydockResourceStatus::newStatusObject($this->getStatus()); 293 + } 294 + 295 + public function getStatusIcon() { 296 + return $this->getStatusObject()->getIcon(); 297 + } 298 + 299 + public function getStatusColor() { 300 + return $this->getStatusObject()->getColor(); 301 + } 302 + 303 + public function getStatusDisplayName() { 304 + return $this->getStatusObject()->getDisplayName(); 305 + } 306 + 307 + public function canRelease() { 308 + return $this->getStatusObject()->canRelease(); 309 + } 310 + 311 + public function canReceiveCommands() { 312 + return $this->getStatusObject()->canReceiveCommands(); 313 + } 314 + 315 + public function isActive() { 316 + return $this->getStatusObject()->isActive(); 315 317 } 316 318 317 319
+4 -16
src/applications/drydock/view/DrydockResourceListView.php
··· 23 23 ->setObjectName(pht('Resource %d', $id)) 24 24 ->setHeader($resource->getResourceName()); 25 25 26 - $status = DrydockResourceStatus::getNameForStatus($resource->getStatus()); 27 - $item->addAttribute($status); 26 + $icon = $resource->getStatusIcon(); 27 + $color = $resource->getStatusColor(); 28 + $label = $resource->getStatusDisplayName(); 28 29 29 - switch ($resource->getStatus()) { 30 - case DrydockResourceStatus::STATUS_PENDING: 31 - $item->setStatusIcon('fa-dot-circle-o yellow'); 32 - break; 33 - case DrydockResourceStatus::STATUS_ACTIVE: 34 - $item->setStatusIcon('fa-dot-circle-o green'); 35 - break; 36 - case DrydockResourceStatus::STATUS_DESTROYED: 37 - $item->setStatusIcon('fa-times-circle-o black'); 38 - break; 39 - default: 40 - $item->setStatusIcon('fa-dot-circle-o red'); 41 - break; 42 - } 30 + $item->setStatusIcon("{$icon} {$color}", $label); 43 31 44 32 $view->addItem($item); 45 33 }