Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion awesome_dashboard/static/src/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
import { Component } from "@odoo/owl";
import { Component, useState } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { Layout } from "@web/search/layout";
import { useService } from "@web/core/utils/hooks";
import { DashboardItem } from "./dashboardItem";
import { rpc } from "@web/core/network/rpc";
import { PieChart } from "./pieChart";


class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";
static components = { Layout, DashboardItem, PieChart };

setup() {
this.action = useService("action");
this.state = useState(useService("statistics"));
}

async openCustomers() {

this.action.doAction({
type: 'ir.actions.act_window',
target: 'current',
res_model: 'res.partner',
views: [[false, 'kanban']],
});
}

async openLeads() {

this.action.doAction({
type: 'ir.actions.act_window',
target: 'current',
res_model: 'crm.lead',
views: [[false, 'list'], [false, 'kanban']],
});
}
}

registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
3 changes: 3 additions & 0 deletions awesome_dashboard/static/src/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.o_dashboard {
background-color: #f8f9fa;
}
61 changes: 58 additions & 3 deletions awesome_dashboard/static/src/dashboard.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,63 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.AwesomeDashboard">
hello dashboard
<Layout display="{ controlPanel: {} }" className="'o_dashboard h-100'">
<t t-set-slot="layout-buttons">
<button t-on-click="openCustomers" type="button" class="btn btn-primary">Customers</button>
<button t-on-click="openLeads" type="button" class="btn btn-primary">Leads</button>
</t>
<div class="d-flex flex-wrap">

<DashboardItem>
<t t-slot="default">
Number of new orders this month
<h4 class="text-success">
<t t-esc="state.nb_new_orders"/>
</h4>
</t>
</DashboardItem>
<DashboardItem size="1">
<t t-slot="default">
Total amount of new orders this month

<h4 class="text-success">
<t t-esc="state.total_amount"/>
</h4>
</t>
</DashboardItem>
<DashboardItem size="1">
<t t-slot="default">
Average amount of t-shirt by order this month
<h4 class="text-success">
<t t-esc="state?.average_quantity"/>
</h4>
</t>
</DashboardItem>
<DashboardItem size="1">
<t t-slot="default">
Number of cancelled orders this month
<h4 class="text-success">
<t t-esc="state?.nb_cancelled_orders"/>
</h4>
</t>
</DashboardItem>
<DashboardItem size="1">
<t t-slot="default">
Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’
<h4 class="text-success">
<t t-esc="state?.average_time"/>
</h4>
</t>
</DashboardItem>

<DashboardItem size="1">
<t t-slot="default">
<PieChart/>
</t>
</DashboardItem>

</div>
</Layout>
</t>

</templates>
12 changes: 12 additions & 0 deletions awesome_dashboard/static/src/dashboardItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component} from "@odoo/owl";


export class DashboardItem extends Component {
static template = "awesome_dashboard.DashboardItem";
static components = { };
static props = {
size: { type: Number, optional: true, default: 1 },
slots: { type: Object, optional: true },
};
}

11 changes: 11 additions & 0 deletions awesome_dashboard/static/src/dashboardItem.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.DashboardItem">
<div class="card m-2 " t-attf-style="width: #{props.size * 18}rem;">
<div class="card-body d-flex flex-column justify-content-center align-items-center" >
<t t-slot="default" />
</div>
</div>
</t>

</templates>
37 changes: 37 additions & 0 deletions awesome_dashboard/static/src/pieChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Component, onWillStart, useRef, useEffect } from "@odoo/owl";
import { loadJS } from "@web/core/assets";


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

setup() {
onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js"));
this.canvasRef = useRef("canvas");
const data ={
"m": 79,
"s": 90,
"xl": 49
}
useEffect(() => {

this.chart = new Chart(
this.canvasRef.el,
{
type: 'pie',
data: {
labels: Object.keys(data),
datasets: [{
data: Object.values(data)
}]
},
size: {
width: 1000,
height: 1000
}
}
)
});
}

}
10 changes: 10 additions & 0 deletions awesome_dashboard/static/src/pieChart.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.PieChart">
<div class="o_pie_chart">
<canvas t-ref="canvas"></canvas>
</div>

</t>

</templates>
20 changes: 20 additions & 0 deletions awesome_dashboard/static/src/statsService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { registry } from "@web/core/registry";
import { rpc } from "@web/core/network/rpc";
import { reactive } from "@odoo/owl";

const statistics = reactive({});

async function loadStatistics() {
const data = await rpc("/awesome_dashboard/statistics");
Object.assign(statistics, data);
}

export const statisticsService = {
start() {
loadStatistics();
setInterval(loadStatistics, 10000);
return statistics;
},
};

registry.category("services").add("statistics", statisticsService);
19 changes: 19 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, useState } from "@odoo/owl";

export class Card extends Component {
static template = "awesome_owl.card";
static props = {
title: { type: String },
slots: { type: Object, optional: true },
};

setup() {
this.state = useState({
isOpen: true,
});
}

onToggle() {
this.state.isOpen = !this.state.isOpen;
}
}
21 changes: 21 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.card">
<div class="card m-2">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="card-title m-0">
<t t-esc="props.title"/>
</h5>
<button class="btn btn-light ml-2" t-on-click="onToggle">Toggle</button>
</div>

<div class="card-body">
<div t-att-class="state.isOpen ? 'd-inline-block' : 'd-none'">
<t t-slot="default" />
</div>
</div>
</div>
</t>

</templates>
18 changes: 18 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, useState } from "@odoo/owl";

export class Counter extends Component {
static template = "awesome_owl.counter";
static props = {
onChange: { type: Function, optional: true },
};

setup() {
this.state = useState({
count: 0,
});
}

increment() {
this.props.onChange?.(++this.state.count);
}
}
13 changes: 13 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.counter">
<div>
<p>
<t t-esc="state.count"/>
</p>
<button class="btn" t-on-click="increment">Increment</button>
</div>
</t>

</templates>
17 changes: 16 additions & 1 deletion awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { Component } from "@odoo/owl";
import { Component, useState } from "@odoo/owl";
import { Counter } from "./counter/counter";
import { Card } from "./card/card";
import { TodoList } from "./todo/todoList";

export class Playground extends Component {
static template = "awesome_owl.playground";
static components = { Counter, Card, TodoList };

setup() {
this.state = useState({
sum: 0,
});
}

incrementSum(count) {
this.state.sum += 1;
}

}
21 changes: 18 additions & 3 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<div class="d-flex align-items-start gap-3 p-3">
<Card title="'Counters'">
<Card title="'Counter 1'">
<Counter onChange.bind="this.incrementSum"/>
</Card>
<Card title="'Counter 2'">
<Counter onChange.bind="this.incrementSum"/>
</Card>
<div>
<p>Sum: <t t-esc="state.sum"/>
</p>
</div>
</Card>

<Card title="'Todo List'">
<TodoList />
</Card>
</div>
</t>

Expand Down
15 changes: 15 additions & 0 deletions awesome_owl/static/src/todo/todoItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, markup } from "@odoo/owl";
import { Counter } from "../counter/counter";

export class TodoItem extends Component {
static template = "awesome_owl.todoItem";
static components = { Counter };
static props = {
id: { type: Number },
description: { type: String },
isCompleted: { type: Boolean},
toggleState: { type: Function, optional: true },
removeTodo: { type: Function, optional: true },
};

}
16 changes: 16 additions & 0 deletions awesome_owl/static/src/todo/todoItem.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.todoItem">
<div class="d-flex flex-row gap-2 justify-center align-items-center">
<input type="checkbox" t-att-checked="props.isCompleted" t-on-click="props.toggleState" />
<label t-att-class="{'text-muted text-decoration-line-through': props.isCompleted}">
<t t-esc="props.id" />
<span>.</span>
<t t-esc="props.description"/>
</label>
<span class="fa fa-remove" t-on-click=" props.removeTodo"/>
</div>
</t>

</templates>
Loading