Skip to content

Commit 0c9dc02

Browse files
committed
[REF] runbot: rewrite data-runbot handling
1 parent 18c6135 commit 0c9dc02

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

runbot/static/src/js/runbot.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,4 @@
11
// @odoo-module ignore
2-
(function($) {
3-
"use strict";
4-
$(function () {
5-
$(document).on('click', '[data-runbot]', function (e) {
6-
e.preventDefault();
7-
var data = $(this).data();
8-
var operation = data.runbot;
9-
if (!operation) {
10-
return;
11-
}
12-
var xhr = new XMLHttpRequest();
13-
var url = e.target.href
14-
if (data.runbotBuild) {
15-
url = '/runbot/build/' + data.runbotBuild + '/' + operation
16-
}
17-
var elem = e.target
18-
xhr.addEventListener('load', function () {
19-
if (operation == 'rebuild' && window.location.href.split('?')[0].endsWith('/build/' + data.runbotBuild)){
20-
window.location.href = window.location.href.replace('/build/' + data.runbotBuild, '/build/' + xhr.responseText);
21-
} else if (operation == 'action') {
22-
elem.parentElement.innerText = this.responseText
23-
} else {
24-
window.location.reload();
25-
}
26-
});
27-
xhr.open('POST', url);
28-
xhr.send();
29-
});
30-
});
31-
})(jQuery);
32-
332

343
function copyToClipboard(text) {
354
if (!navigator.clipboard) {

runbot/static/src/public/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const Interactions = [];
1+
import { Runbot } from "./runbot";
2+
3+
const Interactions = [Runbot];
24

35
async function start() {
46
for (const I of Interactions) {

runbot/static/src/public/runbot.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { DelegatedInteractionLite } from "./delegated_interaction_lite";
2+
3+
export class Runbot extends DelegatedInteractionLite {
4+
// static selector = ".frontend";
5+
6+
dynamicContent = {
7+
"[data-runbot]": {
8+
"t-on-click.prevent": this.onDataRunbotClick,
9+
},
10+
};
11+
12+
async onDataRunbotClick({ delegatedTarget }) {
13+
const { runbot: operation, runbotBuild } = delegatedTarget.dataset;
14+
if (!operation) {
15+
return;
16+
}
17+
let { href: url} = delegatedTarget;
18+
if (runbotBuild) {
19+
url = `/runbot/build/${runbotBuild}/${operation}`;
20+
}
21+
const response = await fetch(url, { method: "POST" });
22+
const responseText = await response.text();
23+
const { href: currentURL, pathname } = window.location;
24+
switch(operation) {
25+
case "rebuild":
26+
if (pathname.endsWith(`/build/${runbotBuild}`)) {
27+
const redirectURL = new URL(currentURL);
28+
redirectURL.pathname = redirectURL.pathname.replace(`/build/${runbotBuild}`, `/build/${responseText}`);
29+
window.location.href = redirectURL.toString();
30+
}
31+
break;
32+
case "action":
33+
delegatedTarget.parentElement.innerText = responseText;
34+
break;
35+
default:
36+
window.location.reload();
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)