diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2917,6 +2917,7 @@ 'PhabricatorDashboardDashboardPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardDashboardPHIDType.php', 'PhabricatorDashboardDatasource' => 'applications/dashboard/typeahead/PhabricatorDashboardDatasource.php', 'PhabricatorDashboardEditController' => 'applications/dashboard/controller/dashboard/PhabricatorDashboardEditController.php', + 'PhabricatorDashboardEditEngine' => 'applications/dashboard/editor/PhabricatorDashboardEditEngine.php', 'PhabricatorDashboardFavoritesInstallWorkflow' => 'applications/dashboard/install/PhabricatorDashboardFavoritesInstallWorkflow.php', 'PhabricatorDashboardHomeInstallWorkflow' => 'applications/dashboard/install/PhabricatorDashboardHomeInstallWorkflow.php', 'PhabricatorDashboardIconSet' => 'applications/dashboard/icon/PhabricatorDashboardIconSet.php', @@ -8910,6 +8911,7 @@ 'PhabricatorDashboardDashboardPHIDType' => 'PhabricatorPHIDType', 'PhabricatorDashboardDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorDashboardEditController' => 'PhabricatorDashboardController', + 'PhabricatorDashboardEditEngine' => 'PhabricatorEditEngine', 'PhabricatorDashboardFavoritesInstallWorkflow' => 'PhabricatorDashboardApplicationInstallWorkflow', 'PhabricatorDashboardHomeInstallWorkflow' => 'PhabricatorDashboardApplicationInstallWorkflow', 'PhabricatorDashboardIconSet' => 'PhabricatorIconSet', diff --git a/src/applications/dashboard/application/PhabricatorDashboardApplication.php b/src/applications/dashboard/application/PhabricatorDashboardApplication.php --- a/src/applications/dashboard/application/PhabricatorDashboardApplication.php +++ b/src/applications/dashboard/application/PhabricatorDashboardApplication.php @@ -41,8 +41,8 @@ => 'PhabricatorDashboardListController', 'view/(?P\d+)/' => 'PhabricatorDashboardViewController', 'archive/(?P\d+)/' => 'PhabricatorDashboardArchiveController', - 'create/' => 'PhabricatorDashboardEditController', - 'edit/(?:(?P\d+)/)?' => 'PhabricatorDashboardEditController', + $this->getEditRoutePattern('edit/') => + 'PhabricatorDashboardEditController', 'install/(?P\d+)/'. '(?:(?P[^/]+)/'. '(?:(?P[^/]+)/)?)?' => diff --git a/src/applications/dashboard/controller/PhabricatorDashboardListController.php b/src/applications/dashboard/controller/PhabricatorDashboardListController.php --- a/src/applications/dashboard/controller/PhabricatorDashboardListController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardListController.php @@ -36,11 +36,9 @@ protected function buildApplicationCrumbs() { $crumbs = parent::buildApplicationCrumbs(); - $crumbs->addAction( - id(new PHUIListItemView()) - ->setIcon('fa-plus-square') - ->setName(pht('Create Dashboard')) - ->setHref($this->getApplicationURI().'create/')); + id(new PhabricatorDashboardEditEngine()) + ->setViewer($this->getViewer()) + ->addActionToCrumbs($crumbs); return $crumbs; } diff --git a/src/applications/dashboard/controller/dashboard/PhabricatorDashboardEditController.php b/src/applications/dashboard/controller/dashboard/PhabricatorDashboardEditController.php --- a/src/applications/dashboard/controller/dashboard/PhabricatorDashboardEditController.php +++ b/src/applications/dashboard/controller/dashboard/PhabricatorDashboardEditController.php @@ -4,185 +4,9 @@ extends PhabricatorDashboardController { public function handleRequest(AphrontRequest $request) { - $viewer = $request->getViewer(); - $id = $request->getURIData('id'); - - if ($id) { - $dashboard = id(new PhabricatorDashboardQuery()) - ->setViewer($viewer) - ->withIDs(array($id)) - ->needPanels(true) - ->requireCapabilities( - array( - PhabricatorPolicyCapability::CAN_VIEW, - PhabricatorPolicyCapability::CAN_EDIT, - )) - ->executeOne(); - if (!$dashboard) { - return new Aphront404Response(); - } - $v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( - $dashboard->getPHID(), - PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); - $v_projects = array_reverse($v_projects); - $is_new = false; - } else { - $dashboard = PhabricatorDashboard::initializeNewDashboard($viewer); - $v_projects = array(); - $is_new = true; - } - - $crumbs = $this->buildApplicationCrumbs(); - - if ($is_new) { - $title = pht('Create Dashboard'); - $header_icon = 'fa-plus-square'; - $button = pht('Create Dashboard'); - $cancel_uri = $this->getApplicationURI(); - - $crumbs->addTextCrumb(pht('Create Dashboard')); - } else { - $cancel_uri = $dashboard->getURI(); - - $title = pht('Edit Dashboard: %s', $dashboard->getName()); - $header_icon = 'fa-pencil'; - $button = pht('Save Changes'); - - $crumbs->addTextCrumb($dashboard->getName(), $cancel_uri); - $crumbs->addTextCrumb(pht('Edit')); - } - - $v_name = $dashboard->getName(); - $v_icon = $dashboard->getIcon(); - $v_layout_mode = $dashboard->getRawLayoutMode(); - $e_name = true; - - $validation_exception = null; - if ($request->isFormPost() && $request->getStr('edit')) { - $v_name = $request->getStr('name'); - $v_icon = $request->getStr('icon'); - $v_layout_mode = $request->getStr('layout_mode'); - $v_view_policy = $request->getStr('viewPolicy'); - $v_edit_policy = $request->getStr('editPolicy'); - $v_projects = $request->getArr('projects'); - - $xactions = array(); - - $type_name = PhabricatorDashboardNameTransaction::TRANSACTIONTYPE; - $type_icon = PhabricatorDashboardIconTransaction::TRANSACTIONTYPE; - $type_layout_mode = - PhabricatorDashboardLayoutTransaction::TRANSACTIONTYPE; - $type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY; - $type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY; - - $xactions[] = id(new PhabricatorDashboardTransaction()) - ->setTransactionType($type_name) - ->setNewValue($v_name); - $xactions[] = id(new PhabricatorDashboardTransaction()) - ->setTransactionType($type_layout_mode) - ->setNewValue($v_layout_mode); - $xactions[] = id(new PhabricatorDashboardTransaction()) - ->setTransactionType($type_icon) - ->setNewValue($v_icon); - $xactions[] = id(new PhabricatorDashboardTransaction()) - ->setTransactionType($type_view_policy) - ->setNewValue($v_view_policy); - $xactions[] = id(new PhabricatorDashboardTransaction()) - ->setTransactionType($type_edit_policy) - ->setNewValue($v_edit_policy); - - $proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; - $xactions[] = id(new PhabricatorDashboardTransaction()) - ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) - ->setMetadataValue('edge:type', $proj_edge_type) - ->setNewValue(array('=' => array_fuse($v_projects))); - - try { - $editor = id(new PhabricatorDashboardTransactionEditor()) - ->setActor($viewer) - ->setContinueOnNoEffect(true) - ->setContentSourceFromRequest($request) - ->applyTransactions($dashboard, $xactions); - - return id(new AphrontRedirectResponse())->setURI($dashboard->getURI()); - } catch (PhabricatorApplicationTransactionValidationException $ex) { - $validation_exception = $ex; - - $e_name = $validation_exception->getShortMessage($type_name); - - $dashboard->setViewPolicy($v_view_policy); - $dashboard->setEditPolicy($v_edit_policy); - } - } - - $policies = id(new PhabricatorPolicyQuery()) - ->setViewer($viewer) - ->setObject($dashboard) - ->execute(); - - $layout_mode_options = - PhabricatorDashboardLayoutConfig::getLayoutModeSelectOptions(); - $form = id(new AphrontFormView()) - ->setUser($viewer) - ->addHiddenInput('edit', true) - ->appendChild( - id(new AphrontFormTextControl()) - ->setLabel(pht('Name')) - ->setName('name') - ->setValue($v_name) - ->setError($e_name)) - ->appendChild( - id(new AphrontFormSelectControl()) - ->setLabel(pht('Layout Mode')) - ->setName('layout_mode') - ->setValue($v_layout_mode) - ->setOptions($layout_mode_options)) - ->appendChild( - id(new PHUIFormIconSetControl()) - ->setLabel(pht('Icon')) - ->setName('icon') - ->setIconSet(new PhabricatorDashboardIconSet()) - ->setValue($v_icon)) - ->appendChild( - id(new AphrontFormPolicyControl()) - ->setName('viewPolicy') - ->setPolicyObject($dashboard) - ->setCapability(PhabricatorPolicyCapability::CAN_VIEW) - ->setPolicies($policies)) - ->appendChild( - id(new AphrontFormPolicyControl()) - ->setName('editPolicy') - ->setPolicyObject($dashboard) - ->setCapability(PhabricatorPolicyCapability::CAN_EDIT) - ->setPolicies($policies)); - - $form->appendControl( - id(new AphrontFormTokenizerControl()) - ->setLabel(pht('Tags')) - ->setName('projects') - ->setValue($v_projects) - ->setDatasource(new PhabricatorProjectDatasource())); - - $form->appendChild( - id(new AphrontFormSubmitControl()) - ->setValue($button) - ->addCancelButton($cancel_uri)); - - $box = id(new PHUIObjectBoxView()) - ->setHeaderText($title) - ->setForm($form) - ->setBackground(PHUIObjectBoxView::WHITE_CONFIG) - ->setValidationException($validation_exception); - - $crumbs->setBorder(true); - - $view = id(new PHUITwoColumnView()) - ->setFooter($box); - - return $this->newPage() - ->setTitle($title) - ->setCrumbs($crumbs) - ->appendChild($view); + return id(new PhabricatorDashboardEditEngine()) + ->setController($this) + ->buildResponse(); } } diff --git a/src/applications/dashboard/editor/PhabricatorDashboardEditEngine.php b/src/applications/dashboard/editor/PhabricatorDashboardEditEngine.php new file mode 100644 --- /dev/null +++ b/src/applications/dashboard/editor/PhabricatorDashboardEditEngine.php @@ -0,0 +1,107 @@ +getViewer(); + return PhabricatorDashboard::initializeNewDashboard($viewer); + } + + protected function newObjectQuery() { + return new PhabricatorDashboardQuery(); + } + + protected function getObjectCreateTitleText($object) { + return pht('Create Dashboard'); + } + + protected function getObjectCreateButtonText($object) { + return pht('Create Dashboard'); + } + + protected function getObjectCreateCancelURI($object) { + return '/dashboard/'; + } + + protected function getObjectEditTitleText($object) { + return pht('Edit Dashboard: %s', $object->getName()); + } + + protected function getObjectEditShortText($object) { + return pht('Edit Dashboard'); + } + + protected function getObjectCreateShortText() { + return pht('Create Dashboard'); + } + + protected function getObjectName() { + return pht('Dashboard'); + } + + protected function getObjectViewURI($object) { + return $object->getURI(); + } + + protected function buildCustomEditFields($object) { + $fields = array( + id(new PhabricatorTextEditField()) + ->setKey('name') + ->setLabel(pht('Name')) + ->setDescription(pht('Name of the dashboard.')) + ->setConduitDescription(pht('Rename the dashboard.')) + ->setConduitTypeDescription(pht('New dashboard name.')) + ->setTransactionType( + PhabricatorDashboardNameTransaction::TRANSACTIONTYPE) + ->setIsRequired(true) + ->setValue($object->getName()), + id(new PhabricatorIconSetEditField()) + ->setKey('icon') + ->setLabel(pht('Icon')) + ->setTransactionType( + PhabricatorDashboardIconTransaction::TRANSACTIONTYPE) + ->setIconSet(new PhabricatorDashboardIconSet()) + ->setDescription(pht('Dashboard icon.')) + ->setConduitDescription(pht('Change the dashboard icon.')) + ->setConduitTypeDescription(pht('New dashboard icon.')) + ->setValue($object->getIcon()), + id(new PhabricatorSelectEditField()) + ->setKey('layout') + ->setLabel(pht('Layout')) + ->setDescription(pht('Dashboard layout mode.')) + ->setConduitDescription(pht('Change the dashboard layout mode.')) + ->setConduitTypeDescription(pht('New dashboard layout mode.')) + ->setTransactionType( + PhabricatorDashboardLayoutTransaction::TRANSACTIONTYPE) + ->setOptions( + PhabricatorDashboardLayoutConfig::getLayoutModeSelectOptions()) + ->setValue($object->getRawLayoutMode()), + ); + + return $fields; + } + +} diff --git a/src/applications/search/controller/PhabricatorApplicationSearchController.php b/src/applications/search/controller/PhabricatorApplicationSearchController.php --- a/src/applications/search/controller/PhabricatorApplicationSearchController.php +++ b/src/applications/search/controller/PhabricatorApplicationSearchController.php @@ -196,9 +196,6 @@ $submit->addButton($save_button); } - // TODO: A "Create Dashboard Panel" action goes here somewhere once - // we sort out T5307. - $form->appendChild($submit); $body = array();