From 0780f2c29fb8efdb1f79508a8852231eab2fb8b6 Mon Sep 17 00:00:00 2001 From: nape-odoo Date: Mon, 25 Nov 2024 16:02:49 +0100 Subject: [PATCH] [IMP]: awesome_dashboard: Tutorial chapter 2: item 11 --- .../static/src/components/dashboard.js | 18 ++++++++- .../static/src/components/dashboard.xml | 16 ++------ .../static/src/components/dashboard_dialog.js | 38 +++++++++++++++++++ .../src/components/dashboard_dialog.xml | 18 +++++++++ 4 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 awesome_dashboard/static/src/components/dashboard_dialog.js create mode 100644 awesome_dashboard/static/src/components/dashboard_dialog.xml diff --git a/awesome_dashboard/static/src/components/dashboard.js b/awesome_dashboard/static/src/components/dashboard.js index f4b0cdf695..e8d59a70ce 100644 --- a/awesome_dashboard/static/src/components/dashboard.js +++ b/awesome_dashboard/static/src/components/dashboard.js @@ -5,10 +5,12 @@ import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks"; import { AwesomeDashboardItem } from "./dashboard_item" +import { browser } from "@web/core/browser/browser"; +import { AwesomeDashboardDialog } from "./dashboard_dialog" class AwesomeDashboard extends Component { static template = "awesome_dashboard.AwesomeDashboard"; - static components = { Layout, AwesomeDashboardItem} + static components = { Layout, AwesomeDashboardItem } setup(){ this.action = useService("action"); /** Previous implementation: leaving here for tutorial review purposes **/ @@ -19,6 +21,11 @@ class AwesomeDashboard extends Component { }); **/ this.data = useState(useService("awesome_dashboard.statistics")); this.dashboardItems = registry.category("awesome_dashboard").getAll(); + this.dialogService = useService("dialog"); + if(browser.localStorage.getItem("AwesomeDashboardUncheckedItems") == null){ + browser.localStorage.setItem("AwesomeDashboardUncheckedItems", ({})); + } + this.uncheckedItems = useState({dashboardItems: browser.localStorage.getItem("AwesomeDashboardUncheckedItems")}); } openCustomerView(){ this.action.doAction("base.action_partner_form"); @@ -31,6 +38,15 @@ class AwesomeDashboard extends Component { target: 'current', }); } + openOptionsDialog(){ + this.dialogService.add(AwesomeDashboardDialog, { + dashboardItems: this.dashboardItems, + updateUncheckedItems: this.updateUncheckedItems.bind(this), + }); + } + updateUncheckedItems(uncheckedItems){ + this.uncheckedItems.dashboardItems = uncheckedItems; + } } registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); diff --git a/awesome_dashboard/static/src/components/dashboard.xml b/awesome_dashboard/static/src/components/dashboard.xml index 71c5cb4f04..a3436cab26 100644 --- a/awesome_dashboard/static/src/components/dashboard.xml +++ b/awesome_dashboard/static/src/components/dashboard.xml @@ -7,19 +7,11 @@ - - + + + - + diff --git a/awesome_dashboard/static/src/components/dashboard_dialog.js b/awesome_dashboard/static/src/components/dashboard_dialog.js new file mode 100644 index 0000000000..ba58abf38d --- /dev/null +++ b/awesome_dashboard/static/src/components/dashboard_dialog.js @@ -0,0 +1,38 @@ +/** @odoo-module **/ + +import { Component, useState} from "@odoo/owl"; +import { Dialog } from "@web/core/dialog/dialog"; +import { CheckBox } from "@web/core/checkbox/checkbox"; +import { browser } from "@web/core/browser/browser"; + +export class AwesomeDashboardDialog extends Component { + static template = "awesome_dashboard.AwesomeDashboardDialog"; + static components = { Dialog, CheckBox } + static props = { + dashboardItems: Object, + updateUncheckedItems: Function, + } + setup(){ + this.dashboardItems = useState(this.props.dashboardItems); + this.itemCheckmarks = useState({ }); + let id; + for(let i = 0; i < this.dashboardItems.length; i++){ + id = this.dashboardItems.at(i).id; + this.itemCheckmarks[id] = !browser.localStorage.getItem("AwesomeDashboardUncheckedItems").includes(id); + } + this.dialogTitle = "Dashboard items configuration"; + } + itemToggle(ev, id){ + this.itemCheckmarks[id] = ev; + } + dialogSave(){ + const newUncheckedItems = []; + for(let i = 0; i < this.dashboardItems.length; i++){ + if(this.itemCheckmarks[this.dashboardItems.at(i).id] == false){ + newUncheckedItems.push(this.dashboardItems.at(i).id); + } + } + browser.localStorage.setItem("AwesomeDashboardUncheckedItems", newUncheckedItems); + this.props.updateUncheckedItems(newUncheckedItems); + } +} diff --git a/awesome_dashboard/static/src/components/dashboard_dialog.xml b/awesome_dashboard/static/src/components/dashboard_dialog.xml new file mode 100644 index 0000000000..c1474ef691 --- /dev/null +++ b/awesome_dashboard/static/src/components/dashboard_dialog.xml @@ -0,0 +1,18 @@ + + + + + +

Check items to be displayed:

+ + + + + + + + +
+
+ +