Page MenuHomePhabricator

D9141.id21709.diff
No OneTemporary

D9141.id21709.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1478,6 +1478,7 @@
'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php',
'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php',
'PhabricatorDashboardPanelTypeQuery' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php',
+ 'PhabricatorDashboardPanelTypeTabs' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeTabs.php',
'PhabricatorDashboardPanelTypeText' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php',
'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php',
'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php',
@@ -4263,6 +4264,7 @@
'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorDashboardPanelType' => 'Phobject',
'PhabricatorDashboardPanelTypeQuery' => 'PhabricatorDashboardPanelType',
+ 'PhabricatorDashboardPanelTypeTabs' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardPanelTypeText' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController',
'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
diff --git a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
--- a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
+++ b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
@@ -20,6 +20,10 @@
return $this;
}
+ public function getParentPanelPHIDs() {
+ return $this->parentPanelPHIDs;
+ }
+
public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer;
return $this;
@@ -59,7 +63,7 @@
}
}
- return $panel_type->renderPanel($viewer, $panel);
+ return $panel_type->renderPanel($viewer, $panel, $this);
} catch (Exception $ex) {
return $this->renderErrorPanel(
$panel->getName(),
@@ -83,7 +87,7 @@
'dashboard-async-panel',
array(
'panelID' => $panel_id,
- 'parentPanelPHIDs' => $this->parentPanelPHIDs,
+ 'parentPanelPHIDs' => $this->getParentPanelPHIDs(),
'uri' => '/dashboard/panel/render/'.$panel->getID().'/',
));
diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php
--- a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php
+++ b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelType.php
@@ -42,9 +42,10 @@
public function renderPanel(
PhabricatorUser $viewer,
- PhabricatorDashboardPanel $panel) {
+ PhabricatorDashboardPanel $panel,
+ PhabricatorDashboardPanelRenderingEngine $engine) {
- $content = $this->renderPanelContent($viewer, $panel);
+ $content = $this->renderPanelContent($viewer, $panel, $engine);
return id(new PHUIObjectBoxView())
->setHeaderText($panel->getName())
@@ -53,7 +54,8 @@
protected function renderPanelContent(
PhabricatorUser $viewer,
- PhabricatorDashboardPanel $panel) {
+ PhabricatorDashboardPanel $panel,
+ PhabricatorDashboardPanelRenderingEngine $engine) {
return pht('TODO: Panel content goes here.');
}
diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php
--- a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php
+++ b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php
@@ -32,7 +32,8 @@
protected function renderPanelContent(
PhabricatorUser $viewer,
- PhabricatorDashboardPanel $panel) {
+ PhabricatorDashboardPanel $panel,
+ PhabricatorDashboardPanelRenderingEngine $engine) {
$class = $panel->getProperty('class');
diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeTabs.php b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeTabs.php
new file mode 100644
--- /dev/null
+++ b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeTabs.php
@@ -0,0 +1,112 @@
+<?php
+
+final class PhabricatorDashboardPanelTypeTabs
+ extends PhabricatorDashboardPanelType {
+
+ public function getPanelTypeKey() {
+ return 'tabs';
+ }
+
+ public function getPanelTypeName() {
+ return pht('Tab Panel');
+ }
+
+ public function getPanelTypeDescription() {
+ return pht(
+ 'Use tabs to switch between several other panels.');
+ }
+
+ public function getFieldSpecifications() {
+ return array(
+ 'config' => array(
+ 'name' => pht('JSON Config'),
+ 'type' => 'remarkup',
+ ),
+ );
+ }
+
+ protected function renderPanelContent(
+ PhabricatorUser $viewer,
+ 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.'));
+ }
+
+ $list = id(new PHUIListView())
+ ->setType(PHUIListView::NAVBAR_LIST);
+
+ $selected = 0;
+
+ // TODO: Instead of using reveal-content here, we should write some nice
+ // JS which loads panels on demand, manages tab selected states, and maybe
+ // saves the tab you selected.
+
+ $node_ids = array();
+ foreach ($config as $idx => $tab_spec) {
+ $node_ids[$idx] = celerity_generate_unique_node_id();
+ }
+
+ Javelin::initBehavior('phabricator-reveal-content');
+
+ foreach ($config as $idx => $tab_spec) {
+ $hide_ids = $node_ids;
+ unset($hide_ids[$idx]);
+
+ $list->addMenuItem(
+ id(new PHUIListItemView())
+ ->setHref('#')
+ ->addSigil('reveal-content')
+ ->setMetadata(
+ array(
+ 'showIDs' => array(idx($node_ids, $idx)),
+ 'hideIDs' => array_values($hide_ids),
+ ))
+ ->setName(idx($tab_spec, 'name', pht('Nameless Tab'))));
+ }
+
+ $ids = ipull($config, 'panelID');
+ if ($ids) {
+ $panels = id(new PhabricatorDashboardPanelQuery())
+ ->setViewer($viewer)
+ ->withIDs($ids)
+ ->execute();
+ } else {
+ $panels = array();
+ }
+
+ $parent_phids = $engine->getParentPanelPHIDs();
+ $parent_phids[] = $panel->getPHID();
+
+ $content = array();
+ foreach ($config as $idx => $tab_spec) {
+ $panel_id = idx($tab_spec, 'panelID');
+ $panel = idx($panels, $panel_id);
+
+ if ($panel) {
+ $panel_content = id(new PhabricatorDashboardPanelRenderingEngine())
+ ->setViewer($viewer)
+ ->setEnableAsyncRendering(true)
+ ->setParentPanelPHIDs($parent_phids)
+ ->setPanel($panel)
+ ->renderPanel();
+ } else {
+ $panel_content = 'nope';
+ }
+
+ $content[] = phutil_tag(
+ 'div',
+ array(
+ 'id' => $node_ids[$idx],
+ 'style' => ($idx == $selected) ? null : 'display: none',
+ ),
+ $panel_content);
+ }
+
+
+ return array($list, $content);
+ }
+
+}
diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php
--- a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php
+++ b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php
@@ -28,7 +28,8 @@
protected function renderPanelContent(
PhabricatorUser $viewer,
- PhabricatorDashboardPanel $panel) {
+ PhabricatorDashboardPanel $panel,
+ PhabricatorDashboardPanelRenderingEngine $engine) {
$text = $panel->getProperty('text', '');

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 12, 10:35 AM (1 d, 18 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6726681
Default Alt Text
D9141.id21709.diff (8 KB)

Event Timeline