1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Rebuild query panels on top of EditEngine

Summary: Depends on D20377. Ref T13272. In D20372, I temporarily removed the controls for actually editing Query panels. Restore them.

Test Plan:
  - Viewed existing Query panels, saw them working like they did before.
  - Created and edited Query panels.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13272

Differential Revision: https://secure.phabricator.com/D20382
This commit is contained in:
epriestley 2019-04-08 09:58:42 -07:00
parent 8d24e3a21a
commit 41afc7c7e6
6 changed files with 191 additions and 2 deletions

View file

@ -2973,7 +2973,11 @@ phutil_register_library_map(array(
'PhabricatorDashboardProfileMenuItem' => 'applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php',
'PhabricatorDashboardProjectInstallWorkflow' => 'applications/dashboard/install/PhabricatorDashboardProjectInstallWorkflow.php',
'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php',
'PhabricatorDashboardQueryPanelApplicationEditField' => 'applications/dashboard/editfield/PhabricatorDashboardQueryPanelApplicationEditField.php',
'PhabricatorDashboardQueryPanelApplicationTransaction' => 'applications/dashboard/xaction/panel/PhabricatorDashboardQueryPanelApplicationTransaction.php',
'PhabricatorDashboardQueryPanelInstallController' => 'applications/dashboard/controller/PhabricatorDashboardQueryPanelInstallController.php',
'PhabricatorDashboardQueryPanelQueryEditField' => 'applications/dashboard/editfield/PhabricatorDashboardQueryPanelQueryEditField.php',
'PhabricatorDashboardQueryPanelQueryTransaction' => 'applications/dashboard/xaction/panel/PhabricatorDashboardQueryPanelQueryTransaction.php',
'PhabricatorDashboardQueryPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardQueryPanelType.php',
'PhabricatorDashboardRemarkupRule' => 'applications/dashboard/remarkup/PhabricatorDashboardRemarkupRule.php',
'PhabricatorDashboardRemovePanelController' => 'applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php',
@ -8952,7 +8956,11 @@ phutil_register_library_map(array(
'PhabricatorDashboardProfileMenuItem' => 'PhabricatorProfileMenuItem',
'PhabricatorDashboardProjectInstallWorkflow' => 'PhabricatorDashboardObjectInstallWorkflow',
'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorDashboardQueryPanelApplicationEditField' => 'PhabricatorEditField',
'PhabricatorDashboardQueryPanelApplicationTransaction' => 'PhabricatorDashboardPanelPropertyTransaction',
'PhabricatorDashboardQueryPanelInstallController' => 'PhabricatorDashboardController',
'PhabricatorDashboardQueryPanelQueryEditField' => 'PhabricatorEditField',
'PhabricatorDashboardQueryPanelQueryTransaction' => 'PhabricatorDashboardPanelPropertyTransaction',
'PhabricatorDashboardQueryPanelType' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'PhabricatorDashboardRemovePanelController' => 'PhabricatorDashboardController',

View file

@ -0,0 +1,59 @@
<?php
final class PhabricatorDashboardQueryPanelApplicationEditField
extends PhabricatorEditField {
private $controlID;
protected function newControl() {
$engines = id(new PhutilClassMapQuery())
->setAncestorClass('PhabricatorApplicationSearchEngine')
->setFilterMethod('canUseInPanelContext')
->execute();
$all_apps = id(new PhabricatorApplicationQuery())
->setViewer($this->getViewer())
->withUnlisted(false)
->withInstalled(true)
->execute();
foreach ($engines as $index => $engine) {
if (!isset($all_apps[$engine->getApplicationClassName()])) {
unset($engines[$index]);
continue;
}
}
$options = array();
$value = $this->getValueForControl();
if (strlen($value) && empty($engines[$value])) {
$options[$value] = $value;
}
$engines = msort($engines, 'getResultTypeDescription');
foreach ($engines as $class_name => $engine) {
$options[$class_name] = $engine->getResultTypeDescription();
}
return id(new AphrontFormSelectControl())
->setID($this->getControlID())
->setOptions($options);
}
protected function newHTTPParameterType() {
return new AphrontSelectHTTPParameterType();
}
public function getControlID() {
if (!$this->controlID) {
$this->controlID = celerity_generate_unique_node_id();
}
return $this->controlID;
}
protected function newConduitParameterType() {
return new ConduitStringParameterType();
}
}

View file

@ -0,0 +1,77 @@
<?php
final class PhabricatorDashboardQueryPanelQueryEditField
extends PhabricatorEditField {
private $applicationControlID;
public function setApplicationControlID($id) {
$this->applicationControlID = $id;
return $this;
}
public function getApplicationControlID() {
return $this->applicationControlID;
}
protected function newControl() {
$engines = id(new PhutilClassMapQuery())
->setAncestorClass('PhabricatorApplicationSearchEngine')
->setFilterMethod('canUseInPanelContext')
->execute();
$value = $this->getValueForControl();
$queries = array();
$seen = false;
foreach ($engines as $engine_class => $engine) {
$engine->setViewer($this->getViewer());
$engine_queries = $engine->loadEnabledNamedQueries();
$query_map = mpull($engine_queries, 'getQueryName', 'getQueryKey');
asort($query_map);
foreach ($query_map as $key => $name) {
$queries[$engine_class][] = array('key' => $key, 'name' => $name);
if ($key == $value) {
$seen = true;
}
}
}
if (strlen($value) && !$seen) {
$name = pht('Custom Query ("%s")', $value);
} else {
$name = pht('(None)');
}
$options = array($value => $name);
$application_id = $this->getApplicationControlID();
$control_id = celerity_generate_unique_node_id();
Javelin::initBehavior(
'dashboard-query-panel-select',
array(
'applicationID' => $application_id,
'queryID' => $control_id,
'options' => $queries,
'value' => array(
'key' => strlen($value) ? $value : null,
'name' => $name,
),
));
return id(new AphrontFormSelectControl())
->setID($control_id)
->setOptions($options);
}
protected function newHTTPParameterType() {
return new AphrontSelectHTTPParameterType();
}
protected function newConduitParameterType() {
return new ConduitStringParameterType();
}
}

View file

@ -22,8 +22,29 @@ final class PhabricatorDashboardQueryPanelType
}
protected function newEditEngineFields(PhabricatorDashboardPanel $panel) {
// TODO: Restore this using EditEngine instead of CustomField.
return array();
$application_field =
id(new PhabricatorDashboardQueryPanelApplicationEditField())
->setKey('class')
->setLabel(pht('Search For'))
->setTransactionType(
PhabricatorDashboardQueryPanelApplicationTransaction::TRANSACTIONTYPE)
->setValue($panel->getProperty('class', ''));
$application_id = $application_field->getControlID();
$query_field =
id(new PhabricatorDashboardQueryPanelQueryEditField())
->setKey('key')
->setLabel(pht('Query'))
->setApplicationControlID($application_id)
->setTransactionType(
PhabricatorDashboardQueryPanelQueryTransaction::TRANSACTIONTYPE)
->setValue($panel->getProperty('key', ''));
return array(
$application_field,
$query_field,
);
}
public function initializeFieldsFromRequest(

View file

@ -0,0 +1,12 @@
<?php
final class PhabricatorDashboardQueryPanelApplicationTransaction
extends PhabricatorDashboardPanelPropertyTransaction {
const TRANSACTIONTYPE = 'query.application';
protected function getPropertyKey() {
return 'class';
}
}

View file

@ -0,0 +1,12 @@
<?php
final class PhabricatorDashboardQueryPanelQueryTransaction
extends PhabricatorDashboardPanelPropertyTransaction {
const TRANSACTIONTYPE = 'search.query';
protected function getPropertyKey() {
return 'key';
}
}