Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / nuance / controller / NuanceQueueWorkController.php
blob8703a693346dae327f8cf36b89135cba05747de6
1 <?php
3 final class NuanceQueueWorkController
4 extends NuanceQueueController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
9 $queue = id(new NuanceQueueQuery())
10 ->setViewer($viewer)
11 ->withIDs(array($request->getURIData('id')))
12 ->executeOne();
13 if (!$queue) {
14 return new Aphront404Response();
17 $title = $queue->getName();
19 $crumbs = $this->buildApplicationCrumbs();
20 $crumbs->addTextCrumb(pht('Queues'), $this->getApplicationURI('queue/'));
21 $crumbs->addTextCrumb($queue->getName(), $queue->getURI());
22 $crumbs->addTextCrumb(pht('Work'));
23 $crumbs->setBorder(true);
25 // For now, just pick the first open item.
27 $items = id(new NuanceItemQuery())
28 ->setViewer($viewer)
29 ->withQueuePHIDs(
30 array(
31 $queue->getPHID(),
33 ->withStatuses(
34 array(
35 NuanceItem::STATUS_OPEN,
37 ->requireCapabilities(
38 array(
39 PhabricatorPolicyCapability::CAN_VIEW,
40 PhabricatorPolicyCapability::CAN_EDIT,
42 ->setLimit(5)
43 ->execute();
45 if (!$items) {
46 return $this->newDialog()
47 ->setTitle(pht('Queue Empty'))
48 ->appendParagraph(
49 pht(
50 'This queue has no open items which you have permission to '.
51 'work on.'))
52 ->addCancelButton($queue->getURI());
55 $item = head($items);
57 $curtain = $this->buildCurtain($queue, $item);
59 $timeline = $this->buildTransactionTimeline(
60 $item,
61 new NuanceItemTransactionQuery());
62 $timeline->setShouldTerminate(true);
64 $impl = $item->getImplementation()
65 ->setViewer($viewer);
67 $commands = $this->buildCommands($item);
68 $work_content = $impl->buildItemWorkView($item);
70 $view = id(new PHUITwoColumnView())
71 ->setCurtain($curtain)
72 ->setMainColumn(
73 array(
74 $commands,
75 $work_content,
76 $timeline,
77 ));
79 return $this->newPage()
80 ->setTitle($title)
81 ->setCrumbs($crumbs)
82 ->appendChild($view);
85 private function buildCurtain(NuanceQueue $queue, NuanceItem $item) {
86 $viewer = $this->getViewer();
87 $id = $queue->getID();
89 $curtain = $this->newCurtainView();
91 $impl = $item->getImplementation();
92 $commands = $impl->buildWorkCommands($item);
94 foreach ($commands as $command) {
95 $command_key = $command->getCommandKey();
97 $item_id = $item->getID();
99 $action_uri = "queue/action/{$id}/{$command_key}/{$item_id}/";
100 $action_uri = $this->getApplicationURI($action_uri);
102 $curtain->addAction(
103 id(new PhabricatorActionView())
104 ->setName($command->getName())
105 ->setIcon($command->getIcon())
106 ->setHref($action_uri)
107 ->setWorkflow(true));
110 $curtain->addAction(
111 id(new PhabricatorActionView())
112 ->setType(PhabricatorActionView::TYPE_DIVIDER));
114 $curtain->addAction(
115 id(new PhabricatorActionView())
116 ->setType(PhabricatorActionView::TYPE_LABEL)
117 ->setName(pht('Queue Actions')));
119 $curtain->addAction(
120 id(new PhabricatorActionView())
121 ->setName(pht('Manage Queue'))
122 ->setIcon('fa-cog')
123 ->setHref($this->getApplicationURI("queue/view/{$id}/")));
125 return $curtain;
128 private function buildCommands(NuanceItem $item) {
129 $viewer = $this->getViewer();
131 $commands = id(new NuanceItemCommandQuery())
132 ->setViewer($viewer)
133 ->withItemPHIDs(array($item->getPHID()))
134 ->withStatuses(
135 array(
136 NuanceItemCommand::STATUS_ISSUED,
137 NuanceItemCommand::STATUS_EXECUTING,
138 NuanceItemCommand::STATUS_FAILED,
140 ->execute();
141 $commands = msort($commands, 'getID');
143 if (!$commands) {
144 return null;
147 $rows = array();
148 foreach ($commands as $command) {
149 $icon = $command->getStatusIcon();
150 $color = $command->getStatusColor();
152 $rows[] = array(
153 $command->getID(),
154 id(new PHUIIconView())
155 ->setIcon($icon, $color),
156 $viewer->renderHandle($command->getAuthorPHID()),
157 $command->getCommand(),
158 phabricator_datetime($command->getDateCreated(), $viewer),
162 $table = id(new AphrontTableView($rows))
163 ->setHeaders(
164 array(
165 pht('ID'),
166 null,
167 pht('Actor'),
168 pht('Command'),
169 pht('Date'),
171 ->setColumnClasses(
172 array(
173 null,
174 'icon',
175 null,
176 'pri',
177 'wide right',
180 return id(new PHUIObjectBoxView())
181 ->setHeaderText(pht('Pending Commands'))
182 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
183 ->setTable($table);