1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 22:10:55 +01:00

Projects - merge create + edit interface code paths

Summary:
Fixes T6145, T4016.

Filed T6287 and T6288 for some polish on this.

Test Plan: Made new projects from Maniphest - great success. Made new projects from project / create - also great success.

Reviewers: chad, epriestley

Reviewed By: epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T4016, T6145

Differential Revision: https://secure.phabricator.com/D10679
This commit is contained in:
Bob Trahan 2014-10-10 16:57:05 -07:00
parent 159e56d58a
commit ee8004ab4d
7 changed files with 130 additions and 162 deletions

View file

@ -2029,7 +2029,6 @@ phutil_register_library_map(array(
'PhabricatorProjectConfiguredCustomField' => 'applications/project/customfield/PhabricatorProjectConfiguredCustomField.php', 'PhabricatorProjectConfiguredCustomField' => 'applications/project/customfield/PhabricatorProjectConfiguredCustomField.php',
'PhabricatorProjectConstants' => 'applications/project/constants/PhabricatorProjectConstants.php', 'PhabricatorProjectConstants' => 'applications/project/constants/PhabricatorProjectConstants.php',
'PhabricatorProjectController' => 'applications/project/controller/PhabricatorProjectController.php', 'PhabricatorProjectController' => 'applications/project/controller/PhabricatorProjectController.php',
'PhabricatorProjectCreateController' => 'applications/project/controller/PhabricatorProjectCreateController.php',
'PhabricatorProjectCustomField' => 'applications/project/customfield/PhabricatorProjectCustomField.php', 'PhabricatorProjectCustomField' => 'applications/project/customfield/PhabricatorProjectCustomField.php',
'PhabricatorProjectCustomFieldNumericIndex' => 'applications/project/storage/PhabricatorProjectCustomFieldNumericIndex.php', 'PhabricatorProjectCustomFieldNumericIndex' => 'applications/project/storage/PhabricatorProjectCustomFieldNumericIndex.php',
'PhabricatorProjectCustomFieldStorage' => 'applications/project/storage/PhabricatorProjectCustomFieldStorage.php', 'PhabricatorProjectCustomFieldStorage' => 'applications/project/storage/PhabricatorProjectCustomFieldStorage.php',
@ -5030,7 +5029,6 @@ phutil_register_library_map(array(
'PhabricatorStandardCustomFieldInterface', 'PhabricatorStandardCustomFieldInterface',
), ),
'PhabricatorProjectController' => 'PhabricatorController', 'PhabricatorProjectController' => 'PhabricatorController',
'PhabricatorProjectCreateController' => 'PhabricatorProjectController',
'PhabricatorProjectCustomField' => 'PhabricatorCustomField', 'PhabricatorProjectCustomField' => 'PhabricatorCustomField',
'PhabricatorProjectCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage', 'PhabricatorProjectCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage',
'PhabricatorProjectCustomFieldStorage' => 'PhabricatorCustomFieldStorage', 'PhabricatorProjectCustomFieldStorage' => 'PhabricatorCustomFieldStorage',

View file

@ -58,7 +58,9 @@ final class PhabricatorProjectApplication extends PhabricatorApplication {
=> 'PhabricatorProjectEditPictureController', => 'PhabricatorProjectEditPictureController',
'icon/(?P<id>[1-9]\d*)/' 'icon/(?P<id>[1-9]\d*)/'
=> 'PhabricatorProjectEditIconController', => 'PhabricatorProjectEditIconController',
'create/' => 'PhabricatorProjectCreateController', 'icon/'
=> 'PhabricatorProjectEditIconController',
'create/' => 'PhabricatorProjectEditDetailsController',
'board/(?P<id>[1-9]\d*)/'. 'board/(?P<id>[1-9]\d*)/'.
'(?P<filter>filter/)?'. '(?P<filter>filter/)?'.
'(?:query/(?P<queryKey>[^/]+)/)?' '(?:query/(?P<queryKey>[^/]+)/)?'

View file

@ -1,115 +0,0 @@
<?php
final class PhabricatorProjectCreateController
extends PhabricatorProjectController {
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$this->requireApplicationCapability(
ProjectCreateProjectsCapability::CAPABILITY);
$project = PhabricatorProject::initializeNewProject($user);
$e_name = true;
$type_name = PhabricatorProjectTransaction::TYPE_NAME;
$v_name = $project->getName();
$validation_exception = null;
if ($request->isFormPost()) {
$xactions = array();
$v_name = $request->getStr('name');
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType($type_name)
->setNewValue($v_name);
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue('edge:type', PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)
->setNewValue(
array(
'+' => array($user->getPHID() => $user->getPHID()),
));
$editor = id(new PhabricatorProjectTransactionEditor())
->setActor($user)
->setContinueOnNoEffect(true)
->setContentSourceFromRequest($request);
try {
$editor->applyTransactions($project, $xactions);
if ($request->isAjax()) {
return id(new AphrontAjaxResponse())
->setContent(array(
'phid' => $project->getPHID(),
'name' => $project->getName(),
));
} else {
return id(new AphrontRedirectResponse())
->setURI('/project/view/'.$project->getID().'/');
}
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
$e_name = $ex->getShortMessage($type_name);
}
}
if ($request->isAjax()) {
$form = new PHUIFormLayoutView();
} else {
$form = new AphrontFormView();
$form->setUser($user);
}
$form
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Name'))
->setName('name')
->setValue($v_name)
->setError($e_name));
if ($request->isAjax()) {
$errors = array();
if ($validation_exception) {
$errors = mpull($ex->getErrors(), 'getMessage');
}
$dialog = id(new AphrontDialogView())
->setUser($user)
->setWidth(AphrontDialogView::WIDTH_FORM)
->setTitle(pht('Create a New Project'))
->setErrors($errors)
->appendChild($form)
->addSubmitButton(pht('Create Project'))
->addCancelButton('/project/');
return id(new AphrontDialogResponse())->setDialog($dialog);
} else {
$form
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Create'))
->addCancelButton('/project/'));
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
$crumbs->addTextCrumb(
pht('Create Project'),
$this->getApplicationURI().'create/');
$form_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Create New Project'))
->setValidationException($validation_exception)
->setForm($form);
return $this->buildApplicationPage(
array(
$crumbs,
$form_box,
),
array(
'title' => pht('Create New Project'),
));
}
}
}

View file

@ -6,25 +6,37 @@ final class PhabricatorProjectEditDetailsController
private $id; private $id;
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$this->id = $data['id']; $this->id = idx($data, 'id');
} }
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$viewer = $request->getUser(); $viewer = $request->getUser();
$project = id(new PhabricatorProjectQuery()) if ($this->id) {
->setViewer($viewer) $is_new = false;
->withIDs(array($this->id))
->needSlugs(true) $project = id(new PhabricatorProjectQuery())
->requireCapabilities( ->setViewer($viewer)
array( ->withIDs(array($this->id))
PhabricatorPolicyCapability::CAN_VIEW, ->needSlugs(true)
PhabricatorPolicyCapability::CAN_EDIT, ->requireCapabilities(
)) array(
->executeOne(); PhabricatorPolicyCapability::CAN_VIEW,
if (!$project) { PhabricatorPolicyCapability::CAN_EDIT,
return new Aphront404Response(); ))
->executeOne();
if (!$project) {
return new Aphront404Response();
}
} else {
$is_new = true;
$this->requireApplicationCapability(
ProjectCreateProjectsCapability::CAPABILITY);
$project = PhabricatorProject::initializeNewProject($viewer);
} }
$field_list = PhabricatorCustomField::getObjectFields( $field_list = PhabricatorCustomField::getObjectFields(
@ -114,10 +126,37 @@ final class PhabricatorProjectEditDetailsController
->setContentSourceFromRequest($request) ->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true); ->setContinueOnNoEffect(true);
if ($is_new) {
$xactions[] = id(new PhabricatorProjectTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
->setMetadataValue(
'edge:type',
PhabricatorEdgeConfig::TYPE_PROJ_MEMBER)
->setNewValue(
array(
'+' => array($viewer->getPHID() => $viewer->getPHID()),
));
}
try { try {
$editor->applyTransactions($project, $xactions); $editor->applyTransactions($project, $xactions);
return id(new AphrontRedirectResponse())->setURI($edit_uri); if ($request->isAjax()) {
return id(new AphrontAjaxResponse())
->setContent(array(
'phid' => $project->getPHID(),
'name' => $project->getName(),
));
}
if ($is_new) {
$redirect_uri = $view_uri;
} else {
$redirect_uri = $edit_uri;
}
return id(new AphrontRedirectResponse())->setURI($redirect_uri);
} catch (PhabricatorApplicationTransactionValidationException $ex) { } catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex; $validation_exception = $ex;
@ -131,8 +170,13 @@ final class PhabricatorProjectEditDetailsController
} }
} }
$header_name = pht('Edit Project'); if ($is_new) {
$title = pht('Edit Project'); $header_name = pht('Create a New Project');
$title = pht('Create Project');
} else {
$header_name = pht('Edit Project');
$title = pht('Edit Project');
}
$policies = id(new PhabricatorPolicyQuery()) $policies = id(new PhabricatorPolicyQuery())
->setViewer($viewer) ->setViewer($viewer)
@ -140,8 +184,7 @@ final class PhabricatorProjectEditDetailsController
->execute(); ->execute();
$v_slugs = implode(', ', $v_slugs); $v_slugs = implode(', ', $v_slugs);
$form = new AphrontFormView(); $form = id(new AphrontFormView())
$form
->setUser($viewer) ->setUser($viewer)
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
@ -153,7 +196,11 @@ final class PhabricatorProjectEditDetailsController
$shades = PhabricatorProjectIcon::getColorMap(); $shades = PhabricatorProjectIcon::getColorMap();
$icon_uri = $this->getApplicationURI('icon/'.$project->getID().'/'); if ($is_new) {
$icon_uri = $this->getApplicationURI('icon/');
} else {
$icon_uri = $this->getApplicationURI('icon/'.$project->getID().'/');
}
$icon_display = PhabricatorProjectIcon::renderIconForChooser($v_icon); $icon_display = PhabricatorProjectIcon::renderIconForChooser($v_icon);
list($can_lock, $lock_message) = $this->explainApplicationCapability( list($can_lock, $lock_message) = $this->explainApplicationCapability(
ProjectCanLockProjectsCapability::CAPABILITY, ProjectCanLockProjectsCapability::CAPABILITY,
@ -221,21 +268,43 @@ final class PhabricatorProjectEditDetailsController
1, 1,
pht('Prevent members from leaving this project.'), pht('Prevent members from leaving this project.'),
$v_locked) $v_locked)
->setCaption($lock_message)) ->setCaption($lock_message));
->appendChild(
id(new AphrontFormSubmitControl()) if ($request->isAjax()) {
->addCancelButton($edit_uri) $errors = array();
->setValue(pht('Save'))); if ($validation_exception) {
$errors = mpull($ex->getErrors(), 'getMessage');
}
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setWidth(AphrontDialogView::WIDTH_FULL)
->setTitle($header_name)
->setErrors($errors)
->appendForm($form)
->addSubmitButton($title)
->addCancelButton('/project/');
return id(new AphrontDialogResponse())->setDialog($dialog);
}
$form->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($edit_uri)
->setValue(pht('Save')));
$form_box = id(new PHUIObjectBoxView()) $form_box = id(new PHUIObjectBoxView())
->setHeaderText($title) ->setHeaderText($title)
->setValidationException($validation_exception) ->setValidationException($validation_exception)
->setForm($form); ->setForm($form);
$crumbs = $this->buildApplicationCrumbs($this->buildSideNavView()) $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
->addTextCrumb($project->getName(), $view_uri) if ($is_new) {
->addTextCrumb(pht('Edit'), $edit_uri) $crumbs->addTextCrumb($title);
->addTextCrumb(pht('Details')); } else {
$crumbs
->addTextCrumb($project->getName(), $view_uri)
->addTextCrumb(pht('Edit'), $edit_uri)
->addTextCrumb(pht('Details'));
}
return $this->buildApplicationPage( return $this->buildApplicationPage(
array( array(

View file

@ -6,27 +6,36 @@ final class PhabricatorProjectEditIconController
private $id; private $id;
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$this->id = $data['id']; $this->id = idx($data, 'id');
} }
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$viewer = $request->getUser(); $viewer = $request->getUser();
$project = id(new PhabricatorProjectQuery()) if ($this->id) {
->setViewer($viewer) $project = id(new PhabricatorProjectQuery())
->withIDs(array($this->id)) ->setViewer($viewer)
->requireCapabilities( ->withIDs(array($this->id))
array( ->requireCapabilities(
PhabricatorPolicyCapability::CAN_VIEW, array(
PhabricatorPolicyCapability::CAN_EDIT, PhabricatorPolicyCapability::CAN_VIEW,
)) PhabricatorPolicyCapability::CAN_EDIT,
->executeOne(); ))
if (!$project) { ->executeOne();
return new Aphront404Response(); if (!$project) {
return new Aphront404Response();
}
$cancel_uri = $this->getApplicationURI('edit/'.$project->getID().'/');
$project_icon = $project->getIcon();
} else {
$this->requireApplicationCapability(
ProjectCreateProjectsCapability::CAPABILITY);
$cancel_uri = '/project/';
$project_icon = $request->getStr('value');
} }
$edit_uri = $this->getApplicationURI('edit/'.$project->getID().'/');
require_celerity_resource('project-icon-css'); require_celerity_resource('project-icon-css');
Javelin::initBehavior('phabricator-tooltips'); Javelin::initBehavior('phabricator-tooltips');
@ -55,7 +64,7 @@ final class PhabricatorProjectEditIconController
), ),
pht('Choose "%s" Icon', $label)); pht('Choose "%s" Icon', $label));
if ($icon == $project->getIcon()) { if ($icon == $project_icon) {
$class_extra = ' selected'; $class_extra = ' selected';
} else { } else {
$class_extra = null; $class_extra = null;
@ -92,6 +101,6 @@ final class PhabricatorProjectEditIconController
return $this->newDialog() return $this->newDialog()
->setTitle(pht('Choose Project Icon')) ->setTitle(pht('Choose Project Icon'))
->appendChild($buttons) ->appendChild($buttons)
->addCancelButton($edit_uri); ->addCancelButton($cancel_uri);
} }
} }

View file

@ -45,7 +45,8 @@ final class PhabricatorProject extends PhabricatorProjectDAO
->setEditPolicy(PhabricatorPolicies::POLICY_USER) ->setEditPolicy(PhabricatorPolicies::POLICY_USER)
->setJoinPolicy(PhabricatorPolicies::POLICY_USER) ->setJoinPolicy(PhabricatorPolicies::POLICY_USER)
->setIsMembershipLocked(0) ->setIsMembershipLocked(0)
->attachMemberPHIDs(array()); ->attachMemberPHIDs(array())
->attachSlugs(array());
} }
public function getCapabilities() { public function getCapabilities() {

View file

@ -146,6 +146,10 @@ final class AphrontDialogView extends AphrontView {
$paragraph)); $paragraph));
} }
public function appendForm(AphrontFormView $form) {
return $this->appendChild($form->buildLayoutView());
}
public function setDisableWorkflowOnSubmit($disable_workflow_on_submit) { public function setDisableWorkflowOnSubmit($disable_workflow_on_submit) {
$this->disableWorkflowOnSubmit = $disable_workflow_on_submit; $this->disableWorkflowOnSubmit = $disable_workflow_on_submit;
return $this; return $this;