diff --git a/runbot/__manifest__.py b/runbot/__manifest__.py index 5cceb00c0..1d7cfa4af 100644 --- a/runbot/__manifest__.py +++ b/runbot/__manifest__.py @@ -79,7 +79,48 @@ 'runbot/static/lib/jquery/jquery.js', 'runbot/static/lib/bootstrap/js/bootstrap.bundle.js', - 'runbot/static/src/js/runbot.js', + + 'web/static/src/module_loader.js', + 'web/static/lib/owl/owl.js', + 'web/static/lib/owl/odoo_module.js', + 'web/static/lib/luxon/luxon.js', + 'web/static/src/env.js', + 'web/static/src/session.js', + 'web/static/src/core/registry.js', + 'web/static/src/core/templates.js', + 'web/static/src/core/template_inheritance.js', + 'web/static/src/core/user.js', + 'web/static/src/core/browser/browser.js', + 'web/static/src/core/browser/cookie.js', + 'web/static/src/core/browser/feature_detection.js', + 'web/static/src/core/network/rpc.js', + 'web/static/src/core/utils/arrays.js', + 'web/static/src/core/utils/cache.js', + 'web/static/src/core/utils/concurrency.js', + 'web/static/src/core/utils/functions.js', + 'web/static/src/core/utils/html.js', + 'web/static/src/core/utils/hooks.js', + 'web/static/src/core/utils/objects.js', + 'web/static/src/core/utils/indexed_db.js', + 'web/static/src/core/utils/render.js', + 'web/static/src/core/utils/timing.js', + 'web/static/src/core/utils/ui.js', + 'web/static/src/core/utils/urls.js', + 'web/static/src/core/utils/strings.js', + 'web/static/src/core/l10n/dates.js', + 'web/static/src/core/l10n/translation.js', + 'web/static/src/core/l10n/localization.js', + 'web/static/src/core/l10n/localization_service.js', + 'web/static/src/core/l10n/utils.js', + 'web/static/src/core/l10n/utils/format_list.js', + 'web/static/src/core/l10n/utils/locales.js', + 'web/static/src/core/l10n/utils/normalize.js', + 'web/static/src/public/interaction.js', + 'web/static/src/public/utils.js', + 'web/static/src/public/colibri.js', + 'web/static/src/public/interaction_service.js', + 'runbot/static/src/public/interactions/**/*', + 'runbot/static/src/public/main.js', ], }, 'post_load': 'runbot_post_load', diff --git a/runbot/static/src/js/runbot.js b/runbot/static/src/js/runbot.js deleted file mode 100644 index 58a902976..000000000 --- a/runbot/static/src/js/runbot.js +++ /dev/null @@ -1,40 +0,0 @@ -// @odoo-module ignore -(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(); - }); - }); -})(jQuery); - - -function copyToClipboard(text) { - if (!navigator.clipboard) { - console.error('Clipboard not supported'); - return; - } - navigator.clipboard.writeText(text); -} diff --git a/runbot/static/src/public/interactions/runbot.js b/runbot/static/src/public/interactions/runbot.js new file mode 100644 index 000000000..687de9e2b --- /dev/null +++ b/runbot/static/src/public/interactions/runbot.js @@ -0,0 +1,50 @@ +import { registry } from "@web/core/registry"; +import { Interaction } from "@web/public/interaction"; + +class Runbot extends Interaction { + static selector = ".runbot-public"; + dynamicContent = { + "[data-runbot]": { + "t-on-click.prevent": this.onClickDataRunbot, + }, + "[data-clipboard-copy]": { + "t-on-click.prevent": this.onClickClipboardCopy + } + }; + + /** + * @param {Event} ev + */ + async onClickDataRunbot({ currentTarget }) { + const { runbot: operation, runbotBuild } = currentTarget.dataset; + if (!operation) { + return; + } + let url = currentTarget.href; + if (runbotBuild) { + url = `/runbot/build/${runbotBuild}/${operation}`; + } + const response = await fetch(url, { + method: "POST", + }); + const responseText = await response.text(); + if (operation === "rebuild" && window.location.pathname.endsWith(`/build/${runbotBuild}`)) { + const currentURL = new URL(window.location.href); + currentURL.pathname = `/build/${responseText}`; + window.location.href = currentURL.toString(); + } else if (operation === "action") { + currentTarget.parentElement.innerText = responseText; + } else { + window.location.reload(); + } + } + + /** + * @param {Event} ev + */ + async onClickClipboardCopy({ currentTarget }) { + navigator.clipboard.writeText(currentTarget.dataset.clipboardCopy); + } +} + +registry.category("public.interactions").add("runbot", Runbot); diff --git a/runbot/static/src/public/main.js b/runbot/static/src/public/main.js new file mode 100644 index 000000000..aca1d813e --- /dev/null +++ b/runbot/static/src/public/main.js @@ -0,0 +1,11 @@ +import { whenReady } from "@odoo/owl"; +import { makeEnv, startServices } from "@web/env"; + +export async function start() { + await whenReady(); + + const env = makeEnv(); + await startServices(env); +} + +start(); diff --git a/runbot/templates/utils.xml b/runbot/templates/utils.xml index 3013c16a9..d7b9e05db 100644 --- a/runbot/templates/utils.xml +++ b/runbot/templates/utils.xml @@ -43,7 +43,7 @@