mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP] runbot: convert basic javascript module
To odoo modules. stats.js not converted because it would make more sense as an owl component.
This commit is contained in:
parent
dd25f8d8b1
commit
47a5480d8a
@ -1,39 +1,46 @@
|
|||||||
(function($) {
|
import publicWidget from "@web/legacy/js/public/public_widget";
|
||||||
"use strict";
|
|
||||||
$(function () {
|
|
||||||
$(document).on('click', '[data-runbot]', function (e) {
|
publicWidget.registry.RunbotPage = publicWidget.Widget.extend({
|
||||||
e.preventDefault();
|
// This selector should not be so broad.
|
||||||
var data = $(this).data();
|
selector: 'body',
|
||||||
var operation = data.runbot;
|
events: {
|
||||||
if (!operation) {
|
'click [data-runbot]': '_onClickDataRunbot',
|
||||||
return;
|
'click [data-runbot-clipboard]': '_onClickRunbotCopy',
|
||||||
}
|
},
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
var url = e.target.href
|
_onClickDataRunbot: async (event) => {
|
||||||
if (data.runbotBuild) {
|
const { currentTarget: target } = event;
|
||||||
url = '/runbot/build/' + data.runbotBuild + '/' + operation
|
if (!target) {
|
||||||
}
|
return;
|
||||||
var elem = e.target
|
}
|
||||||
xhr.addEventListener('load', function () {
|
event.preventDefault();
|
||||||
if (operation == 'rebuild' && window.location.href.split('?')[0].endsWith('/build/' + data.runbotBuild)){
|
const { runbot: operation, runbotBuild } = target.dataset;
|
||||||
window.location.href = window.location.href.replace('/build/' + data.runbotBuild, '/build/' + xhr.responseText);
|
if (!operation) {
|
||||||
} else if (operation == 'action') {
|
return;
|
||||||
elem.parentElement.innerText = this.responseText
|
}
|
||||||
} else {
|
let url = target.href;
|
||||||
window.location.reload();
|
if (runbotBuild) {
|
||||||
}
|
url = `/runbot/build/${runbotBuild}/${operation}`
|
||||||
});
|
}
|
||||||
xhr.open('POST', url);
|
const response = await fetch(url, {
|
||||||
xhr.send();
|
method: 'POST',
|
||||||
});
|
});
|
||||||
});
|
if (operation == 'rebuild' && window.location.href.split('?')[0].endsWith(`/build/${runbotBuild}`)) {
|
||||||
})(jQuery);
|
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();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_onClickRunbotCopy: ({ currentTarget: target }) => {
|
||||||
function copyToClipboard(text) {
|
if (!navigator.clipboard || !target) {
|
||||||
if (!navigator.clipboard) {
|
return;
|
||||||
console.error('Clipboard not supported');
|
}
|
||||||
return;
|
navigator.clipboard.writeText(
|
||||||
|
target.dataset.runbotClipboard
|
||||||
|
);
|
||||||
}
|
}
|
||||||
navigator.clipboard.writeText(text);
|
});
|
||||||
}
|
|
||||||
|
@ -51,7 +51,7 @@ config.options.onClick = function(event, activeElements) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function fetch(path, data, then) {
|
function _fetch(path, data, then) {
|
||||||
const xhttp = new XMLHttpRequest();
|
const xhttp = new XMLHttpRequest();
|
||||||
xhttp.onreadystatechange = function() {
|
xhttp.onreadystatechange = function() {
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
@ -173,7 +173,7 @@ function fetchUpdateChart() {
|
|||||||
chart_spinner.style.visibility = 'visible';
|
chart_spinner.style.visibility = 'visible';
|
||||||
fetch_params = compute_fetch_params();
|
fetch_params = compute_fetch_params();
|
||||||
console.log('fetch')
|
console.log('fetch')
|
||||||
fetch('/runbot/stats/', fetch_params, function(result) {
|
_fetch('/runbot/stats/', fetch_params, function(result) {
|
||||||
config.result = 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 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)
|
Object.values(config.result).forEach(v => v['Aggregate Average'] = Object.values(v).reduce((a, b) => a + b, 0)/Object.values(v).length)
|
||||||
|
@ -384,7 +384,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="runbot.branch_copy_button">
|
<template id="runbot.branch_copy_button">
|
||||||
<button t-attf-class="btn btn-default {{btn_size or 'btn-ssm'}}" title="Copy Bundle name" aria-label="Copy Bundle name" t-attf-onclick="copyToClipboard('{{ bundle.name.split(':')[-1] }}')">
|
<button t-attf-class="btn btn-default {{btn_size or 'btn-ssm'}}" title="Copy Bundle name" aria-label="Copy Bundle name" t-att-data-runbot-clipboard="bundle.name.split(':')[-1]">
|
||||||
<i t-attf-class="fa fa-clipboard"/>
|
<i t-attf-class="fa fa-clipboard"/>
|
||||||
</button>
|
</button>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user