From df2c015e7cff68b949bc417175dd99ec83fa8c4f Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 17 Jun 2014 15:32:55 -0700 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 2 + ...abricatorDashboardPanelTabsCustomField.php | 71 +++++++++++++++++++ .../PhabricatorDashboardPanelTypeTabs.php | 14 ++-- 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 src/applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 7846a57073..fab6d43807 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php b/src/applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php new file mode 100644 index 0000000000..7892a51e60 --- /dev/null +++ b/src/applications/dashboard/customfield/PhabricatorDashboardPanelTabsCustomField.php @@ -0,0 +1,71 @@ +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; + } + +} diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeTabs.php b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeTabs.php index 5e192e4677..a0c16aa5f3 100644 --- a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeTabs.php +++ b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeTabs.php @@ -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,9 +35,13 @@ final class PhabricatorDashboardPanelTypeTabs PhabricatorDashboardPanel $panel, PhabricatorDashboardPanelRenderingEngine $engine) { - $config = phutil_json_decode($panel->getProperty('config'), null); - if ($config === null) { - throw new Exception(pht('The configuration is not valid JSON.')); + $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())