diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-03-07 09:39:41 +0100 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2019-03-07 09:39:41 +0100 |
commit | bf1f1f479980fa2680b3616f48fcfad8fd00f39c (patch) | |
tree | 62e9a005bcce53872f7e605aad9d05a6baf557ce /src/module | |
download | buildslist-bf1f1f479980fa2680b3616f48fcfad8fd00f39c.tar.gz buildslist-bf1f1f479980fa2680b3616f48fcfad8fd00f39c.tar.zst buildslist-bf1f1f479980fa2680b3616f48fcfad8fd00f39c.zip |
Initial commit
Diffstat (limited to 'src/module')
-rw-r--r-- | src/module/buildslist.directive.coffee | 83 | ||||
-rw-r--r-- | src/module/buildslist.tpl.jade | 8 |
2 files changed, 91 insertions, 0 deletions
diff --git a/src/module/buildslist.directive.coffee b/src/module/buildslist.directive.coffee new file mode 100644 index 0000000..474476b --- /dev/null +++ b/src/module/buildslist.directive.coffee | |||
@@ -0,0 +1,83 @@ | |||
1 | # Register new module | ||
2 | class Buildslist extends App | ||
3 | constructor: -> return [ | ||
4 | 'bbData', | ||
5 | 'common' | ||
6 | ] | ||
7 | |||
8 | class 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 | |||
18 | class _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() | ||
diff --git a/src/module/buildslist.tpl.jade b/src/module/buildslist.tpl.jade new file mode 100644 index 0000000..ad36370 --- /dev/null +++ b/src/module/buildslist.tpl.jade | |||
@@ -0,0 +1,8 @@ | |||
1 | basefield | ||
2 | label.control-label.col-sm-2(for="{{build.name}}") | ||
3 | | {{build.label}} | ||
4 | .col-sm-10 | ||
5 | select.form-control(name="{{build.name}}", | ||
6 | ng-model="selectValue", | ||
7 | ng-change="changed(selectValue, true)", | ||
8 | ng-options="v as v.name for v in build.choices | orderBy:'-complete_at' track by v.id") | ||