aboutsummaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/toastergui/static/js/mrbsection.js
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2016-06-29 15:41:56 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-08-11 00:09:26 +0100
commit952ffb3e1f4a00793e0c9c49bc0c8fb8729424c4 (patch)
tree604083d9477c9d3d2f51c714fe3b74ac8196f26c /bitbake/lib/toaster/toastergui/static/js/mrbsection.js
parentc471740f5ba023dccc992438c75f1534950d26af (diff)
downloadopenembedded-core-contrib-952ffb3e1f4a00793e0c9c49bc0c8fb8729424c4.tar.gz
bitbake: toaster: move most recent builds templating to client
The most recent builds area of the all builds and project builds table needs to update as a build progresses. It also needs additional functionality to show other states (e.g. recipe parsing, queued) which again needs to update on the client side. Rather than add to the existing mix of server-side templating with client-side DOM updating, translate all of the server-side templates to client-side ones (jsrender), and add logic which updates the most recent builds area as the state of a build changes. Add a JSON API for mostrecentbuilds, which returns the state of all "recent" builds. Fetch this via Ajax from the build dashboard (rather than fetching the ad hoc API as in the previous version). Then, as new states for builds are fetched via Ajax, determine whether the build state has changed completely, or whether the progress has just updated. If the state completely changed, re-render the template on the client side for that build. If only the progress changed, just update the progress bar. (NB this fixes the task progress bar so it works for the project builds and all builds pages.) In cases where the builds table needs to update as the result of a build finishing, reload the whole page. This work highlighted a variety of other issues, such as build requests not being able to change state as necessary. This was one part of the cause of the "cancelling build..." state being fragile and disappearing entirely when the page refreshed. The cancelling state now persists between page reloads, as the logic for determining whether a build is cancelling is now on the Build object itself. Note that jsrender is redistributed as part of Toaster, so a note was added to LICENSE to that effect. [YOCTO #9631] (Bitbake rev: c868ea036aa34b387a72ec5116a66b2cd863995b) Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/toastergui/static/js/mrbsection.js')
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/mrbsection.js178
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 @@
function mrbSectionInit(ctx){
-
- var projectBuilds;
-
- if (ctx.mrbType === 'project')
- projectBuilds = true;
-
- $(".cancel-build-btn").click(function(e){
+ $('#latest-builds').on('click', '.cancel-build-btn', function(e){
+ e.stopImmediatePropagation();
e.preventDefault();
var url = $(this).data('request-url');
var buildReqIds = $(this).data('buildrequest-id');
- var banner = $(this).parents(".alert");
-
- banner.find(".progress-info").fadeOut().promise().done(function(){
- $("#cancelling-msg-" + buildReqIds).show();
- console.log("cancel build");
- libtoaster.cancelABuild(url, buildReqIds, function(){
- if (projectBuilds == false){
- /* the all builds page is not 'self updating' like thei
- * project Builds
- */
- window.location.reload();
- }
- }, null);
- });
+
+ libtoaster.cancelABuild(url, buildReqIds, function () {
+ window.location.reload();
+ }, null);
});
- $(".run-again-btn").click(function(e){
+ $('#latest-builds').on('click', '.rebuild-btn', function(e){
+ e.stopImmediatePropagation();
e.preventDefault();
var url = $(this).data('request-url');
@@ -38,58 +24,110 @@ function mrbSectionInit(ctx){
}, null);
});
+ // cached version of buildData, so we can determine whether a build has
+ // changed since it was last fetched, and update the DOM appropriately
+ var buildData = {};
- var progressTimer;
-
- if (projectBuilds === true){
- progressTimer = window.setInterval(function() {
- libtoaster.getProjectInfo(libtoaster.ctx.projectPageUrl,
- function(prjInfo){
- /* These two are needed because a build can be 100% and still
- * in progress due to the fact that the % done is updated at the
- * start of a task so it can be doing the last task at 100%
- */
- var inProgress = 0;
- var allPercentDone = 0;
- if (prjInfo.builds.length === 0)
- return
-
- for (var i in prjInfo.builds){
- var build = prjInfo.builds[i];
-
- if (build.outcomeText === "In Progress" ||
- $(".progress .bar").length > 0){
- /* Update the build progress */
- var percentDone;
-
- if (build.outcomeText !== "In Progress"){
- /* We have to ignore the value when it's Succeeded because it
- * goes back to 0
- */
- percentDone = 100;
- } else {
- percentDone = build.percentDone;
- inProgress++;
- }
-
- $("#build-pc-done-" + build.id).text(percentDone);
- $("#build-pc-done-title-" + build.id).attr("title", percentDone);
- $("#build-pc-done-bar-" + build.id).css("width",
- String(percentDone) + "%");
-
- allPercentDone += percentDone;
- }
- }
+ // returns the cached version of this build, or {} is there isn't a cached one
+ function getCached(build) {
+ return buildData[build.id] || {};
+ }
+
+ // returns true if a build's state changed to "Succeeded" or "Failed"
+ // from some other value
+ function buildFinished(build) {
+ var cached = getCached(build);
+ return cached.state &&
+ cached.state !== build.state &&
+ (build.state == 'Succeeded' || build.state == 'Failed' ||
+ build.state == 'Cancelled');
+ }
- if (allPercentDone === (100 * prjInfo.builds.length) && !inProgress)
+ // returns true if the state changed
+ function stateChanged(build) {
+ var cached = getCached(build);
+ return (cached.state !== build.state);
+ }
+
+ // returns true if the complete_percentage changed
+ function progressChanged(build) {
+ var cached = getCached(build);
+ return (cached.tasks_complete_percentage !== build.tasks_complete_percentage);
+ }
+
+ function refreshMostRecentBuilds(){
+ libtoaster.getMostRecentBuilds(
+ libtoaster.ctx.mostRecentBuildsUrl,
+
+ // success callback
+ function (data) {
+ var build;
+ var tmpl;
+ var container;
+ var selector;
+ var colourClass;
+ var elements;
+
+ // classes on the parent which signify the build state and affect
+ // the colour of the container for the build
+ var buildStateClasses = 'alert-info alert-success alert-danger';
+
+ for (var i = 0; i < data.length; i++) {
+ build = data[i];
+
+ if (buildFinished(build)) {
+ // a build finished: reload the whole page so that the build
+ // shows up in the builds table
window.location.reload();
+ }
+ else if (stateChanged(build)) {
+ // update the whole template
+ tmpl = $.templates("#build-template");
+
+ html = tmpl.render(build);
+
+ selector = '[data-latest-build-result="' + build.id + '"] ' +
+ '[data-role="build-status-container"]';
+ container = $(selector);
+
+ container.html(html);
+
+ // style the outermost container for this build to reflect
+ // the new build state (red, green, blue);
+ // NB class set here should be in buildStateClasses
+ colourClass = 'alert-info';
+ if (build.state == 'Succeeded') {
+ colourClass = 'alert-success';
+ }
+ else if (build.state == 'Failed') {
+ colourClass = 'alert-danger';
+ }
- /* Our progress bar is not still showing so shutdown the polling. */
- if ($(".progress .bar").length === 0)
- window.clearInterval(progressTimer);
+ elements = $('[data-latest-build-result="' + build.id + '"]');
+ elements.removeClass(buildStateClasses);
+ elements.addClass(colourClass);
+ }
+ else if (progressChanged(build)) {
+ // update the progress text
+ selector = '#build-pc-done-' + build.id;
+ $(selector).html(build.tasks_complete_percentage);
+
+ // update the progress bar
+ selector = '#build-pc-done-bar-' + build.id;
+ $(selector).width(build.tasks_complete_percentage + '%');
+ }
- });
- }, 1500);
+ buildData[build.id] = build;
+ }
+ },
+
+ // fail callback
+ function (data) {
+ console.error(data);
+ }
+ );
}
-}
+ window.setInterval(refreshMostRecentBuilds, 1000);
+ refreshMostRecentBuilds();
+}