From 21765c4f7e423957bf08900536b04d6afe8eccf5 Mon Sep 17 00:00:00 2001 From: Taras Shabaranskyi Date: Wed, 15 Nov 2023 12:33:26 +0200 Subject: [PATCH] [MIG] web_refresher: Migration to 17.0 --- web_refresher/README.rst | 41 ++++--- web_refresher/__manifest__.py | 6 +- web_refresher/i18n/de.po | 32 ++++++ web_refresher/i18n/uk_UA.po | 38 +++++++ web_refresher/pyproject.toml | 3 + web_refresher/readme/CONTRIBUTORS.md | 9 ++ web_refresher/readme/CONTRIBUTORS.rst | 11 -- web_refresher/readme/DESCRIPTION.md | 4 + web_refresher/readme/DESCRIPTION.rst | 3 - web_refresher/static/description/index.html | 12 +- .../static/src/js/control_panel.esm.js | 30 +++++ web_refresher/static/src/js/pager.esm.js | 9 -- web_refresher/static/src/js/refresher.esm.js | 105 +++++++++++++++++- web_refresher/static/src/scss/refresher.scss | 24 +++- .../src/xml/{pager.xml => control_panel.xml} | 12 +- web_refresher/static/src/xml/refresher.xml | 26 +++-- 16 files changed, 289 insertions(+), 76 deletions(-) create mode 100644 web_refresher/i18n/de.po create mode 100644 web_refresher/i18n/uk_UA.po create mode 100644 web_refresher/pyproject.toml create mode 100644 web_refresher/readme/CONTRIBUTORS.md delete mode 100644 web_refresher/readme/CONTRIBUTORS.rst create mode 100644 web_refresher/readme/DESCRIPTION.md delete mode 100644 web_refresher/readme/DESCRIPTION.rst create mode 100644 web_refresher/static/src/js/control_panel.esm.js delete mode 100644 web_refresher/static/src/js/pager.esm.js rename web_refresher/static/src/xml/{pager.xml => control_panel.xml} (50%) diff --git a/web_refresher/README.rst b/web_refresher/README.rst index 0da754bdc..7f71a9747 100644 --- a/web_refresher/README.rst +++ b/web_refresher/README.rst @@ -17,20 +17,23 @@ Web Refresher :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github - :target: https://github.com/OCA/web/tree/16.0/web_refresher + :target: https://github.com/OCA/web/tree/17.0/web_refresher :alt: OCA/web .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_refresher + :target: https://translation.odoo-community.org/projects/web-17-0/web-17-0-web_refresher :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=16.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=17.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| -Adds a button next to the pager (in trees/kanban views) to refresh the displayed list. +Adds a button next to the pager (in trees/kanban views) to refresh the +displayed list. -.. image:: https://raw.githubusercontent.com/OCA/web/16.0/web_refresher/static/description/refresh.png +|image| + +.. |image| image:: https://raw.githubusercontent.com/OCA/web/17.0/web_refresher/static/description/refresh.png **Table of contents** @@ -43,7 +46,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -51,28 +54,30 @@ Credits ======= Authors -~~~~~~~ +------- * Compassion Switzerland * Tecnativa Contributors -~~~~~~~~~~~~ +------------ -* Samuel Fringeli -* `Tecnativa `__: +- Samuel Fringeli +- `Tecnativa `__: - * João Marques - * Alexandre D. Díaz - * Carlos Roca + - João Marques + - Alexandre D. Díaz + - Carlos Roca -* Thanakrit Pintana -* `Factorlibre `__: +- Thanakrit Pintana +- `Factorlibre `__: - * Hugo Santos + - Hugo Santos + +- Taras Shabaranskyi Maintainers -~~~~~~~~~~~ +----------- This module is maintained by the OCA. @@ -84,6 +89,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/web `_ project on GitHub. +This module is part of the `OCA/web `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_refresher/__manifest__.py b/web_refresher/__manifest__.py index 165320379..14f24f30b 100644 --- a/web_refresher/__manifest__.py +++ b/web_refresher/__manifest__.py @@ -1,6 +1,6 @@ { "name": "Web Refresher", - "version": "16.0.2.0.0", + "version": "17.0.1.0.0", "author": "Compassion Switzerland, Tecnativa, Odoo Community Association (OCA)", "license": "AGPL-3", "website": "https://github.com/OCA/web", @@ -11,9 +11,9 @@ "web.assets_backend": [ "web_refresher/static/src/scss/refresher.scss", "web_refresher/static/src/js/refresher.esm.js", - "web_refresher/static/src/js/pager.esm.js", + "web_refresher/static/src/js/control_panel.esm.js", "web_refresher/static/src/xml/refresher.xml", - "web_refresher/static/src/xml/pager.xml", + "web_refresher/static/src/xml/control_panel.xml", ], }, } diff --git a/web_refresher/i18n/de.po b/web_refresher/i18n/de.po new file mode 100644 index 000000000..39740b816 --- /dev/null +++ b/web_refresher/i18n/de.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_refresher +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2022-12-09 14:45+0000\n" +"Last-Translator: Nils Coenen | NICO SOLUTIONS - ENGINEERING & IT \n" +"Language-Team: none\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.14.1\n" + +#. module: web_refresher +#. openerp-web +#: code:addons/web_refresher/static/src/xml/refresher.xml:0 +#, python-format +msgid "Pager" +msgstr "" + +#. module: web_refresher +#. openerp-web +#: code:addons/web_refresher/static/src/xml/refresher.xml:0 +#, python-format +msgid "Refresh" +msgstr "Aktualisieren" diff --git a/web_refresher/i18n/uk_UA.po b/web_refresher/i18n/uk_UA.po new file mode 100644 index 000000000..4bfdd3734 --- /dev/null +++ b/web_refresher/i18n/uk_UA.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_refresher +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0-20231113\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-11-15 08:17+0000\n" +"PO-Revision-Date: 2023-11-15 08:17+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_refresher +#. odoo-javascript +#: code:addons/web_refresher/static/src/xml/refresher.xml:0 +#: code:addons/web_refresher/static/src/xml/refresher.xml:0 +#, python-format +msgid "Refresh" +msgstr "Оновити" + +#. module: web_refresher +#. odoo-javascript +#: code:addons/web_refresher/static/src/js/refresher.esm.js:0 +#, python-format +msgid "Refreshed" +msgstr "Оновлено" + +#. module: web_refresher +#. odoo-javascript +#: code:addons/web_refresher/static/src/xml/refresher.xml:0 +#, python-format +msgid "Refresher" +msgstr "Оновлювач" diff --git a/web_refresher/pyproject.toml b/web_refresher/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/web_refresher/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_refresher/readme/CONTRIBUTORS.md b/web_refresher/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..c95363164 --- /dev/null +++ b/web_refresher/readme/CONTRIBUTORS.md @@ -0,0 +1,9 @@ +- Samuel Fringeli +- [Tecnativa](https://www.tecnativa.com): + - João Marques + - Alexandre D. Díaz + - Carlos Roca +- Thanakrit Pintana +- [Factorlibre](https://www.factorlibre.com): + - Hugo Santos +- Taras Shabaranskyi diff --git a/web_refresher/readme/CONTRIBUTORS.rst b/web_refresher/readme/CONTRIBUTORS.rst deleted file mode 100644 index 5fdce1e7d..000000000 --- a/web_refresher/readme/CONTRIBUTORS.rst +++ /dev/null @@ -1,11 +0,0 @@ -* Samuel Fringeli -* `Tecnativa `__: - - * João Marques - * Alexandre D. Díaz - * Carlos Roca - -* Thanakrit Pintana -* `Factorlibre `__: - - * Hugo Santos diff --git a/web_refresher/readme/DESCRIPTION.md b/web_refresher/readme/DESCRIPTION.md new file mode 100644 index 000000000..5def2b53b --- /dev/null +++ b/web_refresher/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +Adds a button next to the pager (in trees/kanban views) to refresh the +displayed list. + +![image](./static/description/refresh.png) diff --git a/web_refresher/readme/DESCRIPTION.rst b/web_refresher/readme/DESCRIPTION.rst deleted file mode 100644 index b8b82f543..000000000 --- a/web_refresher/readme/DESCRIPTION.rst +++ /dev/null @@ -1,3 +0,0 @@ -Adds a button next to the pager (in trees/kanban views) to refresh the displayed list. - -.. image:: ./static/description/refresh.png diff --git a/web_refresher/static/description/index.html b/web_refresher/static/description/index.html index 4e48a5e93..6164474f8 100644 --- a/web_refresher/static/description/index.html +++ b/web_refresher/static/description/index.html @@ -369,9 +369,10 @@ ul.auto-toc { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:e460bec11bb6df47946d267a2e46008defe2172b626f0f7c2474478d9e9096df !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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.

-https://raw.githubusercontent.com/OCA/web/16.0/web_refresher/static/description/refresh.png +

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.

+

image

Table of contents

    @@ -389,7 +390,7 @@ ul.auto-toc {

    Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed -feedback.

    +feedback.

    Do not contact contributors directly about support or help with technical issues.

@@ -416,6 +417,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
  • Hugo Santos
  • +
  • Taras Shabaranskyi
  • @@ -425,7 +427,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

    OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

    -

    This module is part of the OCA/web project on GitHub.

    +

    This module is part of the OCA/web project on GitHub.

    You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

    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 000000000..b11aa7b86 --- /dev/null +++ b/web_refresher/static/src/js/control_panel.esm.js @@ -0,0 +1,30 @@ +/** @odoo-module **/ +/* Copyright 2022 Tecnativa - Alexandre D. Díaz + * Copyright 2022 Tecnativa - Carlos Roca + * Copyright 2023 Taras Shabaranskyi + * 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"; +import {patch} from "@web/core/utils/patch"; + +patch(ControlPanel, { + components: {...ControlPanel.components, Refresher}, +}); + +patch(ControlPanel.prototype, { + /** + * @returns {{searchModel: Object<*>, pagerProps: Object<*>}|null} + */ + get refresherProps() { + const {config, searchModel} = this.env; + const forbiddenSubType = ["base_settings"]; + if (forbiddenSubType.includes(config.viewSubType)) { + return null; + } + return { + searchModel: searchModel, + pagerProps: this.pagerProps, + }; + }, +}); diff --git a/web_refresher/static/src/js/pager.esm.js b/web_refresher/static/src/js/pager.esm.js deleted file mode 100644 index 06f9ec77c..000000000 --- a/web_refresher/static/src/js/pager.esm.js +++ /dev/null @@ -1,9 +0,0 @@ -/** @odoo-module **/ -/* Copyright 2022 Tecnativa - Carlos Roca - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ -import {Pager} from "@web/core/pager/pager"; -import {Refresher} from "./refresher.esm"; - -Pager.components = Object.assign({}, Pager.components, { - Refresher, -}); diff --git a/web_refresher/static/src/js/refresher.esm.js b/web_refresher/static/src/js/refresher.esm.js index ce7582d43..60c570ad9 100644 --- a/web_refresher/static/src/js/refresher.esm.js +++ b/web_refresher/static/src/js/refresher.esm.js @@ -1,16 +1,109 @@ /** @odoo-module **/ /* Copyright 2022 Tecnativa - Alexandre D. Díaz * Copyright 2022 Tecnativa - Carlos Roca + * Copyright 2023 Taras Shabaranskyi * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ -const {Component} = owl; +import {Component} from "@odoo/owl"; +import {useDebounced} from "@web/core/utils/timing"; + +export function useRefreshAnimation(timeout) { + const refreshClass = "o_content__refresh"; + let timeoutId = null; + + /** + * @returns {DOMTokenList|null} + */ + function contentClassList() { + const content = document.querySelector(".o_content"); + return content ? content.classList : null; + } + + function clearAnimationTimeout() { + if (timeoutId) { + clearTimeout(timeoutId); + } + timeoutId = null; + } + + function animate() { + clearAnimationTimeout(); + contentClassList().add(refreshClass); + timeoutId = setTimeout(() => { + contentClassList().remove(refreshClass); + clearAnimationTimeout(); + }, timeout); + } + + return animate; +} export class Refresher extends Component { - _doRefresh() { - // Note: here we use the pager props, see xml - const {limit, offset} = this.props; - this.props.onUpdate({offset, limit}); + setup() { + super.setup(); + this.refreshAnimation = useRefreshAnimation(1000); + this.onClickRefresh = useDebounced(this.onClickRefresh, 200); + } + + /** + * @returns {Boolean} + */ + get displayButton() { + const {searchModel, pagerProps} = this.props; + const hasSearchModel = searchModel && searchModel.search; + return Boolean(hasSearchModel || (pagerProps && pagerProps.onUpdate)); + } + + /** + * @returns {Boolean} + * @private + */ + _searchModelRefresh() { + const {searchModel} = this.props; + if (searchModel && typeof searchModel.search === "function") { + searchModel.search(); + return true; + } + return false; + } + + /** + * @returns {Promise} + * @private + */ + async _pagerRefresh() { + const pagerProps = this.props.pagerProps; + if (pagerProps && typeof pagerProps.onUpdate === "function") { + const {limit, offset} = pagerProps; + await pagerProps.onUpdate({offset, limit}); + return true; + } + return false; + } + + /** + * @returns {Promise} + */ + async refresh() { + let updated = this._searchModelRefresh(); + if (!updated) { + updated = await this._pagerRefresh(); + } + return updated; + } + + async onClickRefresh() { + const updated = await this.refresh(); + if (updated) { + this.refreshAnimation(); + } } } -Refresher.template = "web_refresher.Button"; +Object.assign(Refresher, { + template: "web_refresher.Button", + props: { + searchModel: {type: Object, optional: true}, + pagerProps: {type: Object, optional: true}, + }, +}); diff --git a/web_refresher/static/src/scss/refresher.scss b/web_refresher/static/src/scss/refresher.scss index 464069d8a..ef59aa819 100644 --- a/web_refresher/static/src/scss/refresher.scss +++ b/web_refresher/static/src/scss/refresher.scss @@ -1,7 +1,23 @@ .oe_cp_refresher { - margin: auto 0 auto auto; - padding-left: 5px; - text-align: right; + margin: auto 0 auto 0; user-select: none; - flex-grow: 1; +} + +.o_content { + &__refresh { + animation: web_refresh 0.6s ease; + } +} + +@keyframes web_refresh { + 0% { + opacity: 1; + } + 50% { + transform: translateY(10px); + opacity: 0.6; + } + 100% { + opacity: 1; + } } diff --git a/web_refresher/static/src/xml/pager.xml b/web_refresher/static/src/xml/control_panel.xml similarity index 50% rename from web_refresher/static/src/xml/pager.xml rename to web_refresher/static/src/xml/control_panel.xml index 67ed8c952..0f0e8b2f5 100644 --- a/web_refresher/static/src/xml/pager.xml +++ b/web_refresher/static/src/xml/control_panel.xml @@ -1,16 +1,16 @@ -