Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15393664
D19075.id45731.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
D19075.id45731.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1041,7 +1041,6 @@
'DrydockCommandInterface' => 'applications/drydock/interface/command/DrydockCommandInterface.php',
'DrydockCommandQuery' => 'applications/drydock/query/DrydockCommandQuery.php',
'DrydockConsoleController' => 'applications/drydock/controller/DrydockConsoleController.php',
- 'DrydockConstants' => 'applications/drydock/constants/DrydockConstants.php',
'DrydockController' => 'applications/drydock/controller/DrydockController.php',
'DrydockCreateBlueprintsCapability' => 'applications/drydock/capability/DrydockCreateBlueprintsCapability.php',
'DrydockDAO' => 'applications/drydock/storage/DrydockDAO.php',
@@ -6259,7 +6258,6 @@
'DrydockCommandInterface' => 'DrydockInterface',
'DrydockCommandQuery' => 'DrydockQuery',
'DrydockConsoleController' => 'DrydockController',
- 'DrydockConstants' => 'Phobject',
'DrydockController' => 'PhabricatorController',
'DrydockCreateBlueprintsCapability' => 'PhabricatorPolicyCapability',
'DrydockDAO' => 'PhabricatorLiskDAO',
@@ -6347,7 +6345,7 @@
'DrydockResourceReclaimLogType' => 'DrydockLogType',
'DrydockResourceReleaseController' => 'DrydockResourceController',
'DrydockResourceSearchEngine' => 'PhabricatorApplicationSearchEngine',
- 'DrydockResourceStatus' => 'DrydockConstants',
+ 'DrydockResourceStatus' => 'PhabricatorObjectStatus',
'DrydockResourceUpdateWorker' => 'DrydockWorker',
'DrydockResourceViewController' => 'DrydockResourceController',
'DrydockSFTPFilesystemInterface' => 'DrydockFilesystemInterface',
diff --git a/src/applications/drydock/constants/DrydockConstants.php b/src/applications/drydock/constants/DrydockConstants.php
deleted file mode 100644
--- a/src/applications/drydock/constants/DrydockConstants.php
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-
-abstract class DrydockConstants extends Phobject {}
diff --git a/src/applications/drydock/constants/DrydockLeaseStatus.php b/src/applications/drydock/constants/DrydockLeaseStatus.php
--- a/src/applications/drydock/constants/DrydockLeaseStatus.php
+++ b/src/applications/drydock/constants/DrydockLeaseStatus.php
@@ -95,7 +95,7 @@
'key' => self::STATUS_DESTROYED,
'name' => pht('Destroyed'),
'icon' => 'fa-times',
- 'color' => 'red',
+ 'color' => 'grey',
'isReleasable' => false,
'isCommandable' => false,
'isActivating' => false,
diff --git a/src/applications/drydock/constants/DrydockResourceStatus.php b/src/applications/drydock/constants/DrydockResourceStatus.php
--- a/src/applications/drydock/constants/DrydockResourceStatus.php
+++ b/src/applications/drydock/constants/DrydockResourceStatus.php
@@ -1,6 +1,7 @@
<?php
-final class DrydockResourceStatus extends DrydockConstants {
+final class DrydockResourceStatus
+ extends PhabricatorObjectStatus {
const STATUS_PENDING = 'pending';
const STATUS_ACTIVE = 'active';
@@ -8,23 +9,86 @@
const STATUS_BROKEN = 'broken';
const STATUS_DESTROYED = 'destroyed';
+ public static function newStatusObject($key) {
+ return new self($key, id(new self())->getStatusSpecification($key));
+ }
+
public static function getStatusMap() {
- return array(
- self::STATUS_PENDING => pht('Pending'),
- self::STATUS_ACTIVE => pht('Active'),
- self::STATUS_RELEASED => pht('Released'),
- self::STATUS_BROKEN => pht('Broken'),
- self::STATUS_DESTROYED => pht('Destroyed'),
- );
+ $map = id(new self())->getStatusSpecifications();
+ return ipull($map, 'name', 'key');
}
public static function getNameForStatus($status) {
- $map = self::getStatusMap();
- return idx($map, $status, pht('Unknown'));
+ $map = id(new self())->getStatusSpecification($status);
+ return $map['name'];
}
public static function getAllStatuses() {
- return array_keys(self::getStatusMap());
+ return array_keys(id(new self())->getStatusSpecifications());
+ }
+
+ public function isActive() {
+ return ($this->getKey() === self::STATUS_ACTIVE);
+ }
+
+ public function canRelease() {
+ return $this->getStatusProperty('isReleasable');
+ }
+
+ public function canReceiveCommands() {
+ return $this->getStatusProperty('isCommandable');
+ }
+
+ protected function newStatusSpecifications() {
+ return array(
+ array(
+ 'key' => self::STATUS_PENDING,
+ 'name' => pht('Pending'),
+ 'icon' => 'fa-clock-o',
+ 'color' => 'blue',
+ 'isReleasable' => true,
+ 'isCommandable' => true,
+ ),
+ array(
+ 'key' => self::STATUS_ACTIVE,
+ 'name' => pht('Active'),
+ 'icon' => 'fa-check',
+ 'color' => 'green',
+ 'isReleasable' => true,
+ 'isCommandable' => true,
+ ),
+ array(
+ 'key' => self::STATUS_RELEASED,
+ 'name' => pht('Released'),
+ 'icon' => 'fa-circle-o',
+ 'color' => 'blue',
+ 'isReleasable' => false,
+ 'isCommandable' => false,
+ ),
+ array(
+ 'key' => self::STATUS_BROKEN,
+ 'name' => pht('Broken'),
+ 'icon' => 'fa-times',
+ 'color' => 'indigo',
+ 'isReleasable' => true,
+ 'isCommandable' => false,
+ ),
+ array(
+ 'key' => self::STATUS_DESTROYED,
+ 'name' => pht('Destroyed'),
+ 'icon' => 'fa-times',
+ 'color' => 'grey',
+ 'isReleasable' => false,
+ 'isCommandable' => false,
+ ),
+ );
+ }
+
+ protected function newUnknownStatusSpecification($status) {
+ return array(
+ 'isReleasable' => false,
+ 'isCommandable' => false,
+ );
}
}
diff --git a/src/applications/drydock/controller/DrydockResourceViewController.php b/src/applications/drydock/controller/DrydockResourceViewController.php
--- a/src/applications/drydock/controller/DrydockResourceViewController.php
+++ b/src/applications/drydock/controller/DrydockResourceViewController.php
@@ -24,10 +24,19 @@
->setUser($viewer)
->setPolicyObject($resource)
->setHeader($title)
- ->setHeaderIcon('fa-map');
+ ->setHeaderIcon('fa-map')
+ ->setStatus(
+ $resource->getStatusIcon(),
+ $resource->getStatusColor(),
+ $resource->getStatusDisplayName());
if ($resource->isReleasing()) {
- $header->setStatus('fa-exclamation-triangle', 'red', pht('Releasing'));
+ $header->addTag(
+ id(new PHUITagView())
+ ->setType(PHUITagView::TYPE_SHADE)
+ ->setIcon('fa-exclamation-triangle')
+ ->setColor('red')
+ ->setName('Releasing'));
}
$curtain = $this->buildCurtain($resource);
@@ -127,12 +136,6 @@
$viewer = $this->getViewer();
$view = new PHUIPropertyListView();
- $status = $resource->getStatus();
- $status = DrydockResourceStatus::getNameForStatus($status);
-
- $view->addProperty(
- pht('Status'),
- $status);
$until = $resource->getUntil();
if ($until) {
diff --git a/src/applications/drydock/storage/DrydockResource.php b/src/applications/drydock/storage/DrydockResource.php
--- a/src/applications/drydock/storage/DrydockResource.php
+++ b/src/applications/drydock/storage/DrydockResource.php
@@ -235,16 +235,6 @@
return $this->isActivated;
}
- public function canRelease() {
- switch ($this->getStatus()) {
- case DrydockResourceStatus::STATUS_RELEASED:
- case DrydockResourceStatus::STATUS_DESTROYED:
- return false;
- default:
- return true;
- }
- }
-
public function scheduleUpdate($epoch = null) {
PhabricatorWorker::scheduleTask(
'DrydockResourceUpdateWorker',
@@ -282,26 +272,6 @@
}
}
- public function canReceiveCommands() {
- switch ($this->getStatus()) {
- case DrydockResourceStatus::STATUS_RELEASED:
- case DrydockResourceStatus::STATUS_BROKEN:
- case DrydockResourceStatus::STATUS_DESTROYED:
- return false;
- default:
- return true;
- }
- }
-
- public function isActive() {
- switch ($this->getStatus()) {
- case DrydockResourceStatus::STATUS_ACTIVE:
- return true;
- }
-
- return false;
- }
-
public function logEvent($type, array $data = array()) {
$log = id(new DrydockLog())
->setEpoch(PhabricatorTime::getNow())
@@ -315,6 +285,38 @@
}
+/* -( Status )------------------------------------------------------------- */
+
+
+ public function getStatusObject() {
+ return DrydockResourceStatus::newStatusObject($this->getStatus());
+ }
+
+ public function getStatusIcon() {
+ return $this->getStatusObject()->getIcon();
+ }
+
+ public function getStatusColor() {
+ return $this->getStatusObject()->getColor();
+ }
+
+ public function getStatusDisplayName() {
+ return $this->getStatusObject()->getDisplayName();
+ }
+
+ public function canRelease() {
+ return $this->getStatusObject()->canRelease();
+ }
+
+ public function canReceiveCommands() {
+ return $this->getStatusObject()->canReceiveCommands();
+ }
+
+ public function isActive() {
+ return $this->getStatusObject()->isActive();
+ }
+
+
/* -( PhabricatorPolicyInterface )----------------------------------------- */
diff --git a/src/applications/drydock/view/DrydockResourceListView.php b/src/applications/drydock/view/DrydockResourceListView.php
--- a/src/applications/drydock/view/DrydockResourceListView.php
+++ b/src/applications/drydock/view/DrydockResourceListView.php
@@ -23,23 +23,11 @@
->setObjectName(pht('Resource %d', $id))
->setHeader($resource->getResourceName());
- $status = DrydockResourceStatus::getNameForStatus($resource->getStatus());
- $item->addAttribute($status);
-
- switch ($resource->getStatus()) {
- case DrydockResourceStatus::STATUS_PENDING:
- $item->setStatusIcon('fa-dot-circle-o yellow');
- break;
- case DrydockResourceStatus::STATUS_ACTIVE:
- $item->setStatusIcon('fa-dot-circle-o green');
- break;
- case DrydockResourceStatus::STATUS_DESTROYED:
- $item->setStatusIcon('fa-times-circle-o black');
- break;
- default:
- $item->setStatusIcon('fa-dot-circle-o red');
- break;
- }
+ $icon = $resource->getStatusIcon();
+ $color = $resource->getStatusColor();
+ $label = $resource->getStatusDisplayName();
+
+ $item->setStatusIcon("{$icon} {$color}", $label);
$view->addItem($item);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 16, 10:58 PM (2 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7690230
Default Alt Text
D19075.id45731.diff (10 KB)
Attached To
Mode
D19075: Give Drydock Resources more modern status treatment
Attached
Detach File
Event Timeline
Log In to Comment