mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Allow builtin named queries to be disabled
Summary: Applications come with builtin queries, but users might want to get rid of them. Allow users to disable named queries if they prefer. This has one funky behavior, which is that the first time you disable a named query it goes to the top of your list. That will be fixed in the next diff, which will make them reorderable. Test Plan: Added/edited/removed named queries, disabled/enabled builtin named queries. Reviewers: chad Reviewed By: chad CC: aran Differential Revision: https://secure.phabricator.com/D6128
This commit is contained in:
parent
7fbfeca802
commit
758586abda
7 changed files with 144 additions and 54 deletions
8
resources/sql/patches/20130602.namedqueries.sql
Normal file
8
resources/sql/patches/20130602.namedqueries.sql
Normal file
|
@ -0,0 +1,8 @@
|
|||
ALTER TABLE {$NAMESPACE}_search.search_namedquery
|
||||
ADD isBuiltin BOOL NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE {$NAMESPACE}_search.search_namedquery
|
||||
ADD isDisabled BOOL NOT NULL DEFAULT 0;
|
||||
|
||||
ALTER TABLE {$NAMESPACE}_search.search_namedquery
|
||||
ADD sequence INT UNSIGNED NOT NULL DEFAULT 0;
|
|
@ -35,7 +35,8 @@ final class PhabricatorApplicationSearch extends PhabricatorApplication {
|
|||
'hovercard/(?P<mode>retrieve|test)/' =>
|
||||
'PhabricatorSearchHovercardController',
|
||||
'edit/(?P<queryKey>[^/]+)/' => 'PhabricatorSearchEditController',
|
||||
'delete/(?P<queryKey>[^/]+)/' => 'PhabricatorSearchDeleteController',
|
||||
'delete/(?P<queryKey>[^/]+)/(?P<engine>[^/]+)/'
|
||||
=> 'PhabricatorSearchDeleteController',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -226,40 +226,47 @@ final class PhabricatorApplicationSearchController
|
|||
$engine = $this->getSearchEngine();
|
||||
$nav = $this->getNavigation();
|
||||
|
||||
$named_queries = id(new PhabricatorNamedQueryQuery())
|
||||
->setViewer($user)
|
||||
->withUserPHIDs(array($user->getPHID()))
|
||||
->withEngineClassNames(array(get_class($engine)))
|
||||
->execute();
|
||||
|
||||
$named_queries += $engine->getBuiltinQueries();
|
||||
$named_queries = $engine->loadAllNamedQueries();
|
||||
|
||||
$list = new PhabricatorObjectItemListView();
|
||||
$list->setUser($user);
|
||||
|
||||
foreach ($named_queries as $named_query) {
|
||||
$class = get_class($engine);
|
||||
$key = $named_query->getQueryKey();
|
||||
|
||||
$date_created = phabricator_datetime(
|
||||
$named_query->getDateCreated(),
|
||||
$user);
|
||||
|
||||
$item = id(new PhabricatorObjectItemView())
|
||||
->setHeader($named_query->getQueryName())
|
||||
->setHref($engine->getQueryResultsPageURI($named_query->getQueryKey()));
|
||||
->setHref($engine->getQueryResultsPageURI($key));
|
||||
|
||||
if ($named_query->getIsBuiltin() && $named_query->getIsDisabled()) {
|
||||
$icon = 'new';
|
||||
} else {
|
||||
$icon = 'delete';
|
||||
}
|
||||
|
||||
$item->addAction(
|
||||
id(new PhabricatorMenuItemView())
|
||||
->setIcon($icon)
|
||||
->setHref('/search/delete/'.$key.'/'.$class.'/')
|
||||
->setWorkflow(true));
|
||||
|
||||
if ($named_query->getIsBuiltin()) {
|
||||
$item->addIcon('lock-grey', pht('Builtin'));
|
||||
if ($named_query->getIsDisabled()) {
|
||||
$item->addIcon('delete-grey', pht('Disabled'));
|
||||
} else {
|
||||
$item->addIcon('lock-grey', pht('Builtin'));
|
||||
}
|
||||
$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')
|
||||
->setHref('/search/edit/'.$named_query->getQueryKey().'/'));
|
||||
->setHref('/search/edit/'.$key.'/'));
|
||||
}
|
||||
|
||||
$list->addItem($item);
|
||||
|
|
|
@ -7,52 +7,96 @@ final class PhabricatorSearchDeleteController
|
|||
extends PhabricatorSearchBaseController {
|
||||
|
||||
private $queryKey;
|
||||
private $engineClass;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->queryKey = idx($data, 'queryKey');
|
||||
$this->engineClass = idx($data, 'engine');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$saved_query = id(new PhabricatorSavedQueryQuery())
|
||||
->setViewer($user)
|
||||
->withQueryKeys(array($this->queryKey))
|
||||
->executeOne();
|
||||
$key = $this->queryKey;
|
||||
|
||||
if (!$saved_query) {
|
||||
return new Aphront404Response();
|
||||
$base_class = 'PhabricatorApplicationSearchEngine';
|
||||
if (!is_subclass_of($this->engineClass, $base_class)) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$engine = $saved_query->newEngine();
|
||||
$engine = newv($this->engineClass, array());
|
||||
$engine->setViewer($user);
|
||||
|
||||
$named_query = id(new PhabricatorNamedQueryQuery())
|
||||
->setViewer($user)
|
||||
->withQueryKeys(array($saved_query->getQueryKey()))
|
||||
->withEngineClassNames(array($this->engineClass))
|
||||
->withQueryKeys(array($key))
|
||||
->withUserPHIDs(array($user->getPHID()))
|
||||
->executeOne();
|
||||
|
||||
if (!$named_query && $engine->isBuiltinQuery($key)) {
|
||||
$named_query = id(new PhabricatorNamedQuery())
|
||||
->setUserPHID($user->getPHID())
|
||||
->setQueryName('(BUILTIN)')
|
||||
->setQueryKey($key)
|
||||
->setEngineClassName($this->engineClass)
|
||||
->setIsBuiltin(true);
|
||||
}
|
||||
|
||||
if (!$named_query) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$builtin = null;
|
||||
if ($engine->isBuiltinQuery($key)) {
|
||||
$builtin = $engine->getBuiltinQuery($key);
|
||||
}
|
||||
|
||||
$return_uri = $engine->getQueryManagementURI();
|
||||
|
||||
if ($request->isDialogFormPost()) {
|
||||
$named_query->delete();
|
||||
if ($named_query->getIsBuiltin()) {
|
||||
$named_query->setIsDisabled((int)(!$named_query->getIsDisabled()));
|
||||
$named_query->save();
|
||||
} else {
|
||||
$named_query->delete();
|
||||
}
|
||||
|
||||
return id(new AphrontRedirectResponse())->setURI($return_uri);
|
||||
}
|
||||
|
||||
if ($named_query->getIsBuiltin()) {
|
||||
if ($named_query->getIsDisabled()) {
|
||||
$title = pht('Enable Query?');
|
||||
$desc = pht(
|
||||
'Enable the built-in query "%s"? It will appear in your menu again.',
|
||||
$builtin->getQueryName());
|
||||
$button = pht('Enable Query');
|
||||
} else {
|
||||
$title = pht('Disable Query?');
|
||||
$desc = pht(
|
||||
'This built-in query can not be deleted, but you can disable it so '.
|
||||
'it does not appear in your query menu. You can enable it again '.
|
||||
'later. Disable built-in query "%s"?',
|
||||
$builtin->getQueryName());
|
||||
$button = pht('Disable Query');
|
||||
}
|
||||
} else {
|
||||
$title = pht('Really Delete Query?');
|
||||
$desc = pht(
|
||||
'Really delete the query "%s"? You can not undo this. Remember '.
|
||||
'all the great times you had filtering results together?',
|
||||
$named_query->getQueryName());
|
||||
$button = pht('Delete Query');
|
||||
}
|
||||
|
||||
$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()))
|
||||
->setTitle($title)
|
||||
->appendChild($desc)
|
||||
->addCancelButton($return_uri)
|
||||
->addSubmitButton(pht('Delete Query'));
|
||||
->addSubmitButton($button);
|
||||
|
||||
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||
}
|
||||
|
|
|
@ -111,13 +111,7 @@ abstract class PhabricatorApplicationSearchEngine {
|
|||
|
||||
$menu->newLabel(pht('Queries'));
|
||||
|
||||
$named_queries = id(new PhabricatorNamedQueryQuery())
|
||||
->setViewer($viewer)
|
||||
->withUserPHIDs(array($viewer->getPHID()))
|
||||
->withEngineClassNames(array(get_class($this)))
|
||||
->execute();
|
||||
|
||||
$named_queries = $named_queries + $this->getBuiltinQueries($viewer);
|
||||
$named_queries = $this->loadEnabledNamedQueries();
|
||||
|
||||
foreach ($named_queries as $query) {
|
||||
$key = $query->getQueryKey();
|
||||
|
@ -137,6 +131,45 @@ abstract class PhabricatorApplicationSearchEngine {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function loadAllNamedQueries() {
|
||||
$viewer = $this->requireViewer();
|
||||
|
||||
$named_queries = id(new PhabricatorNamedQueryQuery())
|
||||
->setViewer($viewer)
|
||||
->withUserPHIDs(array($viewer->getPHID()))
|
||||
->withEngineClassNames(array(get_class($this)))
|
||||
->execute();
|
||||
$named_queries = mpull($named_queries, null, 'getQueryKey');
|
||||
|
||||
$builtin = $this->getBuiltinQueries($viewer);
|
||||
$builtin = mpull($builtin, null, 'getQueryKey');
|
||||
|
||||
foreach ($named_queries as $key => $named_query) {
|
||||
if ($named_query->getIsBuiltin()) {
|
||||
if (isset($builtin[$key])) {
|
||||
$named_queries[$key]->setQueryName($builtin[$key]->getQueryName());
|
||||
unset($builtin[$key]);
|
||||
} else {
|
||||
unset($named_queries[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
unset($builtin[$key]);
|
||||
}
|
||||
|
||||
return $named_queries + $builtin;
|
||||
}
|
||||
|
||||
public function loadEnabledNamedQueries() {
|
||||
$named_queries = $this->loadAllNamedQueries();
|
||||
foreach ($named_queries as $key => $named_query) {
|
||||
if ($named_query->getIsBuiltin() && $named_query->getIsDisabled()) {
|
||||
unset($named_queries[$key]);
|
||||
}
|
||||
}
|
||||
return $named_queries;
|
||||
}
|
||||
|
||||
|
||||
/* -( Builtin Queries )---------------------------------------------------- */
|
||||
|
||||
|
|
|
@ -6,21 +6,14 @@
|
|||
final class PhabricatorNamedQuery extends PhabricatorSearchDAO
|
||||
implements PhabricatorPolicyInterface {
|
||||
|
||||
protected $queryKey = "";
|
||||
protected $queryName = "";
|
||||
protected $userPHID = "";
|
||||
protected $engineClassName = "";
|
||||
protected $queryKey;
|
||||
protected $queryName;
|
||||
protected $userPHID;
|
||||
protected $engineClassName;
|
||||
|
||||
private $isBuiltin;
|
||||
|
||||
public function setIsBuiltin($is_builtin) {
|
||||
$this->isBuiltin = $is_builtin;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsBuiltin() {
|
||||
return $this->isBuiltin;
|
||||
}
|
||||
protected $isBuiltin = 0;
|
||||
protected $isDisabled = 0;
|
||||
protected $sequence = 0;
|
||||
|
||||
/* -( PhabricatorPolicyInterface )----------------------------------------- */
|
||||
|
||||
|
|
|
@ -1346,6 +1346,10 @@ final class PhabricatorBuiltinPatchList extends PhabricatorSQLPatchList {
|
|||
'type' => 'sql',
|
||||
'name' => $this->getPatchPath('20130602.morediviner.sql'),
|
||||
),
|
||||
'20130602.namedqueries.sql' => array(
|
||||
'type' => 'sql',
|
||||
'name' => $this->getPatchPath('20130602.namedqueries.sql'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue