1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 13:22:42 +01:00

Drive Maniphest statuses with internal pseudo-configuration

Summary: Ref T1812. Without actually exposing configuration, this moves all status information into a config-like chunk of data which can later be exposed to human editors.

Test Plan:
  - Made a bunch of status changes.
  - Merged duplicates.
  - Created task.
  - Viewed feed, transaction record, etc.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T1812

Differential Revision: https://secure.phabricator.com/D8582
This commit is contained in:
epriestley 2014-03-25 13:56:45 -07:00
parent fdc7b8672b
commit 47d6d0bbad
2 changed files with 155 additions and 83 deletions

View file

@ -9,52 +9,119 @@ final class ManiphestTaskStatus extends ManiphestConstants {
const STATUS_CLOSED_DUPLICATE = 4; const STATUS_CLOSED_DUPLICATE = 4;
const STATUS_CLOSED_SPITE = 5; const STATUS_CLOSED_SPITE = 5;
public static function getTaskStatusMap() { const SPECIAL_DEFAULT = 'default';
$open = pht('Open'); const SPECIAL_CLOSED = 'closed';
$resolved = pht('Resolved'); const SPECIAL_DUPLICATE = 'duplicate';
$wontfix = pht('Wontfix');
$invalid = pht('Invalid');
$duplicate = pht('Duplicate');
$spite = pht('Spite');
$statuses = array( private static function getStatusConfig() {
self::STATUS_OPEN => $open, return array(
self::STATUS_CLOSED_RESOLVED => $resolved, self::STATUS_OPEN => array(
self::STATUS_CLOSED_WONTFIX => $wontfix, 'name' => pht('Open'),
self::STATUS_CLOSED_INVALID => $invalid, 'special' => self::SPECIAL_DEFAULT,
self::STATUS_CLOSED_DUPLICATE => $duplicate, ),
self::STATUS_CLOSED_SPITE => $spite, self::STATUS_CLOSED_RESOLVED => array(
'name' => pht('Resolved'),
'name.full' => pht('Closed, Resolved'),
'closed' => true,
'special' => self::SPECIAL_CLOSED,
'prefixes' => array(
'closed',
'closes',
'close',
'fix',
'fixes',
'fixed',
'resolve',
'resolves',
'resolved',
),
'suffixes' => array(
'as resolved',
'as fixed',
),
),
self::STATUS_CLOSED_WONTFIX => array(
'name' => pht('Wontfix'),
'name.full' => pht('Closed, Wontfix'),
'closed' => true,
'prefixes' => array(
'wontfix',
'wontfixes',
'wontfixed',
),
'suffixes' => array(
'as wontfix',
),
),
self::STATUS_CLOSED_INVALID => array(
'name' => pht('Invalid'),
'name.full' => pht('Closed, Invalid'),
'closed' => true,
'prefixes' => array(
'invalidate',
'invalidates',
'invalidated',
),
'suffixes' => array(
'as invalid',
),
),
self::STATUS_CLOSED_DUPLICATE => array(
'name' => pht('Duplicate'),
'name.full' => pht('Closed, Duplicate'),
'transaction.icon' => 'delete',
'special' => self::SPECIAL_DUPLICATE,
'closed' => true,
),
self::STATUS_CLOSED_SPITE => array(
'name' => pht('Spite'),
'name.full' => pht('Closed, Spite'),
'name.action' => pht('Spited'),
'transaction.icon' => 'dislike',
'silly' => true,
'closed' => true,
'prefixes' => array(
'spite',
'spites',
'spited',
),
'suffixes' => array(
'out of spite',
'as spite',
),
),
); );
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
if (!$is_serious) {
$statuses[self::STATUS_CLOSED_SPITE] = pht('Spite');
} }
return $statuses; private static function getEnabledStatusMap() {
$spec = self::getStatusConfig();
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
foreach ($spec as $const => $status) {
if ($is_serious && !empty($status['silly'])) {
unset($spec[$const]);
continue;
}
}
return $spec;
}
public static function getTaskStatusMap() {
return ipull(self::getEnabledStatusMap(), 'name');
} }
public static function getTaskStatusName($status) { public static function getTaskStatusName($status) {
return idx(self::getTaskStatusMap(), $status, pht('Unknown Status')); return self::getStatusAttribute($status, 'name', pht('Unknown Status'));
} }
public static function getTaskStatusFullName($status) { public static function getTaskStatusFullName($status) {
$open = pht('Open'); $name = self::getStatusAttribute($status, 'name.full');
$resolved = pht('Closed, Resolved'); if ($name !== null) {
$wontfix = pht('Closed, Wontfix'); return $name;
$invalid = pht('Closed, Invalid'); }
$duplicate = pht('Closed, Duplicate');
$spite = pht('Closed, Spite');
$map = array( return self::getStatusAttribute($status, 'name', pht('Unknown Status'));
self::STATUS_OPEN => $open,
self::STATUS_CLOSED_RESOLVED => $resolved,
self::STATUS_CLOSED_WONTFIX => $wontfix,
self::STATUS_CLOSED_INVALID => $invalid,
self::STATUS_CLOSED_DUPLICATE => $duplicate,
self::STATUS_CLOSED_SPITE => $spite,
);
return idx($map, $status, '???');
} }
public static function renderFullDescription($status) { public static function renderFullDescription($status) {
@ -83,22 +150,35 @@ final class ManiphestTaskStatus extends ManiphestConstants {
return $tag; return $tag;
} }
private static function getSpecialStatus($special) {
foreach (self::getEnabledStatusMap() as $const => $status) {
if (idx($status, 'special') == $special) {
return $const;
}
}
return null;
}
public static function getDefaultStatus() { public static function getDefaultStatus() {
return self::STATUS_OPEN; return self::getSpecialStatus(self::SPECIAL_DEFAULT);
} }
public static function getDefaultClosedStatus() { public static function getDefaultClosedStatus() {
return self::STATUS_CLOSED_RESOLVED; return self::getSpecialStatus(self::SPECIAL_CLOSED);
} }
public static function getDuplicateStatus() { public static function getDuplicateStatus() {
return self::STATUS_CLOSED_DUPLICATE; return self::getSpecialStatus(self::SPECIAL_DUPLICATE);
} }
public static function getOpenStatusConstants() { public static function getOpenStatusConstants() {
return array( $result = array();
self::STATUS_OPEN, foreach (self::getEnabledStatusMap() as $const => $status) {
); if (empty($status['closed'])) {
$result[] = $const;
}
}
return $result;
} }
public static function getClosedStatusConstants() { public static function getClosedStatusConstants() {
@ -121,67 +201,54 @@ final class ManiphestTaskStatus extends ManiphestConstants {
} }
public static function getStatusActionName($status) { public static function getStatusActionName($status) {
switch ($status) { return self::getStatusAttribute($status, 'name.action');
case self::STATUS_CLOSED_SPITE:
return pht('Spited');
}
return null;
} }
public static function getStatusColor($status) { public static function getStatusColor($status) {
if (self::isOpenStatus($status)) { return self::getStatusAttribute($status, 'transaction.color');
return 'green';
}
return 'black';
} }
public static function getStatusIcon($status) { public static function getStatusIcon($status) {
switch ($status) { return self::getStatusAttribute($status, 'transaction.icon');
case ManiphestTaskStatus::STATUS_CLOSED_SPITE:
return 'dislike';
case ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE:
return 'delete';
} }
}
public static function getStatusPrefixMap() { public static function getStatusPrefixMap() {
return array( $map = array();
'resolve' => self::STATUS_CLOSED_RESOLVED, foreach (self::getEnabledStatusMap() as $const => $status) {
'resolves' => self::STATUS_CLOSED_RESOLVED, foreach (idx($status, 'prefixes', array()) as $prefix) {
'resolved' => self::STATUS_CLOSED_RESOLVED, $map[$prefix] = $const;
'fix' => self::STATUS_CLOSED_RESOLVED, }
'fixes' => self::STATUS_CLOSED_RESOLVED, }
'fixed' => self::STATUS_CLOSED_RESOLVED,
'wontfix' => self::STATUS_CLOSED_WONTFIX, $map += array(
'wontfixes' => self::STATUS_CLOSED_WONTFIX,
'wontfixed' => self::STATUS_CLOSED_WONTFIX,
'spite' => self::STATUS_CLOSED_SPITE,
'spites' => self::STATUS_CLOSED_SPITE,
'spited' => self::STATUS_CLOSED_SPITE,
'invalidate' => self::STATUS_CLOSED_INVALID,
'invaldiates' => self::STATUS_CLOSED_INVALID,
'invalidated' => self::STATUS_CLOSED_INVALID,
'close' => self::STATUS_CLOSED_RESOLVED,
'closes' => self::STATUS_CLOSED_RESOLVED,
'closed' => self::STATUS_CLOSED_RESOLVED,
'ref' => null, 'ref' => null,
'refs' => null, 'refs' => null,
'references' => null, 'references' => null,
'cf.' => null, 'cf.' => null,
); );
return $map;
} }
public static function getStatusSuffixMap() { public static function getStatusSuffixMap() {
return array( $map = array();
'as resolved' => self::STATUS_CLOSED_RESOLVED, foreach (self::getEnabledStatusMap() as $const => $status) {
'as fixed' => self::STATUS_CLOSED_RESOLVED, foreach (idx($status, 'suffixes', array()) as $prefix) {
'as wontfix' => self::STATUS_CLOSED_WONTFIX, $map[$prefix] = $const;
'as spite' => self::STATUS_CLOSED_SPITE, }
'out of spite' => self::STATUS_CLOSED_SPITE, }
'as invalid' => self::STATUS_CLOSED_INVALID, return $map;
);
} }
private static function getStatusAttribute($status, $key, $default = null) {
$config = self::getStatusConfig();
$spec = idx($config, $status);
if ($spec) {
return idx($spec, $key, $default);
}
return $default;
}
} }

View file

@ -143,7 +143,12 @@ final class ManiphestTransaction
if ($color !== null) { if ($color !== null) {
return $color; return $color;
} }
break;
if (ManiphestTaskStatus::isOpenStatus($new)) {
return 'green';
} else {
return 'black';
}
case self::TYPE_PRIORITY: case self::TYPE_PRIORITY:
if ($old == ManiphestTaskPriority::getDefaultPriority()) { if ($old == ManiphestTaskPriority::getDefaultPriority()) {