Differential D17326 Diff 41682 src/applications/dashboard/controller/PhabricatorDashboardManageController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/controller/PhabricatorDashboardManageController.php
<?php | <?php | ||||
final class PhabricatorDashboardManageController | final class PhabricatorDashboardManageController | ||||
extends PhabricatorDashboardController { | extends PhabricatorDashboardProfileController { | ||||
public function shouldAllowPublic() { | |||||
return true; | |||||
} | |||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
$id = $request->getURIData('id'); | $id = $request->getURIData('id'); | ||||
$dashboard_uri = $this->getApplicationURI('view/'.$id.'/'); | |||||
// TODO: This UI should drop a lot of capabilities if the user can't | // TODO: This UI should drop a lot of capabilities if the user can't | ||||
// edit the dashboard, but we should still let them in for "Install" and | // edit the dashboard, but we should still let them in for "Install" and | ||||
// "View History". | // "View History". | ||||
$dashboard = id(new PhabricatorDashboardQuery()) | $dashboard = id(new PhabricatorDashboardQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withIDs(array($id)) | ->withIDs(array($id)) | ||||
->needPanels(true) | ->needPanels(true) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$dashboard) { | if (!$dashboard) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$this->setDashboard($dashboard); | |||||
$can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
$viewer, | $viewer, | ||||
$dashboard, | $dashboard, | ||||
PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
$title = $dashboard->getName(); | $title = $dashboard->getName(); | ||||
$crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
$crumbs->addTextCrumb( | |||||
pht('Dashboard %d', $dashboard->getID()), | |||||
$dashboard_uri); | |||||
$crumbs->addTextCrumb(pht('Manage')); | $crumbs->addTextCrumb(pht('Manage')); | ||||
$crumbs->setBorder(true); | |||||
$header = $this->buildHeaderView($dashboard); | $header = $this->buildHeaderView(); | ||||
$curtain = $this->buildCurtainview($dashboard); | $curtain = $this->buildCurtainview($dashboard); | ||||
$properties = $this->buildPropertyView($dashboard); | $properties = $this->buildPropertyView($dashboard); | ||||
$timeline = $this->buildTransactionTimeline( | $timeline = $this->buildTransactionTimeline( | ||||
$dashboard, | $dashboard, | ||||
new PhabricatorDashboardTransactionQuery()); | new PhabricatorDashboardTransactionQuery()); | ||||
$timeline->setShouldTerminate(true); | |||||
$info_view = null; | $info_view = null; | ||||
if (!$can_edit) { | if (!$can_edit) { | ||||
$no_edit = pht( | $no_edit = pht( | ||||
'You do not have permission to edit this dashboard. If you want to '. | 'You do not have permission to edit this dashboard. If you want to '. | ||||
'make changes, make a copy first.'); | 'make changes, make a copy first.'); | ||||
$info_view = id(new PHUIInfoView()) | $info_view = id(new PHUIInfoView()) | ||||
->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ||||
->setErrors(array($no_edit)); | ->setErrors(array($no_edit)); | ||||
} | } | ||||
$rendered_dashboard = id(new PhabricatorDashboardRenderingEngine()) | |||||
->setViewer($viewer) | |||||
->setDashboard($dashboard) | |||||
->setArrangeMode($can_edit) | |||||
->renderDashboard(); | |||||
$dashboard_box = id(new PHUIBoxView()) | |||||
->addClass('dashboard-preview-box') | |||||
->appendChild($rendered_dashboard); | |||||
$view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
->setHeader($header) | ->setHeader($header) | ||||
->setCurtain($curtain) | ->setCurtain($curtain) | ||||
->setMainColumn(array( | ->setMainColumn(array( | ||||
$info_view, | $info_view, | ||||
$properties, | $properties, | ||||
$timeline, | $timeline, | ||||
)) | )); | ||||
->setFooter($dashboard_box); | |||||
$navigation = $this->buildSideNavView('manage'); | |||||
return $this->newPage() | return $this->newPage() | ||||
->setTitle($title) | ->setTitle($title) | ||||
->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
->setNavigation($navigation) | |||||
->appendChild($view); | ->appendChild($view); | ||||
} | } | ||||
private function buildHeaderView(PhabricatorDashboard $dashboard) { | |||||
$viewer = $this->getViewer(); | |||||
$id = $dashboard->getID(); | |||||
if ($dashboard->isArchived()) { | |||||
$status_icon = 'fa-ban'; | |||||
$status_color = 'dark'; | |||||
} else { | |||||
$status_icon = 'fa-check'; | |||||
$status_color = 'bluegrey'; | |||||
} | |||||
$status_name = idx( | |||||
PhabricatorDashboard::getStatusNameMap(), | |||||
$dashboard->getStatus()); | |||||
$button = id(new PHUIButtonView()) | |||||
->setTag('a') | |||||
->setText(pht('View Dashboard')) | |||||
->setIcon('fa-columns') | |||||
->setHref($this->getApplicationURI("view/{$id}/")); | |||||
return id(new PHUIHeaderView()) | |||||
->setUser($viewer) | |||||
->setHeader($dashboard->getName()) | |||||
->setPolicyObject($dashboard) | |||||
->setStatus($status_icon, $status_color, $status_name) | |||||
->setHeaderIcon($dashboard->getIcon()) | |||||
->addActionLink($button); | |||||
} | |||||
private function buildCurtainView(PhabricatorDashboard $dashboard) { | private function buildCurtainView(PhabricatorDashboard $dashboard) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$id = $dashboard->getID(); | $id = $dashboard->getID(); | ||||
$curtain = $this->newCurtainView($dashboard); | $curtain = $this->newCurtainView($dashboard); | ||||
$can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
$viewer, | $viewer, | ||||
▲ Show 20 Lines • Show All 63 Lines • Show Last 20 Lines |