Christopher Johnson (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/169591
Change subject: Refactor SprintReportBurndownView ...................................................................... Refactor SprintReportBurndownView Change-Id: I29dd2804e76e3e91f173c235e19d0c1d294fff6c --- M src/view/BurndownDataView.php M src/view/SprintReportBurndownView.php 2 files changed, 70 insertions(+), 76 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/phabricator/extensions/Sprint refs/changes/91/169591/1 diff --git a/src/view/BurndownDataView.php b/src/view/BurndownDataView.php index 4ad5323..ac8817b 100644 --- a/src/view/BurndownDataView.php +++ b/src/view/BurndownDataView.php @@ -105,7 +105,7 @@ $transposed_array = array(); if ($array) { foreach ($array as $row_key => $row) { - if (is_array($row) && !empty($row)) { //check to see if there is a second dimension + if (is_array($row) && !empty($row)) { foreach ($row as $column_key => $element) { $transposed_array[$column_key][$row_key] = $element; } @@ -144,29 +144,37 @@ case "task-add": // A task was added to the sprint $operator = "+"; - $this->changeTasksAddedToday($date, $operator); - $this->changePointsAddedToday($date, $task_phid, $operator); + $stat = "tasks_added_today"; + $pstat = "points_added_today"; + $this->changeTasksToday($date, $operator, $stat); + $this->changePointsToday($date, $task_phid, $operator, $pstat); $this->changeTaskInSprint($task_phid, $operator); break; case "task-remove": // A task was removed from the sprint $operator = "-"; - $this->changeTasksAddedToday($date, $operator); - $this->changePointsAddedToday($date, $task_phid, $operator); + $stat = "tasks_closed_today"; + $pstat = "points_closed_today"; + $this->changeTasksToday($date, $operator, $stat); + $this->changePointsToday($date, $task_phid, $operator, $pstat); $this->changeTaskInSprint($task_phid, $operator); break; case "close": // A task was closed, mark it as done $operator = "+"; - $this->changeTasksClosedToday($date, $operator); - $this->changePointsClosedToday($date, $task_phid, $operator); + $stat = "tasks_closed_today"; + $pstat = "points_closed_today"; + $this->changeTasksToday($date, $operator, $stat); + $this->changePointsToday($date, $task_phid, $operator, $pstat); $this->changeTaskStatuses($task_phid, $operator); break; case "reopen": // A task was reopened, subtract from done $operator = "-"; - $this->changeTasksClosedToday($date, $operator); - $this->changePointsClosedToday($date, $task_phid, $operator); + $stat = "tasks_added_today"; + $pstat = "points_closed_today"; + $this->changeTasksToday($date, $operator, $stat); + $this->changePointsToday($date, $task_phid, $operator, $pstat); $this->changeTaskStatuses($task_phid, $operator); break; case "points": @@ -177,28 +185,28 @@ } } - private function changeTasksAddedToday($date, $operator) { + private function changeTasksToday($date, $operator, $stat) { switch ($operator) { case "+": return - $this->dates[$date]->tasks_added_today += 1; + $this->dates[$date]->$stat += 1; case "-": return - $this->dates[$date]->tasks_added_today -= 1; + $this->dates[$date]->$stat -= 1; default: return true; } } - private function changePointsAddedToday($date, $task_phid, $operator) { + private function changePointsToday($date, $task_phid, $operator, $pstat) { if (isset($this->task_points[$task_phid]) == $task_phid) { switch ($operator) { case "+": return - $this->dates[$date]->points_added_today += $this->task_points[$task_phid]; + $this->dates[$date]->$pstat += $this->task_points[$task_phid]; case "-": return - $this->dates[$date]->points_added_today -= $this->task_points[$task_phid]; + $this->dates[$date]->$pstat -= $this->task_points[$task_phid]; default: return true; } @@ -213,32 +221,6 @@ case "-": return $this->task_in_sprint[$task_phid] = 0; - default: - return true; - } - } - - private function changeTasksClosedToday($date, $operator) { - switch ($operator) { - case "+": - return - $this->dates[$date]->tasks_closed_today += 1; - case "-": - return - $this->dates[$date]->tasks_closed_today -= 1; - default: - return true; - } - } - - private function changePointsClosedToday($date, $task_phid, $operator) { - switch ($operator) { - case "+": - return - $this->dates[$date]->points_closed_today += $this->task_points[$task_phid]; - case "-": - return - $this->dates[$date]->points_closed_today -= $this->task_points[$task_phid]; default: return true; } diff --git a/src/view/SprintReportBurndownView.php b/src/view/SprintReportBurndownView.php index 0915a23..8dc929e 100644 --- a/src/view/SprintReportBurndownView.php +++ b/src/view/SprintReportBurndownView.php @@ -5,7 +5,7 @@ private $request; private $timeperiod = array(); - public function setUser ($user) { + public function setUser (PhabricatorUser $user) { $this->user = $user; return $this; } @@ -136,21 +136,8 @@ return $bucket; } - private function buildStatsTable() { - $handle = null; - $project_phid = $this->request->getStr('project'); - - if ($project_phid) { - $phids = array($project_phid); - $handle = $this->getProjectHandle ($phids,$project_phid); - } - - $data = $this->getXactionData($project_phid); - - $stats = $this->buildStatsfromEvents($data); - $day_buckets = $this->buildDayBucketsfromEvents($data); - + private function formatBucketRows ($stats, $day_buckets) { $template = array( 'open' => 0, 'close' => 0, @@ -207,7 +194,24 @@ $period['open'] += $info['open']; $period['close'] += $info['close']; } + return array ($rows,$rowc, $week, $month, $period); + } + private function renderCaption ($handle) { + + $inst = pht( + 'NOTE: This table reflects tasks currently in ' . + 'the project. If a task was opened in the past but added to ' . + 'the project recently, it is counted on the day it was ' . + 'opened, not the day it was categorized. If a task was part ' . + 'of this project in the past but no longer is, it is not ' . + 'counted at all.'); + $header = pht('Task Burn Rate for Project %s', $handle->renderLink()); + $caption = phutil_tag('p', array(), $inst); + return array ($caption, $header); + } + + private function formatStatsTableHeaders($week, $month, $period) { if ($week) { $rows[] = $this->formatBurnRow( pht('Week To Date'), @@ -229,29 +233,37 @@ $rows = array_reverse($rows); $rowc = array_reverse($rowc); + return array ($rows, $rowc); + } + private function buildStatsTable() { + $handle = null; + $project_phid = $this->request->getStr('project'); + + if ($project_phid) { + $phids = array($project_phid); + $handle = $this->getProjectHandle ($phids,$project_phid); + } + + $data = $this->getXactionData($project_phid); + + $stats = $this->buildStatsfromEvents($data); + $day_buckets = $this->buildDayBucketsfromEvents($data); + + list ($rows,$rowc, $week, $month, $period) = $this->formatBucketRows ($stats, $day_buckets); + list ($rows, $rowc) = $this->formatStatsTableHeaders($week, $month, $period, $rows,$rowc); + $table = $this->StatsTableView($rows, $rowc); - if ($handle) { - $inst = pht( - 'NOTE: This table reflects tasks currently in ' . - 'the project. If a task was opened in the past but added to ' . - 'the project recently, it is counted on the day it was ' . - 'opened, not the day it was categorized. If a task was part ' . - 'of this project in the past but no longer is, it is not ' . - 'counted at all.'); - $header = pht('Task Burn Rate for Project %s', $handle->renderLink()); - $caption = phutil_tag('p', array(), $inst); - } else { - $header = pht('Task Burn Rate for All Tasks'); - $caption = null; - } - - if ($caption) { - $caption = id(new AphrontErrorView()) - ->appendChild($caption) - ->setSeverity(AphrontErrorView::SEVERITY_NOTICE); - } + if ($handle) { + list ($caption, $header) = $this->renderCaption ($handle); + $caption = id(new AphrontErrorView()) + ->appendChild($caption) + ->setSeverity(AphrontErrorView::SEVERITY_NOTICE); + } else { + $header = pht('Task Burn Rate for All Tasks'); + $caption = null; + } $panel = new PHUIObjectBoxView(); $panel->setHeaderText($header); -- To view, visit https://gerrit.wikimedia.org/r/169591 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I29dd2804e76e3e91f173c235e19d0c1d294fff6c Gerrit-PatchSet: 1 Gerrit-Project: phabricator/extensions/Sprint Gerrit-Branch: master Gerrit-Owner: Christopher Johnson (WMDE) <christopher.john...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits