From edf4171f190bccebe8f660d039ea81c8ed87e116 Mon Sep 17 00:00:00 2001 From: Ana Rute Mendes Date: Mon, 18 May 2020 13:29:35 -0300 Subject: [PATCH] CCU: display RAG indicator and progress bar in task card Based on the custom field `std:maniphest:collabora:rag-status` display the RAG indicator in the task card as well as a progress bar that exposes the task children points. --- resources/celerity/map.php | 4 +- .../maniphest/storage/ManiphestTask.php | 61 +++++++++++++++++++ .../project/view/ProjectBoardTaskCard.php | 47 ++++++++++++++ .../rsrc/css/phui/phui-segment-bar-view.css | 5 ++ 4 files changed, 115 insertions(+), 2 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index e041de6270..29d000d48d 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -174,7 +174,7 @@ return array( 'rsrc/css/phui/phui-policy-section-view.css' => '139fdc64', 'rsrc/css/phui/phui-property-list-view.css' => '5adf7078', 'rsrc/css/phui/phui-remarkup-preview.css' => '91767007', - 'rsrc/css/phui/phui-segment-bar-view.css' => '5166b370', + 'rsrc/css/phui/phui-segment-bar-view.css' => '570518ea', 'rsrc/css/phui/phui-spacing.css' => 'b05cadc3', 'rsrc/css/phui/phui-status.css' => 'e5ff8be0', 'rsrc/css/phui/phui-tag-view.css' => '8519160a', @@ -878,7 +878,7 @@ return array( 'phui-policy-section-view-css' => '139fdc64', 'phui-property-list-view-css' => '5adf7078', 'phui-remarkup-preview-css' => '91767007', - 'phui-segment-bar-view-css' => '5166b370', + 'phui-segment-bar-view-css' => '570518ea', 'phui-spacing-css' => 'b05cadc3', 'phui-status-list-view-css' => 'e5ff8be0', 'phui-tag-view-css' => '8519160a', diff --git a/src/applications/maniphest/storage/ManiphestTask.php b/src/applications/maniphest/storage/ManiphestTask.php index ad990648b5..bde61e34c2 100644 --- a/src/applications/maniphest/storage/ManiphestTask.php +++ b/src/applications/maniphest/storage/ManiphestTask.php @@ -395,6 +395,67 @@ final class ManiphestTask extends ManiphestDAO } } + public function getRAGStatus() { + // Based on the RAG custom field, return the color of the task + + $fields_list = PhabricatorCustomField::getObjectFields($this, + PhabricatorCustomField::ROLE_STORAGE); + $fields_list->readFieldsFromStorage($this); + $fields = $fields_list->getFields(); + + $status = idx($fields, 'std:maniphest:collabora:rag-status') + ->getProxy()->getFieldValue(); + + switch ($status) { + case 'collabora:rag-red': + return 'red'; + case 'collabora:rag-amber': + return 'yellow'; + case 'collabora:rag-green': + return 'green'; + } + + return ''; + } + + public function getTaskProgress(PhabricatorUser $viewer) { + // If a task has children, sum up all their points and return the + // progress based on closed and in progress tasks. All statuses that are not + // 'open' or 'closed' are considered in progress. + + $total_points = 0; + $completed_points = 0; + $in_progress = 0; + + $children = $this->loadDependsOnTaskPHIDs(); + + foreach ($children as $child) { + $task = id(new ManiphestTaskQuery()) + ->setViewer($viewer) + ->withPHIDs(array($child)) + ->executeOne(); + + $child_progress = $task->getTaskProgress($viewer); + + $total_points += $child_progress['total_points']; + $completed_points += $child_progress['completed_points']; + $in_progress += $child_progress['in_progress']; + } + + $total_points += (float)$this->getPoints(); + if ($this->isClosed()) { + $completed_points += (float)$this->getPoints(); + } elseif ($this->getStatus() != 'open') { + $in_progress += $this->getPoints(); + } + + return array( + "total_points" => $total_points, + "completed_points" => $completed_points, + "in_progress" => $in_progress, + ); + } + /* -( PhabricatorSubscribableInterface )----------------------------------- */ diff --git a/src/applications/project/view/ProjectBoardTaskCard.php b/src/applications/project/view/ProjectBoardTaskCard.php index b7e1ef15f7..3c9cca749e 100644 --- a/src/applications/project/view/ProjectBoardTaskCard.php +++ b/src/applications/project/view/ProjectBoardTaskCard.php @@ -190,6 +190,53 @@ final class ProjectBoardTaskCard extends Phobject { $card->addClass('phui-workcard'); + // CCU: display the RAG indicator and progress bar in the task card + $rag_status = $task->getRAGStatus(); + if ($rag_status) { + $rag_icon = id(new PHUITagView()) + ->setType(PHUITagView::TYPE_OBJECT) + ->setBackgroundColor(null) + ->setIcon('fa-circle ' . $rag_status); + $card->addAttribute($rag_icon); + + $task_progress = $task->getTaskProgress($viewer); + if ($task_progress['total_points'] > 0) { + $bar = id(new PHUISegmentBarView()) + ->setLabel(pht( + 'Progress: %s/%s points', + new PhutilNumber($task_progress['completed_points']), + new PhutilNumber($task_progress['total_points']) + )); + + $bar->newSegment() + ->setWidth($task_progress['completed_points'] / $task_progress['total_points']) + ->setColor('blue') + ->setTooltip(pht( + '%s/%s complete', + new PhutilNumber($task_progress['completed_points']), + new PhutilNumber($task_progress['total_points'])) + ); + + $bar->newSegment() + ->setWidth($task_progress['in_progress'] / $task_progress['total_points']) + ->setColor('lightblue') + ->setTooltip(pht( + '%s/%s in progress', + new PhutilNumber($task_progress['in_progress']), + new PhutilNumber($task_progress['total_points'])) + ); + + $bar = phutil_tag( + 'div', + array( + 'class' => 'phui-profile-segment-bar', + ), + $bar); + $card->addAttribute($bar); + } + } + + return $card; } diff --git a/webroot/rsrc/css/phui/phui-segment-bar-view.css b/webroot/rsrc/css/phui/phui-segment-bar-view.css index b3ce7677e3..b91649e3a9 100644 --- a/webroot/rsrc/css/phui/phui-segment-bar-view.css +++ b/webroot/rsrc/css/phui/phui-segment-bar-view.css @@ -55,6 +55,11 @@ border-color: {$blue}; } +.phui-segment-bar-segment-view.lightblue { + background: {$lightblue}; + border-color: {$lightblue}; +} + .phui-segment-bar-segment-view.indigo { background: {$indigo}; border-color: {$indigo}; -- GitLab