Skip to content

Commit bce86ab

Browse files
committed
[FIX] awesome_dashboard: run prettier
1 parent 9842f55 commit bce86ab

22 files changed

+154
-151
lines changed

awesome_dashboard/static/src/dashboard/configuration_dialog.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,32 @@ import { Dialog } from "@web/core/dialog/dialog";
33
import { CheckBox } from "@web/core/checkbox/checkbox";
44

55
export class ConfigurationDialog extends Component {
6-
static template = "awesome_dashboard.ConfigurationDialog"
7-
static components = { Dialog, CheckBox }
6+
static template = "awesome_dashboard.ConfigurationDialog";
7+
static components = { Dialog, CheckBox };
88
static props = {
9-
items: [Array],
10-
close: [{}],
11-
onApply: [Function]
12-
}
9+
items: Array,
10+
close: {},
11+
onApply: Function,
12+
};
1313

1414
setup() {
15-
this.disabledElements = this.props.items.filter(item => !item.enabled)
16-
.map(item => item.element.id)
15+
this.disabledElements = this.props.items
16+
.filter((item) => !item.enabled)
17+
.map((item) => item.element.id);
1718
}
1819

1920
onChange(id) {
20-
let index = this.disabledElements.indexOf(id)
21-
if(index === -1) {
22-
this.disabledElements.push(id)
21+
let index = this.disabledElements.indexOf(id);
22+
if (index === -1) {
23+
this.disabledElements.push(id);
2324
return;
2425
}
25-
this.disabledElements.splice(index, 1)
26+
this.disabledElements.splice(index, 1);
2627
}
2728

2829
apply() {
29-
localStorage.setItem('disabledElements', this.disabledElements)
30+
localStorage.setItem("disabledElements", this.disabledElements);
3031
this.props.onApply();
31-
this.props.close()
32+
this.props.close();
3233
}
3334
}

awesome_dashboard/static/src/dashboard/dashboard.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,59 @@ import { DashboardItem } from "./dashboard_item";
99
import { PieChart } from "./pie_chart/pie_chart";
1010
import { ConfigurationDialog } from "./configuration_dialog";
1111

12-
1312
class AwesomeDashboard extends Component {
1413
static template = "awesome_dashboard.AwesomeDashboard";
1514
static components = { Layout, DashboardItem, PieChart };
1615

1716
setup() {
1817
this.action = useService("action");
1918
this.statistics = useService("awesome_dashboard.statistics");
20-
this.state = useState({items: [], stats: this.statistics});
19+
this.state = useState({ items: [], stats: this.statistics });
2120
this.dialog = useService("dialog");
22-
this.updateDashboard()
21+
this.updateDashboard();
2322
}
2423

2524
updateDashboard() {
26-
let disabledElements = localStorage.getItem('disabledElements') || '';
27-
if(disabledElements.includes(',')) {
28-
disabledElements = disabledElements.split(',')
29-
}
30-
else{
31-
disabledElements = [disabledElements]
25+
const disabledElementsString = localStorage.getItem("disabledElements") || "";
26+
let disabledElementsList
27+
if (disabledElementsString.includes(",")) {
28+
disabledElementsList = disabledElementsString.split(",");
29+
} else {
30+
disabledElementsList = [disabledElementsString];
3231
}
33-
this.state.items = registry.category("awesome_dashboard")
32+
this.state.items = registry
33+
.category("awesome_dashboard")
3434
.getAll()
35-
.filter(el => !disabledElements.some((e) => e == el.id ))
35+
.filter((el) => !disabledElementsList.some((e) => e == el.id));
3636
}
3737

3838
openCustomers() {
39-
this.action.doAction('base.action_partner_form')
39+
this.action.doAction("base.action_partner_form");
4040
}
4141

4242
openLeads() {
4343
this.action.doAction({
44-
type: 'ir.actions.act_window',
45-
name: _t('Leads'),
46-
res_model: 'crm.lead',
47-
views: [[false, 'list'], [false, 'form']]
48-
})
44+
type: "ir.actions.act_window",
45+
name: _t("Leads"),
46+
res_model: "crm.lead",
47+
views: [
48+
[false, "list"],
49+
[false, "form"],
50+
],
51+
});
4952
}
5053

5154
customizeDashboard() {
52-
let items = []
5355
let all = registry.category("awesome_dashboard").getAll();
54-
all.forEach(el => {
55-
const enabled = this.state.items.some(item => item.id == el.id)
56-
items.push({
57-
element: el,
58-
enabled: enabled
59-
})
60-
})
6156

6257
this.dialog.add(ConfigurationDialog, {
63-
items: items,
64-
onApply: this.updateDashboard.bind(this)
65-
})
58+
items: all.map(item => ({
59+
element: item,
60+
enabled: this.state.items.some((element) => item.id == element.id)
61+
}))
62+
,
63+
onApply: this.updateDashboard.bind(this),
64+
});
6665
}
6766
}
6867

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.o_dashboard {
2-
background-color: gray;
2+
background-color: gray;
33
}

awesome_dashboard/static/src/dashboard/dashboard.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
<t t-foreach="state.items" t-as="item" t-key="item.id">
1515
<DashboardItem size="item.size || 1">
1616
<t t-set="itemProp" t-value="item.props
17-
? item.props(state.stats)
18-
: {'data': state.stats}" />
17+
? item.props(state.stats)
18+
: {'data': state.stats}"
19+
/>
1920
<t t-component="item.Component" t-props="itemProp" />
2021
</DashboardItem>
2122
</t>
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { Component } from "@odoo/owl";
22

33
export class DashboardItem extends Component {
4-
static template = "awesome_dashboard.DashboardItem"
4+
static template = "awesome_dashboard.DashboardItem";
55

66
static props = {
7-
'size': {type: Number, optional: true },
8-
'slots': {}
9-
}
7+
size: { type: Number, optional: true },
8+
slots: {},
9+
};
1010

11-
setup() {
12-
if(!this.props.size) {
13-
this.props.size = 1
14-
}
11+
static defaultProps = {
12+
size: 1
1513
}
1614
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
h1 {
2-
color: green;
2+
color: green;
33
}

awesome_dashboard/static/src/dashboard/dashboard_items.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { registry } from "@web/core/registry";
33
import { PieChartCard } from "./pie_chart_card";
44
import { _t } from "@web/core/l10n/translation";
55

6-
76
const items = [
87
{
98
id: "average_quantity",
@@ -12,18 +11,20 @@ const items = [
1211
size: 1,
1312
props: (data) => ({
1413
title: _t("Average amount of t-shirt by order this month"),
15-
value: data.average_quantity
16-
})
14+
value: data.average_quantity,
15+
}),
1716
},
1817
{
1918
id: "average_time",
2019
description: _t("Average time for orders"),
2120
Component: NumberCard,
2221
size: 1,
2322
props: (data) => ({
24-
title: _t("Average time for an order to go from 'new' to 'sent' or 'cancelled'"),
25-
value: data.average_time
26-
})
23+
title: _t(
24+
"Average time for an order to go from 'new' to 'sent' or 'cancelled'",
25+
),
26+
value: data.average_time,
27+
}),
2728
},
2829
{
2930
id: "nb_new_orders",
@@ -32,8 +33,8 @@ const items = [
3233
size: 1,
3334
props: (data) => ({
3435
title: _t("Number of new orders this month"),
35-
value: data.nb_new_orders
36-
})
36+
value: data.nb_new_orders,
37+
}),
3738
},
3839
{
3940
id: "nb_cancelled_orders",
@@ -42,8 +43,8 @@ const items = [
4243
size: 1,
4344
props: (data) => ({
4445
title: _t("Number of cancelled orders this month"),
45-
value: data.nb_cancelled_orders
46-
})
46+
value: data.nb_cancelled_orders,
47+
}),
4748
},
4849
{
4950
id: "total_amount",
@@ -52,8 +53,8 @@ const items = [
5253
size: 1,
5354
props: (data) => ({
5455
title: _t("Total amount of new orders this month"),
55-
value: data.total_amount
56-
})
56+
value: data.total_amount,
57+
}),
5758
},
5859
{
5960
id: "orders_by_size",
@@ -62,11 +63,11 @@ const items = [
6263
size: 2,
6364
props: (data) => ({
6465
title: _t("Shirt orders by size"),
65-
value: data.orders_by_size
66-
})
66+
value: data.orders_by_size,
67+
}),
6768
},
68-
]
69+
];
6970

70-
for(let item of items) {
71+
for (let item of items) {
7172
registry.category("awesome_dashboard").add(item.id, item);
7273
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Component, xml } from "@odoo/owl"
1+
import { Component, xml } from "@odoo/owl";
22

3-
export class NumberCard extends Component{
3+
export class NumberCard extends Component {
44
static template = xml`
55
<p><t t-esc="props.title" /></p>
66
<h1><b><t t-esc="props.value" /></b></h1>
7-
`
7+
`;
88
static props = {
9-
title: [String],
10-
value: [String, Number]
11-
}
9+
title: String,
10+
value: [String, Number],
11+
};
1212
}
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
import { Component, onWillStart, useEffect, useRef } from "@odoo/owl"
2-
import { loadJS } from "@web/core/assets"
1+
import { Component, onWillStart, useRef, onMounted } from "@odoo/owl";
2+
import { loadJS } from "@web/core/assets";
33

44
export class PieChart extends Component {
55
static template = "awesome_dashboard.PieChart";
66

77
static props = {
8-
'data':{optional: false},
9-
'size': {type: Number, optional: true}
10-
}
8+
data: { },
9+
size: { type: Number, optional: true },
10+
};
1111

1212
setup() {
1313
onWillStart(() => loadJS(["/web/static/lib/Chart/Chart.js"]));
14-
this.ctx = useRef('pieChart')
15-
this.chart = null
16-
useEffect(() => {
17-
if(this.chart) {
18-
this.chart.destroy()
14+
this.ctx = useRef("pieChart");
15+
this.chart = null;
16+
onMounted(() => {
17+
if (this.chart) {
18+
this.chart.destroy();
1919
}
2020
const dataset = {
2121
labels: Object.keys(this.props.data),
22-
datasets: [{
23-
data: Object.values(this.props.data)
24-
}]
25-
}
26-
this.chart = new Chart(this.ctx.el, {type: 'pie', data: dataset})
27-
})
22+
datasets: [
23+
{
24+
data: Object.values(this.props.data),
25+
},
26+
],
27+
};
28+
this.chart = new Chart(this.ctx.el, { type: "pie", data: dataset });
29+
});
2830
}
2931
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { Component, xml } from "@odoo/owl";
22
import { PieChart } from "./pie_chart/pie_chart";
33

4-
export class PieChartCard extends Component{
4+
export class PieChartCard extends Component {
55
static components = { PieChart };
66
static props = {
7-
title: [String],
8-
value: [Object]
9-
}
7+
title: String,
8+
value: Object,
9+
};
1010

1111
static template = xml`
1212
<p><t t-esc="props.title" /></p>
1313
<PieChart data="props.value" />
14-
`
14+
`;
1515
}

0 commit comments

Comments
 (0)