mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 23:45:44 +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($) {
|
||||
"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);
|
||||
}
|
||||
});
|
||||
|
@ -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)
|
||||
|
@ -384,7 +384,7 @@
|
||||
</template>
|
||||
|
||||
<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"/>
|
||||
</button>
|
||||
</template>
|
||||
|
Loading…
Reference in New Issue
Block a user