Skip to content

Commit 63f2fb4

Browse files
committed
[IMP] awesome_dashboard: added selective display of data
This commit introduces display of selective charts via check boxes This allows users to see only preferred charts and data points local storage enables users to automatically save selected preference of charts in browser
1 parent 7c6f7ba commit 63f2fb4

File tree

5 files changed

+105
-9
lines changed

5 files changed

+105
-9
lines changed

awesome_dashboard/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
],
3131
},
3232
'license': 'AGPL-3'
33-
}
33+
}

awesome_dashboard/static/src/dashboard/dashboard.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,39 @@ import { registry } from "@web/core/registry";
55
import { Layout } from "@web/search/layout";
66
import { useService } from "@web/core/utils/hooks";
77
import { DashboardItem } from "./dashboard_item/dashboard_item";
8-
import { PieChart } from "./pie_chart/pie_chart";
8+
import { DashboardSettings } from "./dashboard_settings/dashboard_settings";
9+
import { browser } from "@web/core/browser/browser";
910

1011
class AwesomeDashboard extends Component {
1112
static template = "awesome_dashboard.AwesomeDashboard";
12-
13-
static components = { Layout, DashboardItem, PieChart};
13+
static components = { Layout, DashboardItem };
1414

1515
setup() {
1616
this.actionService = useService("action");
1717
this.statisticsService = useService("awesome_dashboard.statistics");
1818
this.statistics = useState(this.statisticsService.data);
19+
20+
this.dialogService = useService("dialog");
21+
1922
const dashboardItemsRegistry = registry.category("awesome_dashboard");
2023
this.items = dashboardItemsRegistry.getAll();
24+
25+
this.state = useState({
26+
uncheckedItems: browser.localStorage.getItem("uncheckedItems")?.split(",").filter(id => id) || [],
27+
});
28+
}
29+
30+
updateConfiguration(newUncheckedItems) {
31+
this.state.uncheckedItems.length = 0;
32+
this.state.uncheckedItems.push(...newUncheckedItems);
33+
}
34+
35+
openConfiguration() {
36+
this.dialogService.add(DashboardSettings, {
37+
items: this.items,
38+
initialUncheckedItems: this.state.uncheckedItems,
39+
updateConfiguration: this.updateConfiguration.bind(this),
40+
});
2141
}
2242

2343
openCustomers() {

awesome_dashboard/static/src/dashboard/dashboard.xml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@
77
<button t-on-click="openCustomers" type="button" class="btn btn-primary me-2" title="Customers">Customers</button>
88
<button t-on-click="openLeads" type="button" class="btn btn-primary" title="Leads">Leads</button>
99
</t>
10+
11+
<t t-set-slot="control-panel-additional-actions">
12+
<button class="btn btn-light" title="Dashboard Settings" t-on-click="openConfiguration">
13+
<i class="fa fa-cog"></i>
14+
</button>
15+
</t>
1016
<div class="p-3">
1117
<div class="d-flex flex-wrap">
12-
<t t-foreach="items" t-as="item" t-key="item.id">
13-
<DashboardItem size="item.size || 1">
14-
<t t-set="itemProp" t-value="item.props ? item.props(statistics) : {'data': statistics}"/>
15-
<t t-component="item.Component" t-props="itemProp" />
18+
<t t-foreach="Object.values(items)" t-as="item" t-key="item.id">
19+
<DashboardItem t-if="!state.uncheckedItems.includes(item.id)" size="item.size || 1">
20+
<t t-set="itemProp" t-value="item.props ? item.props(statistics) : {'data': statistics}"/>
21+
<t t-component="item.Component" t-props="itemProp" />
1622
</DashboardItem>
17-
</t>
23+
</t>
1824
</div>
1925
</div>
2026
</Layout>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState } from "@odoo/owl";
4+
import { Dialog } from "@web/core/dialog/dialog";
5+
import { browser } from "@web/core/browser/browser";
6+
7+
export class DashboardSettings extends Component {
8+
static template = "awesome_dashboard.DashboardSettings";
9+
static components = { Dialog };
10+
11+
static props = {
12+
close: { type: Function },
13+
};
14+
15+
setup() {
16+
const items = this.props.items || {};
17+
const initialUncheckedItems = this.props.initialUncheckedItems || [];
18+
19+
this.dialogDisplayItems = useState(
20+
Object.values(items).map((item) => ({
21+
...item,
22+
checked: !initialUncheckedItems.includes(item.id),
23+
}))
24+
);
25+
}
26+
27+
onChange(checked, itemInDialog) {
28+
const targetItem = this.dialogDisplayItems.find(i => i.id === itemInDialog.id);
29+
if (targetItem) {
30+
targetItem.checked = checked;
31+
}
32+
}
33+
34+
confirmChanges() {
35+
const newUncheckedItems = this.dialogDisplayItems.filter((item) => !item.checked).map((item) => item.id);
36+
37+
browser.localStorage.setItem("uncheckedItems", newUncheckedItems.join(","));
38+
39+
if (this.props.updateConfiguration) {
40+
this.props.updateConfiguration(newUncheckedItems);
41+
}
42+
this.props.close();
43+
}
44+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_dashboard.DashboardSettings">
4+
<Dialog title="'Dashboard Items Configuration'">
5+
<div class="p-3">
6+
<p>Select items to display on your dashboard:</p>
7+
<div t-foreach="dialogDisplayItems" t-as="item" t-key="item.id" class="form-check mb-2">
8+
<input
9+
type="checkbox"
10+
class="form-check-input"
11+
t-att-id="'settings_item_' + item.id"
12+
t-att-checked="item.checked"
13+
t-on-change="(ev) => this.onChange(ev.target.checked, item)"
14+
/>
15+
<label class="form-check-label" t-att-for="'settings_item_' + item.id">
16+
<t t-out="item.description"/>
17+
</label>
18+
</div>
19+
</div>
20+
<t t-set-slot="footer">
21+
<button class="btn btn-primary" t-on-click="confirmChanges">Apply</button>
22+
<button class="btn btn-secondary ms-2" t-on-click="props.close">Cancel</button>
23+
</t>
24+
</Dialog>
25+
</t>
26+
</templates>

0 commit comments

Comments
 (0)