-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
builder.controller.coffee
101 lines (91 loc) · 4.22 KB
/
builder.controller.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
class Builder extends Controller
constructor: ($rootScope, $scope, dataService, $stateParams, resultsService, recentStorage,
glBreadcrumbService, $state, glTopbarContextualActionsService, $q, $window) ->
# make resultsService utilities available in the template
_.mixin($scope, resultsService)
data = dataService.open().closeOnDestroy($scope)
builderid = $stateParams.builder
$scope.forceschedulers = []
$scope.is_cancelling = false
data.getBuilders(builderid).onNew = (builder) ->
$window.document.title = $state.current.data.pageTitle
builder: builder['name']
$scope.builder = builder
breadcrumb = [
caption: "Builders"
sref: "builders"
,
caption: builder.name
sref: "builder({builder:#{builder.builderid}})"
]
recentStorage.addBuilder
link: "#/builders/#{builder.builderid}"
caption: builder.name
# reinstall breadcrumb when coming back from forcesched
$scope.$on '$stateChangeSuccess', ->
glBreadcrumbService.setBreadcrumb(breadcrumb)
glBreadcrumbService.setBreadcrumb(breadcrumb)
doCancel = ->
if $scope.is_cancelling
return
if not window.confirm("Are you sure you want to cancel all builds?")
return
$scope.is_cancelling = true
refreshContextMenu()
success = (res) ->
$scope.is_cancelling = false
refreshContextMenu()
failure = (why) ->
$scope.is_cancelling = false
$scope.error = "Cannot cancel: " + why.error.message
refreshContextMenu()
dl = []
$scope.buildrequests.forEach (buildrequest) ->
if not buildrequest.claimed
dl.push buildrequest.control('cancel')
$scope.builds.forEach (build) ->
if not build.complete
dl.push build.control('stop')
$q.when(dl).then(success, failure)
refreshContextMenu = ->
if $scope.$$destroyed
return
actions = [
]
canStop = false
$scope.builds.forEach (build) ->
if not build.complete
canStop = true
$scope.buildrequests.forEach (buildrequest) ->
if not buildrequest.claimed
canStop = true
if canStop
if $scope.is_cancelling
actions.push
caption: "Cancelling..."
icon: "spinner fa-spin"
action: doCancel
else
actions.push
caption: "Cancel whole queue"
extra_class: "btn-danger"
icon: "stop"
action: doCancel
_.forEach $scope.forceschedulers, (sch) ->
actions.push
caption: sch.button_name
extra_class: "btn-primary"
action: ->
$state.go("builder.forcebuilder",
scheduler:sch.name)
glTopbarContextualActionsService.setContextualActions(actions)
builder.getForceschedulers().onChange = (forceschedulers) ->
$scope.forceschedulers = forceschedulers
refreshContextMenu()
# reinstall contextual actions when coming back from forcesched
$scope.$on '$stateChangeSuccess', ->
refreshContextMenu()
$scope.builds = builder.getBuilds(limit:20, order:'-number')
$scope.buildrequests = builder.getBuildrequests(claimed:false)
$scope.builds.onChange=refreshContextMenu
$scope.buildrequests.onChange=refreshContextMenu