From 298c4913eb6c0316454a07eaa6279c2a627a1e09 Mon Sep 17 00:00:00 2001 From: Joshua Hesketh Date: Thu, 20 Mar 2014 16:06:25 +1100 Subject: [PATCH] Build status page more jquery like Build the status page DOM with jquery to allow cleaner code and easier modifications to come. Change-Id: Ia64dbe4662e9ac1e77e984fe37103ba9cc3abb41 --- etc/status/public_html/app.js | 226 +++++++++++++++++----------------- 1 file changed, 116 insertions(+), 110 deletions(-) diff --git a/etc/status/public_html/app.js b/etc/status/public_html/app.js index b4c82f82ec..0780346063 100644 --- a/etc/status/public_html/app.js +++ b/etc/status/public_html/app.js @@ -19,7 +19,7 @@ (function ($) { var $container, $msg, $msgWrap, $indicator, $queueInfo, $queueEventsNum, $queueResultsNum, $pipelines, $jq; - var xhr, prevHtml, zuul, + var xhr, zuul, demo = location.search.match(/[?&]demo=([^?&]*)/), source = demo ? './status-' + (demo[1] || 'basic') + '.json-sample' : @@ -47,128 +47,135 @@ zuul.emit('update-start'); - xhr = $.ajax({ - url: source, - dataType: 'json', - cache: false - }) - .done(function (data) { - var html = ''; - data = data || {}; + xhr = $.getJSON(source) + .done(function (data) { + if ('message' in data) { + $msg.text(data.message); + $msgWrap.removeClass('zuul-msg-wrap-off'); + } else { + $msg.empty(); + $msgWrap.addClass('zuul-msg-wrap-off'); + } - if ('message' in data) { - $msg.html(data.message); - $msgWrap.removeClass('zuul-msg-wrap-off'); - } else { - $msg.empty(); - $msgWrap.addClass('zuul-msg-wrap-off'); - } + if ('zuul_version' in data) { + $('#zuul-version-span').text(data['zuul_version']); + } + if ('last_reconfigured' in data) { + var last_reconfigured = + new Date(data['last_reconfigured']); + $('#last-reconfigured-span').text( + last_reconfigured.toString()); + } - if ('zuul_version' in data) { - $('#zuul-version-span').text(data['zuul_version']); - } - if ('last_reconfigured' in data) { - var last_reconfigured = - new Date(data['last_reconfigured']); - $('#last-reconfigured-span').text( - last_reconfigured.toString()); - } + $pipelines.html(''); + $.each(data.pipelines, function (i, pipeline) { + $pipelines.append(zuul.format.pipeline(pipeline)); + }); - $.each(data.pipelines, function (i, pipeline) { - html += zuul.format.pipeline(pipeline); + $queueEventsNum.text( + data.trigger_event_queue ? + data.trigger_event_queue.length : '0' + ); + $queueResultsNum.text( + data.result_event_queue ? + data.result_event_queue.length : '0' + ); + }) + .fail(function (err, jqXHR, errMsg) { + $msg.text(source + ': ' + errMsg).show(); + $msgWrap.removeClass('zuul-msg-wrap-off'); + }) + .complete(function () { + xhr = undefined; + zuul.emit('update-end'); }); - // Only re-parse the DOM if we have to - if (html !== prevHtml) { - prevHtml = html; - $pipelines.html(html); - } - - $queueEventsNum.text( - data.trigger_event_queue ? - data.trigger_event_queue.length : '0' - ); - $queueResultsNum.text( - data.result_event_queue ? - data.result_event_queue.length : '0' - ); - }) - .fail(function (err, jqXHR, errMsg) { - $msg.text(source + ': ' + errMsg).show(); - $msgWrap.removeClass('zuul-msg-wrap-off'); - }) - .complete(function () { - xhr = undefined; - zuul.emit('update-end'); - }); - return xhr; }, format: { change: function (change) { - var html = '
' + - '