[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorDashboardManageController 4 extends PhabricatorDashboardController { 5 6 private $id; 7 8 public function willProcessRequest(array $data) { 9 $this->id = $data['id']; 10 } 11 12 public function processRequest() { 13 $request = $this->getRequest(); 14 $viewer = $request->getUser(); 15 $id = $this->id; 16 $dashboard_uri = $this->getApplicationURI('view/'.$id.'/'); 17 18 // TODO: This UI should drop a lot of capabilities if the user can't 19 // edit the dashboard, but we should still let them in for "Install" and 20 // "View History". 21 22 $dashboard = id(new PhabricatorDashboardQuery()) 23 ->setViewer($viewer) 24 ->withIDs(array($this->id)) 25 ->needPanels(true) 26 ->executeOne(); 27 if (!$dashboard) { 28 return new Aphront404Response(); 29 } 30 31 $can_edit = PhabricatorPolicyFilter::hasCapability( 32 $viewer, 33 $dashboard, 34 PhabricatorPolicyCapability::CAN_EDIT); 35 36 $title = $dashboard->getName(); 37 38 $crumbs = $this->buildApplicationCrumbs(); 39 $crumbs->addTextCrumb( 40 pht('Dashboard %d', $dashboard->getID()), 41 $dashboard_uri); 42 $crumbs->addTextCrumb(pht('Manage')); 43 44 $header = $this->buildHeaderView($dashboard); 45 $actions = $this->buildActionView($dashboard); 46 $properties = $this->buildPropertyView($dashboard); 47 48 $properties->setActionList($actions); 49 $box = id(new PHUIObjectBoxView()) 50 ->setHeader($header) 51 ->addPropertyList($properties); 52 53 if (!$can_edit) { 54 $no_edit = pht( 55 'You do not have permission to edit this dashboard. If you want to '. 56 'make changes, make a copy first.'); 57 58 $box->setErrorView( 59 id(new AphrontErrorView()) 60 ->setSeverity(AphrontErrorView::SEVERITY_NOTICE) 61 ->setErrors(array($no_edit))); 62 } 63 64 $rendered_dashboard = id(new PhabricatorDashboardRenderingEngine()) 65 ->setViewer($viewer) 66 ->setDashboard($dashboard) 67 ->setArrangeMode($can_edit) 68 ->renderDashboard(); 69 70 return $this->buildApplicationPage( 71 array( 72 $crumbs, 73 $box, 74 $rendered_dashboard, 75 ), 76 array( 77 'title' => $title, 78 )); 79 } 80 81 private function buildHeaderView(PhabricatorDashboard $dashboard) { 82 $viewer = $this->getRequest()->getUser(); 83 84 return id(new PHUIHeaderView()) 85 ->setUser($viewer) 86 ->setHeader($dashboard->getName()) 87 ->setPolicyObject($dashboard); 88 } 89 90 private function buildActionView(PhabricatorDashboard $dashboard) { 91 $viewer = $this->getRequest()->getUser(); 92 $id = $dashboard->getID(); 93 94 $actions = id(new PhabricatorActionListView()) 95 ->setObjectURI($this->getApplicationURI('view/'.$dashboard->getID().'/')) 96 ->setUser($viewer); 97 98 $can_edit = PhabricatorPolicyFilter::hasCapability( 99 $viewer, 100 $dashboard, 101 PhabricatorPolicyCapability::CAN_EDIT); 102 103 $actions->addAction( 104 id(new PhabricatorActionView()) 105 ->setName(pht('View Dashboard')) 106 ->setIcon('fa-columns') 107 ->setHref($this->getApplicationURI("view/{$id}/"))); 108 109 $actions->addAction( 110 id(new PhabricatorActionView()) 111 ->setName(pht('Edit Dashboard')) 112 ->setIcon('fa-pencil') 113 ->setHref($this->getApplicationURI("edit/{$id}/")) 114 ->setDisabled(!$can_edit) 115 ->setWorkflow(!$can_edit)); 116 117 $actions->addAction( 118 id(new PhabricatorActionView()) 119 ->setName(pht('Copy Dashboard')) 120 ->setIcon('fa-files-o') 121 ->setHref($this->getApplicationURI("copy/{$id}/")) 122 ->setWorkflow(true)); 123 124 $installed_dashboard = id(new PhabricatorDashboardInstall()) 125 ->loadOneWhere( 126 'objectPHID = %s AND applicationClass = %s', 127 $viewer->getPHID(), 128 'PhabricatorHomeApplication'); 129 if ($installed_dashboard && 130 $installed_dashboard->getDashboardPHID() == $dashboard->getPHID()) { 131 $title_install = pht('Uninstall Dashboard'); 132 $href_install = "uninstall/{$id}/"; 133 } else { 134 $title_install = pht('Install Dashboard'); 135 $href_install = "install/{$id}/"; 136 } 137 $actions->addAction( 138 id(new PhabricatorActionView()) 139 ->setName($title_install) 140 ->setIcon('fa-wrench') 141 ->setHref($this->getApplicationURI($href_install)) 142 ->setWorkflow(true)); 143 144 $actions->addAction( 145 id(new PhabricatorActionView()) 146 ->setName(pht('View History')) 147 ->setIcon('fa-history') 148 ->setHref($this->getApplicationURI("history/{$id}/"))); 149 150 return $actions; 151 } 152 153 private function buildPropertyView(PhabricatorDashboard $dashboard) { 154 $viewer = $this->getRequest()->getUser(); 155 156 $properties = id(new PHUIPropertyListView()) 157 ->setUser($viewer) 158 ->setObject($dashboard); 159 160 $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions( 161 $viewer, 162 $dashboard); 163 164 $properties->addProperty( 165 pht('Editable By'), 166 $descriptions[PhabricatorPolicyCapability::CAN_EDIT]); 167 168 $panel_phids = $dashboard->getPanelPHIDs(); 169 $this->loadHandles($panel_phids); 170 171 $properties->addProperty( 172 pht('Panels'), 173 $this->renderHandlesForPHIDs($panel_phids)); 174 175 return $properties; 176 } 177 178 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |