diff --git a/src/applications/maniphest/constants/ManiphestTaskStatus.php b/src/applications/maniphest/constants/ManiphestTaskStatus.php index 8e2b045e68..276af1ec00 100644 --- a/src/applications/maniphest/constants/ManiphestTaskStatus.php +++ b/src/applications/maniphest/constants/ManiphestTaskStatus.php @@ -9,52 +9,119 @@ final class ManiphestTaskStatus extends ManiphestConstants { const STATUS_CLOSED_DUPLICATE = 4; const STATUS_CLOSED_SPITE = 5; - public static function getTaskStatusMap() { - $open = pht('Open'); - $resolved = pht('Resolved'); - $wontfix = pht('Wontfix'); - $invalid = pht('Invalid'); - $duplicate = pht('Duplicate'); - $spite = pht('Spite'); + const SPECIAL_DEFAULT = 'default'; + const SPECIAL_CLOSED = 'closed'; + const SPECIAL_DUPLICATE = 'duplicate'; - $statuses = array( - 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, + private static function getStatusConfig() { + return array( + self::STATUS_OPEN => array( + 'name' => pht('Open'), + 'special' => self::SPECIAL_DEFAULT, + ), + 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', + ), + ), ); + } + + private static function getEnabledStatusMap() { + $spec = self::getStatusConfig(); $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); - if (!$is_serious) { - $statuses[self::STATUS_CLOSED_SPITE] = pht('Spite'); + foreach ($spec as $const => $status) { + if ($is_serious && !empty($status['silly'])) { + unset($spec[$const]); + continue; + } } - return $statuses; + return $spec; + } + + public static function getTaskStatusMap() { + return ipull(self::getEnabledStatusMap(), 'name'); } 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) { - $open = pht('Open'); - $resolved = pht('Closed, Resolved'); - $wontfix = pht('Closed, Wontfix'); - $invalid = pht('Closed, Invalid'); - $duplicate = pht('Closed, Duplicate'); - $spite = pht('Closed, Spite'); + $name = self::getStatusAttribute($status, 'name.full'); + if ($name !== null) { + return $name; + } - $map = array( - 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, '???'); + return self::getStatusAttribute($status, 'name', pht('Unknown Status')); } public static function renderFullDescription($status) { @@ -83,22 +150,35 @@ final class ManiphestTaskStatus extends ManiphestConstants { 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() { - return self::STATUS_OPEN; + return self::getSpecialStatus(self::SPECIAL_DEFAULT); } public static function getDefaultClosedStatus() { - return self::STATUS_CLOSED_RESOLVED; + return self::getSpecialStatus(self::SPECIAL_CLOSED); } public static function getDuplicateStatus() { - return self::STATUS_CLOSED_DUPLICATE; + return self::getSpecialStatus(self::SPECIAL_DUPLICATE); } public static function getOpenStatusConstants() { - return array( - self::STATUS_OPEN, - ); + $result = array(); + foreach (self::getEnabledStatusMap() as $const => $status) { + if (empty($status['closed'])) { + $result[] = $const; + } + } + return $result; } public static function getClosedStatusConstants() { @@ -121,67 +201,54 @@ final class ManiphestTaskStatus extends ManiphestConstants { } public static function getStatusActionName($status) { - switch ($status) { - case self::STATUS_CLOSED_SPITE: - return pht('Spited'); - } - return null; + return self::getStatusAttribute($status, 'name.action'); } public static function getStatusColor($status) { - if (self::isOpenStatus($status)) { - return 'green'; - } - return 'black'; + return self::getStatusAttribute($status, 'transaction.color'); } public static function getStatusIcon($status) { - switch ($status) { - case ManiphestTaskStatus::STATUS_CLOSED_SPITE: - return 'dislike'; - case ManiphestTaskStatus::STATUS_CLOSED_DUPLICATE: - return 'delete'; - } + return self::getStatusAttribute($status, 'transaction.icon'); } - public static function getStatusPrefixMap() { - return array( - 'resolve' => self::STATUS_CLOSED_RESOLVED, - 'resolves' => self::STATUS_CLOSED_RESOLVED, - 'resolved' => self::STATUS_CLOSED_RESOLVED, - 'fix' => self::STATUS_CLOSED_RESOLVED, - 'fixes' => self::STATUS_CLOSED_RESOLVED, - 'fixed' => self::STATUS_CLOSED_RESOLVED, - 'wontfix' => self::STATUS_CLOSED_WONTFIX, - '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, + $map = array(); + foreach (self::getEnabledStatusMap() as $const => $status) { + foreach (idx($status, 'prefixes', array()) as $prefix) { + $map[$prefix] = $const; + } + } + + $map += array( 'ref' => null, 'refs' => null, 'references' => null, 'cf.' => null, ); + + return $map; } public static function getStatusSuffixMap() { - return array( - 'as resolved' => self::STATUS_CLOSED_RESOLVED, - 'as fixed' => self::STATUS_CLOSED_RESOLVED, - 'as wontfix' => self::STATUS_CLOSED_WONTFIX, - 'as spite' => self::STATUS_CLOSED_SPITE, - 'out of spite' => self::STATUS_CLOSED_SPITE, - 'as invalid' => self::STATUS_CLOSED_INVALID, - ); + $map = array(); + foreach (self::getEnabledStatusMap() as $const => $status) { + foreach (idx($status, 'suffixes', array()) as $prefix) { + $map[$prefix] = $const; + } + } + 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; + } } diff --git a/src/applications/maniphest/storage/ManiphestTransaction.php b/src/applications/maniphest/storage/ManiphestTransaction.php index f6617530e9..cedcb89cde 100644 --- a/src/applications/maniphest/storage/ManiphestTransaction.php +++ b/src/applications/maniphest/storage/ManiphestTransaction.php @@ -143,7 +143,12 @@ final class ManiphestTransaction if ($color !== null) { return $color; } - break; + + if (ManiphestTaskStatus::isOpenStatus($new)) { + return 'green'; + } else { + return 'black'; + } case self::TYPE_PRIORITY: if ($old == ManiphestTaskPriority::getDefaultPriority()) {