mirror of
https://github.com/odoo/runbot.git
synced 2025-03-15 15:35:46 +07:00
[REF] runbot: rewrite runbot.js
Rewrites runbot.js in modern js with the new Interaction framework.
This commit is contained in:
parent
6ba9aaf411
commit
723f9c49ef
@ -76,6 +76,7 @@
|
||||
'runbot/static/src/vendored/**/*', # Vendored files coming from odoo modules
|
||||
|
||||
'runbot/static/src/frontend/root.js',
|
||||
'runbot/static/src/frontend/runbot.js',
|
||||
]
|
||||
},
|
||||
'post_load': 'runbot_post_load',
|
||||
|
@ -1,39 +1,51 @@
|
||||
(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 { registry } from '@web/core/registry';
|
||||
import { Interaction } from '@web/public/interaction';
|
||||
|
||||
|
||||
class Runbot extends Interaction {
|
||||
static selector = '.frontend';
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
let url = target.href;
|
||||
if (runbotBuild) {
|
||||
url = `/runbot/build/${runbotBuild}/${operation}`;
|
||||
}
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
||||
|
||||
|
||||
function copyToClipboard(text) {
|
||||
if (!navigator.clipboard) {
|
||||
console.error('Clipboard not supported');
|
||||
return;
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Event} ev
|
||||
*/
|
||||
async onClickClipboardCopy({ currentTarget: target }) {
|
||||
if (!navigator.clipboard) {
|
||||
return;
|
||||
}
|
||||
navigator.clipboard.writeText(target.dataset.clipboardCopy);
|
||||
}
|
||||
navigator.clipboard.writeText(text);
|
||||
}
|
||||
|
||||
registry.category('public.interactions').add('runbot', Runbot);
|
||||
|
@ -13,7 +13,6 @@
|
||||
<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/bootstrap/js/bootstrap.bundle.js"/>
|
||||
<script type="text/javascript" src="/runbot/static/src/frontend/runbot.js"/>
|
||||
|
||||
<t t-call-assets="runbot.assets_frontend"/>
|
||||
|
||||
@ -392,7 +391,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-attf-data-clipboard-copy="{{ bundle.name.split(':')[-1] }}">
|
||||
<i t-attf-class="fa fa-clipboard"/>
|
||||
</button>
|
||||
</template>
|
||||
|
Loading…
Reference in New Issue
Block a user