mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-24 06:20:56 +01:00
Make Dashboard tab panels editable by humans
Summary: Fixes T5335. This is not pretty, but should reasonably let normal humans create tab panels. Test Plan: See screenshot. Reviewers: chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T5335 Differential Revision: https://secure.phabricator.com/D9600
This commit is contained in:
parent
7892627ccc
commit
df2c015e7c
3 changed files with 82 additions and 5 deletions
|
@ -1498,6 +1498,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDashboardPanelSearchApplicationCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchApplicationCustomField.php',
|
'PhabricatorDashboardPanelSearchApplicationCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchApplicationCustomField.php',
|
||||||
'PhabricatorDashboardPanelSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php',
|
'PhabricatorDashboardPanelSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php',
|
||||||
'PhabricatorDashboardPanelSearchQueryCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchQueryCustomField.php',
|
'PhabricatorDashboardPanelSearchQueryCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchQueryCustomField.php',
|
||||||
|
'PhabricatorDashboardPanelTabsCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php',
|
||||||
'PhabricatorDashboardPanelTransaction' => 'applications/dashboard/storage/PhabricatorDashboardPanelTransaction.php',
|
'PhabricatorDashboardPanelTransaction' => 'applications/dashboard/storage/PhabricatorDashboardPanelTransaction.php',
|
||||||
'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php',
|
'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php',
|
||||||
'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php',
|
'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php',
|
||||||
|
@ -4319,6 +4320,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorDashboardPanelSearchApplicationCustomField' => 'PhabricatorStandardCustomField',
|
'PhabricatorDashboardPanelSearchApplicationCustomField' => 'PhabricatorStandardCustomField',
|
||||||
'PhabricatorDashboardPanelSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'PhabricatorDashboardPanelSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'PhabricatorDashboardPanelSearchQueryCustomField' => 'PhabricatorStandardCustomField',
|
'PhabricatorDashboardPanelSearchQueryCustomField' => 'PhabricatorStandardCustomField',
|
||||||
|
'PhabricatorDashboardPanelTabsCustomField' => 'PhabricatorStandardCustomField',
|
||||||
'PhabricatorDashboardPanelTransaction' => 'PhabricatorApplicationTransaction',
|
'PhabricatorDashboardPanelTransaction' => 'PhabricatorApplicationTransaction',
|
||||||
'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorDashboardPanelTabsCustomField
|
||||||
|
extends PhabricatorStandardCustomField {
|
||||||
|
|
||||||
|
public function getFieldType() {
|
||||||
|
return 'dashboard.tabs';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function shouldAppearInApplicationSearch() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function readValueFromRequest(AphrontRequest $request) {
|
||||||
|
$value = array();
|
||||||
|
|
||||||
|
$names = $request->getArr($this->getFieldKey().'_name');
|
||||||
|
$panels = $request->getArr($this->getFieldKey().'_panelID');
|
||||||
|
foreach ($names as $idx => $name) {
|
||||||
|
$panel_id = idx($panels, $idx);
|
||||||
|
if (strlen($name) && $panel_id) {
|
||||||
|
$value[] = array(
|
||||||
|
'name' => $name,
|
||||||
|
'panelID' => $panel_id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setFieldValue($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function renderEditControl(array $handles) {
|
||||||
|
$panels = id(new PhabricatorDashboardPanelQuery())
|
||||||
|
->setViewer($this->getViewer())
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
$panel_map = array();
|
||||||
|
foreach ($panels as $panel) {
|
||||||
|
$panel_map[$panel->getID()] = pht(
|
||||||
|
'%s %s',
|
||||||
|
$panel->getMonogram(),
|
||||||
|
$panel->getName());
|
||||||
|
}
|
||||||
|
$panel_map = array(
|
||||||
|
'' => pht('(None)'),
|
||||||
|
) + $panel_map;
|
||||||
|
|
||||||
|
$value = $this->getFieldValue();
|
||||||
|
if (!is_array($value)) {
|
||||||
|
$value = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$out = array();
|
||||||
|
for ($ii = 1; $ii <= 6; $ii++) {
|
||||||
|
$tab = idx($value, ($ii - 1), array());
|
||||||
|
$out[] = id(new AphrontFormTextControl())
|
||||||
|
->setName($this->getFieldKey().'_name[]')
|
||||||
|
->setValue(idx($tab, 'name'))
|
||||||
|
->setLabel(pht('Tab %d Name', $ii));
|
||||||
|
|
||||||
|
$out[] = id(new AphrontFormSelectControl())
|
||||||
|
->setName($this->getFieldKey().'_panelID[]')
|
||||||
|
->setValue(idx($tab, 'panelID'))
|
||||||
|
->setOptions($panel_map)
|
||||||
|
->setLabel(pht('Tab %d Panel', $ii));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,8 +19,8 @@ final class PhabricatorDashboardPanelTypeTabs
|
||||||
public function getFieldSpecifications() {
|
public function getFieldSpecifications() {
|
||||||
return array(
|
return array(
|
||||||
'config' => array(
|
'config' => array(
|
||||||
'name' => pht('JSON Config'),
|
'name' => pht('Tabs'),
|
||||||
'type' => 'remarkup',
|
'type' => 'dashboard.tabs',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -35,9 +35,13 @@ final class PhabricatorDashboardPanelTypeTabs
|
||||||
PhabricatorDashboardPanel $panel,
|
PhabricatorDashboardPanel $panel,
|
||||||
PhabricatorDashboardPanelRenderingEngine $engine) {
|
PhabricatorDashboardPanelRenderingEngine $engine) {
|
||||||
|
|
||||||
$config = phutil_json_decode($panel->getProperty('config'), null);
|
$config = $panel->getProperty('config');
|
||||||
if ($config === null) {
|
if (!is_array($config)) {
|
||||||
throw new Exception(pht('The configuration is not valid JSON.'));
|
// NOTE: The older version of this panel stored raw JSON.
|
||||||
|
$config = phutil_json_decode($config, null);
|
||||||
|
if ($config === null) {
|
||||||
|
throw new Exception(pht('The configuration is not valid JSON.'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$list = id(new PHUIListView())
|
$list = id(new PHUIListView())
|
||||||
|
|
Loading…
Reference in a new issue