From c2054bab0916c8a2e876542866adb810cbae682c Mon Sep 17 00:00:00 2001 From: David Reuss Date: Fri, 2 Dec 2011 07:30:20 -0800 Subject: [PATCH] Support limiting maniphest queries to specific ids Summary: This limits a maniphest task query to only contain certain ids set by the tasks query parameter. Test Plan: none yet, i wrote this at a computer with no phabricator install while bored and eating dinner. Reviewers: skrul, epriestley Reviewed By: epriestley CC: aran, davidreuss, epriestley, skrul Differential Revision: 1137 --- .../tasklist/ManiphestTaskListController.php | 26 ++++++++++++++++++- .../controller/tasklist/__init__.php | 1 + .../maniphest/query/ManiphestTaskQuery.php | 18 +++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/applications/maniphest/controller/tasklist/ManiphestTaskListController.php b/src/applications/maniphest/controller/tasklist/ManiphestTaskListController.php index 23f048fcb5..f8bcc2744f 100644 --- a/src/applications/maniphest/controller/tasklist/ManiphestTaskListController.php +++ b/src/applications/maniphest/controller/tasklist/ManiphestTaskListController.php @@ -40,14 +40,17 @@ class ManiphestTaskListController extends ManiphestController { $user_phids = $request->getArr('set_users'); $proj_phids = $request->getArr('set_projects'); + $task_ids = $request->getStr('set_tasks'); $user_phids = implode(',', $user_phids); $proj_phids = implode(',', $proj_phids); $user_phids = nonempty($user_phids, null); $proj_phids = nonempty($proj_phids, null); + $task_ids = nonempty($task_ids, null); $uri = $request->getRequestURI() ->alter('users', $user_phids) - ->alter('projects', $proj_phids); + ->alter('projects', $proj_phids) + ->alter('tasks', $task_ids); return id(new AphrontRedirectResponse())->setURI($uri); } @@ -62,6 +65,8 @@ class ManiphestTaskListController extends ManiphestController { 'All Tasks', 'alltriage' => 'Need Triage', 'all' => 'All Tasks', + '
', + 'custom' => 'Custom', ); if (empty($views[$this->view])) { @@ -116,12 +121,20 @@ class ManiphestTaskListController extends ManiphestController { $project_phids = array(); } + $task_ids = $request->getStr('tasks'); + if (strlen($task_ids)) { + $task_ids = preg_split('/[\s,]+/', $task_ids); + } else { + $task_ids = array(); + } + $page = $request->getInt('page'); $page_size = self::DEFAULT_PAGE_SIZE; list($tasks, $handles, $total_count) = $this->loadTasks( $user_phids, $project_phids, + $task_ids, array( 'status' => $status_map, 'group' => $grouping, @@ -147,6 +160,15 @@ class ManiphestTaskListController extends ManiphestController { ->setValue($tokens)); } + if ($this->view == 'custom') { + $form->appendChild( + id(new AphrontFormTextControl()) + ->setName('set_tasks') + ->setLabel('Task IDs') + ->setValue(join(',', $task_ids)) + ); + } + $tokens = array(); foreach ($project_phids as $phid) { $tokens[$phid] = $handles[$phid]->getFullName(); @@ -258,10 +280,12 @@ class ManiphestTaskListController extends ManiphestController { private function loadTasks( array $user_phids, array $project_phids, + array $task_ids, array $dict) { $query = new ManiphestTaskQuery(); $query->withProjects($project_phids); + $query->withTaskIDs($task_ids); $status = $dict['status']; if (!empty($status['open']) && !empty($status['closed'])) { diff --git a/src/applications/maniphest/controller/tasklist/__init__.php b/src/applications/maniphest/controller/tasklist/__init__.php index 87bd5495f9..4d1fd93445 100644 --- a/src/applications/maniphest/controller/tasklist/__init__.php +++ b/src/applications/maniphest/controller/tasklist/__init__.php @@ -17,6 +17,7 @@ phutil_require_module('phabricator', 'infrastructure/celerity/api'); phutil_require_module('phabricator', 'view/control/pager'); phutil_require_module('phabricator', 'view/form/base'); phutil_require_module('phabricator', 'view/form/control/submit'); +phutil_require_module('phabricator', 'view/form/control/text'); phutil_require_module('phabricator', 'view/form/control/togglebuttons'); phutil_require_module('phabricator', 'view/form/control/tokenizer'); phutil_require_module('phabricator', 'view/layout/listfilter'); diff --git a/src/applications/maniphest/query/ManiphestTaskQuery.php b/src/applications/maniphest/query/ManiphestTaskQuery.php index 4289613735..4e4463eb0b 100644 --- a/src/applications/maniphest/query/ManiphestTaskQuery.php +++ b/src/applications/maniphest/query/ManiphestTaskQuery.php @@ -24,6 +24,7 @@ */ final class ManiphestTaskQuery { + private $taskIDs = array(); private $authorPHIDs = array(); private $ownerPHIDs = array(); private $includeUnowned = null; @@ -63,6 +64,11 @@ final class ManiphestTaskQuery { return $this; } + public function withTaskIDs(array $ids) { + $this->taskIDs = $ids; + return $this; + } + public function withOwners(array $owners) { $this->includeUnowned = false; foreach ($owners as $k => $phid) { @@ -147,6 +153,7 @@ final class ManiphestTaskQuery { } $where = array(); + $where[] = $this->buildTaskIDsWhereClause($conn); $where[] = $this->buildStatusWhereClause($conn); $where[] = $this->buildPriorityWhereClause($conn); $where[] = $this->buildAuthorWhereClause($conn); @@ -227,6 +234,17 @@ final class ManiphestTaskQuery { return $task_dao->loadAllFromArray($data); } + private function buildTaskIDsWhereClause($conn) { + if (!$this->taskIDs) { + return null; + } + + return qsprintf( + $conn, + 'id in (%Ld)', + $this->taskIDs); + } + private function buildStatusWhereClause($conn) { switch ($this->status) { case self::STATUS_ANY: