Skip to content

Commit 5f12bed

Browse files
[IMP] awesome_owl: Web Framework Finished Chapter 2 Part 1-6
1 parent 5044748 commit 5f12bed

File tree

9 files changed

+165
-4
lines changed

9 files changed

+165
-4
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class DashboardItem extends Component {
4+
static template = "awesome_dashboard.DashboardItem";
5+
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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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 border-dark" t-attf-style='width: {{18*props.size}}px'>
5+
<t t-slot="default" class="card-text"/>
6+
</div>
7+
</t>
8+
</templates>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { loadJS } from "@web/core/assets";
2+
import { Component, onWillStart, useRef,onMounted,onPatched,onWillUnmount} from "@odoo/owl";
3+
4+
export class PieChart extends Component
5+
{
6+
static template = "awesome_dashboard.PieChart"
7+
static props = {
8+
label : String,
9+
data : Object
10+
}
11+
setup()
12+
{
13+
this.canvasRef = useRef("canvas");
14+
onWillStart(()=> loadJS("/web/static/lib/Chart/Chart.js"))
15+
16+
onMounted(()=> {this.renderChart();});
17+
18+
onPatched(() =>{
19+
this.chart.destroy();
20+
this.renderChart();
21+
});
22+
23+
onWillUnmount(()=> {this.chart.destroy();});
24+
}
25+
26+
renderChart()
27+
{
28+
console.log(this.props.data)
29+
console.log(this.props.label)
30+
this.chart = new Chart(this.canvasRef.el,
31+
{
32+
type: 'doughnut',
33+
data:{
34+
labels:Object.keys(this.props.data),
35+
datasets: [
36+
{
37+
data: Object.values(this.props.data),
38+
label: this.props.label
39+
}
40+
]
41+
}
42+
43+
});
44+
}
45+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_dashboard.PieChart">
4+
<canvas t-ref="canvas"/>
5+
</t>
6+
</templates>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 statistics = {
6+
dependencies: [],
7+
start(env) {
8+
return {
9+
loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics"))
10+
};
11+
}
12+
};
13+
14+
registry.category("services").add("awsome_dashboard.statistics",statistics)
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,38 @@
1-
import { Component } from "@odoo/owl";
1+
import { Component, onWillStart, useState} 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";
6+
import { PieChart } from "./PieChart/PieChart";
37

48
class AwesomeDashboard extends Component {
59
static template = "awesome_dashboard.AwesomeDashboard";
10+
static components = { Layout , DashboardItem, PieChart};
11+
12+
setup()
13+
{
14+
this.action = useService("action");
15+
const statistics = useService("awsome_dashboard.statistics")
16+
onWillStart(async ()=>
17+
{
18+
this.result = await statistics.loadStatistics();
19+
console.log(this.result);
20+
});
21+
}
22+
openCustomers()
23+
{
24+
this.action.doAction("base.action_partner_form")
25+
}
26+
openLeads()
27+
{
28+
this.action.doAction(({
29+
type: 'ir.actions.act_window',
30+
name: "All leads",
31+
res_model: 'account.move',
32+
views: [[0,'list'],[1,'form']]
33+
}));
34+
}
635
}
736

837
registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
38+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.o_dashboard{
2+
background-color: rgb(255, 209, 122);
3+
4+
}
5+
.o_text{
6+
align-self: center;
7+
}
Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<templates xml:space="preserve">
3-
43
<t t-name="awesome_dashboard.AwesomeDashboard">
5-
hello dashboard
4+
<Layout display="{controlPanel: {}}" className="'o_dashboard h-100'">
5+
<t t-set-slot="layout-buttons">
6+
<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>
9+
</div>
10+
</t>
11+
<div class="d-flex flex-warp">
12+
<DashboardItem size="50">
13+
<h2 class="card-text o_text"> Average amount of t-shirt by order this month</h2>
14+
<t t-esc="result.average_quantity"/>
15+
</DashboardItem>
16+
<DashboardItem size="50">
17+
<h2 class="card-text"> Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’</h2>
18+
<t t-esc="result.average_time"/>
19+
</DashboardItem>
20+
<DashboardItem size="25">
21+
<h2 class="card-text">Number of cancelled orders this month</h2>
22+
<t t-esc="result.nb_cancelled_orders"/>
23+
</DashboardItem>
24+
<DashboardItem size="25">
25+
<h2 class="card-text">Number of new orders this month</h2>
26+
<t t-esc="result.nb_new_orders"/>
27+
</DashboardItem>
28+
<DashboardItem size="75">
29+
<h2 class="card-text">Total amount of new orders this month</h2>
30+
<t t-esc="result.total_amount"/>
31+
</DashboardItem>
32+
<DashboardItem>Test</DashboardItem>
33+
</div>
34+
<DashboardItem size="35">
35+
<PieChart data="result.orders_by_size" label="'Shirt by size'"/>
36+
</DashboardItem>
37+
</Layout>
38+
639
</t>
740

841
</templates>

awesome_owl/static/src/playground.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, useState, markup } from "@odoo/owl";
22
import { Counter } from "./counter/counter";
33
import { Card } from "./card/card";
4-
import { TodoList } from "./TodoList/TodoList"
4+
import { TodoList } from "./TodoList/TodoList";
55

66
export class Playground extends Component {
77
static template = "awesome_owl.playground";

0 commit comments

Comments
 (0)