Skip to content

Commit fbb15af

Browse files
committed
[IMP] awesome_dashboard: changed project structure and made dashboard item more modular
1 parent 33a674e commit fbb15af

File tree

18 files changed

+156
-74
lines changed

18 files changed

+156
-74
lines changed

awesome_dashboard/__manifest__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
'assets': {
2525
'web.assets_backend': [
2626
'awesome_dashboard/static/src/**/*',
27+
('remove', 'awesome_dashboard/static/src/dashboard**/*'),
28+
],
29+
'awesome_dashboard.dashboard': [
30+
'awesome_dashboard/static/src/dashboard/**/*'
2731
],
2832
},
2933
'license': 'AGPL-3'

awesome_dashboard/static/src/dashboard.xml

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

awesome_dashboard/static/src/dashboard.js renamed to awesome_dashboard/static/src/dashboard/dashboard.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ 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 { items } from "./dashboard_items";
99

1010
class AwesomeDashboard extends Component {
1111
static template = "awesome_dashboard.AwesomeDashboard";
1212
static components = {
1313
Layout,
1414
DashboardItem,
15-
PieChart
1615
};
1716

1817
static props = {
@@ -24,6 +23,7 @@ class AwesomeDashboard extends Component {
2423
setup() {
2524
this.action = useService("action");
2625
this.result = useState(useService("awesome_dashboard.getStats"));
26+
this.items = items
2727
}
2828

2929
openCustomerKanban() {
@@ -41,4 +41,4 @@ class AwesomeDashboard extends Component {
4141
}
4242
}
4343

44-
registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
44+
registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_dashboard.AwesomeDashboard">
5+
<div t-ref="root" class="h-100 d-flex flex-column">
6+
<Layout className="'o_dashboard h-100'" display="props.display">
7+
<button class="btn btn-primary myBtnChange" t-on-click="openCustomerKanban"> Open customer kanban </button>
8+
<button class="btn btn-primary myBtnChange" t-on-click="openActivity"> Leads </button>
9+
<div style="margin-left: 1rem; display: flex;">
10+
<t t-foreach="items" t-as="item" t-key="item.id">
11+
<DashboardItem size="item.size || 1">
12+
<t t-set="itemProp" t-value="item.props ? item.props(result) : {'data': result}"/>
13+
<t t-component="item.Component" t-props="itemProp" />
14+
</DashboardItem>
15+
</t>
16+
</div>
17+
</Layout>
18+
19+
</div>
20+
</t>
21+
22+
</templates>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { NumberCard } from "./number_card/number_card";
2+
import { PieChartCard } from "./pie_chart_card/pie_chart_card";
3+
4+
export const items = [
5+
{
6+
id: "average_quantity",
7+
description: "Average amount of t-shirt",
8+
Component: NumberCard,
9+
props: (data) => ({
10+
title: "Average amount of t-shirt by order this month",
11+
value: data.average_quantity,
12+
})
13+
},
14+
{
15+
id: "average_time",
16+
description: "Average time for an order",
17+
Component: NumberCard,
18+
props: (data) => ({
19+
title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'",
20+
value: data.average_time,
21+
})
22+
},
23+
{
24+
id: "number_new_orders",
25+
description: "New orders this month",
26+
Component: NumberCard,
27+
props: (data) => ({
28+
title: "Number of new orders this month",
29+
value: data.nb_new_orders,
30+
})
31+
},
32+
{
33+
id: "cancelled_orders",
34+
description: "Cancelled orders this month",
35+
Component: NumberCard,
36+
props: (data) => ({
37+
title: "Number of cancelled orders this month",
38+
value: data.nb_cancelled_orders,
39+
})
40+
},
41+
{
42+
id: "amount_new_orders",
43+
description: "amount orders this month",
44+
Component: NumberCard,
45+
props: (data) => ({
46+
title: "Total amount of new orders this month",
47+
value: data.total_amount,
48+
})
49+
},
50+
{
51+
id: "pie_chart",
52+
description: "Shirt orders by size",
53+
Component: PieChartCard,
54+
size: 1,
55+
props: (data) => ({
56+
title: "Shirt orders by size",
57+
values: data.orders_by_size,
58+
})
59+
}
60+
]

0 commit comments

Comments
 (0)