1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

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
This commit is contained in:
epriestley 2018-02-13 05:31:29 -08:00
parent 27c3793d40
commit 06bbf237fe
7 changed files with 124 additions and 72 deletions

View file

@ -1041,7 +1041,6 @@ phutil_register_library_map(array(
'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 @@ phutil_register_library_map(array(
'DrydockCommandInterface' => 'DrydockInterface',
'DrydockCommandQuery' => 'DrydockQuery',
'DrydockConsoleController' => 'DrydockController',
'DrydockConstants' => 'Phobject',
'DrydockController' => 'PhabricatorController',
'DrydockCreateBlueprintsCapability' => 'PhabricatorPolicyCapability',
'DrydockDAO' => 'PhabricatorLiskDAO',
@ -6347,7 +6345,7 @@ phutil_register_library_map(array(
'DrydockResourceReclaimLogType' => 'DrydockLogType',
'DrydockResourceReleaseController' => 'DrydockResourceController',
'DrydockResourceSearchEngine' => 'PhabricatorApplicationSearchEngine',
'DrydockResourceStatus' => 'DrydockConstants',
'DrydockResourceStatus' => 'PhabricatorObjectStatus',
'DrydockResourceUpdateWorker' => 'DrydockWorker',
'DrydockResourceViewController' => 'DrydockResourceController',
'DrydockSFTPFilesystemInterface' => 'DrydockFilesystemInterface',

View file

@ -1,3 +0,0 @@
<?php
abstract class DrydockConstants extends Phobject {}

View file

@ -95,7 +95,7 @@ final class DrydockLeaseStatus
'key' => self::STATUS_DESTROYED,
'name' => pht('Destroyed'),
'icon' => 'fa-times',
'color' => 'red',
'color' => 'grey',
'isReleasable' => false,
'isCommandable' => false,
'isActivating' => false,

View file

@ -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 @@ final class DrydockResourceStatus extends DrydockConstants {
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,
);
}
}

View file

@ -24,10 +24,19 @@ final class DrydockResourceViewController extends DrydockResourceController {
->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 @@ final class DrydockResourceViewController extends DrydockResourceController {
$viewer = $this->getViewer();
$view = new PHUIPropertyListView();
$status = $resource->getStatus();
$status = DrydockResourceStatus::getNameForStatus($status);
$view->addProperty(
pht('Status'),
$status);
$until = $resource->getUntil();
if ($until) {

View file

@ -235,16 +235,6 @@ final class DrydockResource extends DrydockDAO
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 @@ final class DrydockResource extends DrydockDAO
}
}
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 @@ final class DrydockResource extends DrydockDAO
}
/* -( 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 )----------------------------------------- */

View file

@ -23,23 +23,11 @@ final class DrydockResourceListView extends AphrontView {
->setObjectName(pht('Resource %d', $id))
->setHeader($resource->getResourceName());
$status = DrydockResourceStatus::getNameForStatus($resource->getStatus());
$item->addAttribute($status);
$icon = $resource->getStatusIcon();
$color = $resource->getStatusColor();
$label = $resource->getStatusDisplayName();
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;
}
$item->setStatusIcon("{$icon} {$color}", $label);
$view->addItem($item);
}