Differential D20408 Diff 48715 src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
| <?php | <?php | ||||
| final class PhabricatorDashboardPanelRenderingEngine extends Phobject { | final class PhabricatorDashboardPanelRenderingEngine extends Phobject { | ||||
| const HEADER_MODE_NORMAL = 'normal'; | const HEADER_MODE_NORMAL = 'normal'; | ||||
| const HEADER_MODE_NONE = 'none'; | const HEADER_MODE_NONE = 'none'; | ||||
| const HEADER_MODE_EDIT = 'edit'; | const HEADER_MODE_EDIT = 'edit'; | ||||
| private $panel; | private $panel; | ||||
| private $panelPHID; | private $panelPHID; | ||||
| private $viewer; | private $viewer; | ||||
| private $enableAsyncRendering; | private $enableAsyncRendering; | ||||
| private $parentPanelPHIDs; | private $parentPanelPHIDs; | ||||
| private $headerMode = self::HEADER_MODE_NORMAL; | private $headerMode = self::HEADER_MODE_NORMAL; | ||||
| private $dashboardID; | |||||
| private $movable = true; | private $movable = true; | ||||
| private $panelHandle; | private $panelHandle; | ||||
| private $editMode; | private $editMode; | ||||
| private $contextObject; | private $contextObject; | ||||
| private $panelKey; | |||||
| public function setContextObject($object) { | public function setContextObject($object) { | ||||
| $this->contextObject = $object; | $this->contextObject = $object; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getContextObject() { | public function getContextObject() { | ||||
| return $this->contextObject; | return $this->contextObject; | ||||
| } | } | ||||
| public function setDashboardID($id) { | public function setPanelKey($panel_key) { | ||||
| $this->dashboardID = $id; | $this->panelKey = $panel_key; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getDashboardID() { | public function getPanelKey() { | ||||
| return $this->dashboardID; | return $this->panelKey; | ||||
| } | } | ||||
| public function setHeaderMode($header_mode) { | public function setHeaderMode($header_mode) { | ||||
| $this->headerMode = $header_mode; | $this->headerMode = $header_mode; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| public function getHeaderMode() { | public function getHeaderMode() { | ||||
| ▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | private function renderNormalPanel() { | ||||
| return $this->renderPanelDiv( | return $this->renderPanelDiv( | ||||
| $content, | $content, | ||||
| $header); | $header); | ||||
| } | } | ||||
| private function renderAsyncPanel() { | private function renderAsyncPanel() { | ||||
| $context_phid = $this->getContextPHID(); | |||||
| $panel = $this->getPanel(); | $panel = $this->getPanel(); | ||||
| $panel_id = celerity_generate_unique_node_id(); | $panel_id = celerity_generate_unique_node_id(); | ||||
| $dashboard_id = $this->getDashboardID(); | |||||
| Javelin::initBehavior( | Javelin::initBehavior( | ||||
| 'dashboard-async-panel', | 'dashboard-async-panel', | ||||
| array( | array( | ||||
| 'panelID' => $panel_id, | 'panelID' => $panel_id, | ||||
| 'parentPanelPHIDs' => $this->getParentPanelPHIDs(), | 'parentPanelPHIDs' => $this->getParentPanelPHIDs(), | ||||
| 'headerMode' => $this->getHeaderMode(), | 'headerMode' => $this->getHeaderMode(), | ||||
| 'dashboardID' => $dashboard_id, | 'contextPHID' => $context_phid, | ||||
| 'panelKey' => $this->getPanelKey(), | |||||
| 'uri' => '/dashboard/panel/render/'.$panel->getID().'/', | 'uri' => '/dashboard/panel/render/'.$panel->getID().'/', | ||||
| )); | )); | ||||
| $header = $this->renderPanelHeader(); | $header = $this->renderPanelHeader(); | ||||
| $content = id(new PHUIPropertyListView()) | $content = id(new PHUIPropertyListView()) | ||||
| ->addTextContent(pht('Loading...')); | ->addTextContent(pht('Loading...')); | ||||
| return $this->renderPanelDiv( | return $this->renderPanelDiv( | ||||
| ▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | private function renderPanelHeader() { | ||||
| return $header; | return $header; | ||||
| } | } | ||||
| private function addPanelHeaderActions( | private function addPanelHeaderActions( | ||||
| PHUIHeaderView $header) { | PHUIHeaderView $header) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $panel = $this->getPanel(); | $panel = $this->getPanel(); | ||||
| $dashboard_id = $this->getDashboardID(); | $context_phid = $this->getContextPHID(); | ||||
| $actions = array(); | $actions = array(); | ||||
| if ($panel) { | if ($panel) { | ||||
| $panel_id = $panel->getID(); | $panel_id = $panel->getID(); | ||||
| $edit_uri = "/dashboard/panel/edit/{$panel_id}/"; | $edit_uri = "/dashboard/panel/edit/{$panel_id}/"; | ||||
| $edit_uri = new PhutilURI($edit_uri); | $params = array( | ||||
| if ($dashboard_id) { | 'contextPHID' => $context_phid, | ||||
| $edit_uri->replaceQueryParam('dashboardID', $dashboard_id); | ); | ||||
| } | $edit_uri = new PhutilURI($edit_uri, $params); | ||||
| $actions[] = id(new PhabricatorActionView()) | $actions[] = id(new PhabricatorActionView()) | ||||
| ->setIcon('fa-pencil') | ->setIcon('fa-pencil') | ||||
| ->setName(pht('Edit Panel')) | ->setName(pht('Edit Panel')) | ||||
| ->setHref((string)$edit_uri); | ->setHref($edit_uri); | ||||
| $actions[] = id(new PhabricatorActionView()) | $actions[] = id(new PhabricatorActionView()) | ||||
| ->setIcon('fa-window-maximize') | ->setIcon('fa-window-maximize') | ||||
| ->setName(pht('View Panel Details')) | ->setName(pht('View Panel Details')) | ||||
| ->setHref($panel->getURI()); | ->setHref($panel->getURI()); | ||||
| } | } | ||||
| if ($dashboard_id) { | if ($context_phid) { | ||||
| $panel_phid = $this->getPanelPHID(); | $panel_phid = $this->getPanelPHID(); | ||||
| $remove_uri = "/dashboard/removepanel/{$dashboard_id}/"; | $remove_uri = urisprintf('/dashboard/adjust/remove/'); | ||||
| $remove_uri = id(new PhutilURI($remove_uri)) | $params = array( | ||||
| ->replaceQueryParam('panelPHID', $panel_phid); | 'contextPHID' => $context_phid, | ||||
| 'panelKey' => $this->getPanelKey(), | |||||
| ); | |||||
| $remove_uri = new PhutilURI($remove_uri, $params); | |||||
| $actions[] = id(new PhabricatorActionView()) | $actions[] = id(new PhabricatorActionView()) | ||||
| ->setIcon('fa-times') | ->setIcon('fa-times') | ||||
| ->setHref((string)$remove_uri) | ->setHref($remove_uri) | ||||
| ->setName(pht('Remove Panel')) | ->setName(pht('Remove Panel')) | ||||
| ->setWorkflow(true); | ->setWorkflow(true); | ||||
| } | } | ||||
| $dropdown_menu = id(new PhabricatorActionListView()) | $dropdown_menu = id(new PhabricatorActionListView()) | ||||
| ->setViewer($viewer); | ->setViewer($viewer); | ||||
| foreach ($actions as $action) { | foreach ($actions as $action) { | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if (in_array($panel->getPHID(), $this->parentPanelPHIDs)) { | ||||
| pht( | pht( | ||||
| 'You awake in a twisting maze of mirrors, all alike. '. | 'You awake in a twisting maze of mirrors, all alike. '. | ||||
| 'You are likely to be eaten by a graph cycle. '. | 'You are likely to be eaten by a graph cycle. '. | ||||
| 'Should you escape alive, you resolve to be more careful about '. | 'Should you escape alive, you resolve to be more careful about '. | ||||
| 'putting dashboard panels inside themselves.')); | 'putting dashboard panels inside themselves.')); | ||||
| } | } | ||||
| } | } | ||||
| private function getContextPHID() { | |||||
| $context = $this->getContextObject(); | |||||
| if ($context) { | |||||
| return $context->getPHID(); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| } | } | ||||