1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

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
This commit is contained in:
David Reuss 2011-12-02 07:30:20 -08:00 committed by epriestley
parent 19f2110e74
commit c2054bab09
3 changed files with 44 additions and 1 deletions

View file

@ -40,14 +40,17 @@ class ManiphestTaskListController extends ManiphestController {
$user_phids = $request->getArr('set_users'); $user_phids = $request->getArr('set_users');
$proj_phids = $request->getArr('set_projects'); $proj_phids = $request->getArr('set_projects');
$task_ids = $request->getStr('set_tasks');
$user_phids = implode(',', $user_phids); $user_phids = implode(',', $user_phids);
$proj_phids = implode(',', $proj_phids); $proj_phids = implode(',', $proj_phids);
$user_phids = nonempty($user_phids, null); $user_phids = nonempty($user_phids, null);
$proj_phids = nonempty($proj_phids, null); $proj_phids = nonempty($proj_phids, null);
$task_ids = nonempty($task_ids, null);
$uri = $request->getRequestURI() $uri = $request->getRequestURI()
->alter('users', $user_phids) ->alter('users', $user_phids)
->alter('projects', $proj_phids); ->alter('projects', $proj_phids)
->alter('tasks', $task_ids);
return id(new AphrontRedirectResponse())->setURI($uri); return id(new AphrontRedirectResponse())->setURI($uri);
} }
@ -62,6 +65,8 @@ class ManiphestTaskListController extends ManiphestController {
'All Tasks', 'All Tasks',
'alltriage' => 'Need Triage', 'alltriage' => 'Need Triage',
'all' => 'All Tasks', 'all' => 'All Tasks',
'<hr />',
'custom' => 'Custom',
); );
if (empty($views[$this->view])) { if (empty($views[$this->view])) {
@ -116,12 +121,20 @@ class ManiphestTaskListController extends ManiphestController {
$project_phids = array(); $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 = $request->getInt('page');
$page_size = self::DEFAULT_PAGE_SIZE; $page_size = self::DEFAULT_PAGE_SIZE;
list($tasks, $handles, $total_count) = $this->loadTasks( list($tasks, $handles, $total_count) = $this->loadTasks(
$user_phids, $user_phids,
$project_phids, $project_phids,
$task_ids,
array( array(
'status' => $status_map, 'status' => $status_map,
'group' => $grouping, 'group' => $grouping,
@ -147,6 +160,15 @@ class ManiphestTaskListController extends ManiphestController {
->setValue($tokens)); ->setValue($tokens));
} }
if ($this->view == 'custom') {
$form->appendChild(
id(new AphrontFormTextControl())
->setName('set_tasks')
->setLabel('Task IDs')
->setValue(join(',', $task_ids))
);
}
$tokens = array(); $tokens = array();
foreach ($project_phids as $phid) { foreach ($project_phids as $phid) {
$tokens[$phid] = $handles[$phid]->getFullName(); $tokens[$phid] = $handles[$phid]->getFullName();
@ -258,10 +280,12 @@ class ManiphestTaskListController extends ManiphestController {
private function loadTasks( private function loadTasks(
array $user_phids, array $user_phids,
array $project_phids, array $project_phids,
array $task_ids,
array $dict) { array $dict) {
$query = new ManiphestTaskQuery(); $query = new ManiphestTaskQuery();
$query->withProjects($project_phids); $query->withProjects($project_phids);
$query->withTaskIDs($task_ids);
$status = $dict['status']; $status = $dict['status'];
if (!empty($status['open']) && !empty($status['closed'])) { if (!empty($status['open']) && !empty($status['closed'])) {

View file

@ -17,6 +17,7 @@ phutil_require_module('phabricator', 'infrastructure/celerity/api');
phutil_require_module('phabricator', 'view/control/pager'); phutil_require_module('phabricator', 'view/control/pager');
phutil_require_module('phabricator', 'view/form/base'); phutil_require_module('phabricator', 'view/form/base');
phutil_require_module('phabricator', 'view/form/control/submit'); 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/togglebuttons');
phutil_require_module('phabricator', 'view/form/control/tokenizer'); phutil_require_module('phabricator', 'view/form/control/tokenizer');
phutil_require_module('phabricator', 'view/layout/listfilter'); phutil_require_module('phabricator', 'view/layout/listfilter');

View file

@ -24,6 +24,7 @@
*/ */
final class ManiphestTaskQuery { final class ManiphestTaskQuery {
private $taskIDs = array();
private $authorPHIDs = array(); private $authorPHIDs = array();
private $ownerPHIDs = array(); private $ownerPHIDs = array();
private $includeUnowned = null; private $includeUnowned = null;
@ -63,6 +64,11 @@ final class ManiphestTaskQuery {
return $this; return $this;
} }
public function withTaskIDs(array $ids) {
$this->taskIDs = $ids;
return $this;
}
public function withOwners(array $owners) { public function withOwners(array $owners) {
$this->includeUnowned = false; $this->includeUnowned = false;
foreach ($owners as $k => $phid) { foreach ($owners as $k => $phid) {
@ -147,6 +153,7 @@ final class ManiphestTaskQuery {
} }
$where = array(); $where = array();
$where[] = $this->buildTaskIDsWhereClause($conn);
$where[] = $this->buildStatusWhereClause($conn); $where[] = $this->buildStatusWhereClause($conn);
$where[] = $this->buildPriorityWhereClause($conn); $where[] = $this->buildPriorityWhereClause($conn);
$where[] = $this->buildAuthorWhereClause($conn); $where[] = $this->buildAuthorWhereClause($conn);
@ -227,6 +234,17 @@ final class ManiphestTaskQuery {
return $task_dao->loadAllFromArray($data); 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) { private function buildStatusWhereClause($conn) {
switch ($this->status) { switch ($this->status) {
case self::STATUS_ANY: case self::STATUS_ANY: