All Downloads are FREE. Search and download functionalities are using the official Maven repository.

static.ui.js.main.js Maven / Gradle / Ivy

There is a newer version: 6.0.0
Show newest version
$(function () {
  $('[data-toggle="tooltip"]').tooltip()
})
$('#logs').on('show.bs.modal', function (event) {
  var link = $(event.relatedTarget);
  var stage = link.data('stage');

  $.ajax('/api/stages/' + stage + '/logs', {
        dataType: "json",
        success: function (array) {
            var dest = $('#logs').find('.modal-body');
            console.log('success ' + array);
            $.each(array, function(index, element) {
                dest.append($('' + element + '
')); }); } }); }) // https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0 function hashCode(s) { var h = 0, l = s.length, i = 0; while (i < l) { h = (h << 5) - h + s.charCodeAt(i++) | 0; } return h; }; function escapeHtml(unsafe) { return unsafe.replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } var dashboard = dashboard || {}; dashboard = { init: function () { this.bootstrap.init(); this.stages.init(); this.feedback.init(); }, bootstrap: { init: function () { $('#search').on('keyup', dashboard.stages.filter); $('#category').on('change', dashboard.stages.filter); } }, stages: { init: function () { dashboard.stages.reload(); $('[data-action]').on('click', dashboard.stages.action); }, reload: function () { $.ajax('/api/stages?select=apps,comment,expire,last-modified-by,running,urls', { dataType: "json", success: function (data) { $('#loading').remove(); var allStages = $('#all-stages'); var done = []; $.each(data, function (name, status) { var name; var eName; var oldTr; var up; var htmlSt; var htmlName; var htmlUrls; var htmlRestart; var mailBody; var htmlMenu; var newTr; var newHash; var actions; eName = escapeHtml(name) done.push(name); oldTr = allStages.find('[data-name="' + name + '"]'); up = status.running.length > 0; htmlSt = "\n" + "
\n" + " " + (up ? "up" : "down") + "\n" "
\n" + ""; htmlName = "\n" + " " + eName + ""; htmlUrls = ""; $.each(status.urls, function (app, url) { htmlUrls = htmlUrls + "" + escapeHtml(app) + "
\n" }) htmlUrls = "" + htmlUrls + "\n" htmlRestart = " \n" + " \n" " " mailBody = "Application links:\n" $.each(status.urls, function (app, url) { mailBody = mailBody + app + " " + url + " \n" }) htmlMenu = "\n" + " \n" + "\n" newTr = "\n" + htmlSt + htmlName + htmlUrls + "" + status.expire + "\n" + "" + status["last-modified-by"] + "\n" + htmlRestart + htmlMenu ""; newHash = String(hashCode(newTr)); if (oldTr.length === 0) { // new stage var appended = allStages.append(newTr); appended = appended.find('[data-name="' + name + '"]'); appended.attr("data-content-hash", newHash); appended.find('[data-action]').on('click', dashboard.stages.action); } else if ($(oldTr).attr("data-content-hash") !== newHash) { // updated stage oldTr.replaceWith(newTr); // replaceWith returns the removed elements replaced = allStages.find('[data-name="' + name + '"]'); replaced.attr("data-content-hash", newHash); replaced.find('[data-action]').on('click', dashboard.stages.action); } else { // no changes } }); $(allStages).children("tr").each(function (i, tr) { var name; name = $(tr).attr("data-name"); if (!done.includes(name)) { $(tr).find('[data-action]').off('click', dashboard.stages.action); tr.remove(); } }); $('[data-toggle="popover"]').popover(); dashboard.stages.filter(); } }); }, action: function () { var stage, action, arguments, i, url, box; if ($(this).parent().hasClass('disabled') && $(this).attr('data-stage') === null) { return false; } stage = $(this).attr('data-stage'); action = $(this).attr('data-action'); arguments = $(this).attr('data-arguments'); $('#' + stage + ' a.action').addClass('disabled'); box = $('#progress'); box.modal('show'); box.find('.modal-header').html("

" + action + " " + stage + "

"); if (action == "restart") { $.post("/api/stages/" + stage + "/stop").fail(function (r) { box.find('.modal-body').html('

failed: ' + r + '

'); dashboard.stages.reload(); }).done(function (r) { $.post("/api/stages/" + stage + "/start").fail(function (r) { box.find('.modal-body').html('

failed: ' + r + '

'); dashboard.stages.reload(); }).done(function (r) { // TODO: doesn't work if the browser is extremely slow (or busy) // from https://stackoverflow.com/questions/51637199/bootstrap-4-open-modal-a-close-modal-a-open-modal-b-a-not-closing setTimeout( function() { box.modal("hide"); }, 500 ); dashboard.stages.reload(); }); }); } else { url = "/api/stages/" + stage + "/" + action; if (arguments != null) { url = url + "?" + arguments; } $.post(url).fail(function (r) { box.find('.modal-body').html('

failed: ' + String(r) + '

'); console.log(url + " failed: " + String(r)) dashboard.stages.reload(); }).done(function (r) { // TODO: doesn't work if the browser is extremely slow (or busy) // from https://stackoverflow.com/questions/51637199/bootstrap-4-open-modal-a-close-modal-a-open-modal-b-a-not-closing setTimeout( function() { box.modal("hide"); }, 500 ); dashboard.stages.reload(); }); } return false; }, filter: function () { var search = $('#search').val().toLowerCase(); var category = $('#category').val().toLowerCase(); found = 0; $('#all-stages').find('tr.stage').each(function (idx, tr) { $(this).toggle(true); found++; }); $('#empty').toggle(found == 0); } }, feedback: { init: function () { $('#feedback-submit').on('click', function (e) { e.preventDefault(); var text = $('#feedback-text'); if (text.val() !== "") { $.post("/ui/feedback", { message: text.val()}) .done(function () { text.parent().parent().prepend("
Thanks.
"); text.val(""); }) .fail(function () { text.parent().parent() .prepend("
Opps, something went wrong =(.
"); }); } }); } } }; dashboard.init();




© 2015 - 2024 Weber Informatics LLC | Privacy Policy