Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/storage/PhabricatorDashboard.php
| Show All 18 Lines | final class PhabricatorDashboard extends PhabricatorDashboardDAO | ||||
| protected $editPolicy; | protected $editPolicy; | ||||
| protected $status; | protected $status; | ||||
| protected $icon; | protected $icon; | ||||
| protected $layoutConfig = array(); | protected $layoutConfig = array(); | ||||
| const STATUS_ACTIVE = 'active'; | const STATUS_ACTIVE = 'active'; | ||||
| const STATUS_ARCHIVED = 'archived'; | const STATUS_ARCHIVED = 'archived'; | ||||
| private $panelPHIDs = self::ATTACHABLE; | |||||
| private $panels = self::ATTACHABLE; | private $panels = self::ATTACHABLE; | ||||
| private $edgeProjectPHIDs = self::ATTACHABLE; | private $edgeProjectPHIDs = self::ATTACHABLE; | ||||
| private $panelRefList; | |||||
| public static function initializeNewDashboard(PhabricatorUser $actor) { | public static function initializeNewDashboard(PhabricatorUser $actor) { | ||||
| return id(new PhabricatorDashboard()) | return id(new PhabricatorDashboard()) | ||||
| ->setName('') | ->setName('') | ||||
| ->setIcon('fa-dashboard') | ->setIcon('fa-dashboard') | ||||
| ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) | ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) | ||||
| ->setEditPolicy($actor->getPHID()) | ->setEditPolicy($actor->getPHID()) | ||||
| ->setStatus(self::STATUS_ACTIVE) | ->setStatus(self::STATUS_ACTIVE) | ||||
| ->setAuthorPHID($actor->getPHID()) | ->setAuthorPHID($actor->getPHID()) | ||||
| ->attachPanels(array()) | ->attachPanels(array()); | ||||
| ->attachPanelPHIDs(array()); | |||||
| } | } | ||||
| public static function getStatusNameMap() { | public static function getStatusNameMap() { | ||||
| return array( | return array( | ||||
| self::STATUS_ACTIVE => pht('Active'), | self::STATUS_ACTIVE => pht('Active'), | ||||
| self::STATUS_ARCHIVED => pht('Archived'), | self::STATUS_ARCHIVED => pht('Archived'), | ||||
| ); | ); | ||||
| } | } | ||||
| Show All 21 Lines | final class PhabricatorDashboard extends PhabricatorDashboardDAO | ||||
| public function getRawLayoutMode() { | public function getRawLayoutMode() { | ||||
| $config = $this->getRawLayoutConfig(); | $config = $this->getRawLayoutConfig(); | ||||
| return idx($config, 'layoutMode'); | return idx($config, 'layoutMode'); | ||||
| } | } | ||||
| public function setRawLayoutMode($mode) { | public function setRawLayoutMode($mode) { | ||||
| $config = $this->getRawLayoutConfig(); | $config = $this->getRawLayoutConfig(); | ||||
| $config['layoutMode'] = $mode; | $config['layoutMode'] = $mode; | ||||
| // If a cached panel ref list exists, clear it. | |||||
| $this->panelRefList = null; | |||||
| return $this->setLayoutConfig($config); | return $this->setLayoutConfig($config); | ||||
| } | } | ||||
| private function getRawLayoutConfig() { | private function getRawLayoutConfig() { | ||||
| $config = $this->getLayoutConfig(); | $config = $this->getLayoutConfig(); | ||||
| if (!is_array($config)) { | if (!is_array($config)) { | ||||
| $config = array(); | $config = array(); | ||||
| } | } | ||||
| return $config; | return $config; | ||||
| } | } | ||||
| public function getLayoutConfigObject() { | public function isArchived() { | ||||
| return PhabricatorDashboardLayoutConfig::newFromDictionary( | return ($this->getStatus() == self::STATUS_ARCHIVED); | ||||
| $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() { | public function getURI() { | ||||
| return $this->assertAttached($this->panelPHIDs); | return urisprintf('/dashboard/view/%d/', $this->getID()); | ||||
| } | } | ||||
| public function attachPanels(array $panels) { | public function getObjectName() { | ||||
| assert_instances_of($panels, 'PhabricatorDashboardPanel'); | return pht('Dashboard %d', $this->getID()); | ||||
| $this->panels = $panels; | |||||
| return $this; | |||||
| } | } | ||||
| public function getPanels() { | public function getPanelRefList() { | ||||
| return $this->assertAttached($this->panels); | if (!$this->panelRefList) { | ||||
| $this->panelRefList = $this->newPanelRefList(); | |||||
| } | } | ||||
| return $this->panelRefList; | |||||
| public function isArchived() { | |||||
| return ($this->getStatus() == self::STATUS_ARCHIVED); | |||||
| } | } | ||||
| public function getURI() { | private function newPanelRefList() { | ||||
| return urisprintf('/dashboard/view/%d/', $this->getID()); | $raw_config = $this->getLayoutConfig(); | ||||
| return PhabricatorDashboardPanelRefList::newFromDictionary($raw_config); | |||||
| } | } | ||||
| public function getObjectName() { | public function getPanelPHIDs() { | ||||
| return pht('Dashboard %d', $this->getID()); | $ref_list = $this->getPanelRefList(); | ||||
| $phids = mpull($ref_list->getPanelRefs(), 'getPanelPHID'); | |||||
| return array_unique($phids); | |||||
amckinley: Intentionally throwing away our new duplicate panels? | |||||
Done Inline ActionsgetPanelPHIDs() is only used for "I want to load all the handles used by this dashboard" or "I want to index all the panels used by this dashboard", so callers don't care about order/layout/sequence. If they care about that stuff, they should use the getPanelRefList() API instead. This one means get[FlatListOfUnique]PanelPHIDs[UsedByThisDashboardInArbitraryOrder](). epriestley: `getPanelPHIDs()` is only used for "I want to load all the handles used by this dashboard" or… | |||||
| } | } | ||||
| /* -( PhabricatorApplicationTransactionInterface )------------------------- */ | /* -( PhabricatorApplicationTransactionInterface )------------------------- */ | ||||
| public function getApplicationTransactionEditor() { | public function getApplicationTransactionEditor() { | ||||
| return new PhabricatorDashboardTransactionEditor(); | return new PhabricatorDashboardTransactionEditor(); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | return array( | ||||
| id(new PhabricatorDashboardNgrams()) | id(new PhabricatorDashboardNgrams()) | ||||
| ->setValue($this->getName()), | ->setValue($this->getName()), | ||||
| ); | ); | ||||
| } | } | ||||
| /* -( PhabricatorDashboardPanelContainerInterface )------------------------ */ | /* -( PhabricatorDashboardPanelContainerInterface )------------------------ */ | ||||
| public function getDashboardPanelContainerPanelPHIDs() { | public function getDashboardPanelContainerPanelPHIDs() { | ||||
| return PhabricatorEdgeQuery::loadDestinationPHIDs( | return $this->getPanelPHIDs(); | ||||
| $this->getPHID(), | |||||
| PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST); | |||||
| } | } | ||||
| } | } | ||||
Intentionally throwing away our new duplicate panels?