Skip to content

Commit bdd3e33

Browse files
committed
[IMP] estate: added pie chart and dashoard items
1 parent 0e8052e commit bdd3e33

20 files changed

+389
-26
lines changed

awesome_dashboard/__manifest__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
],
2424
'assets': {
2525
'web.assets_backend': [
26-
'awesome_dashboard/static/src/**/*',
26+
'awesome_dashboard/static/src/dashboard_action.js',
27+
],
28+
'awesome_dashboard.dashboard': [
29+
'awesome_dashboard/static/src/dashboard/**/*',
2730
],
2831
},
2932
'license': 'AGPL-3'

awesome_dashboard/static/src/dashboard.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

awesome_dashboard/static/src/dashboard.scss

Lines changed: 0 additions & 3 deletions
This file was deleted.

awesome_dashboard/static/src/dashboard.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { Component, useState } from "@odoo/owl";
2+
import { registry } from "@web/core/registry";
3+
import { Layout } from "@web/search/layout";
4+
import { useService } from "@web/core/utils/hooks";
5+
import { DashboardItem } from "./dashboard_item";
6+
import { DashboardConfigDialog } from "./dashboard_config_dialog";
7+
import "./dashboard_items";
8+
import "./statistics_service";
9+
10+
const DASHBOARD_CONFIG_KEY = "awesome_dashboard.config";
11+
12+
class AwesomeDashboard extends Component {
13+
static template = "awesome_dashboard.AwesomeDashboard";
14+
static components = { Layout, DashboardItem };
15+
16+
setup() {
17+
this.action = useService("action");
18+
this.dialog = useService("dialog");
19+
const statisticsService = useService("awesome_dashboard.statistics");
20+
this.statistics = useState(statisticsService.statistics);
21+
22+
const configStr = localStorage.getItem(DASHBOARD_CONFIG_KEY);
23+
this.hiddenItems = configStr ? JSON.parse(configStr) : [];
24+
25+
const allItems = registry.category("awesome_dashboard").getAll();
26+
this.items = allItems.filter(item => !this.hiddenItems.includes(item.id));
27+
}
28+
29+
openConfiguration() {
30+
this.dialog.add(DashboardConfigDialog, {
31+
currentConfig: this.hiddenItems,
32+
onApply: (hiddenItems) => {
33+
this.hiddenItems = hiddenItems;
34+
localStorage.setItem(DASHBOARD_CONFIG_KEY, JSON.stringify(hiddenItems));
35+
36+
const allItems = registry.category("awesome_dashboard").getAll();
37+
this.items = allItems.filter(item => !this.hiddenItems.includes(item.id));
38+
},
39+
});
40+
}
41+
42+
openCustomers() {
43+
this.action.doAction("base.action_partner_form");
44+
}
45+
46+
openLeads() {
47+
this.action.doAction({
48+
type: "ir.actions.act_window",
49+
name: "Leads",
50+
res_model: "crm.lead",
51+
views: [
52+
[false, "list"],
53+
[false, "form"],
54+
],
55+
});
56+
}
57+
}
58+
59+
registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.o_dashboard {
2+
background-color: #fafafa;
3+
}
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+
4+
<t t-name="awesome_dashboard.AwesomeDashboard">
5+
<Layout display="{controlPanel: {}}" className="'o_dashboard h-100'">
6+
<t t-set-slot="control-panel-additional-actions">
7+
<button class="btn btn-primary" t-on-click="openCustomers">Customers</button>
8+
<button class="btn btn-primary ms-2" t-on-click="openLeads">Leads</button>
9+
<button class="btn btn-secondary ms-2" t-on-click="openConfiguration" title="Configure Dashboard">
10+
<i class="fa fa-cog"/>
11+
</button>
12+
</t>
13+
<div class="p-3 overflow-auto">
14+
<div class="d-flex flex-wrap">
15+
<t t-foreach="items" t-as="item" t-key="item.id">
16+
<DashboardItem size="item.size || 1">
17+
<t t-set="itemProp" t-value="item.props ? item.props(statistics) : {'data': statistics}"/>
18+
<t t-component="item.Component" t-props="itemProp"/>
19+
</DashboardItem>
20+
</t>
21+
</div>
22+
</div>
23+
</Layout>
24+
</t>
25+
26+
</templates>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Component } from "@odoo/owl";
2+
import { Dialog } from "@web/core/dialog/dialog";
3+
import { registry } from "@web/core/registry";
4+
5+
export class DashboardConfigDialog extends Component {
6+
static template = "awesome_dashboard.DashboardConfigDialog";
7+
static components = { Dialog };
8+
static props = {
9+
close: Function,
10+
onApply: Function,
11+
currentConfig: Array,
12+
};
13+
14+
setup() {
15+
this.allItems = registry.category("awesome_dashboard").getAll();
16+
this.hiddenItems = new Set(this.props.currentConfig);
17+
}
18+
19+
toggleItem = (itemId) => {
20+
if (this.hiddenItems.has(itemId)) {
21+
this.hiddenItems.delete(itemId);
22+
} else {
23+
this.hiddenItems.add(itemId);
24+
}
25+
}
26+
27+
isItemVisible = (itemId) => {
28+
return !this.hiddenItems.has(itemId);
29+
}
30+
31+
apply = () => {
32+
this.props.onApply(Array.from(this.hiddenItems));
33+
this.props.close();
34+
}
35+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_dashboard.DashboardConfigDialog">
5+
<Dialog title="'Configure Dashboard'" contentClass="'o_dashboard_config_dialog'">
6+
<div class="mb-3">
7+
<h5>Select items to display:</h5>
8+
<t t-foreach="allItems" t-as="item" t-key="item.id">
9+
<div class="form-check">
10+
<input
11+
type="checkbox"
12+
class="form-check-input"
13+
t-att-id="'item_' + item.id"
14+
t-att-checked="isItemVisible(item.id)"
15+
t-on-change="() => toggleItem(item.id)"
16+
/>
17+
<label class="form-check-label" t-att-for="'item_' + item.id">
18+
<t t-esc="item.description"/>
19+
</label>
20+
</div>
21+
</t>
22+
</div>
23+
<t t-set-slot="footer">
24+
<button class="btn btn-secondary" t-on-click="props.close">Cancel</button>
25+
<button class="btn btn-primary" t-on-click="apply">Apply</button>
26+
</t>
27+
</Dialog>
28+
</t>
29+
30+
</templates>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class DashboardItem extends Component {
4+
static template = "awesome_dashboard.DashboardItem";
5+
static props = {
6+
size: { type: Number, optional: true },
7+
slots: { type: Object, optional: true },
8+
};
9+
10+
get width() {
11+
const size = this.props.size || 1;
12+
return `${18 * size}rem`;
13+
}
14+
}

0 commit comments

Comments
 (0)