1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 04:20:55 +01:00
phorge-phorge/src/applications/search/controller/PhabricatorSearchEditController.php
epriestley 58b889c5b0 Make the default ApplicationSearch query explicit, not just the first item in the list
Summary:
Ref T12956. Currently, when you visit `/maniphest/` (or any other ApplicationSearch application) we execute the first query in the list by default.

In T12956, I plan to make changes so that personal queries are always first, then global/builtin queries. Without changing the "default query" rule, this will make it harder to have, for example, some custom queries in Differential but still run a global query like "Active" by default. To make this work, you'd have to save a personal copy of the "Active" query, then put it at the top.

This feels a bit cumbersome and this rule is kind of implicit and a little weird anyway. To make this work a little better as we make changes here, add an explicit pinning action, like the one we have in Project ProfileMenus.

You can now explicitly choose a query to make default.

Test Plan:
  - Browsed without pinning anything, saw normal behavior.
  - Pinned queries, viewed `/maniphest/`, saw a non-initial query selected by default.
  - Pinned a query, deleted it, nothing exploded.

{F5098484}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12956

Differential Revision: https://secure.phabricator.com/D18422
2017-08-24 15:21:00 -07:00

106 lines
2.9 KiB
PHP

<?php
final class PhabricatorSearchEditController
extends PhabricatorSearchBaseController {
public function handleRequest(AphrontRequest $request) {
$viewer = $this->getViewer();
$saved_query = id(new PhabricatorSavedQueryQuery())
->setViewer($viewer)
->withQueryKeys(array($request->getURIData('queryKey')))
->executeOne();
if (!$saved_query) {
return new Aphront404Response();
}
$engine = $saved_query->newEngine()->setViewer($viewer);
$complete_uri = $engine->getQueryManagementURI();
$cancel_uri = $complete_uri;
$named_query = id(new PhabricatorNamedQueryQuery())
->setViewer($viewer)
->withQueryKeys(array($saved_query->getQueryKey()))
->withUserPHIDs(array($viewer->getPHID()))
->executeOne();
if (!$named_query) {
$named_query = id(new PhabricatorNamedQuery())
->setUserPHID($viewer->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->getQueryKey());
}
$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();
return id(new AphrontRedirectResponse())->setURI($complete_uri);
}
}
$form = id(new AphrontFormView())
->setUser($viewer);
$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'))
->addCancelButton($cancel_uri));
if ($named_query->getID()) {
$title = pht('Edit Saved Query');
$header_icon = 'fa-pencil';
} else {
$title = pht('Save Query');
$header_icon = 'fa-search';
}
$form_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Query'))
->setFormErrors($errors)
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
->setForm($form);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb($title);
$crumbs->setBorder(true);
$header = id(new PHUIHeaderView())
->setHeader($title)
->setHeaderIcon($header_icon);
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter($form_box);
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
}
}