1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +01:00

Add a "make the workboard the default view" checkbox when creating a workboard

Summary: Ref T10054. Since we no longer have the "workboard default if it exists" rule, provide a quick way to make it the default.

Test Plan: Created a new workboard with the box checked, saw menu change appropriately.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10054

Differential Revision: https://secure.phabricator.com/D15092
This commit is contained in:
epriestley 2016-01-22 07:36:56 -08:00
parent 66ef506808
commit 0b67e89904
3 changed files with 91 additions and 40 deletions

View file

@ -761,8 +761,15 @@ final class PhabricatorProjectBoardViewController
$board_uri = $this->getApplicationURI("board/{$id}/");
$import_uri = $this->getApplicationURI("board/{$id}/import/");
switch ($type) {
case 'backlog-only':
$set_default = $request->getBool('default');
if ($set_default) {
$this
->getProfilePanelEngine()
->adjustDefault(PhabricatorProject::PANEL_WORKBOARD);
}
if ($request->isFormPost()) {
if ($type == 'backlog-only') {
$column = PhabricatorProjectColumn::initializeNewColumn($viewer)
->setSequence(0)
->setProperty('isDefault', true)
@ -773,12 +780,14 @@ final class PhabricatorProjectBoardViewController
return id(new AphrontRedirectResponse())
->setURI($board_uri);
case 'import':
} else {
return id(new AphrontRedirectResponse())
->setURI($import_uri);
}
}
$new_selector = id(new AphrontFormRadioButtonControl())
->setLabel(pht('Columns'))
->setName('initialize-type')
->setValue('backlog-only')
->addButton(
@ -790,11 +799,20 @@ final class PhabricatorProjectBoardViewController
pht('Import Columns'),
pht('Import board columns from another project.'));
$default_checkbox = id(new AphrontFormCheckboxControl())
->setLabel(pht('Make Default'))
->addCheckbox(
'default',
1,
pht('Make the workboard the default view for this project.'),
true);
$form = id(new AphrontFormView())
->setUser($viewer)
->appendRemarkupInstructions(
pht('The workboard for this project has not been created yet.'))
->appendControl($new_selector)
->appendControl($default_checkbox)
->appendControl(
id(new AphrontFormSubmitControl())
->addCancelButton($profile_uri)

View file

@ -133,6 +133,7 @@ abstract class PhabricatorProjectController extends PhabricatorController {
if ($project) {
$engine = id(new PhabricatorProjectProfilePanelEngine())
->setViewer($viewer)
->setController($this)
->setProfileObject($project);
$this->profilePanelEngine = $engine;
}

View file

@ -891,46 +891,13 @@ abstract class PhabricatorProfilePanelEngine extends Phobject {
->addCancelButton($done_uri);
}
$type_visibility =
PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY;
$v_visible = PhabricatorProfilePanelConfiguration::VISIBILITY_VISIBLE;
$v_default = PhabricatorProfilePanelConfiguration::VISIBILITY_DEFAULT;
if ($request->isFormPost()) {
// First, mark any existing default panels as merely visible.
foreach ($panels as $panel) {
if (!$panel->isDefault()) {
continue;
}
$xactions = array();
$xactions[] = id(new PhabricatorProfilePanelConfigurationTransaction())
->setTransactionType($type_visibility)
->setNewValue($v_visible);
$editor = id(new PhabricatorProfilePanelEditor())
->setContentSourceFromRequest($request)
->setActor($viewer)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true)
->applyTransactions($panel, $xactions);
$key = $configuration->getID();
if (!$key) {
$key = $configuration->getBuiltinKey();
}
// Now, make this panel the default.
$xactions = array();
$xactions[] = id(new PhabricatorProfilePanelConfigurationTransaction())
->setTransactionType($type_visibility)
->setNewValue($v_default);
$editor = id(new PhabricatorProfilePanelEditor())
->setContentSourceFromRequest($request)
->setActor($viewer)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true)
->applyTransactions($configuration, $xactions);
$this->adjustDefault($key);
return id(new AphrontRedirectResponse())
->setURI($done_uri);
@ -950,4 +917,69 @@ abstract class PhabricatorProfilePanelEngine extends Phobject {
return PhabricatorProfilePanelConfiguration::initializeNewBuiltin();
}
public function adjustDefault($key) {
$controller = $this->getController();
$request = $controller->getRequest();
$viewer = $request->getViewer();
$panels = $this->loadPanels();
// To adjust the default panel, we first change any existing panels that
// are marked as defaults to "visible", then make the new default panel
// the default.
$default = array();
$visible = array();
foreach ($panels as $panel) {
$builtin_key = $panel->getBuiltinKey();
$id = $panel->getID();
$is_target =
(($builtin_key !== null) && ($builtin_key === $key)) ||
(($id !== null) && ($id === (int)$key));
if ($is_target) {
if (!$panel->isDefault()) {
$default[] = $panel;
}
} else {
if ($panel->isDefault()) {
$visible[] = $panel;
}
}
}
$type_visibility =
PhabricatorProfilePanelConfigurationTransaction::TYPE_VISIBILITY;
$v_visible = PhabricatorProfilePanelConfiguration::VISIBILITY_VISIBLE;
$v_default = PhabricatorProfilePanelConfiguration::VISIBILITY_DEFAULT;
$apply = array(
array($v_visible, $visible),
array($v_default, $default),
);
foreach ($apply as $group) {
list($value, $panels) = $group;
foreach ($panels as $panel) {
$xactions = array();
$xactions[] = id(new PhabricatorProfilePanelConfigurationTransaction())
->setTransactionType($type_visibility)
->setNewValue($value);
$editor = id(new PhabricatorProfilePanelEditor())
->setContentSourceFromRequest($request)
->setActor($viewer)
->setContinueOnMissingFields(true)
->setContinueOnNoEffect(true)
->applyTransactions($panel, $xactions);
}
}
return $this;
}
}