3 final class PhabricatorSearchEditController
4 extends PhabricatorSearchBaseController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $this->getViewer();
9 $id = $request->getURIData('id');
11 $named_query = id(new PhabricatorNamedQueryQuery())
14 ->requireCapabilities(
16 PhabricatorPolicyCapability
::CAN_VIEW
,
17 PhabricatorPolicyCapability
::CAN_EDIT
,
21 return new Aphront404Response();
24 $query_key = $named_query->getQueryKey();
26 $query_key = $request->getURIData('queryKey');
30 $saved_query = id(new PhabricatorSavedQueryQuery())
32 ->withQueryKeys(array($query_key))
35 return new Aphront404Response();
38 $engine = $saved_query->newEngine()->setViewer($viewer);
40 $complete_uri = $engine->getQueryManagementURI();
41 $cancel_uri = $complete_uri;
44 $named_query = id(new PhabricatorNamedQuery())
45 ->setUserPHID($viewer->getPHID())
46 ->setQueryKey($saved_query->getQueryKey())
47 ->setEngineClassName($saved_query->getEngineClassName());
49 // If we haven't saved the query yet, this is a "Save..." operation, so
50 // take the user back to the query if they cancel instead of back to the
51 // management interface.
52 $cancel_uri = $engine->getQueryResultsPageURI(
53 $saved_query->getQueryKey());
60 $can_global = ($viewer->getIsAdmin() && $is_new);
67 if ($request->isFormPost()) {
69 $v_global = $request->getBool('global');
71 $named_query->setUserPHID(PhabricatorNamedQuery
::SCOPE_GLOBAL
);
75 $named_query->setQueryName($request->getStr('name'));
76 if (!strlen($named_query->getQueryName())) {
77 $e_name = pht('Required');
78 $errors[] = pht('You must name the query.');
86 return id(new AphrontRedirectResponse())->setURI($complete_uri);
90 $form = id(new AphrontFormView())
94 id(new AphrontFormTextControl())
96 ->setLabel(pht('Query Name'))
97 ->setValue($named_query->getQueryName())
102 id(new AphrontFormCheckboxControl())
107 'Save this query as a global query, making it visible to '.
113 id(new AphrontFormSubmitControl())
114 ->setValue(pht('Save Query'))
115 ->addCancelButton($cancel_uri));
117 if ($named_query->getID()) {
118 $title = pht('Edit Saved Query');
119 $header_icon = 'fa-pencil';
121 $title = pht('Save Query');
122 $header_icon = 'fa-search';
125 $form_box = id(new PHUIObjectBoxView())
126 ->setHeaderText(pht('Query'))
127 ->setFormErrors($errors)
128 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
131 $crumbs = $this->buildApplicationCrumbs();
132 $crumbs->addTextCrumb($title);
133 $crumbs->setBorder(true);
135 $header = id(new PHUIHeaderView())
137 ->setHeaderIcon($header_icon);
139 $view = id(new PHUITwoColumnView())
141 ->setFooter($form_box);
143 return $this->newPage()
146 ->appendChild($view);