Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
9 changes: 6 additions & 3 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
'name': "Awesome Dashboard",

'summary': """
Starting module for "Discover the JS framework, chapter 2: Build a dashboard"
Companion addon for the Odoo JS Framework Training
""",

'description': """
Starting module for "Discover the JS framework, chapter 2: Build a dashboard"
Companion addon for the Odoo JS Framework Training
""",

'author': "Odoo",
'website': "https://www.odoo.com/",
'category': 'Tutorials/AwesomeDashboard',
'category': 'Tutorials',
'version': '0.1',
'application': True,
'installable': True,
Expand All @@ -25,6 +25,9 @@
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
],
'awesome_dashboard.dashboard': [
'awesome_dashboard/static/src/dashboard/**/*',
],
},
'license': 'AGPL-3'
}
10 changes: 0 additions & 10 deletions awesome_dashboard/static/src/dashboard.js

This file was deleted.

8 changes: 0 additions & 8 deletions awesome_dashboard/static/src/dashboard.xml

This file was deleted.

31 changes: 31 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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 "./dashboard_item";
import { PieChart } from "./piechart";

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

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

openCustomerView() {
this.action.doAction("base.action_partner_form");
}

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

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

<t t-name="awesome_dashboard.AwesomeDashboard">
<Layout display="{ controlPanel: {} } " className="'o_dashboard h-100'">
<t t-set-slot="layout-buttons">
<button class="btn btn-primary m-3" t-on-click="openCustomerView">Customers</button>
<button class="btn btn-primary m-3" t-on-click="openLeads">Leads</button>
</t>
<div class="d-flex" t-if="statistics.debounce">
<DashboardItem>
Number of new orders this month :
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="statistics.nb_new_orders"/>
</div>
</DashboardItem>
<DashboardItem>
Total amount of new orders this month :
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="statistics.total_amount"/>
</div>
</DashboardItem>
<DashboardItem>
Average amount of t-shirt by order this month :
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="statistics.average_quantity"/>
</div>
</DashboardItem>
<DashboardItem>
Number of cancelled orders this month :
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="statistics.nb_cancelled_orders"/>
</div>
</DashboardItem>
<DashboardItem>
Average time for an order to go from 'new' to 'sent' or 'cancelled':
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="statistics.average_time"/>
</div>
</DashboardItem>

<div class="d-flex">
<DashboardItem>
<PieChart data="statistics['orders_by_size']" label="'Shirt orders by size'"/>
</DashboardItem>
</div>
</div>
</Layout>
</t>

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't do anything from what i understand. Try removing it and see if anything happens

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add a default value for size look for static defaultProps

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what doesn't do anything ? the default parameter ? or the entire size prop ? because we need it for the item dimension

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default parameter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it said this in the tutorial : It should take an optional size number props, that default to 1 ( point 3 of chapter 2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but the default: 1 you have here doesn't do anything. You have to use defaultProps for it to have affect

optional: true,
},
};
}
12 changes: 12 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.DashboardItem">
<div class="card m-2 border-dark" t-attf-style="width: {{18*props.size}}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>

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

export class PieChart extends Component {
static template = "awesome_dashboard.PieChart";
static props = {
label: String,
data: Object,
};

setup() {
this.canvasRef = useRef("canvas");
onWillStart(() => loadJS("/web/static/lib/Chart/Chart.js"));
useEffect(() => {
if (this.chart) { this.chart.destroy();}
this.displayChart();
});
onWillUnmount(() => {
this.chart.destroy();
});
}

displayChart() {
const labels = Object.keys(this.props.data);
const data = Object.values(this.props.data);
this.chart = new Chart(this.canvasRef.el, {
type: "pie",
data: {
labels: labels,
datasets: [
{
label: this.props.label,
data: data,
},
],
},
});
}
}
10 changes: 10 additions & 0 deletions awesome_dashboard/static/src/dashboard/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 t-att-class="'h-100 ' + props.class" t-ref="root">
<div class="h-100 position-relative" t-ref="container">
<canvas t-ref="canvas" />
</div>
</div>
</t>
</templates>
Empty file.
21 changes: 21 additions & 0 deletions awesome_dashboard/static/src/statistics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { registry } from "@web/core/registry";
import { rpc } from "@web/core/network/rpc";
import { reactive } from "@odoo/owl";

const statisticService = {
start() {
const statistics = reactive({debounce: false});

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

setInterval(loadStatistics, 5 * 1000);
loadStatistics();

return statistics;
}
};

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

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

setup() {
this.state = useState({
open: true,
title: this.props.title,
});
}

increment() {
this.state.value++;
}

toggleOpen() {
this.state.open = !this.state.open;
}
}
14 changes: 14 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_owl.card">
<div class="card d-inline-block m-2" style="width: 18rem;">
<button class="btn btn-info" t-on-click="toggleOpen">Toggle</button>
<div class="card-body">
<h5 class="card-title"><t t-out="state.title"/></h5>
<p class="card-text">
<t t-slot="default" t-if="state.open"/>
</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) {
console.log("Incrementing, new value:", this.state.value);
this.props.onChange();
}
}
}
9 changes: 9 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_owl.counter">
<p>Counter: <t t-esc="state.value"/></p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</t>

</templates>
20 changes: 17 additions & 3 deletions awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
/** @odoo-module **/

import { Component } from "@odoo/owl";
import { Component, useState, markup } from "@odoo/owl";
import { Counter } from "./counter/counter";
import { Card } from "./card/card";
import { TodoList } from "./todo/todo_list";

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

setup() {
this.state = useState({ sum: 2 });
this.incrementSum = this.incrementSum.bind(this);
}

fst_value = markup("<strong>fst</strong>");
snd_value = "<em>snd</em>";

incrementSum() {
this.state.sum++;
}
}
15 changes: 12 additions & 3 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<Counter onChange.bind="incrementSum"/>
<Counter onChange.bind="incrementSum"/>
<h1>Sum: <t t-esc="state.sum"/></h1>
<div>
<Card title="'cardfirst'">
<Counter onChange.bind="incrementSum"/>
</Card>
<Card title="'cardsecond'"/>
</div>
<div>
<TodoList/>
</div>
</t>

</templates>
14 changes: 14 additions & 0 deletions awesome_owl/static/src/todo/todo-item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_owl.todoItem">
<div class="form-check">
<t t-set="todo" t-value="props.todo"/>
<input class="form-check-input" type="checkbox" t-att-id="todo.id" t-att-checked="todo.isCompleted" t-on-change="toggle"/>
<label t-att-for="todo.id" t-att-class="todo.isCompleted ? 'text-decoration-line-through text-muted' : '' ">
<t t-esc="todo.id"/>.
<t t-esc="todo.description"/>
</label>
<span role="button" class="fa fa-remove ms-3 text-danger" t-on-click="remove"/>
</div>
</t>
</templates>
Loading