1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-24 06:20:56 +01:00

Separate editing of package data and paths in Owners

Summary:
Ref T8320. There's currently one enormous form; split it into a general information form (name, description, owners) and a paths form.

I think this is a little more manageable from both a UX point of view and from an "I have to convert this to use ApplicationTransactions" point of view.

Test Plan:
  - Edited paths.
  - Edited non-path information.
  - Created new packages.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8320

Differential Revision: https://secure.phabricator.com/D13026
This commit is contained in:
epriestley 2015-05-27 10:29:50 -07:00
parent 05bd6a1682
commit 009598593f
5 changed files with 211 additions and 103 deletions

View file

@ -2181,6 +2181,7 @@ phutil_register_library_map(array(
'PhabricatorOwnersPackageSearchEngine' => 'applications/owners/query/PhabricatorOwnersPackageSearchEngine.php', 'PhabricatorOwnersPackageSearchEngine' => 'applications/owners/query/PhabricatorOwnersPackageSearchEngine.php',
'PhabricatorOwnersPackageTestCase' => 'applications/owners/storage/__tests__/PhabricatorOwnersPackageTestCase.php', 'PhabricatorOwnersPackageTestCase' => 'applications/owners/storage/__tests__/PhabricatorOwnersPackageTestCase.php',
'PhabricatorOwnersPath' => 'applications/owners/storage/PhabricatorOwnersPath.php', 'PhabricatorOwnersPath' => 'applications/owners/storage/PhabricatorOwnersPath.php',
'PhabricatorOwnersPathsController' => 'applications/owners/controller/PhabricatorOwnersPathsController.php',
'PhabricatorPHDConfigOptions' => 'applications/config/option/PhabricatorPHDConfigOptions.php', 'PhabricatorPHDConfigOptions' => 'applications/config/option/PhabricatorPHDConfigOptions.php',
'PhabricatorPHID' => 'applications/phid/storage/PhabricatorPHID.php', 'PhabricatorPHID' => 'applications/phid/storage/PhabricatorPHID.php',
'PhabricatorPHIDConstants' => 'applications/phid/PhabricatorPHIDConstants.php', 'PhabricatorPHIDConstants' => 'applications/phid/PhabricatorPHIDConstants.php',
@ -5588,6 +5589,7 @@ phutil_register_library_map(array(
'PhabricatorOwnersPackageSearchEngine' => 'PhabricatorApplicationSearchEngine', 'PhabricatorOwnersPackageSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorOwnersPackageTestCase' => 'PhabricatorTestCase', 'PhabricatorOwnersPackageTestCase' => 'PhabricatorTestCase',
'PhabricatorOwnersPath' => 'PhabricatorOwnersDAO', 'PhabricatorOwnersPath' => 'PhabricatorOwnersDAO',
'PhabricatorOwnersPathsController' => 'PhabricatorOwnersController',
'PhabricatorPHDConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorPHDConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPHPASTApplication' => 'PhabricatorApplication', 'PhabricatorPHPASTApplication' => 'PhabricatorApplication',
'PhabricatorPHPConfigSetupCheck' => 'PhabricatorSetupCheck', 'PhabricatorPHPConfigSetupCheck' => 'PhabricatorSetupCheck',

View file

@ -47,6 +47,7 @@ final class PhabricatorOwnersApplication extends PhabricatorApplication {
'new/' => 'PhabricatorOwnersEditController', 'new/' => 'PhabricatorOwnersEditController',
'package/(?P<id>[1-9]\d*)/' => 'PhabricatorOwnersDetailController', 'package/(?P<id>[1-9]\d*)/' => 'PhabricatorOwnersDetailController',
'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorOwnersDeleteController', 'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorOwnersDeleteController',
'paths/(?P<id>[1-9]\d*)/' => 'PhabricatorOwnersPathsController',
), ),
); );
} }

View file

@ -188,6 +188,7 @@ final class PhabricatorOwnersDetailController
$id = $package->getID(); $id = $package->getID();
$edit_uri = $this->getApplicationURI("/edit/{$id}/"); $edit_uri = $this->getApplicationURI("/edit/{$id}/");
$paths_uri = $this->getApplicationURI("/paths/{$id}/");
$delete_uri = $this->getApplicationURI("/delete/{$id}/"); $delete_uri = $this->getApplicationURI("/delete/{$id}/");
$view = id(new PhabricatorActionListView()) $view = id(new PhabricatorActionListView())
@ -200,6 +201,13 @@ final class PhabricatorOwnersDetailController
->setDisabled(!$can_edit) ->setDisabled(!$can_edit)
->setWorkflow(!$can_edit) ->setWorkflow(!$can_edit)
->setHref($edit_uri)) ->setHref($edit_uri))
->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Paths'))
->setIcon('fa-folder-open')
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit)
->setHref($paths_uri))
->addAction( ->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setName(pht('Delete Package')) ->setName(pht('Delete Package'))
@ -242,6 +250,18 @@ final class PhabricatorOwnersDetailController
); );
} }
$info = null;
if (!$paths) {
$info = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_WARNING)
->setErrors(
array(
pht(
'This package does not contain any paths yet. Use '.
'"Edit Paths" to add some.'),
));
}
$table = id(new AphrontTableView($rows)) $table = id(new AphrontTableView($rows))
->setHeaders( ->setHeaders(
array( array(
@ -256,10 +276,15 @@ final class PhabricatorOwnersDetailController
'wide', 'wide',
)); ));
return id(new PHUIObjectBoxView()) $box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Paths')) ->setHeaderText(pht('Paths'))
->appendChild($table); ->appendChild($table);
if ($info) {
$box->setInfoView($info);
}
return $box;
} }
} }

View file

@ -21,9 +21,13 @@ final class PhabricatorOwnersEditController
if (!$package) { if (!$package) {
return new Aphront404Response(); return new Aphront404Response();
} }
$is_new = false;
} else { } else {
$package = new PhabricatorOwnersPackage(); $package = new PhabricatorOwnersPackage();
$package->setPrimaryOwnerPHID($viewer->getPHID()); $package->setPrimaryOwnerPHID($viewer->getPHID());
$is_new = true;
} }
$e_name = true; $e_name = true;
@ -51,22 +55,6 @@ final class PhabricatorOwnersEditController
} }
$owners = array_unique($owners); $owners = array_unique($owners);
$paths = $request->getArr('path');
$repos = $request->getArr('repo');
$excludes = $request->getArr('exclude');
$path_refs = array();
for ($ii = 0; $ii < count($paths); $ii++) {
if (empty($paths[$ii]) || empty($repos[$ii])) {
continue;
}
$path_refs[] = array(
'repositoryPHID' => $repos[$ii],
'path' => $paths[$ii],
'excluded' => $excludes[$ii],
);
}
if (!strlen($package->getName())) { if (!strlen($package->getName())) {
$e_name = pht('Required'); $e_name = pht('Required');
$errors[] = pht('Package name is required.'); $errors[] = pht('Package name is required.');
@ -81,13 +69,9 @@ final class PhabricatorOwnersEditController
$e_primary = null; $e_primary = null;
} }
if (!$path_refs) {
$errors[] = pht('Package must include at least one path.');
}
if (!$errors) { if (!$errors) {
$package->attachUnsavedOwners($owners); $package->attachUnsavedOwners($owners);
$package->attachUnsavedPaths($path_refs); $package->attachUnsavedPaths(array());
$package->attachOldAuditingEnabled($old_auditing_enabled); $package->attachOldAuditingEnabled($old_auditing_enabled);
$package->attachOldPrimaryOwnerPHID($old_primary); $package->attachOldPrimaryOwnerPHID($old_primary);
try { try {
@ -95,8 +79,15 @@ final class PhabricatorOwnersEditController
->setActor($viewer) ->setActor($viewer)
->setPackage($package) ->setPackage($package)
->save(); ->save();
return id(new AphrontRedirectResponse())
->setURI('/owners/package/'.$package->getID().'/'); $id = $package->getID();
if ($is_new) {
$next_uri = '/owners/paths/'.$id.'/';
} else {
$next_uri = '/owners/package/'.$id.'/';
}
return id(new AphrontRedirectResponse())->setURI($next_uri);
} catch (AphrontDuplicateKeyQueryException $ex) { } catch (AphrontDuplicateKeyQueryException $ex) {
$e_name = pht('Duplicate'); $e_name = pht('Duplicate');
$errors[] = pht('Package name must be unique.'); $errors[] = pht('Package name must be unique.');
@ -105,16 +96,6 @@ final class PhabricatorOwnersEditController
} else { } else {
$owners = $package->loadOwners(); $owners = $package->loadOwners();
$owners = mpull($owners, 'getUserPHID'); $owners = mpull($owners, 'getUserPHID');
$paths = $package->loadPaths();
$path_refs = array();
foreach ($paths as $path) {
$path_refs[] = array(
'repositoryPHID' => $path->getRepositoryPHID(),
'path' => $path->getPath(),
'excluded' => $path->getExcluded(),
);
}
} }
$primary = $package->getPrimaryOwnerPHID(); $primary = $package->getPrimaryOwnerPHID();
@ -124,52 +105,16 @@ final class PhabricatorOwnersEditController
$value_primary_owner = array(); $value_primary_owner = array();
} }
if ($package->getID()) { if ($is_new) {
$title = pht('Edit Package'); $cancel_uri = '/owners/';
} else {
$title = pht('New Package'); $title = pht('New Package');
$button_text = pht('Continue');
} else {
$cancel_uri = '/owners/package/'.$package->getID().'/';
$title = pht('Edit Package');
$button_text = pht('Save Package');
} }
$repos = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->execute();
$default_paths = array();
foreach ($repos as $repo) {
$default_path = $repo->getDetail('default-owners-path');
if ($default_path) {
$default_paths[$repo->getPHID()] = $default_path;
}
}
$repos = mpull($repos, 'getCallsign', 'getPHID');
asort($repos);
$template = new AphrontTypeaheadTemplateView();
$template = $template->render();
Javelin::initBehavior(
'owners-path-editor',
array(
'root' => 'path-editor',
'table' => 'paths',
'add_button' => 'addpath',
'repositories' => $repos,
'input_template' => $template,
'pathRefs' => $path_refs,
'completeURI' => '/diffusion/services/path/complete/',
'validateURI' => '/diffusion/services/path/validate/',
'repositoryDefaultPaths' => $default_paths,
));
require_celerity_resource('owners-path-editor-css');
$cancel_uri = $package->getID()
? '/owners/package/'.$package->getID().'/'
: '/owners/';
$form = id(new AphrontFormView()) $form = id(new AphrontFormView())
->setUser($viewer) ->setUser($viewer)
->appendChild( ->appendChild(
@ -210,30 +155,6 @@ final class PhabricatorOwnersEditController
$package->getAuditingEnabled() $package->getAuditingEnabled()
? 'enabled' ? 'enabled'
: 'disabled')) : 'disabled'))
->appendChild(
id(new PHUIFormInsetView())
->setTitle(pht('Paths'))
->addDivAttributes(array('id' => 'path-editor'))
->setRightButton(javelin_tag(
'a',
array(
'href' => '#',
'class' => 'button green',
'sigil' => 'addpath',
'mustcapture' => true,
),
pht('Add New Path')))
->setDescription(
pht(
'Specify the files and directories which comprise '.
'this package.'))
->setContent(javelin_tag(
'table',
array(
'class' => 'owners-path-editor-table',
'sigil' => 'paths',
),
'')))
->appendChild( ->appendChild(
id(new AphrontFormTextAreaControl()) id(new AphrontFormTextAreaControl())
->setLabel(pht('Description')) ->setLabel(pht('Description'))
@ -242,7 +163,7 @@ final class PhabricatorOwnersEditController
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->addCancelButton($cancel_uri) ->addCancelButton($cancel_uri)
->setValue(pht('Save Package'))); ->setValue($button_text));
$form_box = id(new PHUIObjectBoxView()) $form_box = id(new PHUIObjectBoxView())
->setHeaderText($title) ->setHeaderText($title)
@ -251,7 +172,10 @@ final class PhabricatorOwnersEditController
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
if ($package->getID()) { if ($package->getID()) {
$crumbs->addTextCrumb(pht('Edit %s', $package->getName())); $crumbs->addTextCrumb(
$package->getName(),
$this->getApplicationURI('package/'.$package->getID().'/'));
$crumbs->addTextCrumb(pht('Edit'));
} else { } else {
$crumbs->addTextCrumb(pht('New Package')); $crumbs->addTextCrumb(pht('New Package'));
} }

View file

@ -0,0 +1,156 @@
<?php
final class PhabricatorOwnersPathsController
extends PhabricatorOwnersController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getUser();
$package = id(new PhabricatorOwnersPackageQuery())
->setViewer($viewer)
->withIDs(array($request->getURIData('id')))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
// TODO: Support this capability.
// PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$package) {
return new Aphront404Response();
}
if ($request->isFormPost()) {
$paths = $request->getArr('path');
$repos = $request->getArr('repo');
$excludes = $request->getArr('exclude');
$path_refs = array();
for ($ii = 0; $ii < count($paths); $ii++) {
if (empty($paths[$ii]) || empty($repos[$ii])) {
continue;
}
$path_refs[] = array(
'repositoryPHID' => $repos[$ii],
'path' => $paths[$ii],
'excluded' => $excludes[$ii],
);
}
$package->attachUnsavedOwners(array());
$package->attachUnsavedPaths($path_refs);
$package->attachOldAuditingEnabled($package->getAuditingEnabled());
$package->attachOldPrimaryOwnerPHID($package->getPrimaryOwnerPHID());
id(new PhabricatorOwnersPackageEditor())
->setActor($viewer)
->setPackage($package)
->save();
return id(new AphrontRedirectResponse())
->setURI('/owners/package/'.$package->getID().'/');
} else {
$paths = $package->loadPaths();
$path_refs = array();
foreach ($paths as $path) {
$path_refs[] = array(
'repositoryPHID' => $path->getRepositoryPHID(),
'path' => $path->getPath(),
'excluded' => $path->getExcluded(),
);
}
}
$repos = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->execute();
$default_paths = array();
foreach ($repos as $repo) {
$default_path = $repo->getDetail('default-owners-path');
if ($default_path) {
$default_paths[$repo->getPHID()] = $default_path;
}
}
$repos = mpull($repos, 'getCallsign', 'getPHID');
asort($repos);
$template = new AphrontTypeaheadTemplateView();
$template = $template->render();
Javelin::initBehavior(
'owners-path-editor',
array(
'root' => 'path-editor',
'table' => 'paths',
'add_button' => 'addpath',
'repositories' => $repos,
'input_template' => $template,
'pathRefs' => $path_refs,
'completeURI' => '/diffusion/services/path/complete/',
'validateURI' => '/diffusion/services/path/validate/',
'repositoryDefaultPaths' => $default_paths,
));
require_celerity_resource('owners-path-editor-css');
$cancel_uri = '/owners/package/'.$package->getID().'/';
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild(
id(new PHUIFormInsetView())
->setTitle(pht('Paths'))
->addDivAttributes(array('id' => 'path-editor'))
->setRightButton(javelin_tag(
'a',
array(
'href' => '#',
'class' => 'button green',
'sigil' => 'addpath',
'mustcapture' => true,
),
pht('Add New Path')))
->setDescription(
pht(
'Specify the files and directories which comprise '.
'this package.'))
->setContent(javelin_tag(
'table',
array(
'class' => 'owners-path-editor-table',
'sigil' => 'paths',
),
'')))
->appendChild(
id(new AphrontFormSubmitControl())
->addCancelButton($cancel_uri)
->setValue(pht('Save Paths')));
$form_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Edit Paths'))
->setForm($form);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(
$package->getName(),
$this->getApplicationURI('package/'.$package->getID().'/'));
$crumbs->addTextCrumb(pht('Edit Paths'));
return $this->buildApplicationPage(
array(
$crumbs,
$form_box,
),
array(
'title' => array(
$package->getName(),
pht('Edit Paths'),
),
));
}
}