diff --git a/runbot_merge/__manifest__.py b/runbot_merge/__manifest__.py index a21ce712..3dba6c95 100644 --- a/runbot_merge/__manifest__.py +++ b/runbot_merge/__manifest__.py @@ -26,7 +26,7 @@ ], 'web.assets_backend': [ 'runbot_merge/static/scss/runbot_merge_backend.scss', - 'runbot_merge/static/project_freeze/index.js', + 'runbot_merge/static/src/project_freeze/index.js', ], }, 'post_load': 'enable_sentry', diff --git a/runbot_merge/static/project_freeze/index.js b/runbot_merge/static/project_freeze/index.js deleted file mode 100644 index a0568962..00000000 --- a/runbot_merge/static/project_freeze/index.js +++ /dev/null @@ -1,62 +0,0 @@ -odoo.define('runbot_merge.index', function (require) { -"use strict"; -const FormController = require('web.FormController'); -const FormView = require('web.FormView'); -const viewRegistry = require('web.view_registry'); - -/** - * Attept at a "smart" controller for the freeze wizard: keeps triggering - * onchange() on the form in order to try and update the error information, as - * some of the "errors" are not under direct operator control. Hopefully this - * allows the operator to just keep the wizard open and wait until the error - * messages disappear so they can proceed. - */ -const FreezeController = FormController.extend({ - async _checkState() { - const record = this.model.get(this.handle) - const requiredPrIds = record.data.required_pr_ids; - - // we're inside the form's mutex, so can use `_applyChange` directly - const changed = await this.model._applyChange(this.handle, { - required_pr_ids: { - operation: 'REPLACE_WITH', - ids: requiredPrIds.res_ids, - } - }); - // not sure why we need to wait for the round *after* the error update - // notification, but even debouncing the rest of the method is not - // sufficient (so it's not just a problem of being behind the mutex, - // there's something wonky going on) - if (!this._updateNext) { - this._updateNext = changed.includes('errors'); - return; - } - - this._updateNext = false; - for(const p of requiredPrIds.data) { - this.renderer.updateState(p.id, {fieldNames: ['state_color']}); - } - this.renderer.updateState(record, {fieldNames: ['errors', 'required_pr_ids']}); - }, - /** - * @override - */ - async start(...args) { - const checker = async () => { - if (this.isDestroyed()) { return; } - await this.model.mutex.exec(() => this._checkState()); - setTimeout(checker, 1000); - }; - const started = await this._super(...args); - const _ = checker(); - return started; - }, -}); - -viewRegistry.add('freeze_wizard', FormView.extend({ - config: Object.assign({}, FormView.prototype.config, { - Controller: FreezeController, - }) -})); -}); - diff --git a/runbot_merge/static/src/project_freeze/index.js b/runbot_merge/static/src/project_freeze/index.js new file mode 100644 index 00000000..8dca49bc --- /dev/null +++ b/runbot_merge/static/src/project_freeze/index.js @@ -0,0 +1,36 @@ +/** @odoo-module */ + +import {useEffect} from "@odoo/owl"; +import {x2ManyCommands} from "@web/core/orm_service"; +import {registry} from "@web/core/registry"; +import {FormController} from "@web/views/form/form_controller"; +import {formView} from "@web/views/form/form_view"; + +class FreezeController extends FormController { + setup() { + super.setup(); + + useEffect(() => { + const interval = setInterval(async () => { + const root = this.model.root; + if (await root.isDirty()) { + root.update({ + required_pr_ids: x2ManyCommands.set( + root.data.required_pr_ids.currentIds, + ), + }); + } else { + root.load(); + } + }, 1000); + return () => { + clearInterval(interval); + }; + }, () => []); + } +} + +registry.category("views").add('freeze_wizard', { + ...formView, + Controller: FreezeController, +});