From 53ea89a9dcd41fcd7d1ceb2b2a1230f1a7c030d1 Mon Sep 17 00:00:00 2001 From: Christopher Rogos Date: Tue, 5 Sep 2023 13:09:03 +0000 Subject: [PATCH] [MIG] web_group_expand: Migration to 16.0 --- web_group_expand/__manifest__.py | 8 +- web_group_expand/readme/CONTRIBUTORS.rst | 1 + .../static/src/js/list_controller.esm.js | 59 ++++++++++++ .../static/src/js/web_group_expand.esm.js | 91 ------------------- .../static/src/xml/expand_buttons.xml | 19 ---- .../static/src/xml/list_controller.xml | 23 +++++ 6 files changed, 86 insertions(+), 115 deletions(-) create mode 100644 web_group_expand/static/src/js/list_controller.esm.js delete mode 100644 web_group_expand/static/src/js/web_group_expand.esm.js delete mode 100644 web_group_expand/static/src/xml/expand_buttons.xml create mode 100644 web_group_expand/static/src/xml/list_controller.xml diff --git a/web_group_expand/__manifest__.py b/web_group_expand/__manifest__.py index 41f808503f06..9931860e912c 100644 --- a/web_group_expand/__manifest__.py +++ b/web_group_expand/__manifest__.py @@ -1,7 +1,7 @@ { "name": "Group Expand Buttons", "category": "Web", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "license": "AGPL-3", "author": "OpenERP SA, " "AvanzOSC, " @@ -13,10 +13,8 @@ "depends": ["web"], "assets": { "web.assets_backend": [ - "/web_group_expand/static/src/js/web_group_expand.esm.js", - ], - "web.assets_qweb": [ - "/web_group_expand/static/src/xml/expand_buttons.xml", + "/web_group_expand/static/src/xml/list_controller.xml", + "/web_group_expand/static/src/js/list_controller.esm.js", ], }, } diff --git a/web_group_expand/readme/CONTRIBUTORS.rst b/web_group_expand/readme/CONTRIBUTORS.rst index 3675a6e329d1..ef1985a3dac4 100644 --- a/web_group_expand/readme/CONTRIBUTORS.rst +++ b/web_group_expand/readme/CONTRIBUTORS.rst @@ -5,3 +5,4 @@ * Jan Verbeek * Manuel Calero * Alvaro Estebanez (brain-tec AG) +* Mayank Patel diff --git a/web_group_expand/static/src/js/list_controller.esm.js b/web_group_expand/static/src/js/list_controller.esm.js new file mode 100644 index 000000000000..0ef08270b281 --- /dev/null +++ b/web_group_expand/static/src/js/list_controller.esm.js @@ -0,0 +1,59 @@ +/** @odoo-module */ + +import {patch} from "@web/core/utils/patch"; +import {ListController} from "@web/views/list/list_controller"; + +patch(ListController.prototype, "web_group_expand.ListController", { + async expandAllGroups() { + // We expand layer by layer. So first we need to find the highest + // layer that's not already fully expanded. + let layer = this.model.root.groups; + while (layer.length) { + const closed = layer.filter(function (group) { + return group.isFolded; + }); + if (closed.length) { + // This layer is not completely expanded, expand it + await layer.forEach((group) => { + group.isFolded = false; + }); + break; + } + // This layer is completely expanded, move to the next + layer = _.flatten( + layer.map(function (group) { + return group.list.groups || []; + }), + true + ); + } + await this.model.root.load(); + this.model.notify(); + }, + + async collapseAllGroups() { + // We collapse layer by layer. So first we need to find the deepest + // layer that's not already fully collapsed. + let layer = this.model.root.groups; + while (layer.length) { + const next = _.flatten( + layer.map(function (group) { + return group.list.groups || []; + }), + true + ).filter(function (group) { + return !group.isFolded; + }); + if (!next.length) { + // Next layer is fully collapsed, so collapse this one + await layer.forEach((group) => { + group.isFolded = true; + }); + break; + } + layer = next; + } + await this.model.root.load(); + this.model.notify(); + }, +}); diff --git a/web_group_expand/static/src/js/web_group_expand.esm.js b/web_group_expand/static/src/js/web_group_expand.esm.js deleted file mode 100644 index ab85b503e60d..000000000000 --- a/web_group_expand/static/src/js/web_group_expand.esm.js +++ /dev/null @@ -1,91 +0,0 @@ -/** @odoo-module */ - -import ListController from "web.ListController"; -import ListRenderer from "web.ListRenderer"; -import core from "web.core"; - -const qweb = core.qweb; - -ListController.include({ - start: function () { - this.$expandGroupButtons = $(qweb.render("web_group_expand.Buttons")); - this.$expandGroupButtons - .find("#oe_group_by_expand") - .on("click", this.expandAllGroups.bind(this)); - this.$expandGroupButtons - .find("#oe_group_by_collapse") - .on("click", this.collapseAllGroups.bind(this)); - return this._super.apply(this, arguments); - }, - - renderButtons: function () { - this._super.apply(this, arguments); - this.$expandGroupButtons.toggleClass("o_hidden", !this.renderer.isGrouped); - this.$buttons.append(this.$expandGroupButtons); - }, - - expandAllGroups: function () { - // We expand layer by layer. So first we need to find the highest - // layer that's not already fully expanded. - let layer = this.renderer.state.data; - while (layer.length) { - const closed = layer.filter(function (group) { - return !group.isOpen; - }); - if (closed.length) { - // This layer is not completely expanded, expand it - this._toggleGroups(closed); - break; - } - // This layer is completely expanded, move to the next - layer = _.flatten( - layer.map(function (group) { - return group.data; - }), - true - ); - } - }, - - collapseAllGroups: function () { - // We collapse layer by layer. So first we need to find the deepest - // layer that's not already fully collapsed. - let layer = this.renderer.state.data.filter(function (group) { - return group.isOpen; - }); - while (layer.length) { - const next = _.flatten( - layer.map(function (group) { - return group.data; - }), - true - ).filter(function (group) { - return group.isOpen; - }); - if (!next.length) { - // Next layer is fully collapsed, so collapse this one - this._toggleGroups(layer); - break; - } - layer = next; - } - }, - - _toggleGroups: function (groups) { - const self = this; - const defs = groups.map(function (group) { - return self.model.toggleGroup(group.id); - }); - $.when(...defs).then( - this.update.bind(this, {}, {keepSelection: true, reload: false}) - ); - }, -}); - -ListRenderer.include({ - updateState: function () { - const res = this._super.apply(this, arguments); - $("nav.oe_group_by_expand_buttons").toggleClass("o_hidden", !this.isGrouped); - return res; - }, -}); diff --git a/web_group_expand/static/src/xml/expand_buttons.xml b/web_group_expand/static/src/xml/expand_buttons.xml deleted file mode 100644 index 68b8e2ba01a9..000000000000 --- a/web_group_expand/static/src/xml/expand_buttons.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - diff --git a/web_group_expand/static/src/xml/list_controller.xml b/web_group_expand/static/src/xml/list_controller.xml new file mode 100644 index 000000000000..743b8aa35c51 --- /dev/null +++ b/web_group_expand/static/src/xml/list_controller.xml @@ -0,0 +1,23 @@ + + + + + +