Skip to content

Commit 35aa75a

Browse files
committed
[IMP] awesome_dashboard: Add a dialog to configure the items
1 parent 8f2fe66 commit 35aa75a

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

awesome_dashboard/static/src/dashboard/dashboard.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ 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";
8+
import { Dialog } from "@web/core/dialog/dialog";
9+
import { CheckBox } from "@web/core/checkbox/checkbox";
10+
import { browser } from "@web/core/browser/browser";
811

912
class AwesomeDashboard extends Component {
1013
static template = "awesome_dashboard.AwesomeDashboard";
@@ -14,11 +17,26 @@ class AwesomeDashboard extends Component {
1417
this.action = useService("action");
1518
this.statistics = useState(useService("awesome_dashboard.statistics"));
1619
this.items = registry.category("item").getAll();
20+
this.dialog = useService("dialog");
1721
this.display = {
1822
controlPanel: {},
1923
};
24+
this.state = useState({
25+
disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || [],
26+
});
27+
}
28+
29+
openConfiguration(newDisabledItems) {
30+
this.dialog.add(ConfigurationDialog, {
31+
items: this.items,
32+
disabledItems: this.state.disabledItems,
33+
onUpdateConfiguration: this.updateConfiguration.bind(this),
34+
})
2035
}
2136

37+
updateConfiguration(newDisabledItems) {
38+
this.state.disabledItems = newDisabledItems;
39+
}
2240
openCustomerView() {
2341
this.action.doAction("base.action_partner_form");
2442
}
@@ -36,4 +54,33 @@ class AwesomeDashboard extends Component {
3654
}
3755
}
3856

57+
class ConfigurationDialog extends Component {
58+
static template = "awesome_dashboard.ConfigurationDialog";
59+
static components = { Dialog, CheckBox };
60+
static props = ["close", "items", "disabledItems", "onUpdateConfiguration"];
61+
62+
setup(){
63+
this.items = useState(this.props.items.map((item) => {
64+
return {
65+
...item,
66+
enabled: !this.props.disabledItems.includes(item.id),
67+
};
68+
}));
69+
}
70+
71+
done(){
72+
this.props.close();
73+
}
74+
75+
onChange(checked, changedItem){
76+
changedItem.enabled = checked;
77+
const newDisabledItems = Object.values(this.items).filter(
78+
(item) => !item.enabled).map((item) => item.id);
79+
80+
browser.localStorage.setItem("disabledDashboardItems", newDisabledItems);
81+
82+
this.props.onUpdateConfiguration(newDisabledItems);
83+
}
84+
}
85+
3986
registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);

awesome_dashboard/static/src/dashboard/dashboard.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,35 @@
77
<button class="btn btn-primary" t-on-click="openCustomerView">Customers</button>
88
<button class="btn btn-primary" t-on-click="openLeadView">Leads</button>
99
</t>
10+
<t t-set-slot="control-panel-additional-actions">
11+
<button t-on-click="openConfiguration" class="btn p-0 ms-1 border-0">
12+
<i class="fa fa-cog"></i>
13+
</button>
14+
</t>
1015
<div class="d-flex flex-wrap" t-if="statistics.isReady">
1116
<t t-foreach="items" t-as="item" t-key="item.id">
12-
<DashboardItem size="item.size || 1">
17+
<DashboardItem t-if="!state.disabledItems.includes(item.id)" size="item.size || 1">
1318
<t t-set="itemProp" t-value="item.props ? item.props(statistics) : {'data': statistics}"/>
1419
<t t-component="item.Component" t-props="itemProp" />
1520
</DashboardItem>
1621
</t>
1722
</div>
1823
</Layout>
1924
</t>
25+
<t t-name="awesome_dashboard.ConfigurationDialog">
26+
<Dialog title="'Dashboard items configuration'">
27+
Which cards do you whish to see ?
28+
<t t-foreach="items" t-as="item" t-key="item.id">
29+
<CheckBox value="item.enabled" onChange="(ev) => this.onChange(ev, item)">
30+
<t t-esc="item.description"/>
31+
</CheckBox>
32+
</t>
33+
<t t-set-slot="footer">
34+
<button class="btn btn-primary" t-on-click="done">
35+
Done
36+
</button>
37+
</t>
38+
</Dialog>
39+
</t>
2040

2141
</templates>

0 commit comments

Comments
 (0)