From a1c20638fa201bdfc63c4abc0bf613f776fbf70c Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 8 Feb 2012 09:47:14 -0800 Subject: [PATCH] Add very very basic reporting to Maniphest Summary: Rough cut for Quora, we want this too eventually but it's super basic right now so I'm not linking it anywhere. Once we get a couple more iterations I'll put it in the UI. Test Plan: Looked at stats for test data. Reviewers: btrahan Reviewed By: btrahan CC: anjali, aran, epriestley Differential Revision: https://secure.phabricator.com/D1594 --- src/__phutil_library_map__.php | 2 + ...AphrontDefaultApplicationConfiguration.php | 1 + .../report/ManiphestReportController.php | 148 ++++++++++++++++++ .../maniphest/controller/report/__init__.php | 23 +++ .../project/controller/create/__init__.php | 1 - 5 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 src/applications/maniphest/controller/report/ManiphestReportController.php create mode 100644 src/applications/maniphest/controller/report/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 7daeada815..fb58757510 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -398,6 +398,7 @@ phutil_register_library_map(array( 'ManiphestDAO' => 'applications/maniphest/storage/base', 'ManiphestDefaultTaskExtensions' => 'applications/maniphest/extensions/task', 'ManiphestReplyHandler' => 'applications/maniphest/replyhandler', + 'ManiphestReportController' => 'applications/maniphest/controller/report', 'ManiphestTask' => 'applications/maniphest/storage/task', 'ManiphestTaskAuxiliaryStorage' => 'applications/maniphest/storage/auxiliary', 'ManiphestTaskDescriptionChangeController' => 'applications/maniphest/controller/descriptionchange', @@ -1139,6 +1140,7 @@ phutil_register_library_map(array( 'ManiphestDAO' => 'PhabricatorLiskDAO', 'ManiphestDefaultTaskExtensions' => 'ManiphestTaskExtensions', 'ManiphestReplyHandler' => 'PhabricatorMailReplyHandler', + 'ManiphestReportController' => 'ManiphestController', 'ManiphestTask' => 'ManiphestDAO', 'ManiphestTaskAuxiliaryStorage' => 'ManiphestDAO', 'ManiphestTaskDescriptionChangeController' => 'ManiphestController', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index e70f0c53fc..4e9bfbfcf3 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -162,6 +162,7 @@ class AphrontDefaultApplicationConfiguration '/maniphest/' => array( '$' => 'ManiphestTaskListController', 'view/(?P\w+)/$' => 'ManiphestTaskListController', + 'report/(?:(?P\w+)/)?$' => 'ManiphestReportController', 'task/' => array( 'create/$' => 'ManiphestTaskEditController', 'edit/(?P\d+)/$' => 'ManiphestTaskEditController', diff --git a/src/applications/maniphest/controller/report/ManiphestReportController.php b/src/applications/maniphest/controller/report/ManiphestReportController.php new file mode 100644 index 0000000000..e871e80efe --- /dev/null +++ b/src/applications/maniphest/controller/report/ManiphestReportController.php @@ -0,0 +1,148 @@ +view = idx($data, 'view'); + } + + public function processRequest() { + + $request = $this->getRequest(); + $user = $request->getUser(); + + $nav = new AphrontSideNavFilterView(); + $nav->setBaseURI(new PhutilURI('/maniphest/report/')); + $nav->addFilter('user', 'User'); + $nav->addFilter('project', 'Project'); + + $this->view = $nav->selectFilter($this->view, 'user'); + + $tasks = id(new ManiphestTaskQuery()) + ->withStatus(ManiphestTaskQuery::STATUS_OPEN) + ->execute(); + + $date = phabricator_date(time(), $user); + + switch ($this->view) { + case 'user': + $result = mgroup($tasks, 'getOwnerPHID'); + $leftover = idx($result, '', array()); + unset($result['']); + $leftover_name = phutil_render_tag( + 'a', + array( + 'href' => '/maniphest/?users=PHID-!!!!-UP-FOR-GRABS', + ), + 'Up For Grabs'); + $col_header = 'User'; + $header = 'Open Tasks by User and Priority ('.$date.')'; + $link = '/maniphest/?users='; + break; + case 'project': + $result = array(); + foreach ($tasks as $task) { + $phids = $task->getProjectPHIDs(); + if ($phids) { + foreach ($phids as $project_phid) { + $result[$project_phid][] = $task; + } + } else { + $leftover[] = $task; + } + } + $leftover_name = 'Uncategorized'; + $col_header = 'Project'; + $header = 'Open Tasks by Project and Priority ('.$date.')'; + $link = '/maniphest/view/all/?projects='; + break; + } + + + $phids = array_keys($result); + $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); + $handles = msort($handles, 'getName'); + + $rows = array(); + $pri_total = array(); + foreach (array_merge($handles, array(null)) as $handle) { + if ($handle) { + $tasks = idx($result, $handle->getPHID(), array()); + $name = phutil_render_tag( + 'a', + array( + 'href' => $link.$handle->getPHID(), + ), + phutil_escape_html($handle->getName())); + } else { + $tasks = $leftover; + $name = $leftover_name; + } + + $tasks = mgroup($tasks, 'getPriority'); + + $row = array(); + $row[] = $name; + $total = 0; + foreach (ManiphestTaskPriority::getTaskPriorityMap() as $pri => $label) { + $n = count(idx($tasks, $pri, array())); + if ($n == 0) { + $row[] = '-'; + } else { + $row[] = number_format($n); + } + $total += $n; + } + $row[] = number_format($total); + + $rows[] = $row; + } + + $cname = array($col_header); + $cclass = array('pri right wide'); + foreach (ManiphestTaskPriority::getTaskPriorityMap() as $pri => $label) { + $cname[] = $label; + $cclass[] = 'n'; + } + $cname[] = 'Total'; + $cclass[] = 'n'; + + $table = new AphrontTableView($rows); + $table->setHeaders($cname); + $table->setColumnClasses($cclass); + + $panel = new AphrontPanelView(); + $panel->setHeader($header); + $panel->appendChild($table); + + $nav->appendChild($panel); + + return $this->buildStandardPageResponse( + $nav, + array( + 'title' => 'Maniphest Reports', + )); + } + +} diff --git a/src/applications/maniphest/controller/report/__init__.php b/src/applications/maniphest/controller/report/__init__.php new file mode 100644 index 0000000000..5ebc991da6 --- /dev/null +++ b/src/applications/maniphest/controller/report/__init__.php @@ -0,0 +1,23 @@ +