Differential D16226 Diff 39032 src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/controller/PhabricatorDashboardPanelEditController.php
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if ($id) { | ||||
| $panel = id(new PhabricatorDashboardPanelQuery()) | $panel = id(new PhabricatorDashboardPanelQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withIDs(array($id)) | ->withIDs(array($id)) | ||||
| ->requireCapabilities($capabilities) | ->requireCapabilities($capabilities) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$panel) { | if (!$panel) { | ||||
| return new Aphront404Response(); | return new Aphront404Response(); | ||||
| } | } | ||||
| $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( | |||||
| $panel->getPHID(), | |||||
| PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); | |||||
| $v_projects = array_reverse($v_projects); | |||||
| if ($dashboard) { | if ($dashboard) { | ||||
| $can_edit = PhabricatorPolicyFilter::hasCapability( | $can_edit = PhabricatorPolicyFilter::hasCapability( | ||||
| $viewer, | $viewer, | ||||
| $panel, | $panel, | ||||
| PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
| if (!$can_edit) { | if (!$can_edit) { | ||||
| if ($request->isFormPost() && $request->getBool('copy')) { | if ($request->isFormPost() && $request->getBool('copy')) { | ||||
| Show All 13 Lines | if ($id) { | ||||
| $is_create = true; | $is_create = true; | ||||
| $panel = PhabricatorDashboardPanel::initializeNewPanel($viewer); | $panel = PhabricatorDashboardPanel::initializeNewPanel($viewer); | ||||
| $types = PhabricatorDashboardPanelType::getAllPanelTypes(); | $types = PhabricatorDashboardPanelType::getAllPanelTypes(); | ||||
| $type = $request->getStr('type'); | $type = $request->getStr('type'); | ||||
| if (empty($types[$type])) { | if (empty($types[$type])) { | ||||
| return $this->processPanelTypeRequest($request); | return $this->processPanelTypeRequest($request); | ||||
| } | } | ||||
| $v_projects = array(); | |||||
| $panel->setPanelType($type); | $panel->setPanelType($type); | ||||
| } | } | ||||
| if ($is_create) { | if ($is_create) { | ||||
| $title = pht('Create New Panel'); | $title = pht('Create New Panel'); | ||||
| $button = pht('Create Panel'); | $button = pht('Create Panel'); | ||||
| $header_icon = 'fa-plus-square'; | $header_icon = 'fa-plus-square'; | ||||
| Show All 34 Lines | public function handleRequest(AphrontRequest $request) { | ||||
| // NOTE: We require 'edit' to distinguish between the "Choose a Type" | // NOTE: We require 'edit' to distinguish between the "Choose a Type" | ||||
| // and "Create a Panel" dialogs. | // and "Create a Panel" dialogs. | ||||
| if ($request->isFormPost() && $request->getBool('edit')) { | if ($request->isFormPost() && $request->getBool('edit')) { | ||||
| $v_name = $request->getStr('name'); | $v_name = $request->getStr('name'); | ||||
| $v_view_policy = $request->getStr('viewPolicy'); | $v_view_policy = $request->getStr('viewPolicy'); | ||||
| $v_edit_policy = $request->getStr('editPolicy'); | $v_edit_policy = $request->getStr('editPolicy'); | ||||
| $v_projects = $request->getArr('projects'); | |||||
| $type_name = PhabricatorDashboardPanelTransaction::TYPE_NAME; | $type_name = PhabricatorDashboardPanelTransaction::TYPE_NAME; | ||||
| $type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY; | $type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY; | ||||
| $type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY; | $type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY; | ||||
| $xactions = array(); | $xactions = array(); | ||||
| $xactions[] = id(new PhabricatorDashboardPanelTransaction()) | $xactions[] = id(new PhabricatorDashboardPanelTransaction()) | ||||
| ->setTransactionType($type_name) | ->setTransactionType($type_name) | ||||
| ->setNewValue($v_name); | ->setNewValue($v_name); | ||||
| $xactions[] = id(new PhabricatorDashboardPanelTransaction()) | $xactions[] = id(new PhabricatorDashboardPanelTransaction()) | ||||
| ->setTransactionType($type_view_policy) | ->setTransactionType($type_view_policy) | ||||
| ->setNewValue($v_view_policy); | ->setNewValue($v_view_policy); | ||||
| $xactions[] = id(new PhabricatorDashboardPanelTransaction()) | $xactions[] = id(new PhabricatorDashboardPanelTransaction()) | ||||
| ->setTransactionType($type_edit_policy) | ->setTransactionType($type_edit_policy) | ||||
| ->setNewValue($v_edit_policy); | ->setNewValue($v_edit_policy); | ||||
| $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; | |||||
| $xactions[] = id(new PhabricatorDashboardPanelTransaction()) | |||||
| ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | |||||
| ->setMetadataValue('edge:type', $proj_edge_type) | |||||
| ->setNewValue(array('=' => array_fuse($v_projects))); | |||||
| $field_xactions = $field_list->buildFieldTransactionsFromRequest( | $field_xactions = $field_list->buildFieldTransactionsFromRequest( | ||||
| new PhabricatorDashboardPanelTransaction(), | new PhabricatorDashboardPanelTransaction(), | ||||
| $request); | $request); | ||||
| $xactions = array_merge($xactions, $field_xactions); | $xactions = array_merge($xactions, $field_xactions); | ||||
| try { | try { | ||||
| $editor = id(new PhabricatorDashboardPanelTransactionEditor()) | $editor = id(new PhabricatorDashboardPanelTransactionEditor()) | ||||
| ->setActor($viewer) | ->setActor($viewer) | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | $form = id(new AphrontFormView()) | ||||
| ->setPolicies($policies)) | ->setPolicies($policies)) | ||||
| ->appendChild( | ->appendChild( | ||||
| id(new AphrontFormPolicyControl()) | id(new AphrontFormPolicyControl()) | ||||
| ->setName('editPolicy') | ->setName('editPolicy') | ||||
| ->setPolicyObject($panel) | ->setPolicyObject($panel) | ||||
| ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) | ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) | ||||
| ->setPolicies($policies)); | ->setPolicies($policies)); | ||||
| $form->appendControl( | |||||
| id(new AphrontFormTokenizerControl()) | |||||
| ->setLabel(pht('Tags')) | |||||
| ->setName('projects') | |||||
| ->setValue($v_projects) | |||||
| ->setDatasource(new PhabricatorProjectDatasource())); | |||||
| $field_list->appendFieldsToForm($form); | $field_list->appendFieldsToForm($form); | ||||
| $crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
| $crumbs->addTextCrumb( | $crumbs->addTextCrumb( | ||||
| pht('Panels'), | pht('Panels'), | ||||
| $this->getApplicationURI('panel/')); | $this->getApplicationURI('panel/')); | ||||
| if ($is_create) { | if ($is_create) { | ||||
| $crumbs->addTextCrumb(pht('New Panel')); | $crumbs->addTextCrumb(pht('New Panel')); | ||||
| ▲ Show 20 Lines • Show All 207 Lines • Show Last 20 Lines | |||||