]> git.immae.eu Git - perso/Immae/Projets/Buildbot/buildslist.git/blame_incremental - src/module/buildslist.directive.coffee
Initial commit
[perso/Immae/Projets/Buildbot/buildslist.git] / src / module / buildslist.directive.coffee
... / ...
CommitLineData
1# Register new module
2class Buildslist extends App
3 constructor: -> return [
4 'bbData',
5 'common'
6 ]
7
8class Buildslistfield extends Directive
9 constructor: ->
10 return {
11 replace: false
12 restrict: 'E'
13 scope: false
14 templateUrl: "buildslist/views/buildslist.html"
15 controller: '_buildslistfieldController'
16 }
17
18class _buildslistfield extends Controller
19 constructor: ($scope, $location, dataService) ->
20 builderid = parseInt(window.location.hash.split("/")[2])
21
22 $scope.build = $scope.field
23
24 $scope.build.choices = [{ "id": 0, "complete_at": 0, "name": "Fetching..."}]
25 $scope.selectValue = $scope.build.choices[0]
26
27 $scope.valueChanged = false
28
29 $scope.changed = (newValue, byUser) ->
30 if byUser?
31 $scope.valueChanged = true
32 if newValue?
33 $scope.build.value = newValue.id
34 else
35 $scope.build.value = $scope.selectValue.id
36 $scope.changed()
37
38 name = (build_file) ->
39 if $scope.project_name == "TestProject"
40 project_name = "test"
41 else
42 project_name = $scope.project_name.toLowerCase()
43 match = build_file.match(project_name + "_(.*).tar.gz")
44 return if match && match.length == 2 then match[1] else build_file
45
46 latest = (arr) ->
47 return arr.reduce((a, b) ->
48 return if a.complete_at > b.complete_at then a else b)
49
50 fillBuilds = (builderid) ->
51 builds = dataService.getBuilds(
52 builderid: builderid, complete: true,
53 results: [0, 1], order: "-complete_at")
54 builds.onNew = (build) ->
55 build.loadSteps().onNew = (step) ->
56 if step.name == "upload package"
57 if $scope.selectValue.id == 0
58 $scope.build.choices.shift()
59
60 elt = {
61 "complete_at": build.complete_at,
62 "name": name(step.urls[0].name),
63 "id": step.urls[0].name,
64 }
65
66 dup_index = $scope.build.choices.findIndex((elt_) ->
67 return (elt_.id == elt.id))
68 if dup_index == -1
69 $scope.build.choices.push(elt)
70 else if $scope.build.choices[dup_index].complete_at < elt.complete_at
71 $scope.build.choices[dup_index] = elt
72
73 if !$scope.valueChanged
74 $scope.selectValue = latest($scope.build.choices)
75 $scope.changed()
76 findBuildBuilder = () ->
77 builderid = parseInt(window.location.hash.split("/")[2])
78 dataService.getBuilders(builderid).onNew = (builder) ->
79 $scope.project_name = builder.name.substr(0, builder.name.lastIndexOf("_"))
80 dataService.getBuilders(name: $scope.project_name + "_build").onNew = (builder_) ->
81 fillBuilds(builder_.builderid)
82
83 findBuildBuilder()