mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 13:00:56 +01:00
Use EditEngine for Harbormaster Build Plans, fix some crumbs/mobile stuff
Summary: Ref T10457. - Use EditEngine for Build Plans. - Fix some minor issues with crumbs being inconsistent. - Fix some minor issues with mobile menus not being consistent/available. Test Plan: - Created and edited build plans. - Poked around in mobile width, verified mobile menu had the right stuff in it. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10457 Differential Revision: https://secure.phabricator.com/D15357
This commit is contained in:
parent
c29ba039bb
commit
5295c6ba1e
14 changed files with 140 additions and 219 deletions
|
@ -1053,6 +1053,7 @@ phutil_register_library_map(array(
|
|||
'HarbormasterBuildPlanDatasource' => 'applications/harbormaster/typeahead/HarbormasterBuildPlanDatasource.php',
|
||||
'HarbormasterBuildPlanDefaultEditCapability' => 'applications/harbormaster/capability/HarbormasterBuildPlanDefaultEditCapability.php',
|
||||
'HarbormasterBuildPlanDefaultViewCapability' => 'applications/harbormaster/capability/HarbormasterBuildPlanDefaultViewCapability.php',
|
||||
'HarbormasterBuildPlanEditEngine' => 'applications/harbormaster/editor/HarbormasterBuildPlanEditEngine.php',
|
||||
'HarbormasterBuildPlanEditor' => 'applications/harbormaster/editor/HarbormasterBuildPlanEditor.php',
|
||||
'HarbormasterBuildPlanPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildPlanPHIDType.php',
|
||||
'HarbormasterBuildPlanQuery' => 'applications/harbormaster/query/HarbormasterBuildPlanQuery.php',
|
||||
|
@ -5202,6 +5203,7 @@ phutil_register_library_map(array(
|
|||
'HarbormasterBuildPlanDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'HarbormasterBuildPlanDefaultEditCapability' => 'PhabricatorPolicyCapability',
|
||||
'HarbormasterBuildPlanDefaultViewCapability' => 'PhabricatorPolicyCapability',
|
||||
'HarbormasterBuildPlanEditEngine' => 'PhabricatorEditEngine',
|
||||
'HarbormasterBuildPlanEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'HarbormasterBuildPlanPHIDType' => 'PhabricatorPHIDType',
|
||||
'HarbormasterBuildPlanQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
|
@ -5283,7 +5285,7 @@ phutil_register_library_map(array(
|
|||
'HarbormasterPlanDisableController' => 'HarbormasterPlanController',
|
||||
'HarbormasterPlanEditController' => 'HarbormasterPlanController',
|
||||
'HarbormasterPlanListController' => 'HarbormasterPlanController',
|
||||
'HarbormasterPlanRunController' => 'HarbormasterController',
|
||||
'HarbormasterPlanRunController' => 'HarbormasterPlanController',
|
||||
'HarbormasterPlanViewController' => 'HarbormasterPlanController',
|
||||
'HarbormasterPrototypeBuildStepGroup' => 'HarbormasterBuildStepGroup',
|
||||
'HarbormasterPublishFragmentBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
|
||||
|
@ -5296,10 +5298,10 @@ phutil_register_library_map(array(
|
|||
'HarbormasterScratchTable' => 'HarbormasterDAO',
|
||||
'HarbormasterSendMessageConduitAPIMethod' => 'HarbormasterConduitAPIMethod',
|
||||
'HarbormasterSleepBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
|
||||
'HarbormasterStepAddController' => 'HarbormasterController',
|
||||
'HarbormasterStepDeleteController' => 'HarbormasterController',
|
||||
'HarbormasterStepEditController' => 'HarbormasterController',
|
||||
'HarbormasterStepViewController' => 'HarbormasterController',
|
||||
'HarbormasterStepAddController' => 'HarbormasterPlanController',
|
||||
'HarbormasterStepDeleteController' => 'HarbormasterPlanController',
|
||||
'HarbormasterStepEditController' => 'HarbormasterPlanController',
|
||||
'HarbormasterStepViewController' => 'HarbormasterPlanController',
|
||||
'HarbormasterTargetEngine' => 'Phobject',
|
||||
'HarbormasterTargetWorker' => 'HarbormasterWorker',
|
||||
'HarbormasterTestBuildStepGroup' => 'HarbormasterBuildStepGroup',
|
||||
|
|
|
@ -76,9 +76,9 @@ final class PhabricatorHarbormasterApplication extends PhabricatorApplication {
|
|||
=> 'HarbormasterBuildActionController',
|
||||
),
|
||||
'plan/' => array(
|
||||
'(?:query/(?P<queryKey>[^/]+)/)?'
|
||||
=> 'HarbormasterPlanListController',
|
||||
'edit/(?:(?P<id>\d+)/)?' => 'HarbormasterPlanEditController',
|
||||
$this->getQueryRoutePattern() => 'HarbormasterPlanListController',
|
||||
$this->getEditRoutePattern('edit/')
|
||||
=> 'HarbormasterPlanEditController',
|
||||
'order/(?:(?P<id>\d+)/)?' => 'HarbormasterPlanOrderController',
|
||||
'disable/(?P<id>\d+)/' => 'HarbormasterPlanDisableController',
|
||||
'run/(?P<id>\d+)/' => 'HarbormasterPlanRunController',
|
||||
|
|
|
@ -7,34 +7,21 @@ final class HarbormasterBuildableListController extends HarbormasterController {
|
|||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$controller = id(new PhabricatorApplicationSearchController())
|
||||
->setQueryKey($request->getURIData('queryKey'))
|
||||
->setSearchEngine(new HarbormasterBuildableSearchEngine())
|
||||
->setNavigation($this->buildSideNavView());
|
||||
$items = array();
|
||||
|
||||
return $this->delegateToController($controller);
|
||||
}
|
||||
$items[] = id(new PHUIListItemView())
|
||||
->setType(PHUIListItemView::TYPE_LABEL)
|
||||
->setName(pht('Build Plans'));
|
||||
|
||||
public function buildSideNavView($for_app = false) {
|
||||
$user = $this->getRequest()->getUser();
|
||||
$items[] = id(new PHUIListItemView())
|
||||
->setType(PHUIListItemView::TYPE_LINK)
|
||||
->setName(pht('Manage Build Plans'))
|
||||
->setHref($this->getApplicationURI('plan/'));
|
||||
|
||||
$nav = new AphrontSideNavFilterView();
|
||||
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||
|
||||
id(new HarbormasterBuildableSearchEngine())
|
||||
->setViewer($user)
|
||||
->addNavigationItems($nav->getMenu());
|
||||
|
||||
$nav->addLabel(pht('Build Plans'));
|
||||
$nav->addFilter('plan/', pht('Manage Build Plans'));
|
||||
|
||||
$nav->selectFilter(null);
|
||||
|
||||
return $nav;
|
||||
}
|
||||
|
||||
public function buildApplicationMenu() {
|
||||
return $this->buildSideNavView(true)->getMenu();
|
||||
return id(new HarbormasterBuildableSearchEngine())
|
||||
->setController($this)
|
||||
->setNavigationItems($items)
|
||||
->buildResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
abstract class HarbormasterController extends PhabricatorController {
|
||||
|
||||
public function buildApplicationMenu() {
|
||||
return $this->newApplicationMenu()
|
||||
->setSearchEngine(new HarbormasterBuildableSearchEngine());
|
||||
}
|
||||
|
||||
protected function addBuildableCrumb(
|
||||
PHUICrumbsView $crumbs,
|
||||
HarbormasterBuildable $buildable) {
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
abstract class HarbormasterPlanController extends HarbormasterController {
|
||||
|
||||
public function buildApplicationMenu() {
|
||||
return $this->newApplicationMenu()
|
||||
->setSearchEngine(new HarbormasterBuildPlanSearchEngine());
|
||||
}
|
||||
|
||||
protected function buildApplicationCrumbs() {
|
||||
$crumbs = parent::buildApplicationCrumbs();
|
||||
|
||||
|
|
|
@ -3,146 +3,9 @@
|
|||
final class HarbormasterPlanEditController extends HarbormasterPlanController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$id = $request->getURIData('id');
|
||||
if ($id) {
|
||||
$plan = id(new HarbormasterBuildPlanQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->requireCapabilities(
|
||||
array(
|
||||
PhabricatorPolicyCapability::CAN_VIEW,
|
||||
PhabricatorPolicyCapability::CAN_EDIT,
|
||||
))
|
||||
->executeOne();
|
||||
if (!$plan) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
} else {
|
||||
$this->requireApplicationCapability(
|
||||
HarbormasterCreatePlansCapability::CAPABILITY);
|
||||
|
||||
$plan = HarbormasterBuildPlan::initializeNewBuildPlan($viewer);
|
||||
}
|
||||
|
||||
$e_name = true;
|
||||
$v_name = $plan->getName();
|
||||
$v_view = $plan->getViewPolicy();
|
||||
$v_edit = $plan->getEditPolicy();
|
||||
$validation_exception = null;
|
||||
if ($request->isFormPost()) {
|
||||
$xactions = array();
|
||||
|
||||
$v_name = $request->getStr('name');
|
||||
$v_view = $request->getStr('viewPolicy');
|
||||
$v_edit = $request->getStr('editPolicy');
|
||||
|
||||
$e_name = null;
|
||||
|
||||
$type_name = HarbormasterBuildPlanTransaction::TYPE_NAME;
|
||||
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||
|
||||
$xactions[] = id(new HarbormasterBuildPlanTransaction())
|
||||
->setTransactionType($type_name)
|
||||
->setNewValue($v_name);
|
||||
|
||||
$xactions[] = id(new HarbormasterBuildPlanTransaction())
|
||||
->setTransactionType($type_view)
|
||||
->setNewValue($v_view);
|
||||
|
||||
$xactions[] = id(new HarbormasterBuildPlanTransaction())
|
||||
->setTransactionType($type_edit)
|
||||
->setNewValue($v_edit);
|
||||
|
||||
$editor = id(new HarbormasterBuildPlanEditor())
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContentSourceFromRequest($request);
|
||||
|
||||
try {
|
||||
$editor->applyTransactions($plan, $xactions);
|
||||
return id(new AphrontRedirectResponse())
|
||||
->setURI($this->getApplicationURI('plan/'.$plan->getID().'/'));
|
||||
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
||||
$validation_exception = $ex;
|
||||
|
||||
$e_name = $validation_exception->getShortMessage(
|
||||
HarbormasterBuildPlanTransaction::TYPE_NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$is_new = (!$plan->getID());
|
||||
if ($is_new) {
|
||||
$title = pht('New Build Plan');
|
||||
$cancel_uri = $this->getApplicationURI('plan/');
|
||||
$save_button = pht('Create Build Plan');
|
||||
} else {
|
||||
$id = $plan->getID();
|
||||
|
||||
$title = pht('Edit Build Plan');
|
||||
$cancel_uri = $this->getApplicationURI('plan/'.$plan->getID().'/');
|
||||
$save_button = pht('Save Build Plan');
|
||||
}
|
||||
|
||||
$policies = id(new PhabricatorPolicyQuery())
|
||||
->setViewer($viewer)
|
||||
->setObject($plan)
|
||||
->execute();
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($viewer)
|
||||
->appendControl(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel(pht('Plan Name'))
|
||||
->setName('name')
|
||||
->setError($e_name)
|
||||
->setValue($v_name))
|
||||
->appendControl(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
||||
->setPolicyObject($plan)
|
||||
->setPolicies($policies)
|
||||
->setValue($v_view)
|
||||
->setName('viewPolicy'))
|
||||
->appendControl(
|
||||
id(new AphrontFormPolicyControl())
|
||||
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
||||
->setPolicyObject($plan)
|
||||
->setPolicies($policies)
|
||||
->setValue($v_edit)
|
||||
->setName('editPolicy'))
|
||||
->appendControl(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue($save_button)
|
||||
->addCancelButton($cancel_uri));
|
||||
|
||||
$box = id(new PHUIObjectBoxView())
|
||||
->setHeaderText($title)
|
||||
->setValidationException($validation_exception)
|
||||
->setForm($form);
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
if ($is_new) {
|
||||
$crumbs->addTextCrumb(pht('New Build Plan'));
|
||||
} else {
|
||||
$id = $plan->getID();
|
||||
$crumbs->addTextCrumb(
|
||||
pht('Plan %d', $id),
|
||||
$this->getApplicationURI("plan/{$id}/"));
|
||||
$crumbs->addTextCrumb(pht('Edit'));
|
||||
}
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
array(
|
||||
$crumbs,
|
||||
$box,
|
||||
),
|
||||
array(
|
||||
'title' => $title,
|
||||
));
|
||||
return id(new HarbormasterBuildPlanEditEngine())
|
||||
->setController($this)
|
||||
->buildResponse();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,53 +7,19 @@ final class HarbormasterPlanListController extends HarbormasterPlanController {
|
|||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$controller = id(new PhabricatorApplicationSearchController())
|
||||
->setQueryKey($request->getURIData('queryKey'))
|
||||
->setSearchEngine(new HarbormasterBuildPlanSearchEngine())
|
||||
->setNavigation($this->buildSideNavView());
|
||||
|
||||
return $this->delegateToController($controller);
|
||||
}
|
||||
|
||||
public function buildSideNavView($for_app = false) {
|
||||
$user = $this->getRequest()->getUser();
|
||||
|
||||
$nav = new AphrontSideNavFilterView();
|
||||
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
|
||||
|
||||
if ($for_app) {
|
||||
$nav->addFilter('new/', pht('New Build Plan'));
|
||||
}
|
||||
|
||||
id(new HarbormasterBuildPlanSearchEngine())
|
||||
->setViewer($user)
|
||||
->addNavigationItems($nav->getMenu());
|
||||
|
||||
$nav->selectFilter(null);
|
||||
|
||||
return $nav;
|
||||
}
|
||||
|
||||
public function buildApplicationMenu() {
|
||||
return $this->buildSideNavView(true)->getMenu();
|
||||
return id(new HarbormasterBuildPlanSearchEngine())
|
||||
->setController($this)
|
||||
->buildResponse();
|
||||
}
|
||||
|
||||
protected function buildApplicationCrumbs() {
|
||||
$crumbs = parent::buildApplicationCrumbs();
|
||||
|
||||
$can_create = $this->hasApplicationCapability(
|
||||
HarbormasterCreatePlansCapability::CAPABILITY);
|
||||
|
||||
$crumbs->addAction(
|
||||
id(new PHUIListItemView())
|
||||
->setName(pht('New Build Plan'))
|
||||
->setHref($this->getApplicationURI('plan/edit/'))
|
||||
->setDisabled(!$can_create)
|
||||
->setWorkflow(!$can_create)
|
||||
->setIcon('fa-plus-square'));
|
||||
id(new HarbormasterBuildPlanEditEngine())
|
||||
->setViewer($this->getViewer())
|
||||
->addActionToCrumbs($crumbs);
|
||||
|
||||
return $crumbs;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterPlanRunController extends HarbormasterController {
|
||||
final class HarbormasterPlanRunController extends HarbormasterPlanController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterStepAddController extends HarbormasterController {
|
||||
final class HarbormasterStepAddController
|
||||
extends HarbormasterPlanController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterStepDeleteController extends HarbormasterController {
|
||||
final class HarbormasterStepDeleteController
|
||||
extends HarbormasterPlanController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterStepEditController extends HarbormasterController {
|
||||
final class HarbormasterStepEditController
|
||||
extends HarbormasterPlanController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterStepViewController extends HarbormasterController {
|
||||
final class HarbormasterStepViewController
|
||||
extends HarbormasterPlanController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $this->getViewer();
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
final class HarbormasterBuildPlanEditEngine
|
||||
extends PhabricatorEditEngine {
|
||||
|
||||
const ENGINECONST = 'harbormaster.buildplan';
|
||||
|
||||
public function isEngineConfigurable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getEngineName() {
|
||||
return pht('Harbormaster Build Plans');
|
||||
}
|
||||
|
||||
public function getSummaryHeader() {
|
||||
return pht('Edit Harbormaster Build Plan Configurations');
|
||||
}
|
||||
|
||||
public function getSummaryText() {
|
||||
return pht('This engine is used to edit Harbormaster build plans.');
|
||||
}
|
||||
|
||||
public function getEngineApplicationClass() {
|
||||
return 'PhabricatorHarbormasterApplication';
|
||||
}
|
||||
|
||||
protected function newEditableObject() {
|
||||
$viewer = $this->getViewer();
|
||||
return HarbormasterBuildPlan::initializeNewBuildPlan($viewer);
|
||||
}
|
||||
|
||||
protected function newObjectQuery() {
|
||||
return new HarbormasterBuildPlanQuery();
|
||||
}
|
||||
|
||||
protected function getObjectCreateTitleText($object) {
|
||||
return pht('Create Build Plan');
|
||||
}
|
||||
|
||||
protected function getObjectCreateButtonText($object) {
|
||||
return pht('Create Build Plan');
|
||||
}
|
||||
|
||||
protected function getObjectEditTitleText($object) {
|
||||
return pht('Edit Build Plan: %s', $object->getName());
|
||||
}
|
||||
|
||||
protected function getObjectEditShortText($object) {
|
||||
return pht('Edit Build Plan');
|
||||
}
|
||||
|
||||
protected function getObjectCreateShortText() {
|
||||
return pht('Create Build Plan');
|
||||
}
|
||||
|
||||
protected function getEditorURI() {
|
||||
return '/harbormaster/plan/edit/';
|
||||
}
|
||||
|
||||
protected function getObjectCreateCancelURI($object) {
|
||||
return '/harbormaster/plan/';
|
||||
}
|
||||
|
||||
protected function getObjectViewURI($object) {
|
||||
$id = $object->getID();
|
||||
return "/harbormaster/plan/{$id}/";
|
||||
}
|
||||
|
||||
protected function getCreateNewObjectPolicy() {
|
||||
return $this->getApplication()->getPolicy(
|
||||
HarbormasterCreatePlansCapability::CAPABILITY);
|
||||
}
|
||||
|
||||
protected function buildCustomEditFields($object) {
|
||||
return array(
|
||||
id(new PhabricatorTextEditField())
|
||||
->setKey('name')
|
||||
->setLabel(pht('Name'))
|
||||
->setIsRequired(true)
|
||||
->setTransactionType(HarbormasterBuildPlanTransaction::TYPE_NAME)
|
||||
->setDescription(pht('The build plan name.'))
|
||||
->setConduitDescription(pht('Rename the plan.'))
|
||||
->setConduitTypeDescription(pht('New plan name.'))
|
||||
->setValue($object->getName()),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -90,7 +90,7 @@ final class HarbormasterBuildPlanEditor
|
|||
$error = new PhabricatorApplicationTransactionValidationError(
|
||||
$type,
|
||||
pht('Required'),
|
||||
pht('Plan name is required.'),
|
||||
pht('You must choose a name for your build plan.'),
|
||||
last($xactions));
|
||||
|
||||
$error->setIsMissingFieldError(true);
|
||||
|
|
Loading…
Reference in a new issue