-
Notifications
You must be signed in to change notification settings - Fork 0
/
job.js
107 lines (94 loc) · 2.77 KB
/
job.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
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
102
103
104
105
106
107
function Job (apiJob) {
EventDispatcher.call(this);
// private vars
var $this = this,
_name = apiJob.name,
_url = apiJob.url,
_percentage = 100,
_fullColor,
_color,
_building,
_failed,
_consoleText,
_build,
_init = function(color) {
_fullColor = color;
if (color.substr(color.length - 6) == '_anime') {
_color = color.substr(0, color.length - 6);
_building = true;
_consoleText = new ConsoleText(_name, _color);
} else {
_color = color;
_building = false;
}
_failed = _color === 'red';
if (_building) {
_percentage = undefined;
$.get(CONFIG.get('PROGRESS_URL') + '?job=' + _name, function(progress) {
_percentage = progress;
if ($this.isLoaded()) {
$this.trigger(Job.events.LOADED, { job: $this });
}
});
}
if (_failed) {
_build = new Build(_name);
}
};
this.isLoaded = function() {
return (typeof _consoleText === 'undefined' || _consoleText.isLoaded()) &&
(typeof _build === 'undefined' || _build.isLoaded()) &&
typeof _percentage !== 'undefined';
};
$this.getColor = function() {
return _color;
};
$this.isBuilding = function() {
return _building;
};
$this.isFailed = function() {
return _failed;
};
$this.getConsoleText = function() {
return _consoleText;
};
$this.getName = function() {
return _name;
};
$this.hasColor = function(colorName) {
return _fullColor === colorName;
};
$this.getDto = function() {
if (!$this.isLoaded()) {
throw new Error('Job is not loaded yet');
}
return {
name: _name,
url: _url,
cssClass: _color + (_building ? ' building' : ''),
culprits: _build ? _build.getCulprits() : [],
percentage: _percentage
};
};
$this.load = function() {
var callBack = function() {
if ($this.isLoaded()) {
$this.trigger(Job.events.LOADED, { job: $this });
}
};
if (_build) {
_build.on(Build.events.LOADED, callBack);
_build.load();
}
if (_consoleText) {
_consoleText.on(ConsoleText.events.LOADED, callBack);
_consoleText.loadText();
}
};
_init(apiJob.color);
}
Job.prototype = new EventDispatcher();
Job.prototype.constructor = Job;
Job.events = {
LOADED: 'job.loaded'
};