forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorHovercardView.php
170 lines (143 loc) · 3.98 KB
/
PhabricatorHovercardView.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
<?php
/**
* The default one-for-all hovercard. We may derive from this one to create
* more specialized ones
*/
final class PhabricatorHovercardView extends AphrontView {
/**
* @var PhabricatorObjectHandle
*/
private $handle;
private $title = array();
private $detail;
private $tags = array();
private $fields = array();
private $actions = array();
private $color = 'lightblue';
public function setObjectHandle(PhabricatorObjectHandle $handle) {
$this->handle = $handle;
return $this;
}
public function setTitle($title) {
$this->title = $title;
return $this;
}
public function setDetail($detail) {
$this->detail = $detail;
return $this;
}
public function addField($label, $value) {
$this->fields[] = array(
'label' => $label,
'value' => $value,
);
return $this;
}
public function addAction($label, $uri, $workflow = false) {
$this->actions[] = array(
'label' => $label,
'uri' => $uri,
'workflow' => $workflow,
);
return $this;
}
public function addTag(PHUITagView $tag) {
$this->tags[] = $tag;
return $this;
}
public function setColor($color) {
$this->color = $color;
return $this;
}
public function render() {
if (!$this->handle) {
throw new Exception('Call setObjectHandle() before calling render()!');
}
$handle = $this->handle;
require_celerity_resource('phabricator-hovercard-view-css');
$title = pht('%s: %s',
$handle->getTypeName(),
$this->title ? $this->title : $handle->getName());
$header = new PHUIActionHeaderView();
$header->setHeaderColor($this->color);
$header->setHeaderTitle($title);
if ($this->tags) {
foreach ($this->tags as $tag) {
$header->setTag($tag);
}
}
$body = array();
if ($this->detail) {
$body_title = $this->detail;
} else {
// Fallback for object handles
$body_title = $handle->getFullName();
}
$body[] = phutil_tag_div('phabricator-hovercard-body-header', $body_title);
foreach ($this->fields as $field) {
$item = array(
phutil_tag('strong', array(), $field['label']),
' ',
phutil_tag('span', array(), $field['value']),
);
$body[] = phutil_tag_div('phabricator-hovercard-body-item', $item);
}
if ($handle->getImageURI()) {
// Probably a user, we don't need to assume something else
// "Prepend" the image by appending $body
$body = phutil_tag(
'div',
array(
'class' => 'phabricator-hovercard-body-image'),
phutil_tag(
'div',
array(
'class' => 'profile-header-picture-frame',
'style' => 'background-image: url('.$handle->getImageURI().');',
),
''))
->appendHTML(
phutil_tag(
'div',
array(
'class' => 'phabricator-hovercard-body-details',
),
$body));
}
$buttons = array();
foreach ($this->actions as $action) {
$options = array(
'class' => 'button grey',
'href' => $action['uri'],
);
if ($action['workflow']) {
$options['sigil'] = 'workflow';
$buttons[] = javelin_tag(
'a',
$options,
$action['label']);
} else {
$buttons[] = phutil_tag(
'a',
$options,
$action['label']);
}
}
$tail = null;
if ($buttons) {
$tail = phutil_tag_div('phabricator-hovercard-tail', $buttons);
}
// Assemble container
// TODO: Add color support
$hovercard = phutil_tag_div(
'phabricator-hovercard-container',
array(
phutil_tag_div('phabricator-hovercard-head', $header),
phutil_tag_div('phabricator-hovercard-body grouped', $body),
$tail,
));
// Wrap for thick border
// and later the tip at the bottom
return phutil_tag_div('phabricator-hovercard-wrapper', $hovercard);
}
}