Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / diffusion / controller / DiffusionRepositoryManagePanelsController.php
bloba0fb5427520c6efb43521ec83d16d44c9f69130b
1 <?php
3 final class DiffusionRepositoryManagePanelsController
4 extends DiffusionRepositoryManageController {
6 private $navigation;
8 public function buildApplicationMenu() {
9 // TODO: This is messy for now; the mobile menu should be set automatically
10 // when the body content is a two-column view with navigation.
11 if ($this->navigation) {
12 return $this->navigation->getMenu();
14 return parent::buildApplicationMenu();
18 public function handleRequest(AphrontRequest $request) {
19 $response = $this->loadDiffusionContext();
20 if ($response) {
21 return $response;
24 $viewer = $this->getViewer();
25 $drequest = $this->getDiffusionRequest();
26 $repository = $drequest->getRepository();
28 $panels = DiffusionRepositoryManagementPanel::getAllPanels();
30 foreach ($panels as $key => $panel) {
31 $panel
32 ->setViewer($viewer)
33 ->setRepository($repository)
34 ->setController($this);
36 if (!$panel->shouldEnableForRepository($repository)) {
37 unset($panels[$key]);
38 continue;
42 $selected = $request->getURIData('panel');
43 if ($selected === null || !strlen($selected)) {
44 $selected = head_key($panels);
47 if (empty($panels[$selected])) {
48 return new Aphront404Response();
51 $nav = $this->renderSideNav($repository, $panels, $selected);
52 $this->navigation = $nav;
54 $panel = $panels[$selected];
56 $crumbs = $this->buildApplicationCrumbs();
57 $crumbs->addTextCrumb($panel->getManagementPanelLabel());
58 $crumbs->setBorder(true);
60 $content = $panel->buildManagementPanelContent();
62 $title = array(
63 $panel->getManagementPanelLabel(),
64 $repository->getDisplayName(),
67 $header = $this->buildHeaderView($repository->getDisplayName());
69 $view = id(new PHUITwoColumnView())
70 ->setHeader($header)
71 ->setMainColumn($content);
73 $curtain = $panel->buildManagementPanelCurtain();
74 if ($curtain) {
75 $view->setCurtain($curtain);
78 return $this->newPage()
79 ->setTitle($title)
80 ->setCrumbs($crumbs)
81 ->setNavigation($nav)
82 ->appendChild($view);
85 private function renderSideNav(
86 PhabricatorRepository $repository,
87 array $panels,
88 $selected) {
90 $base_uri = $repository->getPathURI('manage/');
91 $base_uri = new PhutilURI($base_uri);
93 $nav = id(new AphrontSideNavFilterView())
94 ->setBaseURI($base_uri);
96 $groups = DiffusionRepositoryManagementPanelGroup::getAllPanelGroups();
97 $panel_groups = mgroup($panels, 'getManagementPanelGroupKey');
98 $other_key = DiffusionRepositoryManagementOtherPanelGroup::PANELGROUPKEY;
100 foreach ($groups as $group_key => $group) {
101 // If this is the "Other" group, include everything else that isn't in
102 // some actual group.
103 if ($group_key === $other_key) {
104 $group_panels = array_mergev($panel_groups);
105 $panel_groups = array();
106 } else {
107 $group_panels = idx($panel_groups, $group_key);
108 unset($panel_groups[$group_key]);
111 if (!$group_panels) {
112 continue;
115 $label = $group->getManagementPanelGroupLabel();
116 if ($label) {
117 $nav->addLabel($label);
120 foreach ($group_panels as $panel) {
121 $key = $panel->getManagementPanelKey();
122 $label = $panel->getManagementPanelLabel();
123 $icon = $panel->getManagementPanelIcon();
124 $href = $panel->getPanelNavigationURI();
126 $item = id(new PHUIListItemView())
127 ->setKey($key)
128 ->setName($label)
129 ->setType(PHUIListItemView::TYPE_LINK)
130 ->setHref($href)
131 ->setIcon($icon);
133 $nav->addMenuItem($item);
137 $nav->selectFilter($selected);
139 return $nav;
142 public function buildHeaderView($title) {
143 $viewer = $this->getViewer();
145 $drequest = $this->getDiffusionRequest();
146 $repository = $drequest->getRepository();
148 $header = id(new PHUIHeaderView())
149 ->setHeader($title)
150 ->setProfileHeader(true)
151 ->setHref($repository->getURI())
152 ->setImage($repository->getProfileImageURI());
154 if ($repository->isTracked()) {
155 $header->setStatus('fa-check', 'bluegrey', pht('Active'));
156 } else {
157 $header->setStatus('fa-ban', 'dark', pht('Inactive'));
160 $doc_href = PhabricatorEnv::getDoclink(
161 'Diffusion User Guide: Managing Repositories');
163 $header->addActionLink(
164 id(new PHUIButtonView())
165 ->setTag('a')
166 ->setText(pht('View Repository'))
167 ->setHref($repository->getURI())
168 ->setIcon('fa-code')
169 ->setColor(PHUIButtonView::GREY));
171 $header->addActionLink(
172 id(new PHUIButtonView())
173 ->setTag('a')
174 ->setIcon('fa-book')
175 ->setHref($doc_href)
176 ->setText(pht('Help'))
177 ->setColor(PHUIButtonView::GREY));
179 return $header;
182 public function newTimeline(PhabricatorRepository $repository) {
183 $timeline = $this->buildTransactionTimeline(
184 $repository,
185 new PhabricatorRepositoryTransactionQuery());
186 $timeline->setShouldTerminate(true);
188 return $timeline;