Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/view/AlmanacBindingTableView.php
12256 views
1
<?php
2
3
final class AlmanacBindingTableView extends AphrontView {
4
5
private $bindings;
6
private $noDataString;
7
8
private $hideServiceColumn;
9
10
public function setNoDataString($no_data_string) {
11
$this->noDataString = $no_data_string;
12
return $this;
13
}
14
15
public function getNoDataString() {
16
return $this->noDataString;
17
}
18
19
public function setBindings(array $bindings) {
20
$this->bindings = $bindings;
21
return $this;
22
}
23
24
public function getBindings() {
25
return $this->bindings;
26
}
27
28
public function setHideServiceColumn($hide_service_column) {
29
$this->hideServiceColumn = $hide_service_column;
30
return $this;
31
}
32
33
public function getHideServiceColumn() {
34
return $this->hideServiceColumn;
35
}
36
37
public function render() {
38
$bindings = $this->getBindings();
39
$viewer = $this->getUser();
40
41
$phids = array();
42
foreach ($bindings as $binding) {
43
$phids[] = $binding->getServicePHID();
44
$phids[] = $binding->getDevicePHID();
45
$phids[] = $binding->getInterface()->getNetworkPHID();
46
}
47
$handles = $viewer->loadHandles($phids);
48
49
$icon_disabled = id(new PHUIIconView())
50
->setIcon('fa-ban')
51
->addSigil('has-tooltip')
52
->setMetadata(
53
array(
54
'tip' => pht('Disabled'),
55
));
56
57
$icon_active = id(new PHUIIconView())
58
->setIcon('fa-check')
59
->setColor('green')
60
->addSigil('has-tooltip')
61
->setMetadata(
62
array(
63
'tip' => pht('Active'),
64
));
65
66
$icon_device_disabled = id(new PHUIIconView())
67
->setIcon('fa-times')
68
->setColor('grey')
69
->addSigil('has-tooltip')
70
->setMetadata(
71
array(
72
'tip' => pht('Device Disabled'),
73
));
74
75
$rows = array();
76
foreach ($bindings as $binding) {
77
$addr = $binding->getInterface()->getAddress();
78
$port = $binding->getInterface()->getPort();
79
80
$device = $binding->getDevice();
81
if ($device->isDisabled()) {
82
$binding_icon = $icon_device_disabled;
83
} else if ($binding->getIsDisabled()) {
84
$binding_icon = $icon_disabled;
85
} else {
86
$binding_icon = $icon_active;
87
}
88
89
$rows[] = array(
90
$binding->getID(),
91
$binding_icon,
92
$handles->renderHandle($binding->getServicePHID()),
93
94
$handles->renderHandle($binding->getDevicePHID()),
95
$handles->renderHandle($binding->getInterface()->getNetworkPHID()),
96
$binding->getInterface()->renderDisplayAddress(),
97
phutil_tag(
98
'a',
99
array(
100
'class' => 'small button button-grey',
101
'href' => '/almanac/binding/'.$binding->getID().'/',
102
),
103
pht('Details')),
104
);
105
}
106
107
$table = id(new AphrontTableView($rows))
108
->setNoDataString($this->getNoDataString())
109
->setHeaders(
110
array(
111
pht('ID'),
112
null,
113
pht('Service'),
114
pht('Device'),
115
pht('Network'),
116
pht('Interface'),
117
null,
118
))
119
->setColumnClasses(
120
array(
121
'',
122
'icon',
123
'',
124
'',
125
'',
126
'wide',
127
'action',
128
))
129
->setColumnVisibility(
130
array(
131
true,
132
true,
133
!$this->getHideServiceColumn(),
134
));
135
136
return $table;
137
}
138
139
}
140
141