1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-21 21:10:56 +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');
$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',
'<hr />',
'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'])) {

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/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');

View file

@ -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: