Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / controller / AlmanacServiceViewController.php
blob3cb74514632fb639d0b73c8db23f4981b31af259
1 <?php
3 final class AlmanacServiceViewController
4 extends AlmanacServiceController {
6 public function shouldAllowPublic() {
7 return true;
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
13 $name = $request->getURIData('name');
15 $service = id(new AlmanacServiceQuery())
16 ->setViewer($viewer)
17 ->withNames(array($name))
18 ->needProperties(true)
19 ->executeOne();
20 if (!$service) {
21 return new Aphront404Response();
24 $title = pht('Service %s', $service->getName());
26 $curtain = $this->buildCurtain($service);
27 $details = $this->buildPropertySection($service);
29 $header = id(new PHUIHeaderView())
30 ->setUser($viewer)
31 ->setHeader($service->getName())
32 ->setPolicyObject($service)
33 ->setHeaderIcon('fa-plug');
35 $issue = null;
36 if ($service->isClusterService()) {
37 $issue = $this->addClusterMessage(
38 pht('This is a cluster service.'),
39 pht(
40 'This service is a cluster service. You do not have permission to '.
41 'edit cluster services, so you can not edit this service.'));
44 $bindings = $this->buildBindingList($service);
46 $crumbs = $this->buildApplicationCrumbs();
47 $crumbs->addTextCrumb($service->getName());
48 $crumbs->setBorder(true);
50 $timeline = $this->buildTransactionTimeline(
51 $service,
52 new AlmanacServiceTransactionQuery());
53 $timeline->setShouldTerminate(true);
55 $view = id(new PHUITwoColumnView())
56 ->setHeader($header)
57 ->setCurtain($curtain)
58 ->setMainColumn(array(
59 $issue,
60 $details,
61 $bindings,
62 $this->buildAlmanacPropertiesTable($service),
63 $timeline,
64 ));
66 return $this->newPage()
67 ->setTitle($title)
68 ->setCrumbs($crumbs)
69 ->appendChild($view);
72 private function buildPropertySection(
73 AlmanacService $service) {
74 $viewer = $this->getViewer();
76 $properties = id(new PHUIPropertyListView())
77 ->setUser($viewer);
79 $properties->addProperty(
80 pht('Service Type'),
81 $service->getServiceImplementation()->getServiceTypeShortName());
83 return id(new PHUIObjectBoxView())
84 ->setHeaderText(pht('Details'))
85 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
86 ->appendChild($properties);
89 private function buildCurtain(AlmanacService $service) {
90 $viewer = $this->getViewer();
92 $can_edit = PhabricatorPolicyFilter::hasCapability(
93 $viewer,
94 $service,
95 PhabricatorPolicyCapability::CAN_EDIT);
97 $id = $service->getID();
98 $edit_uri = $this->getApplicationURI("service/edit/{$id}/");
100 $curtain = $this->newCurtainView($service);
102 $curtain->addAction(
103 id(new PhabricatorActionView())
104 ->setIcon('fa-pencil')
105 ->setName(pht('Edit Service'))
106 ->setHref($edit_uri)
107 ->setWorkflow(!$can_edit)
108 ->setDisabled(!$can_edit));
110 return $curtain;
113 private function buildBindingList(AlmanacService $service) {
114 $viewer = $this->getViewer();
115 $id = $service->getID();
117 $can_edit = PhabricatorPolicyFilter::hasCapability(
118 $viewer,
119 $service,
120 PhabricatorPolicyCapability::CAN_EDIT);
122 $bindings = id(new AlmanacBindingQuery())
123 ->setViewer($viewer)
124 ->withServicePHIDs(array($service->getPHID()))
125 ->execute();
127 $table = id(new AlmanacBindingTableView())
128 ->setNoDataString(
129 pht('This service has not been bound to any device interfaces yet.'))
130 ->setUser($viewer)
131 ->setBindings($bindings)
132 ->setHideServiceColumn(true);
134 $header = id(new PHUIHeaderView())
135 ->setHeader(pht('Service Bindings'))
136 ->addActionLink(
137 id(new PHUIButtonView())
138 ->setTag('a')
139 ->setHref($this->getApplicationURI("binding/edit/?serviceID={$id}"))
140 ->setWorkflow(!$can_edit)
141 ->setDisabled(!$can_edit)
142 ->setText(pht('Add Binding'))
143 ->setIcon('fa-plus'));
145 return id(new PHUIObjectBoxView())
146 ->setHeader($header)
147 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
148 ->setTable($table);