Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/controller/HarbormasterStepAddController.php
12256 views
1
<?php
2
3
final class HarbormasterStepAddController
4
extends HarbormasterPlanController {
5
6
public function handleRequest(AphrontRequest $request) {
7
$viewer = $this->getViewer();
8
9
$plan = id(new HarbormasterBuildPlanQuery())
10
->setViewer($viewer)
11
->withIDs(array($request->getURIData('id')))
12
->requireCapabilities(
13
array(
14
PhabricatorPolicyCapability::CAN_VIEW,
15
PhabricatorPolicyCapability::CAN_EDIT,
16
))
17
->executeOne();
18
if (!$plan) {
19
return new Aphront404Response();
20
}
21
22
$plan_id = $plan->getID();
23
$cancel_uri = $this->getApplicationURI("plan/{$plan_id}/");
24
$plan_title = pht('Plan %d', $plan_id);
25
26
$all = HarbormasterBuildStepImplementation::getImplementations();
27
$all = msort($all, 'getName');
28
29
$all_groups = HarbormasterBuildStepGroup::getAllGroups();
30
foreach ($all as $impl) {
31
$group_key = $impl->getBuildStepGroupKey();
32
if (empty($all_groups[$group_key])) {
33
throw new Exception(
34
pht(
35
'Build step "%s" has step group key "%s", but no step group '.
36
'with that key exists.',
37
get_class($impl),
38
$group_key));
39
}
40
}
41
42
$groups = mgroup($all, 'getBuildStepGroupKey');
43
$boxes = array();
44
45
$enabled_groups = HarbormasterBuildStepGroup::getAllEnabledGroups();
46
foreach ($enabled_groups as $group) {
47
$list = id(new PHUIObjectItemListView())
48
->setNoDataString(
49
pht('This group has no available build steps.'));
50
51
$steps = idx($groups, $group->getGroupKey(), array());
52
53
foreach ($steps as $key => $impl) {
54
if ($impl->shouldRequireAutotargeting()) {
55
unset($steps[$key]);
56
continue;
57
}
58
}
59
60
if (!$steps && !$group->shouldShowIfEmpty()) {
61
continue;
62
}
63
64
foreach ($steps as $key => $impl) {
65
$class = get_class($impl);
66
67
$new_uri = $this->getApplicationURI("step/new/{$plan_id}/{$class}/");
68
69
$item = id(new PHUIObjectItemView())
70
->setHeader($impl->getName())
71
->setHref($new_uri)
72
->addAttribute($impl->getGenericDescription());
73
74
$list->addItem($item);
75
}
76
77
$box = id(new PHUIObjectBoxView())
78
->setHeaderText($group->getGroupName())
79
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
80
->appendChild($list);
81
82
$boxes[] = $box;
83
}
84
85
$crumbs = $this->buildApplicationCrumbs()
86
->addTextCrumb($plan_title, $cancel_uri)
87
->addTextCrumb(pht('Add Build Step'))
88
->setBorder(true);
89
90
$title = array($plan_title, pht('Add Build Step'));
91
92
$header = id(new PHUIHeaderView())
93
->setHeader(pht('Add Build Step'))
94
->setHeaderIcon('fa-plus-square');
95
96
$view = id(new PHUITwoColumnView())
97
->setHeader($header)
98
->setFooter(array(
99
$boxes,
100
));
101
102
return $this->newPage()
103
->setTitle($title)
104
->setCrumbs($crumbs)
105
->appendChild($view);
106
107
}
108
109
}
110
111