Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/maniphest/view/ManiphestTaskResultListView.php
12256 views
1
<?php
2
3
final class ManiphestTaskResultListView extends ManiphestView {
4
5
private $tasks;
6
private $savedQuery;
7
private $canBatchEdit;
8
private $showBatchControls;
9
10
public function setSavedQuery(PhabricatorSavedQuery $query) {
11
$this->savedQuery = $query;
12
return $this;
13
}
14
15
public function setTasks(array $tasks) {
16
$this->tasks = $tasks;
17
return $this;
18
}
19
20
public function setCanBatchEdit($can_batch_edit) {
21
$this->canBatchEdit = $can_batch_edit;
22
return $this;
23
}
24
25
public function setShowBatchControls($show_batch_controls) {
26
$this->showBatchControls = $show_batch_controls;
27
return $this;
28
}
29
30
public function render() {
31
$viewer = $this->getUser();
32
$tasks = $this->tasks;
33
$query = $this->savedQuery;
34
35
// If we didn't match anything, just pick up the default empty state.
36
if (!$tasks) {
37
return id(new PHUIObjectItemListView())
38
->setUser($viewer)
39
->setNoDataString(pht('No tasks found.'));
40
}
41
42
$group_parameter = nonempty($query->getParameter('group'), 'priority');
43
$order_parameter = nonempty($query->getParameter('order'), 'priority');
44
45
$handles = ManiphestTaskListView::loadTaskHandles($viewer, $tasks);
46
$groups = $this->groupTasks(
47
$tasks,
48
$group_parameter,
49
$handles);
50
51
$result = array();
52
53
$lists = array();
54
foreach ($groups as $group => $list) {
55
$task_list = new ManiphestTaskListView();
56
$task_list->setShowBatchControls($this->showBatchControls);
57
$task_list->setUser($viewer);
58
$task_list->setTasks($list);
59
$task_list->setHandles($handles);
60
61
$header = id(new PHUIHeaderView())
62
->addSigil('task-group')
63
->setMetadata(array('priority' => head($list)->getPriority()))
64
->setHeader(pht('%s (%s)', $group, phutil_count($list)));
65
66
$lists[] = id(new PHUIObjectBoxView())
67
->setHeader($header)
68
->setObjectList($task_list);
69
70
}
71
72
return array(
73
$lists,
74
$this->showBatchControls ? $this->renderBatchEditor($query) : null,
75
);
76
}
77
78
79
private function groupTasks(array $tasks, $group, array $handles) {
80
assert_instances_of($tasks, 'ManiphestTask');
81
assert_instances_of($handles, 'PhabricatorObjectHandle');
82
83
$groups = $this->getTaskGrouping($tasks, $group);
84
85
$results = array();
86
foreach ($groups as $label_key => $tasks) {
87
$label = $this->getTaskLabelName($group, $label_key, $handles);
88
$results[$label][] = $tasks;
89
}
90
foreach ($results as $label => $task_groups) {
91
$results[$label] = array_mergev($task_groups);
92
}
93
94
return $results;
95
}
96
97
private function getTaskGrouping(array $tasks, $group) {
98
switch ($group) {
99
case 'priority':
100
return mgroup($tasks, 'getPriority');
101
case 'status':
102
return mgroup($tasks, 'getStatus');
103
case 'assigned':
104
return mgroup($tasks, 'getOwnerPHID');
105
case 'project':
106
return mgroup($tasks, 'getGroupByProjectPHID');
107
default:
108
return array(pht('Tasks') => $tasks);
109
}
110
}
111
112
private function getTaskLabelName($group, $label_key, array $handles) {
113
switch ($group) {
114
case 'priority':
115
return ManiphestTaskPriority::getTaskPriorityName($label_key);
116
case 'status':
117
return ManiphestTaskStatus::getTaskStatusFullName($label_key);
118
case 'assigned':
119
if ($label_key) {
120
return $handles[$label_key]->getFullName();
121
} else {
122
return pht('(Not Assigned)');
123
}
124
case 'project':
125
if ($label_key) {
126
return $handles[$label_key]->getFullName();
127
} else {
128
// This may mean "No Projects", or it may mean the query has project
129
// constraints but the task is only in constrained projects (in this
130
// case, we don't show the group because it would always have all
131
// of the tasks). Since distinguishing between these two cases is
132
// messy and the UI is reasonably clear, label generically.
133
return pht('(Ungrouped)');
134
}
135
default:
136
return pht('Tasks');
137
}
138
}
139
140
private function renderBatchEditor(PhabricatorSavedQuery $saved_query) {
141
$user = $this->getUser();
142
143
if (!$this->canBatchEdit) {
144
return null;
145
}
146
147
if (!$user->isLoggedIn()) {
148
// Don't show the batch editor for logged-out users.
149
return null;
150
}
151
152
Javelin::initBehavior(
153
'maniphest-batch-selector',
154
array(
155
'selectAll' => 'batch-select-all',
156
'selectNone' => 'batch-select-none',
157
'submit' => 'batch-select-submit',
158
'status' => 'batch-select-status-cell',
159
'idContainer' => 'batch-select-id-container',
160
'formID' => 'batch-select-form',
161
));
162
163
$select_all = javelin_tag(
164
'a',
165
array(
166
'href' => '#',
167
'mustcapture' => true,
168
'class' => 'button button-grey',
169
'id' => 'batch-select-all',
170
),
171
pht('Select All'));
172
173
$select_none = javelin_tag(
174
'a',
175
array(
176
'href' => '#',
177
'mustcapture' => true,
178
'class' => 'button button-grey',
179
'id' => 'batch-select-none',
180
),
181
pht('Clear Selection'));
182
183
$submit = phutil_tag(
184
'button',
185
array(
186
'id' => 'batch-select-submit',
187
'disabled' => 'disabled',
188
'class' => 'disabled',
189
),
190
pht("Bulk Edit Selected \xC2\xBB"));
191
192
$hidden = phutil_tag(
193
'div',
194
array(
195
'id' => 'batch-select-id-container',
196
),
197
'');
198
199
$editor = hsprintf(
200
'<table class="maniphest-batch-editor-layout">'.
201
'<tr>'.
202
'<td>%s%s</td>'.
203
'<td id="batch-select-status-cell">%s</td>'.
204
'<td class="batch-select-submit-cell">%s%s</td>'.
205
'</tr>'.
206
'</table>',
207
$select_all,
208
$select_none,
209
'',
210
$submit,
211
$hidden);
212
213
$editor = phabricator_form(
214
$user,
215
array(
216
'method' => 'POST',
217
'action' => '/maniphest/bulk/',
218
'id' => 'batch-select-form',
219
),
220
$editor);
221
222
$box = id(new PHUIObjectBoxView())
223
->setHeaderText(pht('Batch Task Editor'))
224
->appendChild($editor);
225
226
$content = phutil_tag_div('maniphest-batch-editor', $box);
227
228
return $content;
229
}
230
}
231
232