Christopher Johnson (WMDE) has uploaded a new change for review.
https://gerrit.wikimedia.org/r/188766
Change subject: adds new DataProvider classes
......................................................................
adds new DataProvider classes
removes debug Data table
refactors SprintDataView
Change-Id: I6310622ee4d60cd30c3367360d948f63885599ba
---
M src/__phutil_library_map__.php
M src/query/SprintQuery.php
A src/storage/BoardDataProvider.php
A src/storage/ChartDataProvider.php
M src/tests/selenium/phabricator.sprint/pom.xml
A src/view/burndown/BoardDataView.php
A src/view/burndown/C3PieView.php
M src/view/burndown/SprintDataView.php
8 files changed, 381 insertions(+), 69 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/phabricator/extensions/Sprint
refs/changes/66/188766/1
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
index e5d565b..89cccbb 100644
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -10,12 +10,16 @@
'__library_version__' => 2,
'class' => array(
'AutoLoader' => 'tests/Autoloader.php',
+ 'BoardDataProvider' => 'storage/BoardDataProvider.php',
+ 'BoardDataView' => 'view/burndown/BoardDataView.php',
'BurndownActionMenuEventListener' =>
'events/BurndownActionMenuEventListener.php',
'BurndownDataDate' => 'util/BurndownDataDate.php',
'BurndownDataDateTest' => 'tests/BurndownDataDateTest.php',
'BurndownException' => 'exception/BurndownException.php',
'C3ChartView' => 'view/burndown/C3ChartView.php',
+ 'C3PieView' => 'view/burndown/C3PieView.php',
'CeleritySprintResources' => 'celerity/CeleritySprintResources.php',
+ 'ChartDataProvider' => 'storage/ChartDataProvider.php',
'DateIterator' => 'tests/DateIterator.php',
'EventTableView' => 'view/burndown/EventTableView.php',
'HistoryTableView' => 'view/burndown/HistoryTableView.php',
@@ -73,7 +77,7 @@
'xmap' => array(
'BurndownActionMenuEventListener' => 'PhabricatorEventListener',
'BurndownDataDateTest' => 'SprintTestCase',
- 'BurndownException' => 'Exception',
+ 'BurndownException' => 'AphrontUsageException',
'CeleritySprintResources' => 'CelerityResourcesOnDisk',
'DateIterator' => 'Iterator',
'PhabricatorFactSprintEngine' => 'PhabricatorFactEngine',
diff --git a/src/query/SprintQuery.php b/src/query/SprintQuery.php
index 2dd78f4..39af964 100644
--- a/src/query/SprintQuery.php
+++ b/src/query/SprintQuery.php
@@ -219,6 +219,38 @@
return $events;
}
+ public function getProjectColumns() {
+ $columns = id(new PhabricatorProjectColumnQuery())
+ ->setViewer($this->viewer)
+ ->withProjectPHIDs(array($this->project_phid))
+ ->execute();
+ return $columns;
+ }
+
+ public function getColumnforPHID($column_phid) {
+ $column = id(new PhabricatorProjectColumnQuery())
+ ->setViewer($this->viewer)
+ ->withPHIDs(array($column_phid))
+ ->execute();
+ return $column;
+ }
+
+ public function getProjectColumnPositionforTask($tasks, $columns) {
+ if ($tasks) {
+ $positions = id(new PhabricatorProjectColumnPositionQuery())
+ ->setViewer($this->viewer)
+ ->withBoardPHIDs(array($this->project_phid))
+ ->withObjectPHIDs(mpull($tasks, 'getPHID'))
+ ->withColumns($columns)
+ ->needColumns(true)
+ ->execute();
+ $positions = mpull($positions, null, 'getObjectPHID');
+ } else {
+ $positions = array();
+ }
+ return $positions;
+ }
+
private function setXActionEventType ($xaction, $old, $new, $scope_phid) {
switch ($xaction->getTransactionType()) {
case ManiphestTransaction::TYPE_STATUS:
@@ -266,7 +298,7 @@
$in_old_scope = array_key_exists($scope_phid, $old);
$in_new_scope = array_key_exists($scope_phid, $new);
- if ($in_new_scope) {
+ if ($in_new_scope ) {
return 'task-add';
} else if ($in_old_scope && !$in_new_scope) {
// NOTE: We will miss some of these events, becuase we are only
diff --git a/src/storage/BoardDataProvider.php
b/src/storage/BoardDataProvider.php
new file mode 100644
index 0000000..f23ccff
--- /dev/null
+++ b/src/storage/BoardDataProvider.php
@@ -0,0 +1,96 @@
+<?php
+
+
+final class BoardDataProvider {
+
+ private $project;
+ private $viewer;
+ private $request;
+ private $tasks;
+ private $taskpoints;
+ private $query;
+
+
+ public function setProject ($project) {
+ $this->project = $project;
+ return $this;
+ }
+
+ public function setViewer ($viewer) {
+ $this->viewer = $viewer;
+ return $this;
+ }
+
+ public function setRequest ($request) {
+ $this->request = $request;
+ return $this;
+ }
+
+ public function setTasks ($tasks) {
+ $this->tasks = $tasks;
+ return $this;
+ }
+
+ public function setTaskPoints ($taskpoints) {
+ $this->taskpoints = $taskpoints;
+ return $this;
+ }
+
+ public function setQuery ($query) {
+ $this->query = $query;
+ return $this;
+ }
+
+ public function buildBoardDataSet() {
+ $columns = $this->query->getProjectColumns();
+ $positions = $this->query->getProjectColumnPositionforTask($this->tasks,
$columns);
+ $task_map = array();
+
+ foreach ($this->tasks as $task) {
+ $task_phid = $task->getPHID();
+ if (empty($positions[$task_phid])) {
+ continue;
+ }
+ $position = $positions[$task_phid];
+ $task_map[$position->getColumnPHID()][] = $task_phid;
+ }
+
+ foreach ($columns as $column) {
+ $board_column = $this->buildColumnTasks($column, $task_map);
+ $board_columns[$column->getPHID()] = $board_column;
+ }
+
+ return $board_columns;
+ }
+
+ private function buildColumnTasks($column, $task_map) {
+ $task_phids = idx($task_map, $column->getPHID(), array());
+ $column_tasks = array_select_keys($this->tasks, $task_phids);
+ return $column_tasks;
+ }
+
+ public function getColumnName($column_phid) {
+ $column = $this->query->getColumnforPHID($column_phid);
+ foreach ($column as $obj) {
+ $name = $obj->getDisplayName();
+ }
+ return $name;
+ }
+
+ public function getTaskPointsSum($tasks) {
+ $points_sum = null;
+ $taskpoints = mpull($this->taskpoints, null, 'getObjectPHID');
+ $column_points = array_intersect_key($taskpoints, $tasks);
+ if (!empty($column_points)) {
+ foreach ($column_points as $key => $value) {
+ $points = $value->getfieldValue();
+ $points_sum += $points;
+ }
+ if (!isset($points_sum)) {
+ $points_sum = '0';
+ }
+ }
+ return $points_sum;
+ }
+
+}
diff --git a/src/storage/ChartDataProvider.php
b/src/storage/ChartDataProvider.php
new file mode 100644
index 0000000..0ebee58
--- /dev/null
+++ b/src/storage/ChartDataProvider.php
@@ -0,0 +1,93 @@
+<?php
+
+final class ChartDataProvider {
+
+ private $project;
+ private $timezone;
+ private $viewer;
+ private $tasks;
+ private $taskpoints;
+ private $query;
+ private $start;
+ private $end;
+ private $before;
+
+
+ public function setStart ($start) {
+ $this->start = $start;
+ return $this;
+ }
+
+ public function setEnd ($end) {
+ $this->end = $end;
+ return $this;
+ }
+
+ public function setProject ($project) {
+ $this->project = $project;
+ return $this;
+ }
+
+ public function setViewer ($viewer) {
+ $this->viewer = $viewer;
+ return $this;
+ }
+
+ public function setTasks ($tasks) {
+ $this->tasks = $tasks;
+ return $this;
+ }
+
+ public function setEvents ($events) {
+ $this->events = $events;
+ return $this;
+ }
+
+ public function setTaskPoints ($taskpoints) {
+ $this->taskpoints = $taskpoints;
+ return $this;
+ }
+
+ public function setTimezone ($timezone) {
+ $this->timezone = $timezone;
+ return $this;
+ }
+
+ public function setQuery ($query) {
+ $this->query = $query;
+ return $this;
+ }
+
+ public function setStats ($stats) {
+ $this->stats = $stats;
+ return $this;
+ }
+
+ public function setBefore ($before) {
+ $this->before = $before;
+ return $this;
+ }
+
+ public function buildChartDataSet() {
+
+ $this->query->checkNull($this->start, $this->end, $this->project,
$this->tasks);
+
+ $date_array = $this->stats->buildDateArray($this->start, $this->end,
$this->timezone);
+ $xactions = $this->query->getXactions($this->tasks);
+ $xaction_map = mpull($xactions, null, 'getPHID');
+
+ $sprint_xaction = id(new SprintTransaction())
+ ->setViewer($this->viewer)
+ ->setTasks($this->tasks)
+ ->setTaskPoints($this->taskpoints);
+
+ $dates = $sprint_xaction->parseEvents($this->events, $this->before,
+ $this->start, $this->end, $date_array, $xaction_map);
+
+ $sprint_data = $this->stats->setSprintData($dates, $this->before);
+ $data = $this->stats->buildDataSet($sprint_data);
+ $data = $this->stats->transposeArray($data);
+ return $data;
+ }
+
+}
diff --git a/src/tests/selenium/phabricator.sprint/pom.xml
b/src/tests/selenium/phabricator.sprint/pom.xml
index 351fd53..c04ba04 100644
--- a/src/tests/selenium/phabricator.sprint/pom.xml
+++ b/src/tests/selenium/phabricator.sprint/pom.xml
@@ -61,4 +61,3 @@
</dependencies>
</dependencyManagement>
</project>
-
diff --git a/src/view/burndown/BoardDataView.php
b/src/view/burndown/BoardDataView.php
new file mode 100644
index 0000000..a21e27f
--- /dev/null
+++ b/src/view/burndown/BoardDataView.php
@@ -0,0 +1,36 @@
+<?php
+
+final class BoardDataView {
+
+ private $board_data;
+
+ public function setBoardData ($board_data) {
+ $this->board_data = $board_data;
+ return $this;
+ }
+
+ public function buildBoardDataTable() {
+
+ $board_columns = $this->board_data->buildBoardDataSet();
+ foreach ($board_columns as $column_phid => $tasks) {
+ $colname = $this->board_data->getColumnName($column_phid);
+ $task_count = count($tasks);
+ $task_points_total = $this->board_data->getTaskPointsSum($tasks);
+ $coldata[] = array(
+ $colname, $task_count, $task_points_total,
+ );
+ }
+ $table = id(new AphrontTableView($coldata))
+ ->setHeaders(
+ array(
+ pht('Column Name'),
+ pht('Number of Tasks'),
+ pht('Total Points'),
+ ));
+
+ $box = id(new PHUIObjectBoxView())
+ ->setHeaderText(pht('Board Column List'))
+ ->appendChild($table);
+ return $box;
+ }
+}
diff --git a/src/view/burndown/C3PieView.php b/src/view/burndown/C3PieView.php
new file mode 100644
index 0000000..88beea1
--- /dev/null
+++ b/src/view/burndown/C3PieView.php
@@ -0,0 +1,54 @@
+<?php
+
+final class C3PieView {
+
+ private $project;
+ private $taskpoints;
+ private $tasks;
+
+ public function setProject($project) {
+ $this->project = $project;
+ return $this;
+ }
+
+ public function setTasks ($tasks) {
+ $this->tasks = $tasks;
+ return $this;
+ }
+
+ public function setTaskPoints ($taskpoints) {
+ $this->taskpoints = $taskpoints;
+ return $this;
+ }
+
+ public function buildC3Pie() {
+ $sprintpoints = id(new SprintPoints())
+ ->setTaskPoints($this->taskpoints)
+ ->setTasks($this->tasks);
+
+ list($task_open_status_sum, $task_closed_status_sum) = $sprintpoints
+ ->getStatusSums();
+
+ require_celerity_resource('d3', 'sprint');
+ require_celerity_resource('c3-css', 'sprint');
+ require_celerity_resource('c3', 'sprint');
+
+ $id = 'pie';
+ Javelin::initBehavior('c3-pie', array(
+ 'hardpoint' => $id,
+ 'open' => $task_open_status_sum,
+ 'resolved' => $task_closed_status_sum,
+ ), 'sprint');
+
+ $pie = id(new PHUIObjectBoxView())
+ ->setHeaderText(pht('Task Status Report for
'.$this->project->getName()))
+ ->appendChild(phutil_tag('div',
+ array(
+ 'id' => 'pie',
+ 'style' => 'width: 100%; height:200px',
+ ), ''));
+
+ return $pie;
+ }
+
+}
diff --git a/src/view/burndown/SprintDataView.php
b/src/view/burndown/SprintDataView.php
index 4d2594f..5a4451f 100644
--- a/src/view/burndown/SprintDataView.php
+++ b/src/view/burndown/SprintDataView.php
@@ -1,21 +1,16 @@
<?php
-/**
- * @author Michael Peters
- * @license GPL version 3
- */
final class SprintDataView extends SprintView
{
private $request;
+ private $timezone;
private $timeseries;
- private $sprint_data;
private $project;
private $viewer;
private $tasks;
private $taskpoints;
private $events;
- private $xactions;
private $start;
private $end;
private $before;
@@ -44,8 +39,29 @@
$this->taskpoints = $query->getTaskData();
$tasks = $query->getTasks();
$this->tasks = mpull($tasks, null, 'getPHID');
+ $stats = id(new SprintBuildStats());
- $chart_data = $this->buildChartDataSet($query);
+ $this->setStartandEndDates($query);
+ $this->setTimezone($stats);
+ $this->setBefore($stats);
+ $this->setTimeSeries($stats);
+ $this->setEvents($query);
+
+ $chart_model = id(new ChartDataProvider())
+ ->setStart($this->start)
+ ->setEnd($this->end)
+ ->setProject($this->project)
+ ->setEvents($this->events)
+ ->setViewer($this->viewer)
+ ->setTasks($this->tasks)
+ ->setTimezone($this->timezone)
+ ->setTaskPoints($this->taskpoints)
+ ->setBefore($this->before)
+ ->setQuery($query)
+ ->setStats($stats);
+
+ $chart_data = $chart_model->buildChartDataSet();
+
$chart_view = id(new C3ChartView())
->setChartData($chart_data)
->setProject($this->project)
@@ -61,13 +77,30 @@
->setQuery($query);
$tasks_table = $tasks_table_view->buildTasksTable();
- $pie = $this->buildC3Pie();
+ $pie_chart_view = id(new C3PieView())
+ ->setTasks($this->tasks)
+ ->setTaskPoints($this->taskpoints)
+ ->setProject($this->project);
+ $pie_chart = $pie_chart_view->buildC3Pie();
+
$history_table_view = new HistoryTableView();
$history_table = $history_table_view->buildHistoryTable($this->before);
- $sprint_table_view = new SprintTableView();
- $sprint_table = $sprint_table_view->buildSprintTable($this->sprint_data,
- $this->before);
+ $board_data = id(new BoardDataProvider())
+ ->setProject($this->project)
+ ->setViewer($this->viewer)
+ ->setRequest($this->request)
+ ->setTasks($this->tasks)
+ ->setTaskPoints($this->taskpoints)
+ ->setQuery($query);
+
+ $board_data_table_view = id(new BoardDataView())
+ ->setBoardData($board_data);
+ $board_table = $board_data_table_view->buildBoardDataTable();
+
+ // $sprint_table_view = new SprintTableView();
+ // $sprint_table = $sprint_table_view->buildSprintTable($this->sprint_data,
+ // $this->before);
$event_table_view = id(new EventTableView())
->setProject($this->project)
@@ -78,71 +111,36 @@
$event_table = $event_table_view->buildEventTable(
$this->start, $this->end);
- return array($chart, $tasks_table, $pie, $history_table, $sprint_table,
- $event_table);
+ return array($chart, $tasks_table, $pie_chart, $history_table,
+ $board_table, $event_table,);
}
- private function buildChartDataSet($query) {
-
+ private function setStartandEndDates($query) {
$field_list = $query->getCustomFieldList();
$aux_fields = $query->getAuxFields($field_list);
$this->start = $query->getStartDate($aux_fields);
$this->end = $query->getEndDate($aux_fields);
- $query->checkNull($this->start, $this->end, $this->project, $this->tasks);
-
- $stats = id(new SprintBuildStats());
- $timezone = $stats->setTimezone($this->viewer);
- $this->before = $stats->buildBefore($this->start, $timezone);
- $dates = $stats->buildDateArray($this->start, $this->end, $timezone);
- $this->timeseries = $stats->buildTimeSeries($this->start, $this->end);
-
-
- $xactions = $query->getXactions($this->tasks);
- $this->events = $query->getEvents($xactions, $this->tasks);
-
- $this->xactions = mpull($xactions, null, 'getPHID');
-
- $sprint_xaction = id(new SprintTransaction())
- ->setViewer($this->viewer)
- ->setTasks($this->tasks)
- ->setTaskPoints($this->taskpoints);
-
- $dates = $sprint_xaction->parseEvents($this->events, $this->before,
- $this->start, $this->end, $dates, $this->xactions);
-
- $this->sprint_data = $stats->setSprintData($dates, $this->before);
- $data = $stats->buildDataSet($this->sprint_data);
- $data = $stats->transposeArray($data);
- return $data;
+ return $this;
}
- private function buildC3Pie() {
- $sprintpoints = id(new SprintPoints())
- ->setTaskPoints($this->taskpoints)
- ->setTasks($this->tasks);
+ private function setBefore($stats) {
+ $this->before = $stats->buildBefore($this->start, $this->timezone);
+ return $this;
+ }
- list($task_open_status_sum, $task_closed_status_sum) = $sprintpoints
- ->getStatusSums();
+ private function setTimezone($stats) {
+ $this->timezone = $stats->setTimezone($this->viewer);
+ return $this;
+ }
- require_celerity_resource('d3', 'sprint');
- require_celerity_resource('c3-css', 'sprint');
- require_celerity_resource('c3', 'sprint');
+ private function setTimeSeries($stats) {
+ $this->timeseries = $stats->buildTimeSeries($this->start, $this->end);
+ return $this;
+ }
- $id = 'pie';
- Javelin::initBehavior('c3-pie', array(
- 'hardpoint' => $id,
- 'open' => $task_open_status_sum,
- 'resolved' => $task_closed_status_sum,
- ), 'sprint');
-
- $pie = id(new PHUIObjectBoxView())
- ->setHeaderText(pht('Task Status Report for ' .
$this->project->getName()))
- ->appendChild(phutil_tag('div',
- array(
- 'id' => 'pie',
- 'style' => 'width: 100%; height:200px'
- ), ''));
-
- return $pie;
+ private function setEvents($query) {
+ $xactions = $query->getXactions($this->tasks);
+ $this->events = $query->getEvents($xactions, $this->tasks);
+ return $this;
}
}
--
To view, visit https://gerrit.wikimedia.org/r/188766
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6310622ee4d60cd30c3367360d948f63885599ba
Gerrit-PatchSet: 1
Gerrit-Project: phabricator/extensions/Sprint
Gerrit-Branch: master
Gerrit-Owner: Christopher Johnson (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits