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

Allow custom queries to be deleted

Summary:
Ref T2625. Currently, custom saved queries can be edited but not deleted. Allow them to be deleted. Also:

  - Clean up an unused property in `PhabricatorPasteViewController`.
  - Fix an issue with left nav highlighting of builtin queries.
  - Improve submit behavior for edits.
  - Add a cancel button on edits.

Test Plan: Saved, edited and deleted queries.

Reviewers: btrahan, blc

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2625

Differential Revision: https://secure.phabricator.com/D6059
This commit is contained in:
epriestley 2013-05-27 13:42:44 -07:00
parent 451ddd76bf
commit 3db82cb2ec
8 changed files with 99 additions and 8 deletions

View file

@ -1362,6 +1362,7 @@ phutil_register_library_map(array(
'PhabricatorSearchConfigOptions' => 'applications/search/config/PhabricatorSearchConfigOptions.php',
'PhabricatorSearchController' => 'applications/search/controller/PhabricatorSearchController.php',
'PhabricatorSearchDAO' => 'applications/search/storage/PhabricatorSearchDAO.php',
'PhabricatorSearchDeleteController' => 'applications/search/controller/PhabricatorSearchDeleteController.php',
'PhabricatorSearchDocument' => 'applications/search/storage/document/PhabricatorSearchDocument.php',
'PhabricatorSearchDocumentField' => 'applications/search/storage/document/PhabricatorSearchDocumentField.php',
'PhabricatorSearchDocumentIndexer' => 'applications/search/index/PhabricatorSearchDocumentIndexer.php',
@ -3147,6 +3148,7 @@ phutil_register_library_map(array(
'PhabricatorSearchConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorSearchController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchDAO' => 'PhabricatorLiskDAO',
'PhabricatorSearchDeleteController' => 'PhabricatorSearchBaseController',
'PhabricatorSearchDocument' => 'PhabricatorSearchDAO',
'PhabricatorSearchDocumentField' => 'PhabricatorSearchDAO',
'PhabricatorSearchDocumentRelationship' => 'PhabricatorSearchDAO',

View file

@ -38,6 +38,11 @@ final class PhabricatorPasteQueriesController
$item->setBarColor('grey');
} else {
$item->addIcon('none', $date_created);
$item->addAction(
id(new PhabricatorMenuItemView())
->setIcon('delete')
->setHref('/search/delete/'.$named_query->getQueryKey().'/')
->setWorkflow(true));
$item->addAction(
id(new PhabricatorMenuItemView())
->setIcon('edit')

View file

@ -2,13 +2,12 @@
final class PhabricatorPasteViewController extends PhabricatorPasteController {
private $id;
public function shouldAllowPublic() {
return true;
}
private $id;
private $handles;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}

View file

@ -84,6 +84,10 @@ final class PhabricatorPasteSearchEngine
return '/paste/query/'.$query->getQueryKey().'/';
}
public function getQueryManagementURI() {
return '/paste/savedqueries/';
}
public function getBuiltinQueryNames() {
$names = array(
'all' => pht('All Pastes'),
@ -99,6 +103,7 @@ final class PhabricatorPasteSearchEngine
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'all':

View file

@ -35,6 +35,7 @@ final class PhabricatorApplicationSearch extends PhabricatorApplication {
'hovercard/(?P<mode>retrieve|test)/' =>
'PhabricatorSearchHovercardController',
'edit/(?P<queryKey>[^/]+)/' => 'PhabricatorSearchEditController',
'delete/(?P<queryKey>[^/]+)/' => 'PhabricatorSearchDeleteController',
),
);
}

View file

@ -0,0 +1,60 @@
<?php
/**
* @group search
*/
final class PhabricatorSearchDeleteController
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) {
return new Aphront404Response();
}
$return_uri = $engine->getQueryManagementURI();
if ($request->isDialogFormPost()) {
$named_query->delete();
return id(new AphrontRedirectResponse())->setURI($return_uri);
}
$dialog = id(new AphrontDialogView())
->setUser($user)
->setTitle(pht("Really Delete Query?"))
->appendChild(
pht(
'Really delete the query "%s"? You can not undo this. Remember '.
'all the great times you had filtering results together?',
$named_query->getQueryName()))
->addCancelButton($return_uri)
->addSubmitButton(pht('Delete Query'));
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}

View file

@ -25,7 +25,10 @@ final class PhabricatorSearchEditController
return new Aphront404Response();
}
$engine = $saved_query->newEngine();
$engine = $saved_query->newEngine()->setViewer($user);
$complete_uri = $engine->getQueryManagementURI();
$cancel_uri = $complete_uri;
$named_query = id(new PhabricatorNamedQueryQuery())
->setViewer($user)
@ -37,6 +40,11 @@ final class PhabricatorSearchEditController
->setUserPHID($user->getPHID())
->setQueryKey($saved_query->getQueryKey())
->setEngineClassName($saved_query->getEngineClassName());
// If we haven't saved the query yet, this is a "Save..." operation, so
// take the user back to the query if they cancel instead of back to the
// management interface.
$cancel_uri = $engine->getQueryResultsPageURI($saved_query);
}
$e_name = true;
@ -53,9 +61,7 @@ final class PhabricatorSearchEditController
if (!$errors) {
$named_query->save();
$results_uri = $engine->getQueryResultsPageURI($saved_query);
return id(new AphrontRedirectResponse())->setURI($results_uri);
return id(new AphrontRedirectResponse())->setURI($complete_uri);
}
}
@ -76,7 +82,8 @@ final class PhabricatorSearchEditController
$form->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Save Query')));
->setValue(pht('Save Query'))
->addCancelButton($cancel_uri));
if ($named_query->getID()) {
$title = pht('Edit Saved Query');

View file

@ -5,6 +5,7 @@
* creating and storing saved queries.
*
* @task builtin Builtin Queries
* @task uri Query URIs
*
* @group search
*/
@ -57,10 +58,21 @@ abstract class PhabricatorApplicationSearchEngine {
*
* @param PhabricatorSavedQuery The query to build a URI for.
* @return string URI where the query can be executed.
* @task uri
*/
abstract public function getQueryResultsPageURI(PhabricatorSavedQuery $query);
/**
* Return an application URI for query management. This is used when, e.g.,
* a query deletion operation is cancelled.
*
* @return string URI where queries can be managed.
* @task uri
*/
abstract public function getQueryManagementURI();
public function newSavedQuery() {
return id(new PhabricatorSavedQuery())
->setEngineClassName(get_class($this));