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
22 changes: 22 additions & 0 deletions awesome_dashboard/static/src/core/statistics_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { memoize } from "@web/core/utils/functions";
import { registry } from "@web/core/registry";
import { rpc } from "@web/core/network/rpc";
import { reactive } from "@odoo/owl";

export const statistics = {
async start() {
const data = reactive({statistics: await rpc("/awesome_dashboard/statistics")})

setInterval(async () => {
const getStatistics = await rpc("/awesome_dashboard/statistics");
data.statistics = getStatistics;
console.log(data)
}, 1_000*10)

return {
data: data
}
}
}

registry.category("services").add("statistics", statistics)
42 changes: 41 additions & 1 deletion awesome_dashboard/static/src/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
import { Component } from "@odoo/owl";
import { Component, onWillStart, useEffect, 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 "./dashboard_item/dashboardItem";
import { PieChart } from "./pie_chart/pieChart"

class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";

static components = { Layout, DashboardItem, PieChart };

setup() {
this.action = useService("action");
const statistics = useService("statistics");

this.statisticsData = useState(statistics.data);


const updateData = ((data) => {
this.result = data

this.data = Object.entries(data.orders_by_size).map(([key, value]) => ({
label: key,
value: value
}));
}).bind(this)

onWillStart(() => {
updateData(this.statisticsData.statistics)
})

useEffect(updateData, () => [this.statisticsData.statistics])
}
openCustomers() {
this.action.doAction("base.action_partner_form");
}

openLeads(){
this.action.doAction({
type: "ir.actions.act_window",
views: [[false, "list"], [false, 'form']],
res_model: "crm.lead",
})
}
}

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: #edfffb;
}
41 changes: 38 additions & 3 deletions awesome_dashboard/static/src/dashboard.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
<?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="control-panel-create-button">
<button class="btn btn-primary" t-on-click.stop.prevent="() => this.openCustomers()">
Customers
</button>
<button class="btn btn-primary" t-on-click.stop.prevent="() => this.openLeads()">
Leads
</button>
</t>
<div>
<DashboardItem size="1.2">
<span style="text-align: center; display:block;">Average amount of t-shirt by order this month</span>
<span style="color: green; font-size:30px; text-align: center; display:block;"><t t-esc="result.average_quantity"/></span>
</DashboardItem>
<DashboardItem size="2">
<span style="text-align: center; display:block;">Average time for an order to go from 'new' to 'sent' or 'cancelled'</span>
<span style="color: green; font-size:30px; text-align: center; display:block;"><t t-esc="result.average_time"/></span>
</DashboardItem>
<DashboardItem>
<span style="text-align: center; display:block;">Number of new orders this month</span>
<span style="color: green; font-size:30px; text-align: center; display:block;"><t t-esc="result.nb_new_orders"/></span>
</DashboardItem>
<DashboardItem>
<span style="text-align: center; display:block;">Number of cancelled orders this month</span>
<span style="color: green; font-size:30px; text-align: center; display:block;"><t t-esc="result.nb_cancelled_orders"/></span>
</DashboardItem>
<DashboardItem>
<span style="text-align: center; display:block;">Total amount of new orders this month</span>
<span style="color: green; font-size:30px; text-align: center; display:block;"><t t-esc="result.total_amount"/></span>
</DashboardItem>
<DashboardItem size="2.5">
<span style="text-align: center; display:block;">Shirt orders by size</span>
<span style="color: green; font-size:30px; margin: auto; display:block; width:50%">
<PieChart label="'Shirts ordered'" data="data" />
</span>
</DashboardItem>
</div>
</Layout>
</t>

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

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

static props = {
size: {type: Number, optional: true},
slots: { type: Object, optional: true },
};

static defaultProps = {
size: 1,
}
}
10 changes: 10 additions & 0 deletions awesome_dashboard/static/src/dashboard_item/dashboardItem.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.DashboardItem">
<div class="card d-inline-block m-2" t-attf-style="width: {{18*props.size}}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>
</templates>
52 changes: 52 additions & 0 deletions awesome_dashboard/static/src/pie_chart/pieChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Component, onWillUnmount, useEffect, useRef, onWillStart } from "@odoo/owl";
import { loadJS } from "@web/core/assets";

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

static props = {
label: {type: String, optional: true},
data: { type: Array, element:{
type: Object, shape: {label: String, value: Number }
} },
};

setup() {
this.canvasRef = useRef("canvas");

this.chart = null;

onWillStart(() => loadJS(["/web/static/lib/Chart/Chart.js"]));

useEffect(() => this.renderChart());
onWillUnmount(this.onWillUnmount);
}

onWillUnmount() {
if (this.chart) {
this.chart.destroy();
}
}

getChartConfig() {
return {
type: "doughnut",
data: {
datasets: [{
data: this.props.data.map((element) => element.value),
label: this.props.label
}],
labels: this.props.data.map((element) => element.label),
}

}
}

renderChart() {
if (this.chart) {
this.chart.destroy();
}
const config = this.getChartConfig();
this.chart = new Chart(this.canvasRef.el, config);
}
}
6 changes: 6 additions & 0 deletions awesome_dashboard/static/src/pie_chart/pieChart.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.PieChart">
<canvas t-ref="canvas" />
</t>
</templates>
10 changes: 10 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from "@odoo/owl";

export class Card extends Component {
static template = "awesome_owl.Card";

static props = {
title: String,
content: String
};
}
12 changes: 12 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<templates xml:space="preserve">
<t t-name="awesome_owl.Card">
<div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title"><t t-out="props.title"/></h5>
<p class="card-text">
<t t-out="props.content"/>
</p>
</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({ value: 0 });
}

increment() {
this.state.value++;
if (this.props.onChange) this.props.onChange();
}
}
5 changes: 5 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<templates xml:space="preserve">
<t t-name="awesome_owl.Counter">
<p>Counter: <t t-esc="state.value"/> <button class="btn btn-primary" t-on-click="increment">Increment</button></p>
</t>
</templates>
18 changes: 17 additions & 1 deletion awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { Component } from "@odoo/owl";
import { Component, markup, useState } from "@odoo/owl";
import { Counter } from "./counter/counter";
import { Card } from "./card/card";
import { TodoList } from "./todoList/todoList";

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

value2 = markup("<a href='http://odoo.com'>Test</a>");

setup() {
this.total = useState({ value: 0 });
}

incrementSum() {
console.log("aaa")
this.total.value++;
}

static components = { Counter, Card, TodoList };
}
9 changes: 6 additions & 3 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
hello world <t t-esc="total.value" />
</div>
<Counter onChange.bind="incrementSum" />
<Counter onChange.bind="incrementSum" />
<Card title="'Card 1'" content="'content of card 1'"/>
<Card title="'Card 2'" content="value2"/>
<TodoList />
</t>

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

export class TodoItem extends Component {
static template = "awesome_owl.TodoItem";

static props = {
id: Number,
description: String,
isCompleted: Boolean
};
}
7 changes: 7 additions & 0 deletions awesome_owl/static/src/todoList/todoItem/todoItem.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<templates xml:space="preserve">
<t t-name="awesome_owl.TodoItem">
<div t-att-class="{'text-muted text-decoration-line-through': props.isCompleted}">
<t t-esc="props.id" />. <t t-esc="props.description" />
</div>
</t>
</templates>
20 changes: 20 additions & 0 deletions awesome_owl/static/src/todoList/todoList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component, useState } from "@odoo/owl";
import { TodoItem } from "./todoItem/todoItem";

export class TodoList extends Component {
static template = "awesome_owl.TodoList";

setup() {
this.todos = useState([]);
this.id = 0;
}

addTodo(event){
if (event.keyCode == 13){
console.log(event)
this.todos.push({id: this.id++, description: event.target.value, isCompleted:false})
}
}

static components = { TodoItem };
}
12 changes: 12 additions & 0 deletions awesome_owl/static/src/todoList/todoList.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<templates xml:space="preserve">
<t t-name="awesome_owl.TodoList">
<div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-body">
<input placeholder="New Task" t-on-keyup="addTodo" />
<t t-foreach="todos" t-as="todo" t-key="todo.id">
<p><TodoItem id="todo.id" description="todo.description" isCompleted="todo.isCompleted" /></p>
</t>
</div>
</div>
</t>
</templates>
1 change: 1 addition & 0 deletions estate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
Loading