diff options
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/mrbsection.js')
-rw-r--r-- | bitbake/lib/toaster/toastergui/static/js/mrbsection.js | 178 |
1 files changed, 108 insertions, 70 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/mrbsection.js b/bitbake/lib/toaster/toastergui/static/js/mrbsection.js index 9a76ee6407..d8c3bf7750 100644 --- a/bitbake/lib/toaster/toastergui/static/js/mrbsection.js +++ b/bitbake/lib/toaster/toastergui/static/js/mrbsection.js | |||
@@ -1,33 +1,19 @@ | |||
1 | 1 | ||
2 | function mrbSectionInit(ctx){ | 2 | function mrbSectionInit(ctx){ |
3 | 3 | $('#latest-builds').on('click', '.cancel-build-btn', function(e){ | |
4 | var projectBuilds; | 4 | e.stopImmediatePropagation(); |
5 | |||
6 | if (ctx.mrbType === 'project') | ||
7 | projectBuilds = true; | ||
8 | |||
9 | $(".cancel-build-btn").click(function(e){ | ||
10 | e.preventDefault(); | 5 | e.preventDefault(); |
11 | 6 | ||
12 | var url = $(this).data('request-url'); | 7 | var url = $(this).data('request-url'); |
13 | var buildReqIds = $(this).data('buildrequest-id'); | 8 | var buildReqIds = $(this).data('buildrequest-id'); |
14 | var banner = $(this).parents(".alert"); | 9 | |
15 | 10 | libtoaster.cancelABuild(url, buildReqIds, function () { | |
16 | banner.find(".progress-info").fadeOut().promise().done(function(){ | 11 | window.location.reload(); |
17 | $("#cancelling-msg-" + buildReqIds).show(); | 12 | }, null); |
18 | console.log("cancel build"); | ||
19 | libtoaster.cancelABuild(url, buildReqIds, function(){ | ||
20 | if (projectBuilds == false){ | ||
21 | /* the all builds page is not 'self updating' like thei | ||
22 | * project Builds | ||
23 | */ | ||
24 | window.location.reload(); | ||
25 | } | ||
26 | }, null); | ||
27 | }); | ||
28 | }); | 13 | }); |
29 | 14 | ||
30 | $(".run-again-btn").click(function(e){ | 15 | $('#latest-builds').on('click', '.rebuild-btn', function(e){ |
16 | e.stopImmediatePropagation(); | ||
31 | e.preventDefault(); | 17 | e.preventDefault(); |
32 | 18 | ||
33 | var url = $(this).data('request-url'); | 19 | var url = $(this).data('request-url'); |
@@ -38,58 +24,110 @@ function mrbSectionInit(ctx){ | |||
38 | }, null); | 24 | }, null); |
39 | }); | 25 | }); |
40 | 26 | ||
27 | // cached version of buildData, so we can determine whether a build has | ||
28 | // changed since it was last fetched, and update the DOM appropriately | ||
29 | var buildData = {}; | ||
41 | 30 | ||
42 | var progressTimer; | 31 | // returns the cached version of this build, or {} is there isn't a cached one |
43 | 32 | function getCached(build) { | |
44 | if (projectBuilds === true){ | 33 | return buildData[build.id] || {}; |
45 | progressTimer = window.setInterval(function() { | 34 | } |
46 | libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl, | 35 | |
47 | function(prjInfo){ | 36 | // returns true if a build's state changed to "Succeeded" or "Failed" |
48 | /* These two are needed because a build can be 100% and still | 37 | // from some other value |
49 | * in progress due to the fact that the % done is updated at the | 38 | function buildFinished(build) { |
50 | * start of a task so it can be doing the last task at 100% | 39 | var cached = getCached(build); |
51 | */ | 40 | return cached.state && |
52 | var inProgress = 0; | 41 | cached.state !== build.state && |
53 | var allPercentDone = 0; | 42 | (build.state == 'Succeeded' || build.state == 'Failed' || |
54 | if (prjInfo.builds.length === 0) | 43 | build.state == 'Cancelled'); |
55 | return | 44 | } |
56 | |||
57 | for (var i in prjInfo.builds){ | ||
58 | var build = prjInfo.builds[i]; | ||
59 | |||
60 | if (build.outcomeText === "In Progress" || | ||
61 | $(".progress .bar").length > 0){ | ||
62 | /* Update the build progress */ | ||
63 | var percentDone; | ||
64 | |||
65 | if (build.outcomeText !== "In Progress"){ | ||
66 | /* We have to ignore the value when it's Succeeded because it | ||
67 | * goes back to 0 | ||
68 | */ | ||
69 | percentDone = 100; | ||
70 | } else { | ||
71 | percentDone = build.percentDone; | ||
72 | inProgress++; | ||
73 | } | ||
74 | |||
75 | $("#build-pc-done-" + build.id).text(percentDone); | ||
76 | $("#build-pc-done-title-" + build.id).attr("title", percentDone); | ||
77 | $("#build-pc-done-bar-" + build.id).css("width", | ||
78 | String(percentDone) + "%"); | ||
79 | |||
80 | allPercentDone += percentDone; | ||
81 | } | ||
82 | } | ||
83 | 45 | ||
84 | if (allPercentDone === (100 * prjInfo.builds.length) && !inProgress) | 46 | // returns true if the state changed |
47 | function stateChanged(build) { | ||
48 | var cached = getCached(build); | ||
49 | return (cached.state !== build.state); | ||
50 | } | ||
51 | |||
52 | // returns true if the complete_percentage changed | ||
53 | function progressChanged(build) { | ||
54 | var cached = getCached(build); | ||
55 | return (cached.tasks_complete_percentage !== build.tasks_complete_percentage); | ||
56 | } | ||
57 | |||
58 | function refreshMostRecentBuilds(){ | ||
59 | libtoaster.getMostRecentBuilds( | ||
60 | libtoaster.ctx.mostRecentBuildsUrl, | ||
61 | |||
62 | // success callback | ||
63 | function (data) { | ||
64 | var build; | ||
65 | var tmpl; | ||
66 | var container; | ||
67 | var selector; | ||
68 | var colourClass; | ||
69 | var elements; | ||
70 | |||
71 | // classes on the parent which signify the build state and affect | ||
72 | // the colour of the container for the build | ||
73 | var buildStateClasses = 'alert-info alert-success alert-danger'; | ||
74 | |||
75 | for (var i = 0; i < data.length; i++) { | ||
76 | build = data[i]; | ||
77 | |||
78 | if (buildFinished(build)) { | ||
79 | // a build finished: reload the whole page so that the build | ||
80 | // shows up in the builds table | ||
85 | window.location.reload(); | 81 | window.location.reload(); |
82 | } | ||
83 | else if (stateChanged(build)) { | ||
84 | // update the whole template | ||
85 | tmpl = $.templates("#build-template"); | ||
86 | |||
87 | html = tmpl.render(build); | ||
88 | |||
89 | selector = '[data-latest-build-result="' + build.id + '"] ' + | ||
90 | '[data-role="build-status-container"]'; | ||
91 | container = $(selector); | ||
92 | |||
93 | container.html(html); | ||
94 | |||
95 | // style the outermost container for this build to reflect | ||
96 | // the new build state (red, green, blue); | ||
97 | // NB class set here should be in buildStateClasses | ||
98 | colourClass = 'alert-info'; | ||
99 | if (build.state == 'Succeeded') { | ||
100 | colourClass = 'alert-success'; | ||
101 | } | ||
102 | else if (build.state == 'Failed') { | ||
103 | colourClass = 'alert-danger'; | ||
104 | } | ||
86 | 105 | ||
87 | /* Our progress bar is not still showing so shutdown the polling. */ | 106 | elements = $('[data-latest-build-result="' + build.id + '"]'); |
88 | if ($(".progress .bar").length === 0) | 107 | elements.removeClass(buildStateClasses); |
89 | window.clearInterval(progressTimer); | 108 | elements.addClass(colourClass); |
109 | } | ||
110 | else if (progressChanged(build)) { | ||
111 | // update the progress text | ||
112 | selector = '#build-pc-done-' + build.id; | ||
113 | $(selector).html(build.tasks_complete_percentage); | ||
114 | |||
115 | // update the progress bar | ||
116 | selector = '#build-pc-done-bar-' + build.id; | ||
117 | $(selector).width(build.tasks_complete_percentage + '%'); | ||
118 | } | ||
90 | 119 | ||
91 | }); | 120 | buildData[build.id] = build; |
92 | }, 1500); | 121 | } |
122 | }, | ||
123 | |||
124 | // fail callback | ||
125 | function (data) { | ||
126 | console.error(data); | ||
127 | } | ||
128 | ); | ||
93 | } | 129 | } |
94 | } | ||
95 | 130 | ||
131 | window.setInterval(refreshMostRecentBuilds, 1000); | ||
132 | refreshMostRecentBuilds(); | ||
133 | } | ||