Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / dashboard / controller / panel / PhabricatorDashboardPanelViewController.php
blob56f9821fcd1097eb87a1929b5e982a1c28e26cd5
1 <?php
3 final class PhabricatorDashboardPanelViewController
4 extends PhabricatorDashboardController {
6 public function shouldAllowPublic() {
7 return true;
10 public function handleRequest(AphrontRequest $request) {
11 $viewer = $request->getViewer();
12 $id = $request->getURIData('id');
14 $panel = id(new PhabricatorDashboardPanelQuery())
15 ->setViewer($viewer)
16 ->withIDs(array($id))
17 ->executeOne();
18 if (!$panel) {
19 return new Aphront404Response();
22 $can_edit = PhabricatorPolicyFilter::hasCapability(
23 $viewer,
24 $panel,
25 PhabricatorPolicyCapability::CAN_EDIT);
27 $title = $panel->getMonogram().' '.$panel->getName();
28 $crumbs = $this->buildApplicationCrumbs();
29 $crumbs->addTextCrumb(
30 pht('Panels'),
31 $this->getApplicationURI('panel/'));
32 $crumbs->addTextCrumb($panel->getMonogram());
33 $crumbs->setBorder(true);
35 $header = $this->buildHeaderView($panel);
36 $curtain = $this->buildCurtainView($panel);
38 $usage_box = $this->newUsageView($panel);
40 $timeline = $this->buildTransactionTimeline(
41 $panel,
42 new PhabricatorDashboardPanelTransactionQuery());
43 $timeline->setShouldTerminate(true);
45 $rendered_panel = id(new PhabricatorDashboardPanelRenderingEngine())
46 ->setViewer($viewer)
47 ->setPanel($panel)
48 ->setContextObject($panel)
49 ->setPanelPHID($panel->getPHID())
50 ->setParentPanelPHIDs(array())
51 ->setEditMode(true)
52 ->renderPanel();
54 $preview = id(new PHUIBoxView())
55 ->addClass('dashboard-preview-box')
56 ->appendChild($rendered_panel);
58 $view = id(new PHUITwoColumnView())
59 ->setHeader($header)
60 ->setCurtain($curtain)
61 ->setMainColumn(array(
62 $rendered_panel,
63 $usage_box,
64 $timeline,
65 ));
67 return $this->newPage()
68 ->setTitle($title)
69 ->setCrumbs($crumbs)
70 ->appendChild($view);
73 private function buildHeaderView(PhabricatorDashboardPanel $panel) {
74 $viewer = $this->getViewer();
75 $id = $panel->getID();
77 $header = id(new PHUIHeaderView())
78 ->setUser($viewer)
79 ->setHeader($panel->getName())
80 ->setPolicyObject($panel)
81 ->setHeaderIcon('fa-window-maximize');
83 if (!$panel->getIsArchived()) {
84 $header->setStatus('fa-check', 'bluegrey', pht('Active'));
85 } else {
86 $header->setStatus('fa-ban', 'red', pht('Archived'));
88 return $header;
91 private function buildCurtainView(PhabricatorDashboardPanel $panel) {
92 $viewer = $this->getViewer();
93 $id = $panel->getID();
95 $curtain = $this->newCurtainView($panel);
97 $can_edit = PhabricatorPolicyFilter::hasCapability(
98 $viewer,
99 $panel,
100 PhabricatorPolicyCapability::CAN_EDIT);
102 $curtain->addAction(
103 id(new PhabricatorActionView())
104 ->setName(pht('Edit Panel'))
105 ->setIcon('fa-pencil')
106 ->setHref($this->getApplicationURI("panel/edit/{$id}/"))
107 ->setDisabled(!$can_edit)
108 ->setWorkflow(!$can_edit));
110 if (!$panel->getIsArchived()) {
111 $archive_text = pht('Archive Panel');
112 $archive_icon = 'fa-ban';
113 } else {
114 $archive_text = pht('Activate Panel');
115 $archive_icon = 'fa-check';
118 $curtain->addAction(
119 id(new PhabricatorActionView())
120 ->setName($archive_text)
121 ->setIcon($archive_icon)
122 ->setHref($this->getApplicationURI("panel/archive/{$id}/"))
123 ->setDisabled(!$can_edit)
124 ->setWorkflow(true));
126 return $curtain;
129 private function newUsageView(PhabricatorDashboardPanel $panel) {
130 $viewer = $this->getViewer();
132 $object_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
133 $panel->getPHID(),
134 PhabricatorDashboardPanelUsedByObjectEdgeType::EDGECONST);
136 if ($object_phids) {
137 $handles = $viewer->loadHandles($object_phids);
138 } else {
139 $handles = array();
142 $rows = array();
143 foreach ($object_phids as $object_phid) {
144 $handle = $handles[$object_phid];
146 $icon = $handle->getIcon();
148 $rows[] = array(
149 id(new PHUIIconView())->setIcon($icon),
150 $handle->getTypeName(),
151 $handle->renderLink(),
155 $usage_table = id(new AphrontTableView($rows))
156 ->setNoDataString(
157 pht(
158 'This panel is not used on any dashboard or inside any other '.
159 'panel container.'))
160 ->setColumnClasses(
161 array(
162 'center',
164 'pri wide',
167 $header_view = id(new PHUIHeaderView())
168 ->setHeader(pht('Panel Used By'));
170 $usage_box = id(new PHUIObjectBoxView())
171 ->setTable($usage_table)
172 ->setHeader($header_view);
174 return $usage_box;