1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Make saved queries editable

Summary: Ref T2625. Rename the "Name" controller to "Edit" and allow it to edit named queries. Also some UI touchups. Add an edit link to the saved query browse view.

Test Plan: Created and edited named queries.

Reviewers: btrahan, blc

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

Differential Revision: https://secure.phabricator.com/D6056
This commit is contained in:
epriestley 2013-05-27 13:42:01 -07:00
parent 587530d973
commit 0abb0c41bf
6 changed files with 115 additions and 74 deletions

View file

@ -1366,6 +1366,7 @@ phutil_register_library_map(array(
'PhabricatorSearchDocumentField' => 'applications/search/storage/document/PhabricatorSearchDocumentField.php',
'PhabricatorSearchDocumentIndexer' => 'applications/search/index/PhabricatorSearchDocumentIndexer.php',
'PhabricatorSearchDocumentRelationship' => 'applications/search/storage/document/PhabricatorSearchDocumentRelationship.php',
'PhabricatorSearchEditController' => 'applications/search/controller/PhabricatorSearchEditController.php',
'PhabricatorSearchEngine' => 'applications/search/engine/PhabricatorSearchEngine.php',
'PhabricatorSearchEngineElastic' => 'applications/search/engine/PhabricatorSearchEngineElastic.php',
'PhabricatorSearchEngineMySQL' => 'applications/search/engine/PhabricatorSearchEngineMySQL.php',
@ -1375,7 +1376,6 @@ phutil_register_library_map(array(
'PhabricatorSearchIndexer' => 'applications/search/index/PhabricatorSearchIndexer.php',
'PhabricatorSearchManagementIndexWorkflow' => 'applications/search/management/PhabricatorSearchManagementIndexWorkflow.php',
'PhabricatorSearchManagementWorkflow' => 'applications/search/management/PhabricatorSearchManagementWorkflow.php',
'PhabricatorSearchNameController' => 'applications/search/controller/PhabricatorSearchNameController.php',
'PhabricatorSearchQuery' => 'applications/search/storage/PhabricatorSearchQuery.php',
'PhabricatorSearchRelationship' => 'applications/search/constants/PhabricatorSearchRelationship.php',
'PhabricatorSearchResultView' => 'applications/search/view/PhabricatorSearchResultView.php',
@ -3150,12 +3150,12 @@ phutil_register_library_map(array(
'PhabricatorSearchDocument' => 'PhabricatorSearchDAO',
'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO',
'PhabricatorSearchDocumentRelationship' => 'PhabricatorSearchDAO',
'PhabricatorSearchEditController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchEngineElastic' => 'PhabricatorSearchEngine',
'PhabricatorSearchEngineMySQL' => 'PhabricatorSearchEngine',
'PhabricatorSearchHovercardController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchManagementIndexWorkflow' => 'PhabricatorSearchManagementWorkflow',
'PhabricatorSearchManagementWorkflow' => 'PhutilArgumentWorkflow',
'PhabricatorSearchNameController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchQuery' => 'PhabricatorSearchDAO',
'PhabricatorSearchResultView' => 'AphrontView',
'PhabricatorSearchSelectController' => 'PhabricatorSearchBaseController',

View file

@ -27,7 +27,11 @@ final class PhabricatorPasteQueriesController
$item = id(new PhabricatorObjectItemView())
->setHeader($named_query->getQueryName())
->setHref('/paste/query/'.$named_query->getQueryKey().'/')
->addIcon('none', $date_created);
->addIcon('none', $date_created)
->addAction(
id(new PhabricatorMenuItemView())
->setIcon('edit')
->setHref('/search/edit/'.$named_query->getQueryKey().'/'));
$list->addItem($item);
}

View file

@ -85,7 +85,7 @@ final class PhabricatorPasteSearchEngine
id(new AphrontFormSubmitControl())
->setValue(pht('Filter Pastes'))
->addCancelButton(
'/search/name/'.$saved_query->getQueryKey().'/',
'/search/edit/'.$saved_query->getQueryKey().'/',
pht('Save Custom Query...')));
return $form;

View file

@ -34,7 +34,7 @@ final class PhabricatorApplicationSearch extends PhabricatorApplication {
'index/(?P<phid>[^/]+)/' => 'PhabricatorSearchIndexController',
'hovercard/(?P<mode>retrieve|test)/' =>
'PhabricatorSearchHovercardController',
'name/(?P<queryKey>[^/]+)/' => 'PhabricatorSearchNameController',
'edit/(?P<queryKey>[^/]+)/' => 'PhabricatorSearchEditController',
),
);
}

View file

@ -0,0 +1,106 @@
<?php
/**
* @group search
*/
final class PhabricatorSearchEditController
extends PhabricatorSearchBaseController {
private $queryKey;
public function willProcessRequest(array $data) {
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$saved_query = id(new PhabricatorSavedQueryQuery())
->setViewer($user)
->withQueryKeys(array($this->queryKey))
->executeOne();
if (!$saved_query) {
return new Aphront404Response();
}
$engine = $saved_query->newEngine();
$named_query = id(new PhabricatorNamedQueryQuery())
->setViewer($user)
->withQueryKeys(array($saved_query->getQueryKey()))
->withUserPHIDs(array($user->getPHID()))
->executeOne();
if (!$named_query) {
$named_query = id(new PhabricatorNamedQuery())
->setUserPHID($user->getPHID())
->setQueryKey($saved_query->getQueryKey())
->setEngineClassName($saved_query->getEngineClassName());
}
$e_name = true;
$errors = array();
if ($request->isFormPost()) {
$named_query->setQueryName($request->getStr('name'));
if (!strlen($named_query->getQueryName())) {
$e_name = pht('Required');
$errors[] = pht('You must name the query.');
} else {
$e_name = null;
}
if (!$errors) {
$named_query->save();
$results_uri = $engine->getQueryResultsPageURI($saved_query);
return id(new AphrontRedirectResponse())->setURI($results_uri);
}
}
if ($errors) {
$errors = id(new AphrontErrorView())
->setErrors($errors);
}
$form = id(new AphrontFormView())
->setUser($user);
$form->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setLabel(pht('Query Name'))
->setValue($named_query->getQueryName())
->setError($e_name));
$form->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save Query')));
if ($named_query->getID()) {
$title = pht('Edit Saved Query');
} else {
$title = pht('Save Query');
}
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName($title));
return $this->buildApplicationPage(
array(
$crumbs,
$errors,
$form,
),
array(
'title' => $title,
'device' => true,
'dust' => true,
));
}
}

View file

@ -1,69 +0,0 @@
<?php
/**
* @group search
*/
final class PhabricatorSearchNameController
extends PhabricatorSearchBaseController {
private $queryKey;
public function willProcessRequest(array $data) {
$this->queryKey = idx($data, 'queryKey');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$saved_query = id(new PhabricatorSavedQueryQuery())
->setViewer($user)
->withQueryKeys(array($this->queryKey))
->executeOne();
if (!$saved_query) {
return new Aphront404Response();
}
$engine = $saved_query->newEngine();
if ($request->isFormPost()) {
$named_query = id(new PhabricatorNamedQuery())
->setUserPHID($user->getPHID())
->setQueryKey($saved_query->getQueryKey())
->setQueryName($request->getStr('name'))
->setEngineClassName($saved_query->getEngineClassName());
try {
$named_query->save();
} catch (AphrontQueryDuplicateKeyException $ex) {
// Ignore, the user is naming an identical query.
}
return id(new AphrontRedirectResponse())
->setURI($engine->getQueryResultsPageURI($saved_query));
}
$form = id(new AphrontFormView())
->setUser($user);
$form->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setLabel(pht('Query Name')));
$form->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save')));
return $this->buildStandardPageResponse(
array(
$form,
),
array(
'title' => 'Name Query',
));
}
}