Christopher Johnson (WMDE) has submitted this change and it was merged. Change subject: refactored BurndownData and created abstract SprintView class ......................................................................
refactored BurndownData and created abstract SprintView class Change-Id: I926cb70cf238fb9d1251c64ca63953ea20d392c4 --- M __phutil_library_map__.php M src/BurndownApplication.php M src/BurndownController.php R src/BurndownDataView.php A src/BurndownDataViewController.php M src/BurndownListController.php M src/SprintConstants.php M src/SprintReportController.php A src/SprintView.php 9 files changed, 166 insertions(+), 108 deletions(-) Approvals: Christopher Johnson (WMDE): Verified; Looks good to me, approved diff --git a/__phutil_library_map__.php b/__phutil_library_map__.php index 39775ae..faf7a05 100644 --- a/__phutil_library_map__.php +++ b/__phutil_library_map__.php @@ -12,25 +12,29 @@ 'BurndownActionMenuEventListener' => 'src/BurndownActionMenuEventListener.php', 'BurndownApplication' => 'src/BurndownApplication.php', 'BurndownController' => 'src/BurndownController.php', - 'BurndownData' => 'src/BurndownData.php', 'BurndownDataDate' => 'src/BurndownDataDate.php', + 'BurndownDataView' => 'src/BurndownDataView.php', + 'BurndownDataViewController' => 'src/BurndownDataViewController.php', 'BurndownException' => 'src/BurndownException.php', 'BurndownListController' => 'src/BurndownListController.php', 'BurndownTestDataGenerator' => 'src/BurndownTestDataGenerator.php', 'SprintConstants' => 'src/SprintConstants.php', - 'SprintStartDateField' => 'src/SprintStartDateField.php', 'SprintEndDateField' => 'src/SprintEndDateField.php', 'SprintProjectCustomField' => 'src/SprintProjectCustomField.php', 'SprintReportController' => 'src/SprintReportController.php', + 'SprintStartDateField' => 'src/SprintStartDateField.php', 'SprintTaskStoryPointsField' => 'src/SprintTaskStoryPointsField.php', + 'SprintView' => 'src/SprintView.php', ), 'function' => array(), 'xmap' => array( 'BurndownActionMenuEventListener' => 'PhabricatorEventListener', 'BurndownApplication' => 'PhabricatorApplication', 'BurndownController' => 'PhabricatorController', + 'BurndownDataView' => 'SprintView', + 'BurndownDataViewController' => 'BurndownController', 'BurndownException' => 'Exception', - 'BurndownListController' => 'PhabricatorController', + 'BurndownListController' => 'BurndownController', 'BurndownTestDataGenerator' => 'PhabricatorTestDataGenerator', 'SprintConstants' => 'ManiphestConstants', 'SprintStartDateField' => 'SprintProjectCustomField', @@ -39,10 +43,11 @@ 'PhabricatorProjectCustomField', 'PhabricatorStandardCustomFieldInterface', ), - 'SprintReportController' => 'ManiphestController', + 'SprintReportController' => 'BurndownController', 'SprintTaskStoryPointsField' => array( - 'ManiphestCustomField', - 'PhabricatorStandardCustomFieldInterface', + 'ManiphestCustomField', + 'PhabricatorStandardCustomFieldInterface', ), + 'SprintView' => 'AphrontView', ), )); diff --git a/src/BurndownApplication.php b/src/BurndownApplication.php index 98413e3..3033320 100644 --- a/src/BurndownApplication.php +++ b/src/BurndownApplication.php @@ -35,7 +35,7 @@ 'report/' => 'BurndownListController', 'report/list/' => 'BurndownListController', 'report/(?:(?P<view>\w+)/)?' => 'SprintReportController', - 'view/(?P<id>\d+)/' => 'BurndownController', + 'view/(?P<id>\d+)/' => 'BurndownDataViewController', ), ); } diff --git a/src/BurndownController.php b/src/BurndownController.php index 59fa771..55e2694 100644 --- a/src/BurndownController.php +++ b/src/BurndownController.php @@ -4,71 +4,65 @@ * Licensed under GNU GPL v3. See LICENSE for full details */ -final class BurndownController extends PhabricatorController { +abstract class BurndownController extends PhabricatorController { - // Project data - private $projectID; - - public function shouldAllowPublic() { + public function shouldAllowPublic() { return true; } - public function willProcessRequest(array $data) { - $this->projectID = $data['id']; - } + public function getProjectsURI() { + return '/project/'; + } - public function processRequest() { + public function buildApplicationMenu() { + return $this->buildSideNavView(true)->getMenu(); + } - $request = $this->getRequest(); - $viewer = $request->getUser(); + public function buildSideNavView($for_app = false) { + $user = $this->getRequest()->getUser(); - // Load the project we're looking at, based on the project ID in the URL. - $project = id(new PhabricatorProjectQuery()) - ->setViewer($viewer) - ->withIDs(array($this->projectID)) - ->executeOne(); - if (!$project) { - return new Aphront404Response(); + $nav = new AphrontSideNavFilterView(); + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); + + if ($for_app) { + $nav->addFilter('create', pht('Create Task')); } - $error_box = false; - $burndown_chart = false; - $burndown_table = false; - $tasks_table = false; - $events_table = false; + id(new ManiphestTaskSearchEngine()) + ->setViewer($user) + ->addNavigationItems($nav->getMenu()); - try { - $data = new BurndownData($project, $viewer); - // $data = new BurndownDataChart($project, $viewer); - $burndown_chart = $data->buildBurnDownChart(); - $tasks_table = $data->buildTasksTable(); - $burndown_table = $data->buildBurnDownTable(); - $events_table = $data->buildEventTable(); - } catch (BurndownException $e) { - $error_box = id(new AphrontErrorView()) - ->setTitle(pht('Burndown could not be rendered for this project')) - ->setErrors(array($e->getMessage())); + if ($user->isLoggedIn()) { + // For now, don't give logged-out users access to reports. + $nav->addLabel(pht('Reports')); + $nav->addFilter('report', pht('Reports')); } - $crumbs = $this->buildApplicationCrumbs(); - $crumbs->addTextCrumb( - $project->getName(), - '/project/view/'.$project->getID()); - $crumbs->addTextCrumb(pht('Burndown')); + $nav->selectFilter(null); - return $this->buildApplicationPage( - array( - $crumbs, - $error_box, - $burndown_chart, - $tasks_table, - $burndown_table, - $events_table, - ), - array( - 'title' => array(pht('Burndown'), $project->getName()), - 'device' => true, - )); + return $nav; + } + + public function getAuxFields($project, $viewer) { + $field_list = PhabricatorCustomField::getObjectFields( + $project, + PhabricatorCustomField::ROLE_EDIT); + $field_list->setViewer($viewer); + $field_list->readFieldsFromStorage($project); + $aux_fields = $field_list->getFields(); + return $aux_fields; + } + + protected function buildApplicationCrumbs() { + $crumbs = parent::buildApplicationCrumbs(); + + $crumbs->addAction( + id(new PHUIListItemView()) + ->setName(pht('Create Sprint')) + ->setHref($this->getProjectsURI().'create/') + ->setIcon('fa-calendar')); + + return $crumbs; } } diff --git a/src/BurndownData.php b/src/BurndownDataView.php similarity index 97% rename from src/BurndownData.php rename to src/BurndownDataView.php index eb8aabd..35ba12b 100644 --- a/src/BurndownData.php +++ b/src/BurndownDataView.php @@ -4,9 +4,9 @@ * Licensed under GNU GPL v3. See LICENSE for full details */ -class BurndownData { +final class BurndownDataView extends SprintView { - // Array of BurndownDataDates + // Array of BurndownDataDatessta // There are two special keys, 'before' and 'after' // // Looks like: array( @@ -16,8 +16,8 @@ // ... // 'after' => BurndownDataDate // ) - private $type_status = 'core:customfield'; - private $storypoints; + private $type_status = SprintConstants::CUSTOMFIELD_TYPE_STATUS; + private $dates; private $data; // These hold an array of each task, and how many points are assigned, and @@ -33,32 +33,23 @@ private $events; private $xactions; - public function __construct($project, $viewer) { - + public function setProject ($project) { $this->project = $project; + return $this; + } + + public function setViewer ($viewer) { $this->viewer = $viewer; + return $this; + } - // We need the custom fields so we can pull out the start and end date - $aux_fields = $this->getAuxFields(); - $start = $this->getStartDate($aux_fields); - $end = $this->getEndDate($aux_fields); - $this->dates = $this->buildDateArray($start, $end); + public function render() { - $tasks = $this->getTasks(); - - $this->checkNull($start, $end, $tasks); - - $xactions = $this->getXactions($tasks); - - $this->examineXactions($xactions, $tasks); - - $this->buildDailyData($start, $end); - $this->buildTaskArrays(); - - - $this->sumSprintStats(); - $this->computeIdealPoints(); - + $chart = $this->buildBurnDownChart(); + $tasks_table = $this->buildTasksTable(); + $burndown_table = $this->buildBurnDownTable(); + $event_table = $this->buildEventTable(); + return array ($chart, $tasks_table, $burndown_table, $event_table); } private function getAuxFields() { @@ -316,7 +307,31 @@ } } + + private function buildChartDataSet() { + + + $aux_fields = $this->getAuxFields(); + $start = $this->getStartDate($aux_fields); + $end = $this->getEndDate($aux_fields); + $this->dates = $this->buildDateArray($start, $end); + + $tasks = $this->getTasks(); + + $this->checkNull($start, $end, $tasks); + + $xactions = $this->getXactions($tasks); + + $this->examineXactions($xactions, $tasks); + + $this->buildDailyData($start, $end); + $this->buildTaskArrays(); + + + $this->sumSprintStats(); + $this->computeIdealPoints(); + $data = array(array( pht('Date'), pht('Total Points'), @@ -343,7 +358,7 @@ } - public function buildBurnDownChart() { + private function buildBurnDownChart() { $this->data = $this->buildChartDataSet(); // Format the data for the chart diff --git a/src/BurndownDataViewController.php b/src/BurndownDataViewController.php new file mode 100644 index 0000000..fa14fa6 --- /dev/null +++ b/src/BurndownDataViewController.php @@ -0,0 +1,56 @@ +<?php + +final class BurndownDataViewController extends BurndownController { + + // Project data + private $projectID; + + public function willProcessRequest(array $data) { + $this->projectID = $data['id']; + } + + public function processRequest() { + + $request = $this->getRequest(); + $viewer = $request->getUser(); + + // Load the project we're looking at, based on the project ID in the URL. + $project = id(new PhabricatorProjectQuery()) + ->setViewer($viewer) + ->withIDs(array($this->projectID)) + ->executeOne(); + if (!$project) { + return new Aphront404Response(); + } + + $error_box = false; + $burndown_view = false; + + try { + $burndown_view = id(new BurndownDataView()) + ->setProject($project) + ->setViewer($viewer); + } catch (BurndownException $e) { + $error_box = id(new AphrontErrorView()) + ->setTitle(pht('Burndown could not be rendered for this project')) + ->setErrors(array($e->getMessage())); + } + + $crumbs = $this->buildApplicationCrumbs(); + $crumbs->addTextCrumb( + $project->getName(), + '/project/view/'.$project->getID()); + $crumbs->addTextCrumb(pht('Burndown')); + + return $this->buildApplicationPage( + array( + $crumbs, + $error_box, + $burndown_view, + ), + array( + 'title' => array(pht('Burndown'), $project->getName()), + 'device' => true, + )); + } +} \ No newline at end of file diff --git a/src/BurndownListController.php b/src/BurndownListController.php index 3fc90eb..31a92d6 100644 --- a/src/BurndownListController.php +++ b/src/BurndownListController.php @@ -4,13 +4,9 @@ * Licensed under GNU GPL v3. See LICENSE for full details */ -final class BurndownListController extends PhabricatorController { +final class BurndownListController extends BurndownController { private $view; - - public function shouldAllowPublic() { - return true; - } public function processRequest() { @@ -149,18 +145,6 @@ ->withDatasourceQuery(SprintConstants::MAGIC_WORD) ->execute(); return $projects; - } - - private function getAuxFields($project, $viewer) { - // We need the custom fields so we can pull out the start and end date - // TODO: query in a loop is bad - $field_list = PhabricatorCustomField::getObjectFields( - $project, - PhabricatorCustomField::ROLE_EDIT); - $field_list->setViewer($viewer); - $field_list->readFieldsFromStorage($project); - $aux_fields = $field_list->getFields(); - return $aux_fields; } private function getStartDate($aux_fields) { diff --git a/src/SprintConstants.php b/src/SprintConstants.php index 65261bf..ceb9fe6 100644 --- a/src/SprintConstants.php +++ b/src/SprintConstants.php @@ -3,4 +3,5 @@ final class SprintConstants extends ManiphestConstants { const MAGIC_WORD = 'ยง'; + const CUSTOMFIELD_TYPE_STATUS = 'core:customfield'; } \ No newline at end of file diff --git a/src/SprintReportController.php b/src/SprintReportController.php index 56dacbf..c0a6e49 100644 --- a/src/SprintReportController.php +++ b/src/SprintReportController.php @@ -1,12 +1,8 @@ <?php -final class SprintReportController extends ManiphestController { +final class SprintReportController extends BurndownController { private $view; - - public function shouldAllowPublic() { - return true; - } public function willProcessRequest(array $data) { $this->view = idx($data, 'view'); diff --git a/src/SprintView.php b/src/SprintView.php new file mode 100644 index 0000000..69e20a0 --- /dev/null +++ b/src/SprintView.php @@ -0,0 +1,7 @@ +<?php + + +abstract class SprintView extends AphrontView +{ + +} \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/166195 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I926cb70cf238fb9d1251c64ca63953ea20d392c4 Gerrit-PatchSet: 2 Gerrit-Project: phabricator/extensions/Sprint Gerrit-Branch: master Gerrit-Owner: Christopher Johnson (WMDE) <christopher.john...@wikimedia.de> Gerrit-Reviewer: Christopher Johnson (WMDE) <christopher.john...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits