diff --git a/runbot/static/src/js/log_display.js b/runbot/static/src/js/log_display.js deleted file mode 100644 index e69de29b..00000000 diff --git a/runbot/static/src/js/runbot.js b/runbot/static/src/js/runbot.js index 4775c9e7..ec396602 100644 --- a/runbot/static/src/js/runbot.js +++ b/runbot/static/src/js/runbot.js @@ -1,39 +1,46 @@ -(function($) { - "use strict"; - $(function () { - $(document).on('click', '[data-runbot]', function (e) { - e.preventDefault(); - var data = $(this).data(); - var operation = data.runbot; - if (!operation) { - return; - } - var xhr = new XMLHttpRequest(); - var url = e.target.href - if (data.runbotBuild) { - url = '/runbot/build/' + data.runbotBuild + '/' + operation - } - var elem = e.target - xhr.addEventListener('load', function () { - if (operation == 'rebuild' && window.location.href.split('?')[0].endsWith('/build/' + data.runbotBuild)){ - window.location.href = window.location.href.replace('/build/' + data.runbotBuild, '/build/' + xhr.responseText); - } else if (operation == 'action') { - elem.parentElement.innerText = this.responseText - } else { - window.location.reload(); - } - }); - xhr.open('POST', url); - xhr.send(); +import publicWidget from "@web/legacy/js/public/public_widget"; + + +publicWidget.registry.RunbotPage = publicWidget.Widget.extend({ + // This selector should not be so broad. + selector: 'body', + events: { + 'click [data-runbot]': '_onClickDataRunbot', + 'click [data-runbot-clipboard]': '_onClickRunbotCopy', + }, + + _onClickDataRunbot: async (event) => { + const { currentTarget: target } = event; + if (!target) { + return; + } + event.preventDefault(); + const { runbot: operation, runbotBuild } = target.dataset; + if (!operation) { + return; + } + let url = target.href; + if (runbotBuild) { + url = `/runbot/build/${runbotBuild}/${operation}` + } + const response = await fetch(url, { + method: 'POST', }); - }); -})(jQuery); + if (operation == 'rebuild' && window.location.href.split('?')[0].endsWith(`/build/${runbotBuild}`)) { + window.location.href = window.location.href.replace('/build/' + runbotBuild, '/build/' + await response.text()); + } else if (operation == 'action') { + target.parentElement.innerText = await response.text(); + } else { + window.location.reload(); + } + }, - -function copyToClipboard(text) { - if (!navigator.clipboard) { - console.error('Clipboard not supported'); - return; + _onClickRunbotCopy: ({ currentTarget: target }) => { + if (!navigator.clipboard || !target) { + return; + } + navigator.clipboard.writeText( + target.dataset.runbotClipboard + ); } - navigator.clipboard.writeText(text); -} +}); diff --git a/runbot/static/src/js/stats.js b/runbot/static/src/js/stats.js index c08ea5a9..c3f312e0 100644 --- a/runbot/static/src/js/stats.js +++ b/runbot/static/src/js/stats.js @@ -51,7 +51,7 @@ config.options.onClick = function(event, activeElements) { }; -function fetch(path, data, then) { +function _fetch(path, data, then) { const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { @@ -173,7 +173,7 @@ function fetchUpdateChart() { chart_spinner.style.visibility = 'visible'; fetch_params = compute_fetch_params(); console.log('fetch') - fetch('/runbot/stats/', fetch_params, function(result) { + _fetch('/runbot/stats/', fetch_params, function(result) { config.result = result; Object.values(config.result).forEach(v => v['Aggregate Sum'] = Object.values(v).reduce((a, b) => a + b, 0)) Object.values(config.result).forEach(v => v['Aggregate Average'] = Object.values(v).reduce((a, b) => a + b, 0)/Object.values(v).length) diff --git a/runbot/templates/utils.xml b/runbot/templates/utils.xml index adcd2c14..00c5d1b1 100644 --- a/runbot/templates/utils.xml +++ b/runbot/templates/utils.xml @@ -384,7 +384,7 @@