Skip to content

Commit ced1c9f

Browse files
committed
[IMP] awesome_dashboard: added DashboardItem component.
added DashboardItem component. added slot props in DashboardItem and created a dynamic card in xml. added rpc call in onWillStart(). render all return values in it's separate card in dashboard.xml. added state as 'badge' widget in kanban view in estate module. refined garden onchange logic.
1 parent 8c73677 commit ced1c9f

File tree

18 files changed

+129
-44
lines changed

18 files changed

+129
-44
lines changed

awesome_dashboard/static/src/dashboard.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1-
import { Component } from "@odoo/owl";
1+
import { Component, onWillStart } from "@odoo/owl";
22
import { registry } from "@web/core/registry";
33
import { Layout } from "@web/search/layout";
44
import { useService } from "@web/core/utils/hooks";
5+
import { DashboardItem } from "./dashboarditem/dashboarditem";
6+
import { rpc } from "@web/core/network/rpc";
57

68
class AwesomeDashboard extends Component {
79
static template = "awesome_dashboard.AwesomeDashboard";
8-
static components = { Layout }
10+
static components = { Layout, DashboardItem }
911

1012
setup() {
1113
this.action = useService("action");
14+
onWillStart(async () => {
15+
this.result = await rpc("/awesome_dashboard/statistics");
16+
})
1217
}
1318

1419
openCustomers() {
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:rgb(27, 29, 38)
33
}

awesome_dashboard/static/src/dashboard.xml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<templates xml:space="preserve">
3+
34
<t t-name="awesome_dashboard.AwesomeDashboard">
45
<Layout className="'o_dashboard h-100'" display="{ controlPanel: {} }">
56
<t t-set-slot="control-panel-buttons">
@@ -10,7 +11,39 @@
1011
Leads
1112
</button>
1213
</t>
13-
<h1 style="color: black;">Hello World</h1>
14+
<div class="d-flex flex-wrap mt-1">
15+
<DashboardItem>
16+
<div class="text-center">
17+
Number of new orders this month
18+
<p t-out="this.result.nb_new_orders" class="fs-1 fw-bold text-success"/>
19+
</div>
20+
</DashboardItem>
21+
<DashboardItem>
22+
<div class="text-center">
23+
Total amount of new orders this month
24+
<p t-out="this.result.total_amount" class="fs-1 fw-bold text-success"/>
25+
</div>
26+
</DashboardItem>
27+
<DashboardItem>
28+
<div class="text-center">
29+
Average amount of t-shirt by order this month
30+
<p t-out="this.result.average_quantity" class="fs-1 fw-bold text-success"/>
31+
</div>
32+
</DashboardItem>
33+
<DashboardItem>
34+
<div class="text-center">
35+
Number of cancelled orders this month
36+
<p t-out="this.result.nb_cancelled_orders" class="fs-1 fw-bold text-success"/>
37+
</div>
38+
</DashboardItem>
39+
<DashboardItem>
40+
<div class="text-center">
41+
Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’
42+
<p t-out="this.result.average_time" class="fs-1 fw-bold text-success"/>
43+
</div>
44+
</DashboardItem>
45+
</div>
1446
</Layout>
1547
</t>
48+
1649
</templates>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class DashboardItem extends Component {
4+
static template = "awesome_dashboard.DashboardItem";
5+
6+
static props = {
7+
slots: {
8+
type: Object,
9+
shape: {
10+
default: Object,
11+
},
12+
},
13+
size: {
14+
type: Number,
15+
default: 1,
16+
optional: true,
17+
},
18+
};
19+
}
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 }}rem; border-radius: 16px;">
5+
<div class="card-body">
6+
<t t-slot="default"/>
7+
</div>
8+
</div>
9+
</t>
10+
</templates>

awesome_owl/static/src/card/card.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ export class Card extends Component {
55
static template = "awesome_owl.card";
66
static props = {
77
title: String,
8-
slots : {
8+
slots: {
99
type: Object,
1010
shape: {
1111
default: {}
1212
}
1313
}
1414
};
1515

16-
setup(){
16+
setup() {
1717
this.state = useState([{
1818
isOpen: false
1919
}])
2020
}
2121

22-
toggleCard(){
22+
toggleCard() {
2323
this.state.isOpen = !this.state.isOpen
2424
}
2525
}

awesome_owl/static/src/counter/counter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class Counter extends Component {
1313

1414
increment() {
1515
this.state.value++;
16-
if (this.props.onChange){
16+
if (this.props.onChange) {
1717
this.props.onChange(1);
1818
}
1919
}

awesome_owl/static/src/counter/counter.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<templates xml:space="preserve">
3+
34
<t t-name="awesome_owl.counter">
45
<div style="border: 2px solid black; border-radius: 12px; width: fit-content; padding: 10px;">
56
<p style="font-weight: bold;">Counter: <t t-esc="state.value"/></p>
@@ -21,4 +22,5 @@
2122
</button>
2223
</div>
2324
</t>
25+
2426
</templates>

awesome_owl/static/src/playground.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ export class Playground extends Component {
99
static components = { Counter, Card, TodoList };
1010

1111
setup() {
12-
this.state = useState({
12+
this.state = useState({
1313
content: markup('<h1>Welcome to your Counter!</h1>'),
1414
sum: 0
1515
});
1616
}
1717

1818
calculateSum(newValue) {
19-
if (newValue > 0){
19+
if (newValue > 0) {
2020
this.state.sum++;
21-
}
22-
if (newValue < 0){
21+
}
22+
if (newValue < 0) {
2323
this.state.sum--;
2424
}
2525
}
2626

27-
reset(){
27+
reset() {
2828
this.state.sum = 0
2929
}
3030
}

awesome_owl/static/src/playground.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<templates xml:space="preserve">
3+
34
<t t-name="awesome_owl.playground">
45
<t t-out="this.state.content"/>
56
<div style="display:flex; align-items:center; gap:12px;">
@@ -38,4 +39,5 @@
3839
</Card>
3940
</div>
4041
</t>
42+
4143
</templates>

0 commit comments

Comments
 (0)