forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorProjectUserListView.php
183 lines (143 loc) · 4.5 KB
/
PhabricatorProjectUserListView.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
abstract class PhabricatorProjectUserListView
extends AphrontView {
private $project;
private $userPHIDs;
private $limit;
private $background;
private $showNote;
public function setProject(PhabricatorProject $project) {
$this->project = $project;
return $this;
}
public function getProject() {
return $this->project;
}
public function setUserPHIDs(array $user_phids) {
$this->userPHIDs = $user_phids;
return $this;
}
public function getUserPHIDs() {
return $this->userPHIDs;
}
public function setLimit($limit) {
$this->limit = $limit;
return $this;
}
public function getLimit() {
return $this->limit;
}
public function setBackground($color) {
$this->background = $color;
return $this;
}
public function setShowNote($show) {
$this->showNote = $show;
return $this;
}
abstract protected function canEditList();
abstract protected function getNoDataString();
abstract protected function getRemoveURI($phid);
abstract protected function getHeaderText();
abstract protected function getMembershipNote();
public function render() {
$viewer = $this->getViewer();
$project = $this->getProject();
$user_phids = $this->getUserPHIDs();
$can_edit = $this->canEditList();
$supports_edit = $project->supportsEditMembers();
$no_data = $this->getNoDataString();
$list = id(new PHUIObjectItemListView())
->setNoDataString($no_data);
$limit = $this->getLimit();
$is_panel = (bool)$limit;
$handles = $viewer->loadHandles($user_phids);
// Reorder users in display order. We're going to put the viewer first
// if they're a member, then enabled users, then disabled/invalid users.
$phid_map = array();
foreach ($user_phids as $user_phid) {
$handle = $handles[$user_phid];
$is_viewer = ($user_phid === $viewer->getPHID());
$is_enabled = ($handle->isComplete() && !$handle->isDisabled());
// If we're showing the main member list, show oldest to newest. If we're
// showing only a slice in a panel, show newest to oldest.
if ($limit) {
$order_scalar = 1;
} else {
$order_scalar = -1;
}
$phid_map[$user_phid] = id(new PhutilSortVector())
->addInt($is_viewer ? 0 : 1)
->addInt($is_enabled ? 0 : 1)
->addInt($order_scalar * count($phid_map));
}
$phid_map = msortv($phid_map, 'getSelf');
$handles = iterator_to_array($handles);
$handles = array_select_keys($handles, array_keys($phid_map));
if ($limit) {
$handles = array_slice($handles, 0, $limit);
}
foreach ($handles as $user_phid => $handle) {
$item = id(new PHUIObjectItemView())
->setHeader($handle->getFullName())
->setHref($handle->getURI())
->setImageURI($handle->getImageURI());
if ($handle->isDisabled()) {
if ($is_panel) {
// Don't show disabled users in the panel view at all.
continue;
}
$item
->setDisabled(true)
->addAttribute(pht('Disabled'));
} else {
$icon = id(new PHUIIconView())
->setIcon($handle->getIcon());
$subtitle = $handle->getSubtitle();
$item->addAttribute(array($icon, ' ', $subtitle));
}
if ($supports_edit && !$is_panel) {
$remove_uri = $this->getRemoveURI($user_phid);
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-times')
->setName(pht('Remove'))
->setHref($remove_uri)
->setDisabled(!$can_edit)
->setWorkflow(true));
}
$list->addItem($item);
}
if ($user_phids) {
$header_text = pht(
'%s (%s)',
$this->getHeaderText(),
phutil_count($user_phids));
} else {
$header_text = $this->getHeaderText();
}
$id = $project->getID();
$header = id(new PHUIHeaderView())
->setHeader($header_text);
if ($limit) {
$list->newTailButton()
->setText(pht('View All'))
->setHref("/project/members/{$id}/");
}
$box = id(new PHUIObjectBoxView())
->setHeader($header)
->setObjectList($list);
if ($this->showNote) {
if ($this->getMembershipNote()) {
$info = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_PLAIN)
->appendChild($this->getMembershipNote());
$box->setInfoView($info);
}
}
if ($this->background) {
$box->setBackground($this->background);
}
return $box;
}
}