diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d75b1d8a..918fbd2c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,6 @@ exclude: | (?x) # NOT INSTALLABLE ADDONS - ^cmis_web_bus/| ^cmis_web_proxy/| ^cmis_web_proxy_alf/| ^cmis_web_report_write/| diff --git a/cmis_web_bus/README.rst b/cmis_web_bus/README.rst new file mode 100644 index 00000000..f5649d9e --- /dev/null +++ b/cmis_web_bus/README.rst @@ -0,0 +1,34 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============ +Cmis Web Bus +============ + +This module provide an update of the cmis widget after adding a new file in the folder via the bus. + +Documentation: `alfodoo.org `_ + +Credits +======= + +Contributors +------------ + +* Laurent Mignon +* Maxime Franco + +Most of the code of the DocumentViewer widget is copied from `Odoo +`_ + + +Maintainer +---------- + +.. image:: https://www.acsone.eu/logo.png + :alt: ACSONE SA/NV + :target: http://www.acsone.eu + +This module is maintained by ACSONE SA/NV. diff --git a/cmis_web_bus/__manifest__.py b/cmis_web_bus/__manifest__.py index f3d89288..c753f6e7 100644 --- a/cmis_web_bus/__manifest__.py +++ b/cmis_web_bus/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Cmis Web Bus", - "description": """ + "summary": """ Instant Messaging Bus to send notification to the CMIS components in live""", "version": "16.0.1.0.0", @@ -11,7 +11,10 @@ "author": "ACSONE SA/NV", "website": "https://alfodoo.org", "depends": ["cmis_web", "bus"], - "data": ["views/cmis_web_bus.xml"], - "demo": [], - "installable": False, + "installable": True, + "assets": { + "web.assets_backend": [ + "cmis_web_bus/static/src/**/*", + ], + }, } diff --git a/cmis_web_bus/models/bus_bus.py b/cmis_web_bus/models/bus_bus.py index 82e49dcb..3969e876 100644 --- a/cmis_web_bus/models/bus_bus.py +++ b/cmis_web_bus/models/bus_bus.py @@ -20,4 +20,4 @@ def _notify_cmis_node(self, cmis_objectid, cmis_backend, action): "action": action, "user_id": self.env.user.id, } - self.sendone("notify_cmis_node", bus_message) + self._sendone(self.env.user.partner_id, "cmis_node_notification", bus_message) diff --git a/cmis_web_bus/static/src/cmis_folder/cmis_folder.js b/cmis_web_bus/static/src/cmis_folder/cmis_folder.js new file mode 100644 index 00000000..8f079fe7 --- /dev/null +++ b/cmis_web_bus/static/src/cmis_folder/cmis_folder.js @@ -0,0 +1,27 @@ +/** @odoo-module **/ + +/* --------------------------------------------------------- ++ * Odoo cmis_web_bus ++ * Authors Laurent Mignon 2016, Maxime Franco 2023 Acsone SA/NV ++ * License in __openerp__.py at root level of the module ++ *--------------------------------------------------------- ++*/ + +import {CmisFolderField} from "@cmis_web/cmis_folder/cmis_folder"; +import {patch} from "web.utils"; +import {useBus, useService} from "@web/core/utils/hooks"; + +patch(CmisFolderField.prototype, "cmis_folder_notification", { + setup() { + this._super.apply(this, arguments); + this.cmis_service = useService("deliveryCmisService"); + useBus(this.cmis_service, "cmis_bus", (event) => { + this._handleNotify(event); + }); + }, + _handleNotify(event) { + if (event.detail.action === "update") { + this.queryCmisData(); + } + }, +}); diff --git a/cmis_web_bus/static/src/cmis_folder/delivery_cmis_service.js b/cmis_web_bus/static/src/cmis_folder/delivery_cmis_service.js new file mode 100644 index 00000000..c63677fb --- /dev/null +++ b/cmis_web_bus/static/src/cmis_folder/delivery_cmis_service.js @@ -0,0 +1,27 @@ +/** @odoo-module **/ + +/* --------------------------------------------------------- ++ * Odoo cmis_web_bus ++ * Authors Laurent Mignon 2016, Maxime Franco 2023 Acsone SA/NV ++ * License in __openerp__.py at root level of the module ++ *--------------------------------------------------------- ++*/ + +import {EventBus} from "@odoo/owl"; +import {registry} from "@web/core/registry"; + +export const deliveryCmisService = { + dependencies: ["bus_service", "notification"], + start(_, {bus_service, notification}) { + const bus = new EventBus(); + bus_service.addEventListener("notification", ({detail: notifications}) => { + for (const {payload, type} of notifications) { + if (type === "cmis_node_notification") { + bus.trigger("cmis_bus", payload); + } + } + }); + return bus; + }, +}; +registry.category("services").add("deliveryCmisService", deliveryCmisService); diff --git a/cmis_web_bus/static/src/js/form_widgets.js b/cmis_web_bus/static/src/js/form_widgets.js deleted file mode 100644 index fd4c108a..00000000 --- a/cmis_web_bus/static/src/js/form_widgets.js +++ /dev/null @@ -1,50 +0,0 @@ -/* --------------------------------------------------------- - + * Odoo cmis_web - + * Author Laurent Mignon 2016 Acsone SA/NV - + * License in __manifest__.py at root level of the module - + *--------------------------------------------------------- - +*/ - -odoo.define("cmis_web_bus.form_widgets", function (require) { - "use strict"; - - require("bus.BusService"); - var form_widgets = require("cmis_web.form_widgets"); - - form_widgets.FieldCmisFolder.include({ - init: function () { - this._super.apply(this, arguments); - this._channel_notify_cmis_node = "notify_cmis_node"; - }, - - start: function () { - this.call("bus_service", "onNotification", this, this.bus_notification); - return this._super(); - }, - - bus_notification: function (notifications) { - var self = this; - _.each(notifications, function (notification) { - var channel = notification[0]; - var message = notification[1]; - if (channel === self._channel_notify_cmis_node) { - self.on_notify_cmis_node(message); - } - }); - }, - - on_notify_cmis_node: function (message) { - var cmis_objectid = message.cmis_objectid; - if (this.root_folder_id !== cmis_objectid) { - return; - } - if (message.action === "update") { - if (this.datatable) { - // Avoid multiple refresh in cass of multiple notification - // of update of the same node - _.debounce(this.datatable.ajax.reload, 300, true)(); - } - } - }, - }); -}); diff --git a/cmis_web_bus/views/cmis_web_bus.xml b/cmis_web_bus/views/cmis_web_bus.xml deleted file mode 100644 index a3ea9ba2..00000000 --- a/cmis_web_bus/views/cmis_web_bus.xml +++ /dev/null @@ -1,15 +0,0 @@ - - -