[IMP] web: remove legacy service system
This commit removes the legacy service classes: - AbstractService - AjaxService - AbstractStorageService - LocalStorageService, - SessionStorageService Only AjaxService was still used as a service so it is moves in the "common_env" file. task 3439226 closes odoo/odoo#131683 Signed-off-by: Samuel Degueldre (sad) <sad@odoo.com>
This commit is contained in:
@@ -116,7 +116,6 @@ Help your customers with this chat, and analyse their feedback.
|
||||
'web/static/src/core/utils/transitions.scss',
|
||||
'web/static/src/core/**/*',
|
||||
'web/static/src/env.js',
|
||||
('remove', 'web/static/src/legacy/js/services/ajax_service.js'),
|
||||
('remove', 'web/static/src/legacy/js/common_env.js'),
|
||||
('remove', 'web/static/src/core/emoji_picker/emoji_data.js'),
|
||||
'web/static/src/views/fields/formatters.js',
|
||||
|
||||
@@ -174,7 +174,6 @@ For more specific needs, you may also assign custom-defined actions
|
||||
'web/static/src/core/utils/transitions.scss', # included early because used by other files
|
||||
'web/static/src/core/**/*',
|
||||
'web/static/src/env.js',
|
||||
('remove', 'web/static/src/legacy/js/services/ajax_service.js'),
|
||||
('remove', 'web/static/src/core/emoji_picker/emoji_data.js'),
|
||||
'web/static/src/views/fields/formatters.js',
|
||||
'web/static/src/views/fields/file_handler.*',
|
||||
|
||||
@@ -119,8 +119,6 @@ This module provides the core of the Odoo Web Client.
|
||||
'web/static/src/legacy/js/libs/pdfjs.js',
|
||||
'web/static/src/legacy/js/libs/zoomodoo.js',
|
||||
'web/static/src/legacy/js/libs/jSignatureCustom.js',
|
||||
'web/static/src/legacy/js/core/abstract_service.js',
|
||||
'web/static/src/legacy/js/core/abstract_storage_service.js',
|
||||
'web/static/src/legacy/js/core/ajax.js',
|
||||
'web/static/src/legacy/js/core/bus.js',
|
||||
'web/static/src/legacy/js/core/class.js',
|
||||
@@ -141,11 +139,8 @@ This module provides the core of the Odoo Web Client.
|
||||
'web/static/src/legacy/js/core/translation.js',
|
||||
'web/static/src/legacy/js/core/utils.js',
|
||||
'web/static/src/legacy/js/core/widget.js',
|
||||
'web/static/src/legacy/js/services/ajax_service.js',
|
||||
'web/static/src/legacy/js/services/config.js',
|
||||
'web/static/src/legacy/js/services/core.js',
|
||||
'web/static/src/legacy/js/services/local_storage_service.js',
|
||||
'web/static/src/legacy/js/services/session_storage_service.js',
|
||||
'web/static/src/legacy/js/common_env.js',
|
||||
'web/static/src/legacy/js/widgets/name_and_signature.js',
|
||||
'web/static/src/legacy/xml/name_and_signature.xml',
|
||||
@@ -314,8 +309,6 @@ This module provides the core of the Odoo Web Client.
|
||||
'web/static/src/legacy/js/libs/pdfjs.js',
|
||||
'web/static/src/legacy/js/libs/zoomodoo.js',
|
||||
'web/static/src/legacy/js/libs/jSignatureCustom.js',
|
||||
'web/static/src/legacy/js/core/abstract_service.js',
|
||||
'web/static/src/legacy/js/core/abstract_storage_service.js',
|
||||
'web/static/src/legacy/js/core/ajax.js',
|
||||
'web/static/src/legacy/js/core/bus.js',
|
||||
'web/static/src/legacy/js/core/class.js',
|
||||
@@ -336,11 +329,8 @@ This module provides the core of the Odoo Web Client.
|
||||
'web/static/src/legacy/js/core/translation.js',
|
||||
'web/static/src/legacy/js/core/utils.js',
|
||||
'web/static/src/legacy/js/core/widget.js',
|
||||
'web/static/src/legacy/js/services/ajax_service.js',
|
||||
'web/static/src/legacy/js/services/config.js',
|
||||
'web/static/src/legacy/js/services/core.js',
|
||||
'web/static/src/legacy/js/services/local_storage_service.js',
|
||||
'web/static/src/legacy/js/services/session_storage_service.js',
|
||||
'web/static/src/legacy/js/common_env.js',
|
||||
'web/static/src/legacy/js/widgets/name_and_signature.js',
|
||||
'web/static/src/legacy/xml/name_and_signature.xml',
|
||||
|
||||
@@ -50,6 +50,25 @@
|
||||
device,
|
||||
isDebug,
|
||||
services: {
|
||||
ajax: {
|
||||
rpc(route, args, options, target) {
|
||||
let rpcPromise = null;
|
||||
const promise = new Promise(function (resolve, reject) {
|
||||
rpcPromise = session.rpc(route, args, options);
|
||||
rpcPromise.then(function (result) {
|
||||
if (!target.isDestroyed()) {
|
||||
resolve(result);
|
||||
}
|
||||
}).guardedCatch(function (reason) {
|
||||
if (!target.isDestroyed()) {
|
||||
reject(reason);
|
||||
}
|
||||
});
|
||||
});
|
||||
promise.abort = rpcPromise.abort.bind(rpcPromise);
|
||||
return promise;
|
||||
},
|
||||
},
|
||||
ajaxJsonRPC() {
|
||||
return jsonRpc(...arguments);
|
||||
},
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import Class from "@web/legacy/js/core/class";
|
||||
import { serviceRegistry } from "@web/legacy/js/services/core";
|
||||
import Mixins from "@web/legacy/js/core/mixins";
|
||||
import ServicesMixin from "@web/legacy/js/core/service_mixins";
|
||||
|
||||
var AbstractService = Class.extend(Mixins.EventDispatcherMixin, ServicesMixin, {
|
||||
dependencies: [],
|
||||
init: function (env) {
|
||||
Mixins.EventDispatcherMixin.init.call(this, arguments);
|
||||
this.env = env;
|
||||
},
|
||||
/**
|
||||
* @abstract
|
||||
*/
|
||||
start: function () {},
|
||||
/**
|
||||
* Directly calls the requested service, instead of triggering a
|
||||
* 'call_service' event up, which wouldn't work as services have no parent
|
||||
*
|
||||
* @param {OdooEvent} ev
|
||||
*/
|
||||
_trigger_up: function (ev) {
|
||||
Mixins.EventDispatcherMixin._trigger_up.apply(this, arguments);
|
||||
if (ev.is_stopped()) {
|
||||
return;
|
||||
}
|
||||
const payload = ev.data;
|
||||
if (ev.name === 'call_service') {
|
||||
let args = payload.args || [];
|
||||
if (payload.service === 'ajax' && payload.method === 'rpc') {
|
||||
// ajax service uses an extra 'target' argument for rpc
|
||||
args = args.concat(ev.target);
|
||||
}
|
||||
const service = this.env.services[payload.service];
|
||||
const result = service[payload.method].apply(service, args);
|
||||
payload.callback(result);
|
||||
} else if (ev.name === 'do_action') {
|
||||
this.env.bus.trigger('do-action', payload);
|
||||
}
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Static
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Deploy services in the env (specializations of AbstractService registered
|
||||
* into the serviceRegistry).
|
||||
*
|
||||
* @static
|
||||
* @param {Object} env
|
||||
*/
|
||||
deployServices(env) {
|
||||
const UndeployedServices = Object.assign({}, serviceRegistry.map);
|
||||
function _deployServices() {
|
||||
let done = false;
|
||||
while (!done) {
|
||||
// find a service with no missing dependency
|
||||
const serviceName = Object.keys(UndeployedServices).find(serviceName => {
|
||||
const Service = UndeployedServices[serviceName];
|
||||
return Service.prototype.dependencies.every(depName => {
|
||||
return env.services[depName];
|
||||
});
|
||||
});
|
||||
if (serviceName) {
|
||||
const Service = UndeployedServices[serviceName];
|
||||
const service = new Service(env);
|
||||
env.services[serviceName] = service;
|
||||
delete UndeployedServices[serviceName];
|
||||
service.start();
|
||||
} else {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
serviceRegistry.onAdd((serviceName, Service) => {
|
||||
if (serviceName in env.services || serviceName in UndeployedServices) {
|
||||
throw new Error(`Service ${serviceName} is already loaded.`);
|
||||
}
|
||||
UndeployedServices[serviceName] = Service;
|
||||
_deployServices();
|
||||
});
|
||||
_deployServices();
|
||||
}
|
||||
});
|
||||
|
||||
export default AbstractService;
|
||||
@@ -1,85 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
/**
|
||||
* This module defines an abstraction for services that write into Storage
|
||||
* objects (e.g. localStorage or sessionStorage).
|
||||
*/
|
||||
|
||||
import AbstractService from "@web/legacy/js/core/abstract_service";
|
||||
|
||||
var AbstractStorageService = AbstractService.extend({
|
||||
// the 'storage' attribute must be set by actual StorageServices extending
|
||||
// this abstraction
|
||||
storage: null,
|
||||
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
destroy: function () {
|
||||
// storage can be permanent or transient, destroy transient ones
|
||||
if ((this.storage || {}).destroy) {
|
||||
this.storage.destroy();
|
||||
}
|
||||
this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Public
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Removes all data from the storage
|
||||
*/
|
||||
clear: function() {
|
||||
this.storage.clear();
|
||||
},
|
||||
/**
|
||||
* Returns the value associated with a given key in the storage
|
||||
*
|
||||
* @param {string} key
|
||||
* @returns {string}
|
||||
*/
|
||||
getItem: function(key, defaultValue) {
|
||||
var val = this.storage.getItem(key);
|
||||
return val ? JSON.parse(val) : defaultValue;
|
||||
},
|
||||
/**
|
||||
* @param {integer} index
|
||||
* @return {string}
|
||||
*/
|
||||
key: function (index) {
|
||||
return this.storage.key(index);
|
||||
},
|
||||
/**
|
||||
* @return {integer}
|
||||
*/
|
||||
length: function () {
|
||||
return this.storage.length;
|
||||
},
|
||||
/**
|
||||
* Removes the given key from the storage
|
||||
*
|
||||
* @param {string} key
|
||||
*/
|
||||
removeItem: function(key) {
|
||||
this.storage.removeItem(key);
|
||||
},
|
||||
/**
|
||||
* Sets the value of a given key in the storage
|
||||
*
|
||||
* @param {string} key
|
||||
* @param {string} value
|
||||
*/
|
||||
setItem: function(key, value) {
|
||||
this.storage.setItem(key, JSON.stringify(value));
|
||||
},
|
||||
/**
|
||||
* Add an handler on storage event
|
||||
*
|
||||
*/
|
||||
onStorage: function () {
|
||||
this.storage.on.apply(this.storage, ["storage"].concat(Array.prototype.slice.call(arguments)));
|
||||
},
|
||||
});
|
||||
|
||||
export default AbstractStorageService;
|
||||
@@ -7,7 +7,6 @@ import {getCookie} from '@web/legacy/js/core/cookie_utils';
|
||||
import publicWidget from '@web/legacy/js/public/public_widget';
|
||||
import { registry } from '@web/core/registry';
|
||||
|
||||
import AbstractService from "@web/legacy/js/core/abstract_service";
|
||||
import lazyloader from "@web/legacy/js/public/lazyloader";
|
||||
|
||||
import {
|
||||
@@ -361,7 +360,6 @@ owl.Component.env = legacyEnv;
|
||||
*/
|
||||
export async function createPublicRoot(RootWidget) {
|
||||
await lazyloader.allScriptsLoaded;
|
||||
AbstractService.prototype.deployServices(legacyEnv);
|
||||
// add a bunch of mapping services that will redirect service calls from the legacy env
|
||||
// to the wowl env
|
||||
serviceRegistry.add("legacy_session", makeLegacySessionService(legacyEnv, session));
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import AbstractService from "@web/legacy/js/core/abstract_service";
|
||||
import core from "@web/legacy/js/services/core";
|
||||
import session from "web.session";
|
||||
|
||||
var AjaxService = AbstractService.extend({
|
||||
rpc: function (route, args, options, target) {
|
||||
var rpcPromise;
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
rpcPromise = session.rpc(route, args, options);
|
||||
rpcPromise.then(function (result) {
|
||||
if (!target.isDestroyed()) {
|
||||
resolve(result);
|
||||
}
|
||||
}).guardedCatch(function (reason) {
|
||||
if (!target.isDestroyed()) {
|
||||
reject(reason);
|
||||
}
|
||||
});
|
||||
});
|
||||
promise.abort = rpcPromise.abort.bind(rpcPromise);
|
||||
return promise;
|
||||
},
|
||||
});
|
||||
|
||||
core.serviceRegistry.add('ajax', AjaxService);
|
||||
|
||||
export default AjaxService;
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import Bus from "@web/legacy/js/core/bus";
|
||||
import Class from "@web/legacy/js/core/class";
|
||||
import Registry from "@web/legacy/js/core/registry";
|
||||
import translation from "@web/legacy/js/core/translation";
|
||||
|
||||
/**
|
||||
@@ -25,7 +24,6 @@ export var bus = new Bus();
|
||||
|
||||
export const _t = translation._t;
|
||||
export const _lt = translation._lt;
|
||||
export const serviceRegistry = new Registry();
|
||||
export const csrf_token = odoo.csrf_token;
|
||||
|
||||
export default {
|
||||
@@ -34,9 +32,6 @@ export default {
|
||||
bus: bus,
|
||||
_t: _t,
|
||||
_lt: _lt,
|
||||
|
||||
// registries
|
||||
serviceRegistry: serviceRegistry,
|
||||
/**
|
||||
* @type {String}
|
||||
*/
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
/**
|
||||
* This module defines a service to access the localStorage object.
|
||||
*/
|
||||
|
||||
import AbstractStorageService from "@web/legacy/js/core/abstract_storage_service";
|
||||
import core from "@web/legacy/js/services/core";
|
||||
import localStorage from "@web/legacy/js/core/local_storage";
|
||||
|
||||
var LocalStorageService = AbstractStorageService.extend({
|
||||
storage: localStorage,
|
||||
});
|
||||
|
||||
core.serviceRegistry.add('local_storage', LocalStorageService);
|
||||
|
||||
export default LocalStorageService;
|
||||
@@ -1,17 +0,0 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
/**
|
||||
* This module defines a service to access the sessionStorage object.
|
||||
*/
|
||||
|
||||
import AbstractStorageService from "@web/legacy/js/core/abstract_storage_service";
|
||||
import core from "@web/legacy/js/services/core";
|
||||
import sessionStorage from "@web/legacy/js/core/session_storage";
|
||||
|
||||
var SessionStorageService = AbstractStorageService.extend({
|
||||
storage: sessionStorage,
|
||||
});
|
||||
|
||||
core.serviceRegistry.add('session_storage', SessionStorageService);
|
||||
|
||||
export default SessionStorageService;
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
makeLegacyDropdownService,
|
||||
} from "./utils";
|
||||
import { makeLegacyActionManagerService } from "./backend_utils";
|
||||
import AbstractService from "@web/legacy/js/core/abstract_service";
|
||||
import legacyEnv from "@web/legacy/js/env";
|
||||
import session from "web.session";
|
||||
import { templates } from "@web/core/assets";
|
||||
@@ -25,7 +24,6 @@ export const legacySetupProm = new Promise((resolve) => {
|
||||
// build the legacy env and set it on Component (this was done in main.js,
|
||||
// with the starting of the webclient)
|
||||
(async () => {
|
||||
AbstractService.prototype.deployServices(legacyEnv);
|
||||
Component.env = legacyEnv;
|
||||
const legacyActionManagerService = makeLegacyActionManagerService(legacyEnv);
|
||||
const serviceRegistry = registry.category("services");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { browser } from "../core/browser/browser";
|
||||
import AbstractStorageService from "@web/legacy/js/core/abstract_storage_service";
|
||||
import {
|
||||
ConnectionAbortedError,
|
||||
RPCError,
|
||||
@@ -169,14 +168,7 @@ export function mapLegacyEnvToWowlEnv(legacyEnv, wowlEnv) {
|
||||
prom.abort = rejection;
|
||||
return prom;
|
||||
};
|
||||
// Storages
|
||||
function mapStorage(storage) {
|
||||
const StorageService = AbstractStorageService.extend({ storage });
|
||||
return new StorageService();
|
||||
}
|
||||
|
||||
legacyEnv.services.local_storage = mapStorage(browser.localStorage);
|
||||
legacyEnv.services.session_storage = mapStorage(browser.sessionStorage);
|
||||
legacyEnv.services.dialog = wowlEnv.services.dialog;
|
||||
// map WebClientReady
|
||||
wowlEnv.bus.addEventListener("WEB_CLIENT_READY", () => {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import AjaxService from "@web/legacy/js/services/ajax_service";
|
||||
import Dialog from "@web/legacy/js/core/dialog";
|
||||
import Widget from "@web/legacy/js/core/widget";
|
||||
import session from "web.session";
|
||||
import { patchWithCleanup } from "@web/../tests/helpers/utils";
|
||||
import testUtils from "@web/../tests/legacy/helpers/test_utils";
|
||||
import { renderToString } from "@web/core/utils/render";
|
||||
import env from "@web/legacy/js/common_env";
|
||||
|
||||
QUnit.module('core', {}, function () {
|
||||
|
||||
@@ -412,10 +412,9 @@ QUnit.module('core', {}, function () {
|
||||
return def;
|
||||
},
|
||||
});
|
||||
var ajaxService = new AjaxService();
|
||||
testUtils.mock.intercept(parent, 'call_service', function ({ data }) {
|
||||
if (data.service === "ajax" && data.method === "rpc") {
|
||||
data.callback(ajaxService.rpc(...data.args));
|
||||
data.callback(env.services.ajax.rpc(...data.args));
|
||||
}
|
||||
});
|
||||
var widget = new Widget(parent);
|
||||
|
||||
@@ -200,8 +200,6 @@ Featuring
|
||||
'web/static/src/legacy/js/libs/pdfjs.js',
|
||||
'web/static/src/legacy/js/libs/zoomodoo.js',
|
||||
'web/static/src/legacy/js/libs/jSignatureCustom.js',
|
||||
'web/static/src/legacy/js/core/abstract_service.js',
|
||||
'web/static/src/legacy/js/core/abstract_storage_service.js',
|
||||
'web/static/src/legacy/js/core/ajax.js',
|
||||
'web/static/src/legacy/js/core/bus.js',
|
||||
'web/static/src/legacy/js/core/class.js',
|
||||
@@ -222,11 +220,8 @@ Featuring
|
||||
'web/static/src/legacy/js/core/translation.js',
|
||||
'web/static/src/legacy/js/core/utils.js',
|
||||
'web/static/src/legacy/js/core/widget.js',
|
||||
'web/static/src/legacy/js/services/ajax_service.js',
|
||||
'web/static/src/legacy/js/services/config.js',
|
||||
'web/static/src/legacy/js/services/core.js',
|
||||
'web/static/src/legacy/js/services/local_storage_service.js',
|
||||
'web/static/src/legacy/js/services/session_storage_service.js',
|
||||
'web/static/src/legacy/js/common_env.js',
|
||||
'web/static/src/legacy/js/widgets/name_and_signature.js',
|
||||
'web/static/src/legacy/xml/name_and_signature.xml',
|
||||
|
||||
Reference in New Issue
Block a user