diff --git a/web_filter_header_button/README.rst b/web_filter_header_button/README.rst new file mode 100644 index 000000000..b2c3bd49a --- /dev/null +++ b/web_filter_header_button/README.rst @@ -0,0 +1,146 @@ +============= +Filter Button +============= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c2b64cc19b28ee8850599360a44f1ba6ad28db0bc8574f041a845a5ca9529af1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :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/18.0/web_filter_header_button + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_filter_header_button + :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=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to add some selected filters as buttons in the header +control panel. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +This developement is aimed to ease the filter access for touch screens +users. + +Configuration +============= + +To show a filter in the header of the views, it should have the a +``context`` attribute with the key ``shown_in_panel``. + +.. code:: xml + + + +This will show the filter in the header with its name. You can customize +the button adding an icon or with a custom name passing an object to +that key: + +.. code:: python + + {'shown_in_panel': {'icon': 'fa-thumbs-up', 'name': 'Ok'}} + +You might be interested in leaving just the icon. In that case, set an +empty string on the ``name`` property: + +.. code:: python + + {'shown_in_panel': {'icon': 'fa-thumbs-up', 'name': ''}} + +You could also want to add a hotkey. In such case add the ``hotkey`` +property: + +.. code:: python + + {'shown_in_panel': {'icon': 'fa-thumbs-up', 'hotkey': 'F'}} + +You can show filter, groups or even favorites. + +Usage +===== + +In a search view with header filter buttons, you'll see a filter icon +(funnel). Use it to unfold the filters. + +There's a demo implementation in ``Apps`` and you can play around +following the *Configure* section. + +Known issues / Roadmap +====================== + +- Group filters by kind +- As we use the ``context`` attribute, the inheritance could be + limiting in some cases. Keep it in mind or use + ``base_view_inheritance_extension`` if you want to use proper context + inheritance. +- Another nice to have would be to be able to hide the filters in the + filter list to be able to show them just in the header, although + there's not a straigh forward way to do it and it could lead to side + effects. + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__ + + - David Vidal + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_filter_header_button/__init__.py b/web_filter_header_button/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/web_filter_header_button/__manifest__.py b/web_filter_header_button/__manifest__.py new file mode 100644 index 000000000..dcf1f8403 --- /dev/null +++ b/web_filter_header_button/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Filter Button", + "version": "18.0.1.0.0", + "summary": "Show selected filters as buttons in the control panel", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Server UX", + "website": "https://github.com/OCA/web", + "depends": ["web"], + "data": [], + "demo": [ + "demo/ir_module_module_view.xml", + ], + "assets": { + "web.assets_backend": ["web_filter_header_button/static/src/**/*"], + }, +} diff --git a/web_filter_header_button/demo/ir_module_module_view.xml b/web_filter_header_button/demo/ir_module_module_view.xml new file mode 100644 index 000000000..1742e196d --- /dev/null +++ b/web_filter_header_button/demo/ir_module_module_view.xml @@ -0,0 +1,24 @@ + + + + ir.module.module + + + + {'shown_in_panel': {'icon': 'fa-toggle-on', 'hotkey': 'i'}} + + + {'shown_in_panel': {'icon': 'fa-toggle-off', 'hotkey': 'u'}} + + + {'group_by':'state', 'shown_in_panel': {'icon': 'fa-th-list', 'hotkey': 's'}} + + + + diff --git a/web_filter_header_button/i18n/web_filter_header_button.pot b/web_filter_header_button/i18n/web_filter_header_button.pot new file mode 100644 index 000000000..a11baf5cd --- /dev/null +++ b/web_filter_header_button/i18n/web_filter_header_button.pot @@ -0,0 +1,13 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \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" diff --git a/web_filter_header_button/pyproject.toml b/web_filter_header_button/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/web_filter_header_button/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_filter_header_button/readme/CONFIGURE.md b/web_filter_header_button/readme/CONFIGURE.md new file mode 100644 index 000000000..8f87f4e5b --- /dev/null +++ b/web_filter_header_button/readme/CONFIGURE.md @@ -0,0 +1,32 @@ +To show a filter in the header of the views, it should have the a `context` attribute with the key `shown_in_panel`. + +```xml + +``` + +This will show the filter in the header with its name. You can customize the button +adding an icon or with a custom name passing an object to that key: + +```python +{'shown_in_panel': {'icon': 'fa-thumbs-up', 'name': 'Ok'}} +``` + +You might be interested in leaving just the icon. In that case, set an empty string on +the `name` property: + +```python +{'shown_in_panel': {'icon': 'fa-thumbs-up', 'name': ''}} +``` + +You could also want to add a hotkey. In such case add the `hotkey` property: + +```python +{'shown_in_panel': {'icon': 'fa-thumbs-up', 'hotkey': 'F'}} +``` + +You can show filter, groups or even favorites. diff --git a/web_filter_header_button/readme/CONTEXT.md b/web_filter_header_button/readme/CONTEXT.md new file mode 100644 index 000000000..2d9eb2fe0 --- /dev/null +++ b/web_filter_header_button/readme/CONTEXT.md @@ -0,0 +1 @@ +This developement is aimed to ease the filter access for touch screens users. diff --git a/web_filter_header_button/readme/CONTRIBUTORS.md b/web_filter_header_button/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..96d0c4c7f --- /dev/null +++ b/web_filter_header_button/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Tecnativa](https://tecnativa.com) + - David Vidal diff --git a/web_filter_header_button/readme/DESCRIPTION.md b/web_filter_header_button/readme/DESCRIPTION.md new file mode 100644 index 000000000..064783469 --- /dev/null +++ b/web_filter_header_button/readme/DESCRIPTION.md @@ -0,0 +1 @@ +This module allows to add some selected filters as buttons in the header control panel. diff --git a/web_filter_header_button/readme/ROADMAP.md b/web_filter_header_button/readme/ROADMAP.md new file mode 100644 index 000000000..b91b7003b --- /dev/null +++ b/web_filter_header_button/readme/ROADMAP.md @@ -0,0 +1,5 @@ +- Group filters by kind +- As we use the `context` attribute, the inheritance could be limiting in some cases. Keep it in mind or use `base_view_inheritance_extension` if you want to use proper context inheritance. +- Another nice to have would be to be able to hide the filters in the filter list to be + able to show them just in the header, although there's not a straigh forward way to + do it and it could lead to side effects. diff --git a/web_filter_header_button/readme/USAGE.md b/web_filter_header_button/readme/USAGE.md new file mode 100644 index 000000000..16c1ab4e8 --- /dev/null +++ b/web_filter_header_button/readme/USAGE.md @@ -0,0 +1,5 @@ +In a search view with header filter buttons, you'll see a filter icon (funnel). Use it +to unfold the filters. + +There's a demo implementation in `Apps` and you can play around following the *Configure* +section. diff --git a/web_filter_header_button/static/description/icon.png b/web_filter_header_button/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/web_filter_header_button/static/description/icon.png differ diff --git a/web_filter_header_button/static/description/index.html b/web_filter_header_button/static/description/index.html new file mode 100644 index 000000000..9c227eaa5 --- /dev/null +++ b/web_filter_header_button/static/description/index.html @@ -0,0 +1,487 @@ + + + + + +Filter Button + + + +
+

Filter Button

+ + +

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

+

This module allows to add some selected filters as buttons in the header +control panel.

+

Table of contents

+ +
+

Use Cases / Context

+

This developement is aimed to ease the filter access for touch screens +users.

+
+
+

Configuration

+

To show a filter in the header of the views, it should have the a +context attribute with the key shown_in_panel.

+
+<filter
+    string="My filter"
+    name="my_filter"
+    domain="[('active', '!=', False)]"
+    context="{'shown_in_panel': True}"
+>
+
+

This will show the filter in the header with its name. You can customize +the button adding an icon or with a custom name passing an object to +that key:

+
+{'shown_in_panel': {'icon': 'fa-thumbs-up', 'name': 'Ok'}}
+
+

You might be interested in leaving just the icon. In that case, set an +empty string on the name property:

+
+{'shown_in_panel': {'icon': 'fa-thumbs-up', 'name': ''}}
+
+

You could also want to add a hotkey. In such case add the hotkey +property:

+
+{'shown_in_panel': {'icon': 'fa-thumbs-up', 'hotkey': 'F'}}
+
+

You can show filter, groups or even favorites.

+
+
+

Usage

+

In a search view with header filter buttons, you’ll see a filter icon +(funnel). Use it to unfold the filters.

+

There’s a demo implementation in Apps and you can play around +following the Configure section.

+
+
+

Known issues / Roadmap

+
    +
  • Group filters by kind
  • +
  • As we use the context attribute, the inheritance could be +limiting in some cases. Keep it in mind or use +base_view_inheritance_extension if you want to use proper context +inheritance.
  • +
  • Another nice to have would be to be able to hide the filters in the +filter list to be able to show them just in the header, although +there’s not a straigh forward way to do it and it could lead to side +effects.
  • +
+
+
+

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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

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

+
+
+
+ + diff --git a/web_filter_header_button/static/src/control_panel/control_panel.xml b/web_filter_header_button/static/src/control_panel/control_panel.xml new file mode 100644 index 000000000..8913d8eb1 --- /dev/null +++ b/web_filter_header_button/static/src/control_panel/control_panel.xml @@ -0,0 +1,35 @@ + + + + + + +
+ +
+
+
+
+ + + + +
+
diff --git a/web_filter_header_button/static/src/control_panel/control_panel_patch.esm.js b/web_filter_header_button/static/src/control_panel/control_panel_patch.esm.js new file mode 100644 index 000000000..f2ece582a --- /dev/null +++ b/web_filter_header_button/static/src/control_panel/control_panel_patch.esm.js @@ -0,0 +1,37 @@ +import {ControlPanel} from "@web/search/control_panel/control_panel"; +import {FilterButton} from "../filter_button/filter_button.esm"; +import {browser} from "@web/core/browser/browser"; +import {patch} from "@web/core/utils/patch"; +import {useState} from "@odoo/owl"; +import {user} from "@web/core/user"; + +patch(ControlPanel, { + components: {...ControlPanel.components, FilterButton}, +}); + +patch(ControlPanel.prototype, { + setup() { + super.setup(...arguments); + this.buttonFiltersVisibilityKey = `visibleHeaderButtons${this.env.config.actionId}+${user.userId}`; + this.state = useState({ + ...this.state, + headerButtonFilters: this.env.searchModel?.headerButtonFilters, + showButtonFilters: + this.env.searchModel?.headerButtonFilters.length > 0 && + Boolean(this.env.config.actionId) && + Boolean( + JSON.parse( + browser.localStorage.getItem(this.buttonFiltersVisibilityKey) + ) + ), + }); + }, + onClickShowshowButtonFilters() { + if (this.state.showButtonFilters) { + browser.localStorage.removeItem(this.buttonFiltersVisibilityKey); + } else { + browser.localStorage.setItem(this.buttonFiltersVisibilityKey, true); + } + this.state.showButtonFilters = !this.state.showButtonFilters; + }, +}); diff --git a/web_filter_header_button/static/src/filter_button/filter_button.esm.js b/web_filter_header_button/static/src/filter_button/filter_button.esm.js new file mode 100644 index 000000000..a62f20fc2 --- /dev/null +++ b/web_filter_header_button/static/src/filter_button/filter_button.esm.js @@ -0,0 +1,44 @@ +import {Component} from "@odoo/owl"; + +export class FilterButton extends Component { + static template = "filter_button.FilterButton"; + static props = { + filters: {type: Object, optional: false}, + }; + setup() { + this.model = this.env.searchModel; + } + /** + * Return custom properties depending on the filter properties + * + * @param {Object} filter + * @returns {Object} + */ + mapFilterType(filter) { + const mapping = { + filter: { + color: "primary", + }, + favorite: { + color: "warning", + }, + groupBy: { + color: "info", + }, + }; + return mapping[filter.type]; + } + /** + * Clear filters + */ + onClickReset() { + this.model.clearQuery(); + } + /** + * Set / unset filter + * @param {Object} filter + */ + onToggleFilter(filter) { + this.model.toggleSearchItem(filter.id); + } +} diff --git a/web_filter_header_button/static/src/filter_button/filter_button.xml b/web_filter_header_button/static/src/filter_button/filter_button.xml new file mode 100644 index 000000000..366770d53 --- /dev/null +++ b/web_filter_header_button/static/src/filter_button/filter_button.xml @@ -0,0 +1,39 @@ + + + + +
+
+ + + + + + + + + + +
+
+
+
diff --git a/web_filter_header_button/static/src/search/search_arch_parser_patch.esm.js b/web_filter_header_button/static/src/search/search_arch_parser_patch.esm.js new file mode 100644 index 000000000..51f78a40d --- /dev/null +++ b/web_filter_header_button/static/src/search/search_arch_parser_patch.esm.js @@ -0,0 +1,23 @@ +import {SearchArchParser} from "@web/search/search_arch_parser"; +import {patch} from "@web/core/utils/patch"; +import {makeContext} from "@web/core/context"; + +patch(SearchArchParser.prototype, { + /** + * Allow groupBy filters to show up as buttons + * @override + */ + visitFilter(node) { + var context_to_keep = false; + if (node.hasAttribute("context")) { + const context = makeContext([node.getAttribute("context")]); + if (context.group_by && context.shown_in_panel) { + context_to_keep = context; + } + } + super.visitFilter(...arguments); + if (context_to_keep) { + this.currentGroup.at(-1).context = context_to_keep; + } + }, +}); diff --git a/web_filter_header_button/static/src/search/search_model_patch.esm.js b/web_filter_header_button/static/src/search/search_model_patch.esm.js new file mode 100644 index 000000000..1a1b5de7e --- /dev/null +++ b/web_filter_header_button/static/src/search/search_model_patch.esm.js @@ -0,0 +1,55 @@ +import {makeContext} from "@web/core/context"; +import {patch} from "@web/core/utils/patch"; +import {SearchModel} from "@web/search/search_model"; +import {useEffect} from "@odoo/owl"; + +patch(SearchModel.prototype, { + setup() { + super.setup(...arguments); + // Filter flagged filters to be shown in the control panel. + useEffect( + () => { + this.headerButtonFilters = this.getHeaderButtonFilters(); + }, + () => [this.searchItems] + ); + }, + async load() { + await super.load(...arguments); + this.headerButtonFilters = this.getHeaderButtonFilters(); + }, + /** + * Filter flagged filters to be shown in the control panel. + * + * @returns {Array} + */ + getHeaderButtonFilters() { + return Object.values(this.getSearchItems()) + .filter((f) => { + return f.context && makeContext([f.context]).shown_in_panel; + }) + .map((f) => { + return {...f, context: makeContext([f.context])}; + }); + }, + /** + * Clear the `show_in_panel` context to prevent it being saved with this context + * @override + * @returns {Object} + */ + _getIrFilterDescription() { + const {preFavorite, irFilter} = super._getIrFilterDescription(...arguments); + if (preFavorite?.context) { + delete preFavorite.context.shown_in_panel; + } + return {preFavorite, irFilter}; + }, + /** + * Update the header filters buttons state + * @override + */ + async _reloadSections() { + await super._reloadSections(); + this.headerButtonFilters = this.getHeaderButtonFilters(); + }, +});