mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +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/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',
|
||||||
|
@ -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 = {
|
||||||
if (!operation) {
|
'[data-runbot]': {
|
||||||
return;
|
't-on-click.prevent': this.onClickDataRunbot,
|
||||||
}
|
},
|
||||||
var xhr = new XMLHttpRequest();
|
'[data-clipboard-copy]': {
|
||||||
var url = e.target.href
|
't-on-click.prevent': this.onClickClipboardCopy
|
||||||
if (data.runbotBuild) {
|
}
|
||||||
url = '/runbot/build/' + data.runbotBuild + '/' + operation
|
};
|
||||||
}
|
|
||||||
var elem = e.target
|
/**
|
||||||
xhr.addEventListener('load', function () {
|
* @param {Event} ev
|
||||||
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);
|
async onClickDataRunbot({currentTarget: target}) {
|
||||||
} else if (operation == 'action') {
|
const {runbot: operation, runbotBuild} = target.dataset;
|
||||||
elem.parentElement.innerText = this.responseText
|
if (!operation) {
|
||||||
} else {
|
return;
|
||||||
window.location.reload();
|
}
|
||||||
}
|
let url = target.href;
|
||||||
});
|
if (runbotBuild) {
|
||||||
xhr.open('POST', url);
|
url = `/runbot/build/${runbotBuild}/${operation}`;
|
||||||
xhr.send();
|
}
|
||||||
|
const response = await fetch(url, {
|
||||||
|
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();
|
||||||
function copyToClipboard(text) {
|
} else {
|
||||||
if (!navigator.clipboard) {
|
window.location.reload();
|
||||||
console.error('Clipboard not supported');
|
}
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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 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>
|
||||||
|
Loading…
Reference in New Issue
Block a user