Skip to content

Commit 22db8f3

Browse files
committed
Add base javascript for build detail
1 parent 365d8d9 commit 22db8f3

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

gulpfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var gulp = require('gulp'),
1717
// picking up dependencies of the primary entry points and putting any
1818
// limitations on directory structure for entry points.
1919
var sources = {
20+
builds: ['js/detail.js'],
2021
core: [
2122
'js/readthedocs-doc-embed.js',
2223
'js/autocomplete.js',
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Build detail view
2+
3+
var ko = window.knockout || require('knockout');
4+
var $ = window.jquery || require('jquery');
5+
6+
7+
function BuildCommand (data) {
8+
var self = this;
9+
self.id = ko.observable(data.id);
10+
self.command = ko.observable(data.command);
11+
self.output = ko.observable(data.output);
12+
self.exit_code = ko.observable(data.exit_code || 0);
13+
self.successful = ko.observable(self.exit_code() == 0);
14+
self.run_time = ko.observable(data.run_time);
15+
self.is_showing = ko.observable(!self.successful());
16+
17+
self.toggleCommand = function () {
18+
self.is_showing(!self.is_showing());
19+
};
20+
21+
self.command_status = ko.computed(function () {
22+
return self.successful() ?
23+
'build-command-successful' :
24+
'build-command-failed';
25+
});
26+
}
27+
28+
function BuildDetailView (instance) {
29+
var self = this,
30+
instance = instance || {};
31+
32+
/* Instance variables */
33+
self.state = ko.observable(instance.state);
34+
self.state_display = ko.observable(instance.state_display);
35+
self.finished = ko.computed(function () {
36+
return self.state() == 'finished';
37+
});
38+
self.date = ko.observable(instance.date);
39+
self.success = ko.observable(instance.success);
40+
self.error = ko.observable(instance.error);
41+
self.length = ko.observable(instance.length);
42+
self.commands = ko.observableArray(instance.commands);
43+
self.display_commands = ko.computed(function () {
44+
var commands_display = [],
45+
commands_raw = self.commands();
46+
for (n in commands_raw) {
47+
var command = new BuildCommand(commands_raw[n]);
48+
commands_display.push(command)
49+
}
50+
return commands_display;
51+
});
52+
self.commit = ko.observable(instance.commit);
53+
54+
/* Others */
55+
self.legacy_output = ko.observable(false);
56+
self.show_legacy_output = function () {
57+
self.legacy_output(true);
58+
};
59+
60+
function poll_api () {
61+
if (self.finished()) {
62+
return;
63+
}
64+
$.getJSON('/api/v2/build/' + instance.id + '/', function (data) {
65+
self.state(data.state);
66+
self.state_display(data.state_display);
67+
self.date(data.date);
68+
self.success(data.success);
69+
self.error(data.error);
70+
self.length(data.length);
71+
self.commit(data.commit);
72+
for (n in data.commands) {
73+
var command = data.commands[n];
74+
var match = ko.utils.arrayFirst(
75+
self.commands(),
76+
function(command_cmp) {
77+
return (command_cmp.id == command.id);
78+
}
79+
);
80+
if (!match) {
81+
self.commands.push(command);
82+
}
83+
}
84+
});
85+
86+
setTimeout(poll_api, 2000);
87+
}
88+
89+
poll_api();
90+
}
91+
92+
BuildDetailView.init = function (instance, domobj) {
93+
var view = new BuildDetailView(instance),
94+
domobj = domobj || $('#build-detail')[0];
95+
ko.applyBindings(view, domobj);
96+
return view;
97+
};
98+
99+
module.exports.BuildDetailView = BuildDetailView;
100+
101+
if (typeof(window) != 'undefined') {
102+
window.build = module.exports;
103+
}

readthedocs/builds/static/builds/js/detail.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)