forked from marcells/node-build-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildViewModel.js
70 lines (62 loc) · 2.48 KB
/
BuildViewModel.js
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
define(['ko', 'moment', 'countdown'], function (ko, moment, countdown) {
var BuildViewModel = function (build) {
this.isMenuVisible = ko.observable(false);
this.id = ko.observable();
this.isRunning = ko.observable();
this.project = ko.observable();
this.branch = ko.observable();
this.commit = ko.observable();
this.definition = ko.observable();
this.number = ko.observable();
this.startedAt = ko.observable();
this.finishedAt = ko.observable();
this.status = ko.observable(build.status);
this.statusText = ko.observable();
this.reason = ko.observable();
this.requestedFor = ko.observable();
this.hasWarnings = ko.observable();
this.hasErrors = ko.observable();
this.url = ko.observable();
this.update = function (build) {
this.id(build.id);
this.isRunning(build.isRunning);
this.project(build.project);
this.branch(build.branch);
this.commit(build.commit);
this.definition(build.definition);
this.number(build.number);
this.startedAt(moment(build.startedAt));
this.finishedAt(moment(build.finishedAt));
this.status(build.status);
this.statusText(build.statusText);
this.reason(build.reason);
this.requestedFor(build.requestedFor);
this.hasWarnings(build.hasWarnings);
this.hasErrors(build.hasErrors);
this.url(build.url);
};
this.update(build);
this.style = ko.computed(function () {
if (this.status()) {
return {
'color': 'white',
'background-color': this.status().toLowerCase()
};
}
}, this);
this.time = ko.forcibleComputed(function () {
return this.isRunning() ?
'started ' + moment(this.startedAt()).fromNow() :
'finished ' + moment(this.finishedAt()).fromNow();
}, this);
this.duration = ko.forcibleComputed(function () {
return this.isRunning() ?
'running for ' + countdown(this.startedAt()).toString() :
'ran for ' + countdown(this.startedAt(), this.finishedAt()).toString();
}, this);
this.isMenuAvailable = ko.computed(function () {
return this.url() || false;
}, this);
};
return BuildViewModel;
});