Move Dashboards main edit flow to EditEngine
Summary: Depends on D20402. Ref T13272. Replaces an old-school hard-coded "EditController" with a more modern one. The actual panel stuff is still using a weird mix of legacy manual `save()` calls, but that's up next. Test Plan: Created Dashboards, edited all dashboard fields via "Edit Dashboard". Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13272 Differential Revision: https://secure.phabricator.com/D20403
This commit is contained in:
@@ -2917,6 +2917,7 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorDashboardDashboardPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardDashboardPHIDType.php',
|
'PhabricatorDashboardDashboardPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardDashboardPHIDType.php',
|
||||||
'PhabricatorDashboardDatasource' => 'applications/dashboard/typeahead/PhabricatorDashboardDatasource.php',
|
'PhabricatorDashboardDatasource' => 'applications/dashboard/typeahead/PhabricatorDashboardDatasource.php',
|
||||||
'PhabricatorDashboardEditController' => 'applications/dashboard/controller/dashboard/PhabricatorDashboardEditController.php',
|
'PhabricatorDashboardEditController' => 'applications/dashboard/controller/dashboard/PhabricatorDashboardEditController.php',
|
||||||
|
'PhabricatorDashboardEditEngine' => 'applications/dashboard/editor/PhabricatorDashboardEditEngine.php',
|
||||||
'PhabricatorDashboardFavoritesInstallWorkflow' => 'applications/dashboard/install/PhabricatorDashboardFavoritesInstallWorkflow.php',
|
'PhabricatorDashboardFavoritesInstallWorkflow' => 'applications/dashboard/install/PhabricatorDashboardFavoritesInstallWorkflow.php',
|
||||||
'PhabricatorDashboardHomeInstallWorkflow' => 'applications/dashboard/install/PhabricatorDashboardHomeInstallWorkflow.php',
|
'PhabricatorDashboardHomeInstallWorkflow' => 'applications/dashboard/install/PhabricatorDashboardHomeInstallWorkflow.php',
|
||||||
'PhabricatorDashboardIconSet' => 'applications/dashboard/icon/PhabricatorDashboardIconSet.php',
|
'PhabricatorDashboardIconSet' => 'applications/dashboard/icon/PhabricatorDashboardIconSet.php',
|
||||||
@@ -8910,6 +8911,7 @@ phutil_register_library_map(array(
|
|||||||
'PhabricatorDashboardDashboardPHIDType' => 'PhabricatorPHIDType',
|
'PhabricatorDashboardDashboardPHIDType' => 'PhabricatorPHIDType',
|
||||||
'PhabricatorDashboardDatasource' => 'PhabricatorTypeaheadDatasource',
|
'PhabricatorDashboardDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||||
'PhabricatorDashboardEditController' => 'PhabricatorDashboardController',
|
'PhabricatorDashboardEditController' => 'PhabricatorDashboardController',
|
||||||
|
'PhabricatorDashboardEditEngine' => 'PhabricatorEditEngine',
|
||||||
'PhabricatorDashboardFavoritesInstallWorkflow' => 'PhabricatorDashboardApplicationInstallWorkflow',
|
'PhabricatorDashboardFavoritesInstallWorkflow' => 'PhabricatorDashboardApplicationInstallWorkflow',
|
||||||
'PhabricatorDashboardHomeInstallWorkflow' => 'PhabricatorDashboardApplicationInstallWorkflow',
|
'PhabricatorDashboardHomeInstallWorkflow' => 'PhabricatorDashboardApplicationInstallWorkflow',
|
||||||
'PhabricatorDashboardIconSet' => 'PhabricatorIconSet',
|
'PhabricatorDashboardIconSet' => 'PhabricatorIconSet',
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ final class PhabricatorDashboardApplication extends PhabricatorApplication {
|
|||||||
=> 'PhabricatorDashboardListController',
|
=> 'PhabricatorDashboardListController',
|
||||||
'view/(?P<id>\d+)/' => 'PhabricatorDashboardViewController',
|
'view/(?P<id>\d+)/' => 'PhabricatorDashboardViewController',
|
||||||
'archive/(?P<id>\d+)/' => 'PhabricatorDashboardArchiveController',
|
'archive/(?P<id>\d+)/' => 'PhabricatorDashboardArchiveController',
|
||||||
'create/' => 'PhabricatorDashboardEditController',
|
$this->getEditRoutePattern('edit/') =>
|
||||||
'edit/(?:(?P<id>\d+)/)?' => 'PhabricatorDashboardEditController',
|
'PhabricatorDashboardEditController',
|
||||||
'install/(?P<id>\d+)/'.
|
'install/(?P<id>\d+)/'.
|
||||||
'(?:(?P<workflowKey>[^/]+)/'.
|
'(?:(?P<workflowKey>[^/]+)/'.
|
||||||
'(?:(?P<modeKey>[^/]+)/)?)?' =>
|
'(?:(?P<modeKey>[^/]+)/)?)?' =>
|
||||||
|
|||||||
@@ -36,11 +36,9 @@ final class PhabricatorDashboardListController
|
|||||||
protected function buildApplicationCrumbs() {
|
protected function buildApplicationCrumbs() {
|
||||||
$crumbs = parent::buildApplicationCrumbs();
|
$crumbs = parent::buildApplicationCrumbs();
|
||||||
|
|
||||||
$crumbs->addAction(
|
id(new PhabricatorDashboardEditEngine())
|
||||||
id(new PHUIListItemView())
|
->setViewer($this->getViewer())
|
||||||
->setIcon('fa-plus-square')
|
->addActionToCrumbs($crumbs);
|
||||||
->setName(pht('Create Dashboard'))
|
|
||||||
->setHref($this->getApplicationURI().'create/'));
|
|
||||||
|
|
||||||
return $crumbs;
|
return $crumbs;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,185 +4,9 @@ final class PhabricatorDashboardEditController
|
|||||||
extends PhabricatorDashboardController {
|
extends PhabricatorDashboardController {
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
$viewer = $request->getViewer();
|
return id(new PhabricatorDashboardEditEngine())
|
||||||
$id = $request->getURIData('id');
|
->setController($this)
|
||||||
|
->buildResponse();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorDashboardEditEngine
|
||||||
|
extends PhabricatorEditEngine {
|
||||||
|
|
||||||
|
const ENGINECONST = 'dashboard';
|
||||||
|
|
||||||
|
public function isEngineConfigurable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEngineName() {
|
||||||
|
return pht('Dashboards');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSummaryHeader() {
|
||||||
|
return pht('Edit Dashboards');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSummaryText() {
|
||||||
|
return pht('This engine is used to modify dashboards.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEngineApplicationClass() {
|
||||||
|
return 'PhabricatorDashboardApplication';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function newEditableObject() {
|
||||||
|
$viewer = $this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -196,9 +196,6 @@ final class PhabricatorApplicationSearchController
|
|||||||
$submit->addButton($save_button);
|
$submit->addButton($save_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: A "Create Dashboard Panel" action goes here somewhere once
|
|
||||||
// we sort out T5307.
|
|
||||||
|
|
||||||
$form->appendChild($submit);
|
$form->appendChild($submit);
|
||||||
$body = array();
|
$body = array();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user