Skip to content

Commit 051470d

Browse files
[IMP] awsome_owl: Framework Finished Chapter 7-12
1 parent 3507035 commit 051470d

File tree

9 files changed

+124
-31
lines changed

9 files changed

+124
-31
lines changed

awesome_dashboard/static/src/dashboard/ChartCard/ChartCard.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export class ChartCard extends Component {
88
static props = {
99
title: String,
1010
label : String,
11-
data : Object,
11+
data : {type : Object, optional: true},
1212
}
1313
}

awesome_dashboard/static/src/dashboard/NumberCard/NumberCard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export class NumberCard extends Component {
33
static template = "awesome_dashboard.NumberCard";
44
static components = { };
55
static props = {
6-
title: String,
7-
value: Number
6+
title: {type : String, optional: true},
7+
value: { type: Number, optional: true}
88
};
99
}

awesome_dashboard/static/src/dashboard/PieChart/PieChart.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { loadJS } from "@web/core/assets";
2+
import { useService } from "@web/core/utils/hooks";
23
import { Component, onWillStart, useRef,onMounted,onPatched,onWillUnmount} from "@odoo/owl";
34

45
export class PieChart extends Component
56
{
67
static template = "awesome_dashboard.PieChart"
78
static props = {
89
label : String,
9-
data : Object
10+
data : {type : Object, optional: true},
1011
}
1112
setup()
1213
{
1314
this.canvasRef = useRef("canvas");
15+
this.action = useService("action");
1416
onWillStart(()=> loadJS("/web/static/lib/Chart/Chart.js"))
1517

1618
onMounted(()=> {this.renderChart();});
@@ -36,8 +38,52 @@ export class PieChart extends Component
3638
label: this.props.label
3739
}
3840
]
39-
}
41+
},
42+
options: {
43+
responsive: true,
44+
onClick: (e) =>{
45+
const activePoints = this.chart.getElementsAtEventForMode(e, 'nearest', {
46+
intersect: true
47+
}, false);
48+
if (activePoints.length > 0) {
49+
const index = activePoints[0].index;
50+
const label = this.chart.data.labels[index];
51+
const value = this.chart.data.datasets[0].data[index];
52+
this.onClick(label)
53+
}
54+
}
55+
// events: ['click'],
56+
},
57+
// plugins: [{
58+
// id: 'custome_plugin',
59+
// afterEvent(chart, args, pluginOptions)
60+
// {
61+
// // this.onClick(chart.tooltip.title)
62+
// console.log(args);
63+
// import { useService } from "@web/core/utils/hooks";
64+
// this.action = useService("action");
65+
// // this.action.doAction(({
66+
// // type: 'ir.actions.act_window',
67+
// // name: "All leads",
68+
// // res_model: 'account.move',
69+
// // views: [[0,'list'],[1,'form']]
70+
// // }));
71+
// }
72+
// }]
4073

4174
});
75+
76+
}
77+
onClick(title)
78+
{
79+
this.action.doAction(({
80+
type: 'ir.actions.act_window',
81+
name: "Sales Order",
82+
res_model: 'sale.order',
83+
//domain: [["order_line.product_id.name", "=", "Shirt"]],
84+
domain: [["order_line.product_id.product_template_variant_value_ids.product_attribute_value_id.display_name", "=", title]],
85+
views: [[0,'list'],[1,'form']]
86+
}));
4287
}
88+
4389
}
Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
import { Component} from "@odoo/owl";
1+
import { Component, useState} from "@odoo/owl";
22
import { Dialog } from "@web/core/dialog/dialog";
3+
import { registry } from "@web/core/registry";
4+
import { browser } from "@web/core/browser/browser";
5+
import {CheckBox} from "@web/core/checkbox/checkbox";
36

47
export class SettingsDialog extends Component
58
{
69
static template = "awesome_dashboard.SettingsDialog";
7-
static components = {Dialog}
8-
static props = {}
10+
static components = {Dialog, CheckBox}
11+
static props = ['close','disabled','items','OnChange'];
912

1013
setup()
1114
{
12-
console.log("dialogue open");
15+
console.log(this.props.disabled);
16+
this.items = useState(this.props.items.map((item) =>
17+
{
18+
return {
19+
...item,
20+
enabled: !this.props.disabled.includes(item.id),
21+
}
22+
}))
1323
}
1424
done()
1525
{
1626
this.props.close();
1727
}
28+
onChange(state, item)
29+
{
30+
item.enabled = state;
31+
const updateDisabled = Object.values(this.items).filter(
32+
(item) => !item.enabled
33+
).map((item) => item.id)
34+
35+
browser.localStorage.setItem("disabledDashboardItems",updateDisabled);
36+
this.props.OnChange(updateDisabled);
37+
}
1838
}
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<templates xml:space="preserve">
33
<t t-name="awesome_dashboard.SettingsDialog">
4-
<div height="20">
5-
<h1> Test Dialogue</h1>
6-
<button t-on-click="done">Done</button>
7-
</div>
4+
<Dialog title="Settings">
5+
6+
<t t-foreach="items" t-as="item" t-key="item.id">
7+
<div>
8+
<CheckBox value="item.enabled" onChange="(ev) =>this.onChange(ev,item)">
9+
<t t-esc="item.description"/>
10+
</CheckBox>
11+
</div>
12+
</t>
13+
<t t-set-solt="footer">
14+
<button class="btn btn-primary" t-on-click="done">Done</button>
15+
</t>
16+
</Dialog>
817
</t>
918
</templates>

awesome_dashboard/static/src/dashboard/dashboard.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import {_t } from "@web/core/l10n/translation";
12
import { Component, onWillStart, useState} from "@odoo/owl";
23
import { registry } from "@web/core/registry";
34
import { Layout } from "@web/search/layout";
45
import { useService } from "@web/core/utils/hooks";
56
import { DashboardItem } from "./DashboardItem/DashboardItem";
67
import { PieChart } from "./PieChart/PieChart";
78
import { SettingsDialog } from "./SettingsDialog/SettingsDialog";
9+
import { browser } from "@web/core/browser/browser";
810

911
class AwesomeDashboard extends Component {
1012
static template = "awesome_dashboard.AwesomeDashboard";
@@ -16,6 +18,9 @@ class AwesomeDashboard extends Component {
1618
this.result = useState(useService("awesome_dashboard.statistics"));
1719
this.items = registry.category("awesome_dashboard").getAll();
1820
this.dialog = useService("dialog");
21+
this.state = useState({disabledItems : browser.localStorage.getItem("disabledDashboardItems")?.split(",")||[]});
22+
this.Customer = _t("Customer");
23+
this.Leads = _t("Leads");
1924

2025
}
2126
openCustomers()
@@ -33,7 +38,15 @@ class AwesomeDashboard extends Component {
3338
}
3439
openSettings()
3540
{
36-
this.dialog.add(SettingsDialog, {})
41+
this.dialog.add(SettingsDialog, {
42+
disabled:this.state.disabledItems,
43+
items:this.items,
44+
OnChange:this.updateSettings.bind(this),
45+
})
46+
}
47+
updateSettings(disabledItems)
48+
{
49+
this.state.disabledItems = disabledItems;
3750
}
3851
}
3952

awesome_dashboard/static/src/dashboard/dashboard.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
}
55
.o_text{
66
align-self: center;
7-
}
7+
}
8+
.o_settings_text
9+
{
10+
padding-left: 15px;
11+
}

awesome_dashboard/static/src/dashboard/dashboard.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<Layout display="{controlPanel: {}}" className="'o_dashboard h-100'">
55
<t t-set-slot="layout-buttons">
66
<div class="d-flex flex-warp">
7-
<button class="btn btn-primary" t-on-click="openCustomers">Customers</button>
8-
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
7+
<button class="btn btn-primary" t-on-click="openCustomers"><t t-esc="Customer"/></button>
8+
<button class="btn btn-primary" t-on-click="openLeads"><t t-esc="Leads"/></button>
99
</div>
1010
</t>
1111
<t t-set-slot="control-panel-additional-actions">
@@ -15,7 +15,7 @@
1515
</t>
1616
<div class="flex-d flex-warp">
1717
<t t-foreach="items" t-as="item" t-key="item.id">
18-
<DashboardItem size="item.size || 10">
18+
<DashboardItem t-if="!state.disabledItems.includes(item.id)" size="item.size || 10">
1919
<t t-set="itemProp" t-value="item.props ? item.props(result) : {'data': result}"/>
2020
<t t-component="item.Component" t-props="itemProp" />
2121
</DashboardItem>

awesome_dashboard/static/src/dashboard/dashboard_items.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,66 @@
1+
import { _t } from "@web/core/l10n/translation";
12
import { ChartCard } from "./ChartCard/ChartCard";
23
import { NumberCard } from "./NumberCard/NumberCard";
34
import { registry } from "@web/core/registry";
45

56
const items = [
67
{
78
id:"avg_amount",
8-
description: "Average amount of t-shirt by order this month",
9+
description: _t("Average amount of t-shirt by order this month"),
910
Component : NumberCard,
1011
size: 35,
1112
props: (data) => ({
12-
title: "Average amount of t-shirt by order this month",
13+
title: _t("Average amount of t-shirt by order this month"),
1314
value: data.average_quantity,
1415
})
1516
},
1617
{
1718
id:"avg_time",
18-
description: "Average time for an order",
19+
description: _t("Average time for an order"),
1920
Component : NumberCard,
2021
size: 35,
2122
props: (data) => ({
22-
title: "Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’",
23+
title: _t("Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’"),
2324
value: data.average_time
2425
})
2526
},
2627
{
2728
id:"nb_cancelled_orders",
28-
description: "Number of cancelled orders this month",
29+
description: _t("Number of cancelled orders this month"),
2930
Component : NumberCard,
3031
size: 25,
3132
props: (data) => ({
32-
title: "Number of cancelled orders this month",
33+
title: _t("Number of cancelled orders this month"),
3334
value: data.nb_cancelled_orders
3435
})
3536
},
3637
{
3738
id:"nb_new_orders",
38-
description: "Number of new orders this month",
39+
description: _t("Number of new orders this month"),
3940
Component : NumberCard,
4041
props: (data) => ({
41-
title: "Number of new orders this month",
42+
title: _t("Number of new orders this month"),
4243
value: data.nb_new_orders
4344
})
4445
},
4546
{
4647
id:"total_amount",
47-
description: "Total amount of new orders this month",
48+
description: _t("Total amount of new orders this month"),
4849
Component : NumberCard,
4950
size: 45,
5051
props: (data) => ({
51-
title: "Total amount of new orders this month",
52+
title: _t("Total amount of new orders this month"),
5253
value: data.total_amount
5354
})
5455
},
5556
{
5657
id:"orders_by_size",
57-
description: "Shirt by size",
58+
description: _t("Shirt by size"),
5859
Component : ChartCard,
5960
size: 25,
6061
props: (data) => ({
61-
title: "Shirt by size",
62-
label : "Shirt by size",
62+
title: _t("Shirt by size"),
63+
label : _t("Shirt by size"),
6364
data : data.orders_by_size,
6465
})
6566
},

0 commit comments

Comments
 (0)