Skip to content

Commit bc8b5a3

Browse files
committed
[ADD] awesome_dashboard: Adding JS - from chapter 1 to chapter 5
1 parent 17880f0 commit bc8b5a3

8 files changed

Lines changed: 139 additions & 2 deletions

File tree

2.22 MB
Loading
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class DashboardItem extends Component {
4+
static template = "awesome_dashboard.dashboardItem";
5+
static props = {
6+
size: { type: Number, default: 1, optional: true }
7+
};
8+
9+
get cardStyle() {
10+
const width = 18 * this.props.size;
11+
return `width: ${width}rem;`;
12+
}
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.o_dashboard_item {
2+
background: white;
3+
border-radius: 10px;
4+
padding: 16px;
5+
margin: 8px;
6+
opacity: 0.9;
7+
display: flex;
8+
flex-direction: column;
9+
align-items: center;
10+
justify-content: center;
11+
}
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+
4+
<t t-name="awesome_dashboard.dashboardItem">
5+
<div class="o_dashboard_item" t-att-style="cardStyle">
6+
<t t-slot="default" />
7+
</div>
8+
</t>
9+
10+
</templates>
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
1-
import { Component } from "@odoo/owl";
1+
import { Component, onWillStart } from "@odoo/owl";
22
import { registry } from "@web/core/registry";
3+
import { Layout } from "@web/search/layout";
4+
import { useService } from "@web/core/utils/hooks";
5+
import { DashboardItem } from "./DashboardItem/dashboarditem";
36

47
class AwesomeDashboard extends Component {
58
static template = "awesome_dashboard.AwesomeDashboard";
9+
static components = { Layout, DashboardItem };
10+
11+
setup() {
12+
this.actionService = useService("action");
13+
this.statisticsService = useService("awesome_dashboard.statistics");
14+
15+
onWillStart(async () => {
16+
const result = await this.statisticsService.loadStatistics();
17+
this.average_quantity = result.average_quantity;
18+
this.average_time = result.average_time;
19+
this.nb_cancelled_orders = result.nb_cancelled_orders;
20+
this.nb_new_orders = result.nb_new_orders;
21+
this.total_amount = result.total_amount;
22+
});
23+
24+
}
25+
26+
openCustomers() {
27+
this.actionService.doAction("base.action_partner_form");
28+
}
29+
30+
openLeads() {
31+
this.actionService.doAction({
32+
type: "ir.actions.act_window",
33+
name: "Leads",
34+
res_model: "crm.lead",
35+
views: [[false, "list"], [false, "form"]],
36+
});
37+
}
38+
639
}
740

841
registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.o_dashboard {
2+
background-image: url("/awesome_dashboard/static/img/dashboard_bg.jpg");
3+
background-repeat: no-repeat;
4+
background-position: center;
5+
background-size: cover;
6+
}
7+
8+
.o_dashboard_row {
9+
display: flex;
10+
flex-wrap: wrap;
11+
justify-content: center;
12+
}
13+
14+
.o_header_dashboard_item {
15+
font-size: 1.5em;
16+
}
17+
18+
.o_average_quantity {
19+
font-size: 2em;
20+
color: #008528;
21+
font-weight: bold;
22+
}

awesome_dashboard/static/src/dashboard.xml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,38 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_dashboard.AwesomeDashboard">
5-
hello dashboard
5+
<Layout className="'o_dashboard h-100'" display="{ controlPanel: {} }">
6+
<button type="button" class="btn btn-primary m-3" t-on-click="openCustomers">Customers</button>
7+
<button type="button" class="btn btn-primary m-3" t-on-click="openLeads">Leads</button>
8+
9+
<div class="o_dashboard_row">
10+
<DashboardItem>
11+
<p class="o_header_dashboard_item">Average amount of t-shirt by order this moth</p>
12+
<p class="o_average_quantity"><t t-esc="average_quantity"/></p>
13+
</DashboardItem>
14+
15+
<DashboardItem>
16+
<p class="o_header_dashboard_item">Average time for an order to go from 'new' to 'send' r 'cancelled'</p>
17+
<p class="o_average_quantity"><t t-esc="average_time"/></p>
18+
</DashboardItem>
19+
20+
<DashboardItem>
21+
<p class="o_header_dashboard_item">Number of new order this month</p>
22+
<p class="o_average_quantity"><t t-esc="nb_new_orders"/></p>
23+
</DashboardItem>
24+
25+
<DashboardItem>
26+
<p class="o_header_dashboard_item">Number of new cancelled order this month</p>
27+
<p class="o_average_quantity"><t t-esc="nb_cancelled_orders"/></p>
28+
</DashboardItem>
29+
30+
<DashboardItem>
31+
<p class="o_header_dashboard_item">Total amount of new orders this month</p>
32+
<p class="o_average_quantity"><t t-esc="total_amount"/></p>
33+
</DashboardItem>
34+
35+
</div>
36+
</Layout>
637
</t>
738

839
</templates>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { registry } from "@web/core/registry";
2+
import { rpc } from "@web/core/network/rpc";
3+
import { memoize } from "@web/core/utils/functions";
4+
5+
const loadStatistics = memoize(async () => {
6+
return rpc("/awesome_dashboard/statistics", {});
7+
});
8+
9+
export const statisticsService = {
10+
start() {
11+
return {
12+
loadStatistics,
13+
};
14+
},
15+
};
16+
17+
registry.category("services").add("awesome_dashboard.statistics", statisticsService);

0 commit comments

Comments
 (0)