Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / dashboard / engine / PhabricatorDashboardRenderingEngine.php
blob9b63fcac558fae556bea92eb836c6b5fa2b4f3b5
1 <?php
3 final class PhabricatorDashboardRenderingEngine extends Phobject {
5 private $dashboard;
6 private $viewer;
7 private $arrangeMode;
9 public function setViewer(PhabricatorUser $viewer) {
10 $this->viewer = $viewer;
11 return $this;
14 public function getViewer() {
15 return $this->viewer;
18 public function setDashboard(PhabricatorDashboard $dashboard) {
19 $this->dashboard = $dashboard;
20 return $this;
23 public function getDashboard() {
24 return $this->dashboard;
27 public function setArrangeMode($mode) {
28 $this->arrangeMode = $mode;
29 return $this;
32 public function renderDashboard() {
33 require_celerity_resource('phabricator-dashboard-css');
34 $dashboard = $this->getDashboard();
35 $viewer = $this->getViewer();
37 $is_editable = $this->arrangeMode;
39 if ($is_editable) {
40 $h_mode = PhabricatorDashboardPanelRenderingEngine::HEADER_MODE_EDIT;
41 } else {
42 $h_mode = PhabricatorDashboardPanelRenderingEngine::HEADER_MODE_NORMAL;
45 $panel_phids = $dashboard->getPanelPHIDs();
46 if ($panel_phids) {
47 $panels = id(new PhabricatorDashboardPanelQuery())
48 ->setViewer($viewer)
49 ->withPHIDs($panel_phids)
50 ->execute();
51 $panels = mpull($panels, null, 'getPHID');
53 $handles = $viewer->loadHandles($panel_phids);
54 } else {
55 $panels = array();
56 $handles = array();
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())
75 ->setViewer($viewer)
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)
83 ->setMovable(true)
84 ->setPanelHandle($handles[$panel_phid]);
86 $panel = idx($panels, $panel_phid);
87 if ($panel) {
88 $panel_engine->setPanel($panel);
91 $column_views[] = $panel_engine->renderPanel();
94 $column_classes = $column->getClasses();
96 $column_tail = array();
97 if ($is_editable) {
98 $column_tail[] = $this->renderAddPanelPlaceHolder();
99 $column_tail[] = $this->renderAddPanelUI($column);
102 $sigil = 'dashboard-column';
104 $metadata = array(
105 'columnKey' => $column->getColumnKey(),
108 $column_view = javelin_tag(
109 'div',
110 array(
111 'sigil' => $sigil,
112 'meta' => $metadata,
114 $column_views);
116 $result->addColumn(
117 array(
118 $column_view,
119 $column_tail,
121 implode(' ', $column_classes));
124 if ($is_editable) {
125 $params = array(
126 'contextPHID' => $dashboard->getPHID(),
128 $move_uri = new PhutilURI('/dashboard/adjust/move/', $params);
130 Javelin::initBehavior(
131 'dashboard-move-panels',
132 array(
133 'dashboardNodeID' => $dashboard_id,
134 'moveURI' => (string)$move_uri,
138 $view = id(new PHUIBoxView())
139 ->addClass('dashboard-view')
140 ->appendChild(
141 array(
142 $result,
145 return $view;
148 private function renderAddPanelPlaceHolder() {
149 return javelin_tag(
150 'span',
151 array(
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())
171 ->setTag('a')
172 ->setHref($create_uri)
173 ->setIcon('fa-plus')
174 ->setColor(PHUIButtonView::GREY)
175 ->setWorkflow(true)
176 ->setText(pht('Create Panel'))
177 ->addClass(PHUI::MARGIN_MEDIUM);
179 $add_button = id(new PHUIButtonView())
180 ->setTag('a')
181 ->setHref($add_uri)
182 ->setIcon('fa-window-maximize')
183 ->setColor(PHUIButtonView::GREY)
184 ->setWorkflow(true)
185 ->setText(pht('Add Existing Panel'))
186 ->addClass(PHUI::MARGIN_MEDIUM);
188 return phutil_tag(
189 'div',
190 array(
191 'style' => 'text-align: center;',
193 array(
194 $create_button,
195 $add_button,