From a3c43c473be9d1d985ef4e8882aa248d2f83ff68 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 12 Apr 2019 08:34:48 -0700 Subject: [PATCH] Convert dashboard read/display pathways to the new panel storage format Summary: Depends on D20406. Ref T13272. This gets about half of Dashboards working with the new "duplicate panel friendly" storage format. Followups will fix the write pathways. Collateral damage here includes: - Remove the old Dashboard/Panel edge type. We have a new, more general edge type for "container X uses panel Y", and we don't need this edge type for anything else. - Remove "attachPanels()" from Dashboard. Only rendering actually needs this, and it can just load the panels. - Remove "attachPanelPHIDs()" from Dashboard. We can look at the panel refs to figure this out. - Remove "attachProjects()" from Dashboard. Nothing uses this and it's not a very modern approach. - `getPanelPHIDs()` just looks at the config now. - Deleted some `LayoutConfig`-related code which is broken/obsolete. Test Plan: - Viewed various dashboards which were created before the changes, saw them render correctly. - Viewed a dashboard with two of the same panel! AMAZING! Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13272 Differential Revision: https://secure.phabricator.com/D20407 --- src/__phutil_library_map__.php | 8 +- ...PhabricatorDashboardAddPanelController.php | 1 - ...habricatorDashboardMovePanelController.php | 1 - ...bricatorDashboardRemovePanelController.php | 11 -- .../PhabricatorDashboardViewController.php | 1 - ...atorDashboardDashboardHasPanelEdgeType.php | 103 ------------------ ...atorDashboardPanelHasDashboardEdgeType.php | 103 ------------------ .../PhabricatorDashboardTransactionEditor.php | 32 ------ .../PhabricatorDashboardRenderingEngine.php | 74 ++++++------- .../PhabricatorDashboardColumn.php | 10 ++ .../PhabricatorDashboardPanelRef.php | 37 +++++++ .../PhabricatorDashboardPanelRefList.php | 76 +++++++++++++ .../query/PhabricatorDashboardQuery.php | 65 ----------- .../PhabricatorDashboardSearchEngine.php | 13 +-- .../storage/PhabricatorDashboard.php | 78 +++++-------- .../storage/PhabricatorDashboardInstall.php | 1 - .../PhabricatorDashboardProfileMenuItem.php | 1 - 17 files changed, 190 insertions(+), 425 deletions(-) delete mode 100644 src/applications/dashboard/edge/PhabricatorDashboardDashboardHasPanelEdgeType.php delete mode 100644 src/applications/dashboard/edge/PhabricatorDashboardPanelHasDashboardEdgeType.php create mode 100644 src/applications/dashboard/layoutconfig/PhabricatorDashboardPanelRef.php create mode 100644 src/applications/dashboard/layoutconfig/PhabricatorDashboardPanelRefList.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b751a0aa41..dcccc7c6d6 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2914,7 +2914,6 @@ phutil_register_library_map(array( 'PhabricatorDashboardConsoleController' => 'applications/dashboard/controller/PhabricatorDashboardConsoleController.php', 'PhabricatorDashboardController' => 'applications/dashboard/controller/PhabricatorDashboardController.php', 'PhabricatorDashboardDAO' => 'applications/dashboard/storage/PhabricatorDashboardDAO.php', - 'PhabricatorDashboardDashboardHasPanelEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardDashboardHasPanelEdgeType.php', 'PhabricatorDashboardDashboardPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardDashboardPHIDType.php', 'PhabricatorDashboardDatasource' => 'applications/dashboard/typeahead/PhabricatorDashboardDatasource.php', 'PhabricatorDashboardEditController' => 'applications/dashboard/controller/dashboard/PhabricatorDashboardEditController.php', @@ -2945,13 +2944,14 @@ phutil_register_library_map(array( 'PhabricatorDashboardPanelEditConduitAPIMethod' => 'applications/dashboard/conduit/PhabricatorDashboardPanelEditConduitAPIMethod.php', 'PhabricatorDashboardPanelEditController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelEditController.php', 'PhabricatorDashboardPanelEditEngine' => 'applications/dashboard/editor/PhabricatorDashboardPanelEditEngine.php', - 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardPanelHasDashboardEdgeType.php', 'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelListController.php', 'PhabricatorDashboardPanelNameTransaction' => 'applications/dashboard/xaction/panel/PhabricatorDashboardPanelNameTransaction.php', 'PhabricatorDashboardPanelNgrams' => 'applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php', 'PhabricatorDashboardPanelPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardPanelPHIDType.php', 'PhabricatorDashboardPanelPropertyTransaction' => 'applications/dashboard/xaction/panel/PhabricatorDashboardPanelPropertyTransaction.php', 'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php', + 'PhabricatorDashboardPanelRef' => 'applications/dashboard/layoutconfig/PhabricatorDashboardPanelRef.php', + 'PhabricatorDashboardPanelRefList' => 'applications/dashboard/layoutconfig/PhabricatorDashboardPanelRefList.php', 'PhabricatorDashboardPanelRenderController' => 'applications/dashboard/controller/panel/PhabricatorDashboardPanelRenderController.php', 'PhabricatorDashboardPanelRenderingEngine' => 'applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php', 'PhabricatorDashboardPanelSearchEngine' => 'applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php', @@ -8914,7 +8914,6 @@ phutil_register_library_map(array( 'PhabricatorDashboardConsoleController' => 'PhabricatorDashboardController', 'PhabricatorDashboardController' => 'PhabricatorController', 'PhabricatorDashboardDAO' => 'PhabricatorLiskDAO', - 'PhabricatorDashboardDashboardHasPanelEdgeType' => 'PhabricatorEdgeType', 'PhabricatorDashboardDashboardPHIDType' => 'PhabricatorPHIDType', 'PhabricatorDashboardDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorDashboardEditController' => 'PhabricatorDashboardController', @@ -8952,13 +8951,14 @@ phutil_register_library_map(array( 'PhabricatorDashboardPanelEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod', 'PhabricatorDashboardPanelEditController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelEditEngine' => 'PhabricatorEditEngine', - 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'PhabricatorEdgeType', 'PhabricatorDashboardPanelListController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelNameTransaction' => 'PhabricatorDashboardPanelTransactionType', 'PhabricatorDashboardPanelNgrams' => 'PhabricatorSearchNgrams', 'PhabricatorDashboardPanelPHIDType' => 'PhabricatorPHIDType', 'PhabricatorDashboardPanelPropertyTransaction' => 'PhabricatorDashboardPanelTransactionType', 'PhabricatorDashboardPanelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'PhabricatorDashboardPanelRef' => 'Phobject', + 'PhabricatorDashboardPanelRefList' => 'Phobject', 'PhabricatorDashboardPanelRenderController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelRenderingEngine' => 'Phobject', 'PhabricatorDashboardPanelSearchEngine' => 'PhabricatorApplicationSearchEngine', diff --git a/src/applications/dashboard/controller/PhabricatorDashboardAddPanelController.php b/src/applications/dashboard/controller/PhabricatorDashboardAddPanelController.php index 65560f624f..d91a1a9da6 100644 --- a/src/applications/dashboard/controller/PhabricatorDashboardAddPanelController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardAddPanelController.php @@ -10,7 +10,6 @@ final class PhabricatorDashboardAddPanelController $dashboard = id(new PhabricatorDashboardQuery()) ->setViewer($viewer) ->withIDs(array($id)) - ->needPanels(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, diff --git a/src/applications/dashboard/controller/PhabricatorDashboardMovePanelController.php b/src/applications/dashboard/controller/PhabricatorDashboardMovePanelController.php index d1962517f9..cf3abe96af 100644 --- a/src/applications/dashboard/controller/PhabricatorDashboardMovePanelController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardMovePanelController.php @@ -15,7 +15,6 @@ final class PhabricatorDashboardMovePanelController $dashboard = id(new PhabricatorDashboardQuery()) ->setViewer($viewer) ->withIDs(array($id)) - ->needPanels(true) ->requireCapabilities( array( PhabricatorPolicyCapability::CAN_VIEW, diff --git a/src/applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php b/src/applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php index 672cecca03..0e6c095fe9 100644 --- a/src/applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php +++ b/src/applications/dashboard/controller/PhabricatorDashboardRemovePanelController.php @@ -47,17 +47,6 @@ final class PhabricatorDashboardRemovePanelController if ($request->isFormPost()) { $xactions = array(); - $xactions[] = id(new PhabricatorDashboardTransaction()) - ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) - ->setMetadataValue( - 'edge:type', - PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST) - ->setNewValue( - array( - '-' => array( - $v_panel => $v_panel, - ), - )); $layout_config->removePanel($v_panel); $dashboard->setLayoutConfigFromObject($layout_config); diff --git a/src/applications/dashboard/controller/dashboard/PhabricatorDashboardViewController.php b/src/applications/dashboard/controller/dashboard/PhabricatorDashboardViewController.php index 77de8df128..f43afd7e57 100644 --- a/src/applications/dashboard/controller/dashboard/PhabricatorDashboardViewController.php +++ b/src/applications/dashboard/controller/dashboard/PhabricatorDashboardViewController.php @@ -14,7 +14,6 @@ final class PhabricatorDashboardViewController $dashboard = id(new PhabricatorDashboardQuery()) ->setViewer($viewer) ->withIDs(array($id)) - ->needPanels(true) ->executeOne(); if (!$dashboard) { return new Aphront404Response(); diff --git a/src/applications/dashboard/edge/PhabricatorDashboardDashboardHasPanelEdgeType.php b/src/applications/dashboard/edge/PhabricatorDashboardDashboardHasPanelEdgeType.php deleted file mode 100644 index 8b31ea7476..0000000000 --- a/src/applications/dashboard/edge/PhabricatorDashboardDashboardHasPanelEdgeType.php +++ /dev/null @@ -1,103 +0,0 @@ -setTransactionType(PhabricatorTransactions::TYPE_EDGE) - ->setMetadataValue( - 'edge:type', - PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST) - ->setNewValue( - array( - '+' => array( - $panel->getPHID() => $panel->getPHID(), - ), - )); - - $layout_config = $dashboard->getLayoutConfigObject(); - $layout_config->setPanelLocation($column, $panel->getPHID()); - $dashboard->setLayoutConfigFromObject($layout_config); - - $editor = id(new PhabricatorDashboardTransactionEditor()) - ->setActor($actor) - ->setContentSource($content_source) - ->setContinueOnMissingFields(true) - ->setContinueOnNoEffect(true) - ->applyTransactions($dashboard, $xactions); - } - public function getTransactionTypes() { $types = parent::getTransactionTypes(); diff --git a/src/applications/dashboard/engine/PhabricatorDashboardRenderingEngine.php b/src/applications/dashboard/engine/PhabricatorDashboardRenderingEngine.php index acb09b7493..66e34f43ee 100644 --- a/src/applications/dashboard/engine/PhabricatorDashboardRenderingEngine.php +++ b/src/applications/dashboard/engine/PhabricatorDashboardRenderingEngine.php @@ -31,44 +31,46 @@ final class PhabricatorDashboardRenderingEngine extends Phobject { public function renderDashboard() { require_celerity_resource('phabricator-dashboard-css'); - $dashboard = $this->dashboard; - $viewer = $this->viewer; + $dashboard = $this->getDashboard(); + $viewer = $this->getViewer(); $is_editable = $this->arrangeMode; - $layout_config = $dashboard->getLayoutConfigObject(); - $panel_grid_locations = $layout_config->getPanelLocations(); - $panels = mpull($dashboard->getPanels(), null, 'getPHID'); - $dashboard_id = celerity_generate_unique_node_id(); - $result = id(new AphrontMultiColumnView()) - ->setID($dashboard_id) - ->setFluidLayout(true) - ->setGutter(AphrontMultiColumnView::GUTTER_LARGE); - if ($is_editable) { $h_mode = PhabricatorDashboardPanelRenderingEngine::HEADER_MODE_EDIT; } else { $h_mode = PhabricatorDashboardPanelRenderingEngine::HEADER_MODE_NORMAL; } - $panel_phids = array(); - foreach ($panel_grid_locations as $panel_column_locations) { - foreach ($panel_column_locations as $panel_phid) { - $panel_phids[] = $panel_phid; - } + $panel_phids = $dashboard->getPanelPHIDs(); + if ($panel_phids) { + $panels = id(new PhabricatorDashboardPanelQuery()) + ->setViewer($viewer) + ->withPHIDs($panel_phids) + ->execute(); + $panels = mpull($panels, null, 'getPHID'); + + $handles = $viewer->loadHandles($panel_phids); + } else { + $panels = array(); + $handles = array(); } - $handles = $viewer->loadHandles($panel_phids); - foreach ($panel_grid_locations as $column => $panel_column_locations) { - $panel_phids = $panel_column_locations; + $ref_list = $dashboard->getPanelRefList(); + $columns = $ref_list->getColumns(); - // TODO: This list may contain duplicates when the dashboard itself - // does not? Perhaps this is related to T10612. For now, just unique - // the list before moving on. - $panel_phids = array_unique($panel_phids); + $dashboard_id = celerity_generate_unique_node_id(); + + $result = id(new AphrontMultiColumnView()) + ->setID($dashboard_id) + ->setFluidLayout(true) + ->setGutter(AphrontMultiColumnView::GUTTER_LARGE); + + foreach ($columns as $column) { + $column_views = array(); + foreach ($column->getPanelRefs() as $panel_ref) { + $panel_phid = $panel_ref->getPanelPHID(); - $column_result = array(); - foreach ($panel_phids as $panel_phid) { $panel_engine = id(new PhabricatorDashboardPanelRenderingEngine()) ->setViewer($viewer) ->setDashboardID($dashboard->getID()) @@ -85,18 +87,19 @@ final class PhabricatorDashboardRenderingEngine extends Phobject { $panel_engine->setPanel($panel); } - $column_result[] = $panel_engine->renderPanel(); + $column_views[] = $panel_engine->renderPanel(); } - $column_class = $layout_config->getColumnClass( - $column, - $is_editable); + + $column_classes = $column->getClasses(); + if ($is_editable) { - $column_result[] = $this->renderAddPanelPlaceHolder($column); - $column_result[] = $this->renderAddPanelUI($column); + $column_views[] = $this->renderAddPanelPlaceHolder(); + $column_views[] = $this->renderAddPanelUI($column->getColumnKey()); } + $result->addColumn( - $column_result, - $column_class, + $column_views, + implode(' ', $column_classes), $sigil = 'dashboard-column', $metadata = array('columnID' => $column)); } @@ -120,10 +123,7 @@ final class PhabricatorDashboardRenderingEngine extends Phobject { return $view; } - private function renderAddPanelPlaceHolder($column) { - $dashboard = $this->dashboard; - $panels = $dashboard->getPanels(); - + private function renderAddPanelPlaceHolder() { return javelin_tag( 'span', array( diff --git a/src/applications/dashboard/layoutconfig/PhabricatorDashboardColumn.php b/src/applications/dashboard/layoutconfig/PhabricatorDashboardColumn.php index 4f9d6b9f74..4dd15b0072 100644 --- a/src/applications/dashboard/layoutconfig/PhabricatorDashboardColumn.php +++ b/src/applications/dashboard/layoutconfig/PhabricatorDashboardColumn.php @@ -5,6 +5,7 @@ final class PhabricatorDashboardColumn private $columnKey; private $classes = array(); + private $refs = array(); public function setColumnKey($column_key) { $this->columnKey = $column_key; @@ -24,4 +25,13 @@ final class PhabricatorDashboardColumn return $this->classes; } + public function addPanelRef(PhabricatorDashboardPanelRef $ref) { + $this->refs[] = $ref; + return $this; + } + + public function getPanelRefs() { + return $this->refs; + } + } diff --git a/src/applications/dashboard/layoutconfig/PhabricatorDashboardPanelRef.php b/src/applications/dashboard/layoutconfig/PhabricatorDashboardPanelRef.php new file mode 100644 index 0000000000..5f43562d31 --- /dev/null +++ b/src/applications/dashboard/layoutconfig/PhabricatorDashboardPanelRef.php @@ -0,0 +1,37 @@ +panelPHID = $panel_phid; + return $this; + } + + public function getPanelPHID() { + return $this->panelPHID; + } + + public function setColumnKey($column_key) { + $this->columnKey = $column_key; + return $this; + } + + public function getColumnKey() { + return $this->columnKey; + } + + public function setPanelKey($panel_key) { + $this->panelKey = $panel_key; + return $this; + } + + public function getPanelKey() { + return $this->panelKey; + } + +} diff --git a/src/applications/dashboard/layoutconfig/PhabricatorDashboardPanelRefList.php b/src/applications/dashboard/layoutconfig/PhabricatorDashboardPanelRefList.php new file mode 100644 index 0000000000..fd186887cd --- /dev/null +++ b/src/applications/dashboard/layoutconfig/PhabricatorDashboardPanelRefList.php @@ -0,0 +1,76 @@ +getLayoutModeColumns(); + $columns = mpull($columns, null, 'getColumnKey'); + $default_column = head($columns); + + $panels = idx($config, 'panels'); + if (!is_array($panels)) { + $panels = array(); + } + + $seen_panels = array(); + $refs = array(); + foreach ($panels as $panel) { + $panel_phid = idx($panel, 'panelPHID'); + if (!strlen($panel_phid)) { + continue; + } + + $panel_key = idx($panel, 'panelKey'); + if (!strlen($panel_key)) { + continue; + } + + if (isset($seen_panels[$panel_key])) { + continue; + } + $seen_panels[$panel_key] = true; + + $column_key = idx($panel, 'columnKey'); + $column = idx($columns, $column_key, $default_column); + + $ref = id(new PhabricatorDashboardPanelRef()) + ->setPanelPHID($panel_phid) + ->setPanelKey($panel_key) + ->setColumnKey($column->getColumnKey()); + + $column->addPanelRef($ref); + $refs[] = $ref; + } + + $list = new self(); + + $list->columns = $columns; + $list->refs = $refs; + + return $list; + } + + public function getColumns() { + return $this->columns; + } + + public function getPanelRefs() { + return $this->refs; + } + +} diff --git a/src/applications/dashboard/query/PhabricatorDashboardQuery.php b/src/applications/dashboard/query/PhabricatorDashboardQuery.php index 9f5e256391..df4df155e5 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardQuery.php +++ b/src/applications/dashboard/query/PhabricatorDashboardQuery.php @@ -9,9 +9,6 @@ final class PhabricatorDashboardQuery private $authorPHIDs; private $canEdit; - private $needPanels; - private $needProjects; - public function withIDs(array $ids) { $this->ids = $ids; return $this; @@ -32,16 +29,6 @@ final class PhabricatorDashboardQuery return $this; } - public function needPanels($need_panels) { - $this->needPanels = $need_panels; - return $this; - } - - public function needProjects($need_projects) { - $this->needProjects = $need_projects; - return $this; - } - public function withCanEdit($can_edit) { $this->canEdit = $can_edit; return $this; @@ -74,58 +61,6 @@ final class PhabricatorDashboardQuery ->apply($dashboards); } - if ($this->needPanels) { - $edge_query = id(new PhabricatorEdgeQuery()) - ->withSourcePHIDs($phids) - ->withEdgeTypes( - array( - PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST, - )); - $edge_query->execute(); - - $panel_phids = $edge_query->getDestinationPHIDs(); - if ($panel_phids) { - // NOTE: We explicitly disable policy exceptions when loading panels. - // If a particular panel is invalid or not visible to the viewer, - // we'll still render the dashboard, just not that panel. - - $panels = id(new PhabricatorDashboardPanelQuery()) - ->setParentQuery($this) - ->setRaisePolicyExceptions(false) - ->setViewer($this->getViewer()) - ->withPHIDs($panel_phids) - ->execute(); - $panels = mpull($panels, null, 'getPHID'); - } else { - $panels = array(); - } - - foreach ($dashboards as $dashboard) { - $dashboard_phids = $edge_query->getDestinationPHIDs( - array($dashboard->getPHID())); - $dashboard_panels = array_select_keys($panels, $dashboard_phids); - - $dashboard->attachPanelPHIDs($dashboard_phids); - $dashboard->attachPanels($dashboard_panels); - } - } - - if ($this->needProjects) { - $edge_query = id(new PhabricatorEdgeQuery()) - ->withSourcePHIDs($phids) - ->withEdgeTypes( - array( - PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, - )); - $edge_query->execute(); - - foreach ($dashboards as $dashboard) { - $project_phids = $edge_query->getDestinationPHIDs( - array($dashboard->getPHID())); - $dashboard->attachProjectPHIDs($project_phids); - } - } - return $dashboards; } diff --git a/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php b/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php index 545d77da29..32bd2e6d6e 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php +++ b/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php @@ -12,8 +12,7 @@ final class PhabricatorDashboardSearchEngine } public function newQuery() { - return id(new PhabricatorDashboardQuery()) - ->needPanels(true); + return id(new PhabricatorDashboardQuery()); } public function canUseInPanelContext() { @@ -139,16 +138,6 @@ final class PhabricatorDashboardSearchEngine $bg_color = 'bg-grey'; } - $panels = $dashboard->getPanels(); - foreach ($panels as $panel) { - $item->addAttribute($panel->getName()); - } - - if (empty($panels)) { - $empty = phutil_tag('em', array(), pht('No panels.')); - $item->addAttribute($empty); - } - $icon = id(new PHUIIconView()) ->setIcon($dashboard->getIcon()) ->setBackground($bg_color); diff --git a/src/applications/dashboard/storage/PhabricatorDashboard.php b/src/applications/dashboard/storage/PhabricatorDashboard.php index fb5b58e5ac..c229f80736 100644 --- a/src/applications/dashboard/storage/PhabricatorDashboard.php +++ b/src/applications/dashboard/storage/PhabricatorDashboard.php @@ -24,10 +24,10 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO const STATUS_ACTIVE = 'active'; const STATUS_ARCHIVED = 'archived'; - private $panelPHIDs = self::ATTACHABLE; private $panels = self::ATTACHABLE; private $edgeProjectPHIDs = self::ATTACHABLE; + private $panelRefList; public static function initializeNewDashboard(PhabricatorUser $actor) { return id(new PhabricatorDashboard()) @@ -37,8 +37,7 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO ->setEditPolicy($actor->getPHID()) ->setStatus(self::STATUS_ACTIVE) ->setAuthorPHID($actor->getPHID()) - ->attachPanels(array()) - ->attachPanelPHIDs(array()); + ->attachPanels(array()); } public static function getStatusNameMap() { @@ -76,6 +75,10 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO public function setRawLayoutMode($mode) { $config = $this->getRawLayoutConfig(); $config['layoutMode'] = $mode; + + // If a cached panel ref list exists, clear it. + $this->panelRefList = null; + return $this->setLayoutConfig($config); } @@ -89,53 +92,6 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO return $config; } - public function getLayoutConfigObject() { - return PhabricatorDashboardLayoutConfig::newFromDictionary( - $this->getLayoutConfig()); - } - - public function setLayoutConfigFromObject( - PhabricatorDashboardLayoutConfig $object) { - - $this->setLayoutConfig($object->toDictionary()); - - // See PHI385. Dashboard panel mutations rely on changes to the Dashboard - // object persisting when transactions are applied, but this assumption is - // no longer valid after T13054. For now, just save the dashboard - // explicitly. - $this->save(); - - return $this; - } - - public function getProjectPHIDs() { - return $this->assertAttached($this->edgeProjectPHIDs); - } - - public function attachProjectPHIDs(array $phids) { - $this->edgeProjectPHIDs = $phids; - return $this; - } - - public function attachPanelPHIDs(array $phids) { - $this->panelPHIDs = $phids; - return $this; - } - - public function getPanelPHIDs() { - return $this->assertAttached($this->panelPHIDs); - } - - public function attachPanels(array $panels) { - assert_instances_of($panels, 'PhabricatorDashboardPanel'); - $this->panels = $panels; - return $this; - } - - public function getPanels() { - return $this->assertAttached($this->panels); - } - public function isArchived() { return ($this->getStatus() == self::STATUS_ARCHIVED); } @@ -148,6 +104,24 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO return pht('Dashboard %d', $this->getID()); } + public function getPanelRefList() { + if (!$this->panelRefList) { + $this->panelRefList = $this->newPanelRefList(); + } + return $this->panelRefList; + } + + private function newPanelRefList() { + $raw_config = $this->getLayoutConfig(); + return PhabricatorDashboardPanelRefList::newFromDictionary($raw_config); + } + + public function getPanelPHIDs() { + $ref_list = $this->getPanelRefList(); + $phids = mpull($ref_list->getPanelRefs(), 'getPanelPHID'); + return array_unique($phids); + } + /* -( PhabricatorApplicationTransactionInterface )------------------------- */ @@ -216,9 +190,7 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO /* -( PhabricatorDashboardPanelContainerInterface )------------------------ */ public function getDashboardPanelContainerPanelPHIDs() { - return PhabricatorEdgeQuery::loadDestinationPHIDs( - $this->getPHID(), - PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST); + return $this->getPanelPHIDs(); } } diff --git a/src/applications/dashboard/storage/PhabricatorDashboardInstall.php b/src/applications/dashboard/storage/PhabricatorDashboardInstall.php index 318c064808..f8a808cecc 100644 --- a/src/applications/dashboard/storage/PhabricatorDashboardInstall.php +++ b/src/applications/dashboard/storage/PhabricatorDashboardInstall.php @@ -43,7 +43,6 @@ final class PhabricatorDashboardInstall $dashboard = id(new PhabricatorDashboardQuery()) ->setViewer($viewer) ->withPHIDs(array($dashboard_install->getDashboardPHID())) - ->needPanels(true) ->executeOne(); } diff --git a/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php index 7954aefff3..9d89c52ff8 100644 --- a/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php @@ -54,7 +54,6 @@ final class PhabricatorDashboardProfileMenuItem $dashboard = id(new PhabricatorDashboardQuery()) ->setViewer($viewer) ->withPHIDs(array($dashboard_phid)) - ->needPanels(true) ->executeOne(); if (!$dashboard) { return $this->newEmptyView(