From a9713b466750999d3cc2a40831c7b9d698a570f5 Mon Sep 17 00:00:00 2001 From: Matt Marcha Date: Fri, 20 Sep 2024 15:32:22 -1000 Subject: [PATCH] ch2.7 Real life update --- awesome_dashboard/static/src/dashboard.js | 7 ++----- awesome_dashboard/static/src/dashboard.xml | 2 +- awesome_dashboard/static/src/statistics_service.js | 14 +++++++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/awesome_dashboard/static/src/dashboard.js b/awesome_dashboard/static/src/dashboard.js index 6ace3f8..c7f7d8a 100644 --- a/awesome_dashboard/static/src/dashboard.js +++ b/awesome_dashboard/static/src/dashboard.js @@ -1,6 +1,6 @@ /** @odoo-module **/ -import { Component, onWillStart } from "@odoo/owl"; +import { Component, onWillStart, useState } from "@odoo/owl"; import { registry } from "@web/core/registry"; import { Layout } from "@web/search/layout"; import { useService } from "@web/core/utils/hooks" @@ -18,10 +18,7 @@ class AwesomeDashboard extends Component { this.action = useService("action"); - this.stats = useService('awesome_dashboard.statistics'); - onWillStart(async () => { - this.stats = await this.stats.loadStatistics(); - }); + this.stats = useState(useService('awesome_dashboard.statistics')); } openCustomers() { diff --git a/awesome_dashboard/static/src/dashboard.xml b/awesome_dashboard/static/src/dashboard.xml index fd3586f..1bb3e3a 100644 --- a/awesome_dashboard/static/src/dashboard.xml +++ b/awesome_dashboard/static/src/dashboard.xml @@ -7,7 +7,7 @@ -
+
Number of new orders this month
diff --git a/awesome_dashboard/static/src/statistics_service.js b/awesome_dashboard/static/src/statistics_service.js index 1ee547b..ae4fee3 100644 --- a/awesome_dashboard/static/src/statistics_service.js +++ b/awesome_dashboard/static/src/statistics_service.js @@ -1,15 +1,19 @@ /** @odoo-module **/ import { registry } from "@web/core/registry"; -import { memoize } from "@web/core/utils/functions" +import { reactive } from "@odoo/owl"; const statisticsService = { dependencies: ["rpc"], - async: ["loadStatistics"], start(env, { rpc }) { - return { - loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")), - }; + const statistics = reactive({ isReady: false }); + async function loadData() { + const updates = await rpc("/awesome_dashboard/statistics"); + Object.assign(statistics, updates, { isReady: true }); + } + setInterval(loadData, 10*60*1000); + loadData(); + return statistics; }, };