2 class Buildslist extends App
3 constructor: -> return [
8 class Buildslistfield extends Directive
14 templateUrl: "buildslist/views/buildslist.html"
15 controller: '_buildslistfieldController'
18 class _buildslistfield extends Controller
19 constructor: ($scope, $location, dataService) ->
20 builderid = parseInt(window.location.hash.split("/")[2])
22 $scope.build = $scope.field
24 $scope.build.choices = [{ "id": 0, "complete_at": 0, "name": "Fetching..."}]
25 $scope.selectValue = $scope.build.choices[0]
27 $scope.valueChanged = false
29 $scope.changed = (newValue, byUser) ->
31 $scope.valueChanged = true
33 $scope.build.value = newValue.id
35 $scope.build.value = $scope.selectValue.id
38 name = (build_file) ->
39 if $scope.project_name == "TestProject"
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
47 return arr.reduce((a, b) ->
48 return if a.complete_at > b.complete_at then a else b)
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()
61 "complete_at": build.complete_at,
62 "name": name(step.urls[0].name),
63 "id": step.urls[0].name,
66 dup_index = $scope.build.choices.findIndex((elt_) ->
67 return (elt_.id == elt.id))
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
73 if !$scope.valueChanged
74 $scope.selectValue = latest($scope.build.choices)
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)