Path: blob/master/src/applications/almanac/controller/AlmanacServiceViewController.php
12256 views
<?php12final class AlmanacServiceViewController3extends AlmanacServiceController {45public function shouldAllowPublic() {6return true;7}89public function handleRequest(AphrontRequest $request) {10$viewer = $request->getViewer();1112$name = $request->getURIData('name');1314$service = id(new AlmanacServiceQuery())15->setViewer($viewer)16->withNames(array($name))17->needProperties(true)18->executeOne();19if (!$service) {20return new Aphront404Response();21}2223$title = pht('Service %s', $service->getName());2425$curtain = $this->buildCurtain($service);26$details = $this->buildPropertySection($service);2728$header = id(new PHUIHeaderView())29->setUser($viewer)30->setHeader($service->getName())31->setPolicyObject($service)32->setHeaderIcon('fa-plug');3334$issue = null;35if ($service->isClusterService()) {36$issue = $this->addClusterMessage(37pht('This is a cluster service.'),38pht(39'This service is a cluster service. You do not have permission to '.40'edit cluster services, so you can not edit this service.'));41}4243$bindings = $this->buildBindingList($service);4445$crumbs = $this->buildApplicationCrumbs();46$crumbs->addTextCrumb($service->getName());47$crumbs->setBorder(true);4849$timeline = $this->buildTransactionTimeline(50$service,51new AlmanacServiceTransactionQuery());52$timeline->setShouldTerminate(true);5354$view = id(new PHUITwoColumnView())55->setHeader($header)56->setCurtain($curtain)57->setMainColumn(array(58$issue,59$details,60$bindings,61$this->buildAlmanacPropertiesTable($service),62$timeline,63));6465return $this->newPage()66->setTitle($title)67->setCrumbs($crumbs)68->appendChild($view);69}7071private function buildPropertySection(72AlmanacService $service) {73$viewer = $this->getViewer();7475$properties = id(new PHUIPropertyListView())76->setUser($viewer);7778$properties->addProperty(79pht('Service Type'),80$service->getServiceImplementation()->getServiceTypeShortName());8182return id(new PHUIObjectBoxView())83->setHeaderText(pht('Details'))84->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)85->appendChild($properties);86}8788private function buildCurtain(AlmanacService $service) {89$viewer = $this->getViewer();9091$can_edit = PhabricatorPolicyFilter::hasCapability(92$viewer,93$service,94PhabricatorPolicyCapability::CAN_EDIT);9596$id = $service->getID();97$edit_uri = $this->getApplicationURI("service/edit/{$id}/");9899$curtain = $this->newCurtainView($service);100101$curtain->addAction(102id(new PhabricatorActionView())103->setIcon('fa-pencil')104->setName(pht('Edit Service'))105->setHref($edit_uri)106->setWorkflow(!$can_edit)107->setDisabled(!$can_edit));108109return $curtain;110}111112private function buildBindingList(AlmanacService $service) {113$viewer = $this->getViewer();114$id = $service->getID();115116$can_edit = PhabricatorPolicyFilter::hasCapability(117$viewer,118$service,119PhabricatorPolicyCapability::CAN_EDIT);120121$bindings = id(new AlmanacBindingQuery())122->setViewer($viewer)123->withServicePHIDs(array($service->getPHID()))124->execute();125126$table = id(new AlmanacBindingTableView())127->setNoDataString(128pht('This service has not been bound to any device interfaces yet.'))129->setUser($viewer)130->setBindings($bindings)131->setHideServiceColumn(true);132133$header = id(new PHUIHeaderView())134->setHeader(pht('Service Bindings'))135->addActionLink(136id(new PHUIButtonView())137->setTag('a')138->setHref($this->getApplicationURI("binding/edit/?serviceID={$id}"))139->setWorkflow(!$can_edit)140->setDisabled(!$can_edit)141->setText(pht('Add Binding'))142->setIcon('fa-plus'));143144return id(new PHUIObjectBoxView())145->setHeader($header)146->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)147->setTable($table);148}149150}151152153