From 78d2a099176fd810168286a9102e32f0e9ba60f3 Mon Sep 17 00:00:00 2001 From: liugang Date: Tue, 4 Jul 2023 17:08:11 +0800 Subject: [PATCH] * block: display the execution overview block by overviewBlock widget. --- .../block/ui/executionoverviewblock.html.php | 19 ++++++ module/block/zen.php | 67 ++++++++++++++----- 2 files changed, 70 insertions(+), 16 deletions(-) create mode 100644 module/block/ui/executionoverviewblock.html.php diff --git a/module/block/ui/executionoverviewblock.html.php b/module/block/ui/executionoverviewblock.html.php new file mode 100644 index 0000000000..9937b3c19f --- /dev/null +++ b/module/block/ui/executionoverviewblock.html.php @@ -0,0 +1,19 @@ + +* @package block +* @link https://www.zentao.net +*/ + +namespace zin; + +overviewBlock +( + set(array('block' => $block, 'groups' => $groups)) +); + +render(); diff --git a/module/block/zen.php b/module/block/zen.php index 3e1cdfbeef..6ebee59a94 100644 --- a/module/block/zen.php +++ b/module/block/zen.php @@ -1531,29 +1531,64 @@ class blockZen extends block */ protected function printExecutionOverviewBlock(object $block): void { - $projectID = $block->dashboard == 'my' ? 0 : (int)$this->session->project; - $executions = $this->loadModel('execution')->getList($projectID); + $query = $this->dao->select('id, status, Year(closedDate) AS year')->from(TABLE_PROJECT) + ->where('deleted')->eq('0') + ->andWhere('type')->in('sprint, stage, kanban') + ->andWhere('multiple')->eq('1') + ->andWhere('vision')->eq($this->config->vision) + ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->sprints)->fi(); - $total = 0; - foreach($executions as $execution) + $statusPairs = $query->fetchPairs('id', 'status'); + $yearPairs = $query->fetchPairs('id', 'year'); + $yearPairs = array_map(function($year){return $year == null ? 0 : $year;}, $yearPairs); + $statusStats = array_count_values($statusPairs); + $yearStats = array_count_values($yearPairs); + + $cards = array(); + $cards[0] = new stdclass(); + $cards[0]->value = array_sum($statusStats); + $cards[0]->class = 'text-primary'; + $cards[0]->label = $this->lang->block->executionoverview->totalExecution; + $cards[0]->url = common::hasPriv('execution', 'all') ? helper::createLink('execution', 'all', 'status=all') : null; + + $cards[1] = new stdclass(); + $cards[1]->value = zget($yearStats, date('Y'), 0); + $cards[1]->label = $this->lang->block->executionoverview->thisYear; + + $cardGroup = new stdclass(); + $cardGroup->type = 'cards'; + $cardGroup->cards = $cards; + + $this->app->loadLang('execution'); + + $max = 0; + foreach($this->lang->execution->statusList as $status => $label) { - if(empty($execution->multiple)) continue; - if(!isset($overview[$execution->status])) $overview[$execution->status] = 0; - $overview[$execution->status]++; - $total++; + if($status == 'closed') continue; + + $$status = zget($statusStats, $status, 0); + if($max < $$status) $max = $$status; } - $overviewPercent = array(); - $this->app->loadLang('project'); - foreach($this->lang->project->statusList as $statusKey => $statusName) + $bars = array(); + foreach($this->lang->execution->statusList as $status => $label) { - if(!isset($overview[$statusKey])) $overview[$statusKey] = 0; - $overviewPercent[$statusKey] = $total ? round($overview[$statusKey] / $total, 2) * 100 . '%' : '0%'; + if($status == 'closed') continue; + + $bar = new stdclass(); + $bar->label = $label; + $bar->value = $$status; + $bar->rate = $max ? round($$status / $max, 4) * 100 . '%' : '0%'; + + $bars[] = $bar; } - $this->view->total = $total; - $this->view->overview = $overview; - $this->view->overviewPercent = $overviewPercent; + $barGroup = new stdclass(); + $barGroup->type = 'barChart'; + $barGroup->title = $this->lang->block->executionoverview->statusCount; + $barGroup->bars = $bars; + + $this->view->groups = array($cardGroup, $barGroup); } /**