ch2.7 Real life update

This commit is contained in:
Matt Marcha 2024-09-20 15:32:22 -10:00
parent f89514d21f
commit a9713b4667
3 changed files with 12 additions and 11 deletions

View file

@ -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() {

View file

@ -7,7 +7,7 @@
<button class="btn btn-primary" t-on-click="openCustomers">Customers</button>
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
</t>
<div class="d-flex flex-wrap">
<div class="d-flex flex-wrap" t-if="stats.isReady">
<DashboardItem>
Number of new orders this month
<div class="fs-1 fw-bold text-success text-center">

View file

@ -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;
},
};