3 final class PhabricatorDashboardRenderingEngine
extends Phobject
{
9 public function setViewer(PhabricatorUser
$viewer) {
10 $this->viewer
= $viewer;
14 public function getViewer() {
18 public function setDashboard(PhabricatorDashboard
$dashboard) {
19 $this->dashboard
= $dashboard;
23 public function getDashboard() {
24 return $this->dashboard
;
27 public function setArrangeMode($mode) {
28 $this->arrangeMode
= $mode;
32 public function renderDashboard() {
33 require_celerity_resource('phabricator-dashboard-css');
34 $dashboard = $this->getDashboard();
35 $viewer = $this->getViewer();
37 $is_editable = $this->arrangeMode
;
40 $h_mode = PhabricatorDashboardPanelRenderingEngine
::HEADER_MODE_EDIT
;
42 $h_mode = PhabricatorDashboardPanelRenderingEngine
::HEADER_MODE_NORMAL
;
45 $panel_phids = $dashboard->getPanelPHIDs();
47 $panels = id(new PhabricatorDashboardPanelQuery())
49 ->withPHIDs($panel_phids)
51 $panels = mpull($panels, null, 'getPHID');
53 $handles = $viewer->loadHandles($panel_phids);
59 $ref_list = $dashboard->getPanelRefList();
60 $columns = $ref_list->getColumns();
62 $dashboard_id = celerity_generate_unique_node_id();
64 $result = id(new AphrontMultiColumnView())
65 ->setID($dashboard_id)
66 ->setFluidLayout(true)
67 ->setGutter(AphrontMultiColumnView
::GUTTER_LARGE
);
69 foreach ($columns as $column) {
70 $column_views = array();
71 foreach ($column->getPanelRefs() as $panel_ref) {
72 $panel_phid = $panel_ref->getPanelPHID();
74 $panel_engine = id(new PhabricatorDashboardPanelRenderingEngine())
76 ->setEnableAsyncRendering(true)
77 ->setContextObject($dashboard)
78 ->setPanelKey($panel_ref->getPanelKey())
79 ->setPanelPHID($panel_phid)
80 ->setParentPanelPHIDs(array())
81 ->setHeaderMode($h_mode)
82 ->setEditMode($is_editable)
84 ->setPanelHandle($handles[$panel_phid]);
86 $panel = idx($panels, $panel_phid);
88 $panel_engine->setPanel($panel);
91 $column_views[] = $panel_engine->renderPanel();
94 $column_classes = $column->getClasses();
96 $column_tail = array();
98 $column_tail[] = $this->renderAddPanelPlaceHolder();
99 $column_tail[] = $this->renderAddPanelUI($column);
102 $sigil = 'dashboard-column';
105 'columnKey' => $column->getColumnKey(),
108 $column_view = javelin_tag(
121 implode(' ', $column_classes));
126 'contextPHID' => $dashboard->getPHID(),
128 $move_uri = new PhutilURI('/dashboard/adjust/move/', $params);
130 Javelin
::initBehavior(
131 'dashboard-move-panels',
133 'dashboardNodeID' => $dashboard_id,
134 'moveURI' => (string)$move_uri,
138 $view = id(new PHUIBoxView())
139 ->addClass('dashboard-view')
148 private function renderAddPanelPlaceHolder() {
152 'sigil' => 'workflow',
153 'class' => 'drag-ghost dashboard-panel-placeholder',
155 pht('This column does not have any panels yet.'));
158 private function renderAddPanelUI(PhabricatorDashboardColumn
$column) {
159 $dashboard = $this->getDashboard();
160 $column_key = $column->getColumnKey();
162 $create_uri = id(new PhutilURI('/dashboard/panel/edit/'))
163 ->replaceQueryParam('contextPHID', $dashboard->getPHID())
164 ->replaceQueryParam('columnKey', $column_key);
166 $add_uri = id(new PhutilURI('/dashboard/adjust/add/'))
167 ->replaceQueryParam('contextPHID', $dashboard->getPHID())
168 ->replaceQueryParam('columnKey', $column_key);
170 $create_button = id(new PHUIButtonView())
172 ->setHref($create_uri)
174 ->setColor(PHUIButtonView
::GREY
)
176 ->setText(pht('Create Panel'))
177 ->addClass(PHUI
::MARGIN_MEDIUM
);
179 $add_button = id(new PHUIButtonView())
182 ->setIcon('fa-window-maximize')
183 ->setColor(PHUIButtonView
::GREY
)
185 ->setText(pht('Add Existing Panel'))
186 ->addClass(PHUI
::MARGIN_MEDIUM
);
191 'style' => 'text-align: center;',