Skip to content

Commit a29fb48

Browse files
committed
[FIX] estate,estate_estate,awesome_owl,awesome_dashboard: fix issues and code improvements
- Fixed linting issues - Added missing licensing - Removed unnecessary code
1 parent f093f18 commit a29fb48

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+360
-434
lines changed
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
import { Component } from "@odoo/owl"
22

3-
export class DashboardItem extends Component{
3+
export class DashboardItem extends Component {
44
static template = "awesome_dashboard.dashboard_item"
55
static props = {
6-
slots:{
7-
type: Object,
8-
shape: {
9-
default: Object
10-
}
11-
},
12-
size:{
13-
type: Number,
14-
default: 1,
15-
optional: true
16-
}
17-
}
18-
19-
setup(){
20-
this.size = this.props.size || 1
6+
slots: { type: Object, shape: { default: Object } },
7+
size: { type: Number, default: 1, optional: true }
218
}
229
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<?xml version="1.0" encoding="UTF-8" ?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<templates xml:space="preserve">
33
<t t-name="awesome_dashboard.dashboard_item">
4-
<div class="card m-2 border-dark pie-chart-card" t-attf-style="width: {{18 * size}}rem;">
5-
<div class="card-body">
6-
<t t-slot="default"/>
4+
<div class="card m-2 border-dark pie-chart-card" t-attf-style="width: {{18 * this.props.size}}rem;">
5+
<div class="card-body">
6+
<t t-slot="default"/>
7+
</div>
78
</div>
8-
</div>
99
</t>
1010
</templates>
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { Component } from "@odoo/owl";
22

3-
export class NumberCard extends Component{
3+
export class NumberCard extends Component {
44
static template = "awesome_dashboard.number_card"
55
static props = {
6-
title :{
7-
type:String
8-
},
9-
value:{
10-
type:[Number,String]
11-
}
6+
title: { type: String },
7+
value: { type: [Number, String] }
128
}
139
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<t t-name="awesome_dashboard.number_card">
2-
<h4>
3-
<t t-esc="props.title" />
4-
</h4>
5-
<div class="fs-1 fw-bold text-success text-center">
6-
<t t-esc="props.value"/>
7-
</div>
8-
</t>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_dashboard.number_card">
4+
<h4><t t-out="props.title"/></h4>
5+
<div class="fs-1 fw-bold text-success text-center"><t t-out="props.value"/>
6+
</div>
7+
</t>
8+
</templates>
Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { Component, onWillStart,onMounted, useRef, onWillUpdateProps } from "@odoo/owl";
1+
import { Component, onWillStart, onMounted, useRef, onWillUpdateProps } from "@odoo/owl";
22
import { loadJS } from "@web/core/assets";
33
import { _t } from "@web/core/l10n/translation";
44

55

6-
export class PieChartCard extends Component{
6+
export class PieChartCard extends Component {
77
static template = "awesome_dashboard.pie_chart"
88

9-
setup(){
9+
setup() {
1010
this.canvasRef = useRef("canvas")
1111

12-
onWillStart(async()=>{
12+
onWillStart(async () => {
1313
await loadJS("/web/static/lib/Chart/Chart.js")
1414
})
1515
onMounted(() => {
@@ -23,28 +23,21 @@ export class PieChartCard extends Component{
2323
});
2424
}
2525

26-
27-
renderChart(){
28-
const labels = Object.keys(this.props.data);
29-
const data = Object.values(this.props.data);
30-
const color = ["#007BFF", "#FFA500", "#808090",];
31-
const ctx = this.canvasRef.el.getContext("2d");
32-
this.chart = new Chart(ctx,{
33-
type:"pie",
34-
data:{
35-
labels:labels,
36-
datasets: [
37-
{
38-
label: this.props.title,
39-
data:data,
40-
backgroundColor: color
41-
}
42-
]
26+
renderChart() {
27+
this.chart = new Chart(this.canvasRef.el.getContext("2d"), {
28+
type: "pie",
29+
data: {
30+
labels: Object.keys(this.props.data),
31+
datasets: [{
32+
label: this.props.title,
33+
data: Object.values(this.props.data),
34+
backgroundColor: ["#007BFF", "#FFA500", "#808090"]
35+
}]
4336
},
4437
options: {
4538
responsive: true,
4639
maintainAspectRatio: false
47-
},
40+
},
4841
})
4942
}
5043
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<t t-name="awesome_dashboard.pie_chart">
2-
<h4>
3-
<t t-esc="props.title"/>
4-
</h4>
5-
<div>
6-
<canvas t-ref="canvas"/>
7-
</div>
8-
</t>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_dashboard.pie_chart">
4+
<h4><t t-out="props.title"/></h4>
5+
<div><canvas t-ref="canvas"/></div>
6+
</t>
7+
</templates>

awesome_dashboard/static/src/dashboard/components/services/statistics_service.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { rpc } from "@web/core/network/rpc";
33
import { reactive } from "@odoo/owl";
44

55
const statisticsService = {
6-
start(){
6+
start() {
77
const stats = reactive({
88
nb_new_orders: 0,
99
total_amount: 0,
@@ -14,17 +14,16 @@ const statisticsService = {
1414
});
1515
const loadStatistics = async () => {
1616
const result = await rpc("/awesome_dashboard/statistics");
17-
1817
if (result) {
1918
Object.assign(stats, result);
2019
}
2120
};
2221
loadStatistics();
2322
setInterval(() => {
2423
loadStatistics();
25-
}, 10*60*1000);
24+
}, 10 * 60 * 1000);
2625

27-
return {data : stats};
26+
return { data: stats };
2827
}
2928
}
3029

awesome_dashboard/static/src/dashboard/dashboard.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/** @odoo-module **/
2-
31
import { Component, useState, onWillStart } from "@odoo/owl";
42
import { registry } from "@web/core/registry";
53
import { Layout } from "@web/search/layout";
@@ -11,37 +9,37 @@ import { DashboardItem } from "@awesome_dashboard/dashboard/components/dashboard
119

1210
class AwesomeDashboard extends Component {
1311
static template = "awesome_dashboard.AwesomeDashboard";
14-
static components = { Layout ,DashboardItem }
12+
static components = { Layout, DashboardItem }
1513

16-
setup(){
14+
setup() {
1715
this.action = useService("action")
1816
this.dialog = useService("dialog")
1917
this.statisticsService = useService("awesome_dashboard.statistics");
20-
this.statistics = useState(this.statisticsService.data);
18+
this.statistics = useState(this.statisticsService.data);
2119
this.display = { controlPanel: {} }
2220
this.items = registry.category("awesome_dashboard").getAll();
2321
this.state = useState({
2422
disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || []
2523
})
2624
}
2725

28-
openCustomersKanban(){
26+
openCustomersKanban() {
2927
this.action.doAction("base.action_partner_form")
3028
}
3129

32-
openLeads(){
30+
openLeads() {
3331
this.action.doAction({
3432
type: "ir.actions.act_window",
3533
name: "Leads",
3634
res_model: "crm.lead",
37-
views:[
38-
[false,"list"],
39-
[false,"form"]
35+
views: [
36+
[false, "list"],
37+
[false, "form"]
4038
]
4139
})
4240
}
4341

44-
openConfigDialog(){
42+
openConfigDialog() {
4543
this.dialog.add(ConfigurationDialog, {
4644
items: this.items,
4745
disabledItems: this.state.disabledItems,
@@ -55,21 +53,26 @@ class AwesomeDashboard extends Component {
5553

5654
}
5755

58-
class ConfigurationDialog extends Component{
56+
class ConfigurationDialog extends Component {
5957
static template = "awesome_dashboard.ConfigurationDialog";
6058
static components = { CheckBox, Dialog };
61-
62-
63-
setup(){
64-
this.items = useState(this.props.items.map((item)=>{
59+
static props = {
60+
items: { type: Array },
61+
disabledItems: { type: Array },
62+
onUpdateConfiguration: { type: Function },
63+
close: { type: Function }
64+
};
65+
66+
setup() {
67+
this.items = useState(this.props.items.map((item) => {
6568
return {
6669
...item,
6770
enabled: !this.props.disabledItems.includes(item.id)
6871
}
6972
}))
7073
}
7174

72-
done(){
75+
done() {
7376
this.props.close();
7477
}
7578

awesome_dashboard/static/src/dashboard/dashboard.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.o_dashboard{
2-
background-color: gray;
3-
}
4-
51
@media (max-width: 767px) {
62
.pie-chart-card {
73
width: 100% !important;
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
1-
<?xml version="1.0" encoding="UTF-8" ?>
1+
<?xml version="1.0" encoding="UTF-8"?>
22
<templates xml:space="preserve">
3-
43
<t t-name="awesome_dashboard.AwesomeDashboard">
5-
<Layout display="display" className="'o_dashboard h-100'">
4+
<Layout display="display" class="bg-secondary">
65
<t t-set-slot="layout-buttons">
7-
<button class="btn btn-primary" t-on-click="openCustomersKanban">Customers</button>
8-
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
6+
<button class="btn btn-primary" t-on-click="() => this.openCustomersKanban()">Customers</button>
7+
<button class="btn btn-primary" t-on-click="() => this.openLeads()">Leads</button>
98
</t>
109
<t t-set-slot="control-panel-additional-actions">
11-
<button t-on-click="openConfigDialog" class="btn p-0 ms-1 border-0">
10+
<button t-on-click="() => this.openConfigDialog()" class="btn p-0 ms-1 border-0">
1211
<i class="fa fa-cog" />
1312
</button>
1413
</t>
1514
<div class="d-flex flex-wrap">
16-
<t t-foreach="items" t-as="item" t-key="item.id">
17-
<DashboardItem t-if="!state.disabledItems.includes(item.id)" size="item.size || 1">
18-
<t t-set="itemProp" t-value="item.props ? item.props(statistics) : {'data' : statistics}"/>
19-
<t t-component="item.Component" t-props="itemProp" />
20-
</DashboardItem>
21-
</t>
15+
<t t-foreach="items" t-as="item" t-key="item.id">
16+
<DashboardItem t-if="!state.disabledItems.includes(item.id)" 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>
2221
</div>
2322
</Layout>
2423
</t>
25-
2624
<t t-name="awesome_dashboard.ConfigurationDialog">
2725
<Dialog title="'Items configuration'">
2826
Which cards do you want to see?
2927
<t t-foreach="items" t-as="item" t-key="item.id">
3028
<CheckBox value="item.enabled" onChange="(e) => this.onChange(e, item)">
31-
<t t-esc="item.description"/>
29+
<t t-out="item.description"/>
3230
</CheckBox>
3331
</t>
3432
<t t-set-slot="footer">
35-
<button class="btn btn-primary" t-on-click="done">
33+
<button class="btn btn-primary" t-on-click="() => this.done()">
3634
Done
3735
</button>
3836
</t>
3937
</Dialog>
40-
</t>
41-
38+
</t>
4239
</templates>

0 commit comments

Comments
 (0)