mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-10 14:51:06 +01: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:
parent
587530d973
commit
0abb0c41bf
6 changed files with 115 additions and 74 deletions
|
@ -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',
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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',
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue