Skip to content

Commit ae9a44d

Browse files
committed
[IMP] awesome_dashboard: add item list and pie chart in dashboard
add dashboard item which is number card and pie chart card add lazy loading functionality for dashboard making our dashboard generic added functionality add and remove dashboard items
1 parent 3aa257c commit ae9a44d

31 files changed

+472
-127
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,10 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
131+
.eslintignore
132+
.eslintrc.json
133+
jsconfig.json
134+
package.json
135+
package-lock.json
136+
node_modules

awesome_dashboard/__manifest__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
'web.assets_backend': [
2626
'awesome_dashboard/static/src/**/*',
2727
],
28+
'awesome_dashboard.dashboard': [
29+
'awesome_dashboard/static/src/dashboard/**/*',
30+
],
2831
},
2932
'license': 'AGPL-3'
3033
}
29.9 KB
Loading

awesome_dashboard/static/src/dashboard.js

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

awesome_dashboard/static/src/dashboard.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class DashboardItem extends Component {
4+
static template = "awesome_dashboard.DashboardItem";
5+
static props = {
6+
title: {
7+
type: String,
8+
optional: true
9+
},
10+
slots: {
11+
type: Object,
12+
shape: {
13+
default: Object,
14+
},
15+
},
16+
size: {
17+
type: Number,
18+
optional: true,
19+
},
20+
};
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_dashboard.DashboardItem">
4+
<div class="card m-2" t-attf-style="width: {{ 18 * props.size || 18 }}rem;">
5+
<div class="card-body">
6+
<t t-slot="default"/>
7+
</div>
8+
</div>
9+
</t>
10+
</templates>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class NumberCard extends Component {
4+
static template = "awesome_dashboard.NumberCard";
5+
static props = {
6+
title: {
7+
type: String,
8+
optional: true
9+
},
10+
value: Number,
11+
};
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_dashboard.NumberCard">
4+
<h5 class="mb-0" t-esc="props.title"/>
5+
<p class='fs-1 fw-bold text-success mb-0' t-esc="props.value"/>
6+
</t>
7+
</templates>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Component, onWillStart, onPatched, useRef, onMounted } from "@odoo/owl";
2+
import { loadJS } from "@web/core/assets";
3+
4+
export class PieChart extends Component {
5+
static template = "awesome_dashboard.PieChart";
6+
static props = {
7+
items: {
8+
type: Object,
9+
optional: true,
10+
default: () => ({}),
11+
},
12+
}
13+
14+
setup() {
15+
this.chartRef = useRef("pie-canvas");
16+
this.myPieChart = null;
17+
onWillStart(async () => {
18+
await loadJS("/web/static/lib/Chart/Chart.js");
19+
});
20+
onMounted(() => {
21+
this.renderChart()
22+
});
23+
onPatched(() => {
24+
this.renderChart()
25+
});
26+
}
27+
28+
renderChart() {
29+
if (!this.chartRef.el) {
30+
return;
31+
}
32+
if (this.myPieChart) {
33+
this.myPieChart.destroy();
34+
}
35+
this.pieChartData = {
36+
labels: ['M', 'S', 'XL'],
37+
datasets: [{
38+
label: 'Sales Count',
39+
data: [this.props.items.m, this.props.items.s, this.props.items.xl],
40+
backgroundColor: [
41+
'rgba(255, 99, 132, 0.6)',
42+
'rgba(54, 162, 235, 0.6)',
43+
'rgba(255, 206, 86, 0.6)'
44+
],
45+
borderColor: [
46+
'rgba(255, 99, 132, 1)',
47+
'rgba(54, 162, 235, 1)',
48+
'rgba(255, 206, 86, 1)'
49+
],
50+
borderWidth: 1
51+
}]
52+
};
53+
this.pieChartOptions = {
54+
responsive: true,
55+
maintainAspectRatio: false,
56+
plugins: {
57+
legend: {
58+
position: 'top',
59+
}
60+
}
61+
};
62+
this.myPieChart = new Chart(this.chartRef.el, {
63+
type: 'pie',
64+
data: this.pieChartData,
65+
options: this.pieChartOptions
66+
});
67+
}
68+
}

0 commit comments

Comments
 (0)