[REF] runbot: rewrite runbot.js

Rewrites runbot.js in modern js with the new Interaction framework.
This commit is contained in:
William Braeckman 2025-03-10 16:34:39 +01:00
parent 6ba9aaf411
commit 723f9c49ef
3 changed files with 50 additions and 38 deletions

View File

@ -76,6 +76,7 @@
'runbot/static/src/vendored/**/*', # Vendored files coming from odoo modules 'runbot/static/src/vendored/**/*', # Vendored files coming from odoo modules
'runbot/static/src/frontend/root.js', 'runbot/static/src/frontend/root.js',
'runbot/static/src/frontend/runbot.js',
] ]
}, },
'post_load': 'runbot_post_load', 'post_load': 'runbot_post_load',

View File

@ -1,39 +1,51 @@
(function($) { import { registry } from '@web/core/registry';
"use strict"; import { Interaction } from '@web/public/interaction';
$(function () {
$(document).on('click', '[data-runbot]', function (e) {
e.preventDefault(); class Runbot extends Interaction {
var data = $(this).data(); static selector = '.frontend';
var operation = data.runbot; dynamicContent = {
'[data-runbot]': {
't-on-click.prevent': this.onClickDataRunbot,
},
'[data-clipboard-copy]': {
't-on-click.prevent': this.onClickClipboardCopy
}
};
/**
* @param {Event} ev
*/
async onClickDataRunbot({currentTarget: target}) {
const {runbot: operation, runbotBuild} = target.dataset;
if (!operation) { if (!operation) {
return; return;
} }
var xhr = new XMLHttpRequest(); let url = target.href;
var url = e.target.href if (runbotBuild) {
if (data.runbotBuild) { url = `/runbot/build/${runbotBuild}/${operation}`;
url = '/runbot/build/' + data.runbotBuild + '/' + operation
} }
var elem = e.target const response = await fetch(url, {
xhr.addEventListener('load', function () { method: 'POST',
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); 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') { } else if (operation == 'action') {
elem.parentElement.innerText = this.responseText target.parentElement.innerText = await response.text();
} else { } else {
window.location.reload(); window.location.reload();
} }
}); }
xhr.open('POST', url);
xhr.send();
});
});
})(jQuery);
/**
function copyToClipboard(text) { * @param {Event} ev
*/
async onClickClipboardCopy({ currentTarget: target }) {
if (!navigator.clipboard) { if (!navigator.clipboard) {
console.error('Clipboard not supported');
return; return;
} }
navigator.clipboard.writeText(text); navigator.clipboard.writeText(target.dataset.clipboardCopy);
} }
}
registry.category('public.interactions').add('runbot', Runbot);

View File

@ -13,7 +13,6 @@
<script src="/runbot/static/libs/jquery/jquery.js" type="text/javascript"/> <script src="/runbot/static/libs/jquery/jquery.js" type="text/javascript"/>
<script type="text/javascript" src="/runbot/static/libs/popper/popper.js"/> <script type="text/javascript" src="/runbot/static/libs/popper/popper.js"/>
<script type="text/javascript" src="/runbot/static/libs/bootstrap/js/bootstrap.bundle.js"/> <script type="text/javascript" src="/runbot/static/libs/bootstrap/js/bootstrap.bundle.js"/>
<script type="text/javascript" src="/runbot/static/src/frontend/runbot.js"/>
<t t-call-assets="runbot.assets_frontend"/> <t t-call-assets="runbot.assets_frontend"/>
@ -392,7 +391,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-attf-data-clipboard-copy="{{ bundle.name.split(':')[-1] }}">
<i t-attf-class="fa fa-clipboard"/> <i t-attf-class="fa fa-clipboard"/>
</button> </button>
</template> </template>