From c044cabaf3f7c0ee36fae2be3d63d705b04c4432 Mon Sep 17 00:00:00 2001 From: Carlos Roca Date: Fri, 9 Feb 2024 11:49:48 +0100 Subject: [PATCH] [IMP] web_refresher: Provide the ability to reload information from a report view --- web_refresher/README.rst | 2 +- web_refresher/__manifest__.py | 2 + web_refresher/static/description/index.html | 2 +- .../static/src/js/control_panel.esm.js | 9 +++++ web_refresher/static/src/js/refresher.esm.js | 24 +++++++++++- web_refresher/static/src/scss/refresher.scss | 4 ++ .../static/src/xml/control_panel.xml | 39 +++++++++++++++++++ 7 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 web_refresher/static/src/js/control_panel.esm.js create mode 100644 web_refresher/static/src/xml/control_panel.xml diff --git a/web_refresher/README.rst b/web_refresher/README.rst index 0da754bdc7ee..39e1ba396615 100644 --- a/web_refresher/README.rst +++ b/web_refresher/README.rst @@ -7,7 +7,7 @@ Web Refresher !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:e460bec11bb6df47946d267a2e46008defe2172b626f0f7c2474478d9e9096df + !! source digest: sha256:c5a87e1531dfe91e360d9f92c4b110bda762f4e85405a12ae847e6fbcfc55815 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/web_refresher/__manifest__.py b/web_refresher/__manifest__.py index 16532037975f..c58385340456 100644 --- a/web_refresher/__manifest__.py +++ b/web_refresher/__manifest__.py @@ -11,8 +11,10 @@ "web.assets_backend": [ "web_refresher/static/src/scss/refresher.scss", "web_refresher/static/src/js/refresher.esm.js", + "web_refresher/static/src/js/control_panel.esm.js", "web_refresher/static/src/js/pager.esm.js", "web_refresher/static/src/xml/refresher.xml", + "web_refresher/static/src/xml/control_panel.xml", "web_refresher/static/src/xml/pager.xml", ], }, diff --git a/web_refresher/static/description/index.html b/web_refresher/static/description/index.html index 4e48a5e931c8..f221344509c1 100644 --- a/web_refresher/static/description/index.html +++ b/web_refresher/static/description/index.html @@ -367,7 +367,7 @@

Web Refresher

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:e460bec11bb6df47946d267a2e46008defe2172b626f0f7c2474478d9e9096df +!! source digest: sha256:c5a87e1531dfe91e360d9f92c4b110bda762f4e85405a12ae847e6fbcfc55815 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

Adds a button next to the pager (in trees/kanban views) to refresh the displayed list.

diff --git a/web_refresher/static/src/js/control_panel.esm.js b/web_refresher/static/src/js/control_panel.esm.js new file mode 100644 index 000000000000..972d07784125 --- /dev/null +++ b/web_refresher/static/src/js/control_panel.esm.js @@ -0,0 +1,9 @@ +/** @odoo-module **/ +/* Copyright 2024 Tecnativa - Carlos Roca + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ +import {ControlPanel} from "@web/search/control_panel/control_panel"; +import {Refresher} from "./refresher.esm"; + +ControlPanel.components = Object.assign({}, ControlPanel.components, { + Refresher, +}); diff --git a/web_refresher/static/src/js/refresher.esm.js b/web_refresher/static/src/js/refresher.esm.js index ce7582d437ae..a006e0e4ca8b 100644 --- a/web_refresher/static/src/js/refresher.esm.js +++ b/web_refresher/static/src/js/refresher.esm.js @@ -4,12 +4,32 @@ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ const {Component} = owl; +import {useService} from "@web/core/utils/hooks"; export class Refresher extends Component { - _doRefresh() { + setup() { + super.setup(); + this.action = useService("action"); + } + async _doRefresh() { + const viewAction = this.action.currentController.action; + // Allow refresh reports + if (["ir.actions.report", "ir.actions.client"].includes(viewAction.type)) { + const options = {}; + if (this.env.config.breadcrumbs.length > 1) { + const breadcrumb = this.env.config.breadcrumbs.slice(-1); + await this.action.restore(breadcrumb.jsId); + } else { + options.clearBreadcrumbs = true; + } + return this.action.doAction(viewAction, options); + } // Note: here we use the pager props, see xml const {limit, offset} = this.props; - this.props.onUpdate({offset, limit}); + if (!limit && !offset) { + return; + } + return this.props.onUpdate({offset, limit}); } } diff --git a/web_refresher/static/src/scss/refresher.scss b/web_refresher/static/src/scss/refresher.scss index 464069d8a177..edc1102ca69c 100644 --- a/web_refresher/static/src/scss/refresher.scss +++ b/web_refresher/static/src/scss/refresher.scss @@ -5,3 +5,7 @@ user-select: none; flex-grow: 1; } +.o_cp_bottom_right.oe_cp_refresher { + display: flex; + flex-direction: row-reverse; +} diff --git a/web_refresher/static/src/xml/control_panel.xml b/web_refresher/static/src/xml/control_panel.xml new file mode 100644 index 000000000000..81aa4553aaa6 --- /dev/null +++ b/web_refresher/static/src/xml/control_panel.xml @@ -0,0 +1,39 @@ + + +