Path: blob/master/src/applications/dashboard/controller/panel/PhabricatorDashboardPanelEditController.php
12242 views
<?php12final class PhabricatorDashboardPanelEditController3extends PhabricatorDashboardController {45public function handleRequest(AphrontRequest $request) {6$viewer = $this->getViewer();78$engine = id(new PhabricatorDashboardPanelEditEngine())9->setController($this);1011// We can create or edit a panel in the context of a dashboard or12// container panel, like a tab panel. If we started this flow on some13// container object, we want to return to that container when we're done14// editing.1516$context_phid = $request->getStr('contextPHID');17if (phutil_nonempty_string($context_phid)) {18$context = id(new PhabricatorObjectQuery())19->setViewer($viewer)20->withPHIDs(array($context_phid))21->requireCapabilities(22array(23PhabricatorPolicyCapability::CAN_VIEW,24PhabricatorPolicyCapability::CAN_EDIT,25))26->executeOne();27if (!$context) {28return new Aphront404Response();29}3031if (!($context instanceof PhabricatorDashboardPanelContainerInterface)) {32return new Aphront404Response();33}3435$engine36->setContextObject($context)37->addContextParameter('contextPHID', $context_phid);38} else {39$context = null;40}4142$id = $request->getURIData('id');43if (!$id) {44$column_key = $request->getStr('columnKey');4546if ($context) {47$cancel_uri = $context->getURI();48} else {49$cancel_uri = $this->getApplicationURI('panel/');50}5152$panel_type = $request->getStr('panelType');53$panel_types = PhabricatorDashboardPanelType::getAllPanelTypes();54if (empty($panel_types[$panel_type])) {55return $this->buildPanelTypeResponse($cancel_uri);56}5758$engine59->addContextParameter('panelType', $panel_type)60->addContextParameter('columnKey', $column_key)61->setPanelType($panel_type)62->setColumnKey($column_key);63}6465return $engine->buildResponse();66}6768private function buildPanelTypeResponse($cancel_uri) {69$viewer = $this->getViewer();70$request = $this->getRequest();7172$base_uri = $request->getRequestURI();73$base_uri = new PhutilURI($base_uri);7475$menu = id(new PHUIObjectItemListView())76->setViewer($viewer)77->setFlush(true)78->setBig(true);7980$panel_types = PhabricatorDashboardPanelType::getAllPanelTypes();81foreach ($panel_types as $panel_type) {82$item = id(new PHUIObjectItemView())83->setClickable(true)84->setImageIcon($panel_type->getIcon())85->setHeader($panel_type->getPanelTypeName())86->addAttribute($panel_type->getPanelTypeDescription());8788$type_uri = id(clone $base_uri)89->replaceQueryParam('panelType', $panel_type->getPanelTypeKey());9091$item->setHref($type_uri);9293$menu->addItem($item);94}9596return $this->newDialog()97->setTitle(pht('Choose Panel Type'))98->setWidth(AphrontDialogView::WIDTH_FORM)99->appendChild($menu)100->addCancelButton($cancel_uri);101}102103}104105106