Skip to content

Commit af96612

Browse files
Merge branch '17.0' into 640-openspp-modules
2 parents 139d65e + 0501c8e commit af96612

File tree

16 files changed

+318
-6
lines changed

16 files changed

+318
-6
lines changed

spp_dashboard_base/__init__.py

Whitespace-only changes.

spp_dashboard_base/__manifest__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Part of OpenSPP. See LICENSE file for full copyright and licensing details.
2+
3+
4+
{
5+
"name": "OpenSPP Dashboard: Base",
6+
"category": "OpenSPP",
7+
"version": "17.0.1.0.0",
8+
"sequence": 1,
9+
"author": "OpenSPP.org",
10+
"website": "https://github.com/OpenSPP/openspp-modules",
11+
"license": "LGPL-3",
12+
"development_status": "Beta",
13+
"maintainers": ["reichie020212"],
14+
"depends": [
15+
"base",
16+
],
17+
"data": [],
18+
"assets": {
19+
"web.assets_backend": [
20+
"spp_dashboard_base/static/src/dashboard/**/*",
21+
"spp_dashboard_base/static/src/chart/**/*",
22+
"spp_dashboard_base/static/src/card_board/**/*",
23+
],
24+
},
25+
"demo": [],
26+
"images": [],
27+
"application": False,
28+
"installable": True,
29+
"auto_install": False,
30+
}

spp_dashboard_base/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
12.3 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @odoo-module **/
2+
3+
import {Component} from "@odoo/owl";
4+
5+
export class CardBoardComponent extends Component {}
6+
7+
CardBoardComponent.template = "spp_dashboard_base.CardBoardTemplate";
8+
CardBoardComponent.props = {
9+
title: {type: String, optional: true},
10+
data: {type: [String, Number], optional: true},
11+
size: {type: String, optional: true},
12+
};
13+
CardBoardComponent.defaultProps = {
14+
title: "Title",
15+
data: "Data",
16+
size: "col-md-4",
17+
};
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>
3+
<t t-name="spp_dashboard_base.CardBoardTemplate">
4+
<div t-att-class="props.size" style="padding-top: 30px;">
5+
<div
6+
class="oh-card"
7+
style="box-shadow: 2px 4px 8px 2px rgba(0, 0, 0, 0.2); display: flex; justify-content: center; align-items: center; height: 100px;"
8+
role="button"
9+
>
10+
<div class="oh-card-body" style="padding: 5px; width: 100%; box-sizing: border-box;">
11+
<div
12+
class="stat-widget-one"
13+
style="display: flex; justify-content: center; align-items: center; height: 100%;"
14+
>
15+
<div class="stat_content" style="text-align: center; font-weight: bold;">
16+
<div style="font-size: 17px;">
17+
<t t-esc="props.data" />
18+
</div>
19+
<div class="stat-head" style="font-size: 14px;"><t t-esc="props.title" /></div>
20+
</div>
21+
</div>
22+
</div>
23+
</div>
24+
</div>
25+
</t>
26+
</templates>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/** @odoo-module **/
2+
3+
import {Component, onMounted, onWillStart, useRef} from "@odoo/owl";
4+
import {loadBundle} from "@web/core/assets";
5+
6+
export class ChartComponent extends Component {
7+
setup() {
8+
onMounted(() => this.renderChart());
9+
this.canvasRef = useRef("canvas");
10+
11+
this.chartTitle = "";
12+
const chartTypesWithTitle = ["pie", "doughnut"];
13+
if (chartTypesWithTitle.includes(this.props.chart_type)) {
14+
this.chartTitle = this.props.data_label;
15+
}
16+
17+
onWillStart(async () => {
18+
return Promise.all([
19+
// Load external JavaScript and CSS libraries.
20+
loadBundle({
21+
jsLibs: [
22+
// "/awesome_dashboard/static/lib/chart-js.4.4.4/chart.umd.min.js",
23+
"https://cdn.jsdelivr.net/npm/chart.js@4.4.4/dist/chart.umd.min.js",
24+
],
25+
}),
26+
]);
27+
});
28+
}
29+
30+
renderChart() {
31+
const ctx = this.canvasRef.el.getContext("2d");
32+
33+
new Chart(ctx, {
34+
type: this.props.chart_type,
35+
data: {
36+
labels: this.props.labels,
37+
datasets: [
38+
{
39+
label: this.props.data_label,
40+
data: this.props.data,
41+
backgroundColor: this.props.backgroundColor,
42+
hoverOffset: 2,
43+
},
44+
],
45+
},
46+
options: {...this.props.options},
47+
});
48+
}
49+
}
50+
51+
ChartComponent.template = "spp_dashboard_base.ChartComponentTemplate";
52+
ChartComponent.props = {
53+
chart_type: {type: String, optional: true},
54+
labels: {type: Array, optional: true},
55+
data_label: {type: String, optional: true},
56+
data: {type: Array, optional: true},
57+
backgroundColor: {type: Array, optional: true},
58+
options: {type: Object, optional: true},
59+
size: {type: String, optional: true},
60+
};
61+
ChartComponent.defaultProps = {
62+
chart_type: "pie",
63+
labels: ["Red", "Blue", "Yellow"],
64+
data_label: "Number of Colors",
65+
data: [300, 50, 150],
66+
backgroundColor: ["rgb(255, 99, 132)", "rgb(54, 162, 235)", "rgb(255, 205, 86)"],
67+
options: {
68+
maintainAspectRatio: true,
69+
aspectRatio: 2,
70+
},
71+
size: "col-md-6",
72+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates>
3+
<t t-name="spp_dashboard_base.ChartComponentTemplate">
4+
<style>
5+
.pie-chart-container {
6+
border: 2px solid #000;
7+
border-radius: 10px;
8+
margin-top : 2em;
9+
}
10+
</style>
11+
<div class="container" t-att-class="props.size">
12+
<div class="pie-chart-container">
13+
<h3 style="text-align: center;"><t t-esc="chartTitle" /></h3>
14+
<canvas id="myChart" t-ref="canvas" />
15+
</div>
16+
</div>
17+
</t>
18+
</templates>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/** @odoo-module **/
2+
import {Component, onWillStart, useState} from "@odoo/owl";
3+
import {CardBoardComponent} from "../card_board/card_board";
4+
import {ChartComponent} from "../chart/chart";
5+
import {registry} from "@web/core/registry";
6+
import {useService} from "@web/core/utils/hooks";
7+
8+
export class SppDashboard extends Component {
9+
setup() {
10+
super.setup();
11+
this.orm = useService("orm");
12+
this.state = useState({hierarchy: []});
13+
this.card_board_data = {};
14+
onWillStart(this.onWillStart);
15+
this.dashboard_title = "Dashboard";
16+
}
17+
18+
async onWillStart() {
19+
// Super this function to get data from the server
20+
// sample
21+
// this.dashboard_data = await this.orm.call("res.partner", "get_data", []);
22+
}
23+
}
24+
25+
SppDashboard.template = "spp_dashboard_base.dashboard_page";
26+
SppDashboard.components = {ChartComponent, CardBoardComponent};
27+
28+
registry.category("actions").add("spp_dashboard_tag", SppDashboard);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates>
3+
<t t-name="spp_dashboard_base.dashboard_page">
4+
<div class="main" style="height: 100vh; overflow-y: auto;">
5+
<div class="title" name="title">
6+
<center>
7+
<h1><t t-esc="dashboard_title" /></h1>
8+
</center>
9+
</div>
10+
<div class="container dashboard-container" name="dashboard-container">
11+
</div>
12+
</div>
13+
</t>
14+
</templates>

0 commit comments

Comments
 (0)