1
0
Fork 0
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:
epriestley 2014-06-17 15:32:55 -07:00
parent 7892627ccc
commit df2c015e7c
3 changed files with 82 additions and 5 deletions

View file

@ -1498,6 +1498,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelSearchApplicationCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchApplicationCustomField.php',
'PhabricatorDashboardPanelSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php',
'PhabricatorDashboardPanelSearchQueryCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelSearchQueryCustomField.php',
'PhabricatorDashboardPanelTabsCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php',
'PhabricatorDashboardPanelTransaction' => 'applications/dashboard/storage/PhabricatorDashboardPanelTransaction.php',
'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php',
'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php',
@ -4319,6 +4320,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelSearchApplicationCustomField' => 'PhabricatorStandardCustomField',
'PhabricatorDashboardPanelSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorDashboardPanelSearchQueryCustomField' => 'PhabricatorStandardCustomField',
'PhabricatorDashboardPanelTabsCustomField' => 'PhabricatorStandardCustomField',
'PhabricatorDashboardPanelTransaction' => 'PhabricatorApplicationTransaction',
'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery',

View file

@ -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;
}
}

View file

@ -19,8 +19,8 @@ final class PhabricatorDashboardPanelTypeTabs
public function getFieldSpecifications() {
return array(
'config' => array(
'name' => pht('JSON Config'),
'type' => 'remarkup',
'name' => pht('Tabs'),
'type' => 'dashboard.tabs',
),
);
}
@ -35,10 +35,14 @@ final class PhabricatorDashboardPanelTypeTabs
PhabricatorDashboardPanel $panel,
PhabricatorDashboardPanelRenderingEngine $engine) {
$config = phutil_json_decode($panel->getProperty('config'), null);
$config = $panel->getProperty('config');
if (!is_array($config)) {
// 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())
->setType(PHUIListView::NAVBAR_LIST);