1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 02:32:42 +01:00

Add a "tabs" dashboard panel type

Summary:
Ref T4986. Allows you to create a dashboard panel out of dashboard panels.

bwahaha

Test Plan:
{F155472}

{F155473}

Reviewers: chad, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4986

Differential Revision: https://secure.phabricator.com/D9141
This commit is contained in:
epriestley 2014-05-15 19:23:13 -07:00
parent 63acd90cef
commit bf6e87da24
6 changed files with 129 additions and 7 deletions

View file

@ -1481,6 +1481,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php', 'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php',
'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php', 'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php',
'PhabricatorDashboardPanelTypeQuery' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php', 'PhabricatorDashboardPanelTypeQuery' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php',
'PhabricatorDashboardPanelTypeTabs' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeTabs.php',
'PhabricatorDashboardPanelTypeText' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php', 'PhabricatorDashboardPanelTypeText' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php',
'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php', 'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php',
'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php', 'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php',
@ -4268,6 +4269,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorDashboardPanelType' => 'Phobject', 'PhabricatorDashboardPanelType' => 'Phobject',
'PhabricatorDashboardPanelTypeQuery' => 'PhabricatorDashboardPanelType', 'PhabricatorDashboardPanelTypeQuery' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardPanelTypeTabs' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardPanelTypeText' => 'PhabricatorDashboardPanelType', 'PhabricatorDashboardPanelTypeText' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController',
'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',

View file

@ -20,6 +20,10 @@ final class PhabricatorDashboardPanelRenderingEngine extends Phobject {
return $this; return $this;
} }
public function getParentPanelPHIDs() {
return $this->parentPanelPHIDs;
}
public function setViewer(PhabricatorUser $viewer) { public function setViewer(PhabricatorUser $viewer) {
$this->viewer = $viewer; $this->viewer = $viewer;
return $this; return $this;
@ -59,7 +63,7 @@ final class PhabricatorDashboardPanelRenderingEngine extends Phobject {
} }
} }
return $panel_type->renderPanel($viewer, $panel); return $panel_type->renderPanel($viewer, $panel, $this);
} catch (Exception $ex) { } catch (Exception $ex) {
return $this->renderErrorPanel( return $this->renderErrorPanel(
$panel->getName(), $panel->getName(),
@ -83,7 +87,7 @@ final class PhabricatorDashboardPanelRenderingEngine extends Phobject {
'dashboard-async-panel', 'dashboard-async-panel',
array( array(
'panelID' => $panel_id, 'panelID' => $panel_id,
'parentPanelPHIDs' => $this->parentPanelPHIDs, 'parentPanelPHIDs' => $this->getParentPanelPHIDs(),
'uri' => '/dashboard/panel/render/'.$panel->getID().'/', 'uri' => '/dashboard/panel/render/'.$panel->getID().'/',
)); ));

View file

@ -42,9 +42,10 @@ abstract class PhabricatorDashboardPanelType extends Phobject {
public function renderPanel( public function renderPanel(
PhabricatorUser $viewer, PhabricatorUser $viewer,
PhabricatorDashboardPanel $panel) { PhabricatorDashboardPanel $panel,
PhabricatorDashboardPanelRenderingEngine $engine) {
$content = $this->renderPanelContent($viewer, $panel); $content = $this->renderPanelContent($viewer, $panel, $engine);
return id(new PHUIObjectBoxView()) return id(new PHUIObjectBoxView())
->addSigil('dashboard-panel') ->addSigil('dashboard-panel')
@ -56,7 +57,8 @@ abstract class PhabricatorDashboardPanelType extends Phobject {
protected function renderPanelContent( protected function renderPanelContent(
PhabricatorUser $viewer, PhabricatorUser $viewer,
PhabricatorDashboardPanel $panel) { PhabricatorDashboardPanel $panel,
PhabricatorDashboardPanelRenderingEngine $engine) {
return pht('TODO: Panel content goes here.'); return pht('TODO: Panel content goes here.');
} }

View file

@ -32,7 +32,8 @@ final class PhabricatorDashboardPanelTypeQuery
protected function renderPanelContent( protected function renderPanelContent(
PhabricatorUser $viewer, PhabricatorUser $viewer,
PhabricatorDashboardPanel $panel) { PhabricatorDashboardPanel $panel,
PhabricatorDashboardPanelRenderingEngine $engine) {
$class = $panel->getProperty('class'); $class = $panel->getProperty('class');

View file

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

View file

@ -28,7 +28,8 @@ final class PhabricatorDashboardPanelTypeText
protected function renderPanelContent( protected function renderPanelContent(
PhabricatorUser $viewer, PhabricatorUser $viewer,
PhabricatorDashboardPanel $panel) { PhabricatorDashboardPanel $panel,
PhabricatorDashboardPanelRenderingEngine $engine) {
$text = $panel->getProperty('text', ''); $text = $panel->getProperty('text', '');