Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / meta / controller / PhabricatorApplicationDetailViewController.php
blob8be6d73a1d1f0e894d5b8313aeaaa8534d359dd5
1 <?php
3 final class PhabricatorApplicationDetailViewController
4 extends PhabricatorApplicationsController {
7 public function shouldAllowPublic() {
8 return true;
11 public function handleRequest(AphrontRequest $request) {
12 $viewer = $this->getViewer();
13 $application = $request->getURIData('application');
15 $selected = id(new PhabricatorApplicationQuery())
16 ->setViewer($viewer)
17 ->withClasses(array($application))
18 ->executeOne();
19 if (!$selected) {
20 return new Aphront404Response();
23 $title = $selected->getName();
25 $crumbs = $this->buildApplicationCrumbs();
26 $crumbs->addTextCrumb($selected->getName());
27 $crumbs->setBorder(true);
29 $header = id(new PHUIHeaderView())
30 ->setHeader($title)
31 ->setUser($viewer)
32 ->setPolicyObject($selected)
33 ->setHeaderIcon($selected->getIcon());
35 if ($selected->isInstalled()) {
36 $header->setStatus('fa-check', 'bluegrey', pht('Installed'));
37 } else {
38 $header->setStatus('fa-ban', 'dark', pht('Uninstalled'));
41 $timeline = $this->buildTransactionTimeline(
42 $selected,
43 new PhabricatorApplicationApplicationTransactionQuery());
44 $timeline->setShouldTerminate(true);
46 $curtain = $this->buildCurtain($selected);
47 $details = $this->buildPropertySectionView($selected);
48 $policies = $this->buildPolicyView($selected);
50 $configs =
51 PhabricatorApplicationConfigurationPanel::loadAllPanelsForApplication(
52 $selected);
54 $panels = array();
55 foreach ($configs as $config) {
56 $config->setViewer($viewer);
57 $config->setApplication($selected);
58 $panel = $config->buildConfigurationPagePanel();
59 $panel->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
60 $panels[] = $panel;
63 $view = id(new PHUITwoColumnView())
64 ->setHeader($header)
65 ->setCurtain($curtain)
66 ->setMainColumn(array(
67 $policies,
68 $panels,
69 $timeline,
71 ->addPropertySection(pht('Details'), $details);
73 return $this->newPage()
74 ->setTitle($title)
75 ->setCrumbs($crumbs)
76 ->appendChild(
77 array(
78 $view,
79 ));
82 private function buildPropertySectionView(
83 PhabricatorApplication $application) {
85 $viewer = $this->getViewer();
86 $properties = id(new PHUIPropertyListView());
88 $properties->addProperty(
89 pht('Description'),
90 $application->getShortDescription());
92 if ($application->getFlavorText()) {
93 $properties->addProperty(
94 null,
95 phutil_tag('em', array(), $application->getFlavorText()));
98 if ($application->isPrototype()) {
99 $proto_href = PhabricatorEnv::getDoclink(
100 'User Guide: Prototype Applications');
101 $learn_more = phutil_tag(
102 'a',
103 array(
104 'href' => $proto_href,
105 'target' => '_blank',
107 pht('Learn More'));
109 $properties->addProperty(
110 pht('Prototype'),
111 pht(
112 'This application is a prototype. %s',
113 $learn_more));
116 $overview = $application->getOverview();
117 if (strlen($overview)) {
118 $overview = new PHUIRemarkupView($viewer, $overview);
119 $properties->addSectionHeader(
120 pht('Overview'), PHUIPropertyListView::ICON_SUMMARY);
121 $properties->addTextContent($overview);
124 return $properties;
127 private function buildPolicyView(
128 PhabricatorApplication $application) {
130 $viewer = $this->getViewer();
131 $properties = id(new PHUIPropertyListView());
133 $header = id(new PHUIHeaderView())
134 ->setHeader(pht('Policies'));
136 $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
137 $viewer,
138 $application);
140 foreach ($application->getCapabilities() as $capability) {
141 $properties->addProperty(
142 $application->getCapabilityLabel($capability),
143 idx($descriptions, $capability));
146 return id(new PHUIObjectBoxView())
147 ->setHeader($header)
148 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
149 ->appendChild($properties);
153 private function buildCurtain(PhabricatorApplication $application) {
154 $viewer = $this->getViewer();
156 $can_edit = PhabricatorPolicyFilter::hasCapability(
157 $viewer,
158 $application,
159 PhabricatorPolicyCapability::CAN_EDIT);
161 $key = get_class($application);
162 $edit_uri = $this->getApplicationURI("edit/{$key}/");
163 $install_uri = $this->getApplicationURI("{$key}/install/");
164 $uninstall_uri = $this->getApplicationURI("{$key}/uninstall/");
166 $curtain = $this->newCurtainView($application);
168 $curtain->addAction(
169 id(new PhabricatorActionView())
170 ->setName(pht('Edit Policies'))
171 ->setIcon('fa-pencil')
172 ->setDisabled(!$can_edit)
173 ->setWorkflow(!$can_edit)
174 ->setHref($edit_uri));
176 if ($application->canUninstall()) {
177 if ($application->isInstalled()) {
178 $curtain->addAction(
179 id(new PhabricatorActionView())
180 ->setName(pht('Uninstall'))
181 ->setIcon('fa-times')
182 ->setDisabled(!$can_edit)
183 ->setWorkflow(true)
184 ->setHref($uninstall_uri));
185 } else {
186 $action = id(new PhabricatorActionView())
187 ->setName(pht('Install'))
188 ->setIcon('fa-plus')
189 ->setDisabled(!$can_edit)
190 ->setWorkflow(true)
191 ->setHref($install_uri);
193 $prototypes_enabled = PhabricatorEnv::getEnvConfig(
194 'phabricator.show-prototypes');
195 if ($application->isPrototype() && !$prototypes_enabled) {
196 $action->setDisabled(true);
199 $curtain->addAction($action);
201 } else {
202 $curtain->addAction(
203 id(new PhabricatorActionView())
204 ->setName(pht('Uninstall'))
205 ->setIcon('fa-times')
206 ->setWorkflow(true)
207 ->setDisabled(true)
208 ->setHref($uninstall_uri));
211 return $curtain;