Skip to content
Open
Show file tree
Hide file tree
Changes from 14 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
26 changes: 26 additions & 0 deletions .vscode/launch.json

Choose a reason for hiding this comment

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

don't push anything inside .vscode 💢

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Run (Update)",
"type": "debugpy",
"request": "launch",
"python": "/usr/bin/python3",
"program": "/home/odoo/odoo/odoo-bin",
"console": "integratedTerminal",
"args": [
"--database", "rd-demo",
"--dev", "xml",
// "-u", "we_guarantee",
"--addons-path", "/home/odoo/enterprise,/home/odoo/odoo/addons,/home/odoo/tutorials",
"--log-level", "info",
"--limit-time-real=0",
"--limit-time-cpu=0",
],
"variablePresentation": {},
},
]
}
4 changes: 4 additions & 0 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
'assets': {
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
('remove', 'awesome_dashboard/static/src/dashboard/*'),
],
'awesome_dashboard.dashboard': [
'awesome_dashboard/static/src/dashboard/*',
],
},
'license': 'AGPL-3'
Expand Down
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.

4 changes: 4 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.o_dashboard {
background-color: #f0f0f0;
}

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, onWillStart,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 "./pie_chart";

class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";
static components = { Layout, DashboardItem, PieChart }
setup() {
this.action = useService("action");
this.statistics = useService("awesome_dashboard.statistics");
this.result = useState(this.statistics);
}
openCustomers() {
this.action.doAction("base.action_partner_form");
}
openLeads() {
this.action.doAction({
type: 'ir.actions.act_window',
name: 'CRM Leads',

Choose a reason for hiding this comment

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

You can make the name translatable
Also check where the name shows up when you run the action. It's important to know

target: 'current',
res_model: 'crm.lead',
views: [[false,'list'],[false, 'form']],
});
}
}

registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);

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

<t t-name="awesome_dashboard.AwesomeDashboard" owl="1">
<Layout className="'o_dashboard h-100'" display="{ controlPanel: {} }">
<t t-set-slot="layout-buttons">
<button class="btn btn-primary" t-on-click="openCustomers">Customers</button>
<button class="btn btn-secondary" t-on-click="openLeads">Leads</button>
</t>
<t t-set-slot="default">
<div class="o-awesome-dashboard-content" t-if="statistics.isReady">

<DashboardItem>
Average amount of t-shirt by order this month
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="result.average_quantity"/>
</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="result.average_time"/>
</div>
</DashboardItem>
<DashboardItem>
Number of new orders this month
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="result.nb_new_orders"/>
</div>
</DashboardItem>
<DashboardItem>
Number of cancelled orders this month
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="result.nb_cancelled_orders"/>
</div>
</DashboardItem>
<DashboardItem>
Total amount of new orders this month
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="result.total_amount"/>
</div>
</DashboardItem>
<DashboardItem>
Shirt order by size
<PieChart label="'Orders By Size'" data="result.orders_by_size"/>
</DashboardItem>
</div>
</t>
</Layout>
</t>

</templates>

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

export class DashboardItem extends Component {
static template = "awesome_dashboard.dashboard_item";
static props = {
size: {
type: Number,
default: 1,
optional: true,
},
slots: {
type: Object,
},
};
get Width() {
return 18*this.props.size
}

Choose a reason for hiding this comment

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

You could do this in the xml. But I actually quite like it. Not sure about the capitalized variable name though 🤔

Copy link
Author

Choose a reason for hiding this comment

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

i capitalized it so it can be destinguished from "width" inside "t-aff-style" in the corresponding xml file

Choose a reason for hiding this comment

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

you should maybe name it something like itemWidth

}

13 changes: 13 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_item.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_dashboard.dashboard_item" owl='1'>
<div class="card d-inline-block m-2" t-attf-style="width: {{Width}}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>

</templates>

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


export class PieChart extends Component {
static template = "awesome_dashboard.pie_chart";
static props = {
label: String,
data : Object,
}
setup(){
this.canvasRef = useRef("canvas_pie");
onWillStart(async () => loadJS("/web/static/lib/Chart/Chart.js"));
onMounted(()=> {
this.renderChart();
}
);
onWillUnmount(()=> {
this.chart.destroy();

Choose a reason for hiding this comment

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

At this point you're not sure you have a chart so this might create an error.
Better to use this.chart?.destroy(); imo

});


}

renderChart(){
this.chart = new Chart(this.canvasRef.el,{
type: 'pie',
data : {
labels : Object.keys(this.props.data),
datasets:[
{
label: this.props.label,
data : Object.values(this.props.data),
},
],
}
})

}
}

13 changes: 13 additions & 0 deletions awesome_dashboard/static/src/dashboard/pie_chart.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_dashboard.pie_chart" owl='1'>
<div t-att-class="'h-100 ' + props.class">
<div class="h-100 position-relative">
<canvas t-ref="canvas_pie" />
</div>
</div>
</t>

</templates>

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


const statisticsService = {
start() {

const statistics = reactive({isReady : false});

async function loadingData() {
const data = await rpc("/awesome_dashboard/statistics");
Object.assign(statistics,data,{isReady : true});
setInterval(loadingData, 10*60*1000);
}

loadingData();
return statistics;
},
};

registry.category("services").add("awesome_dashboard.statistics", statisticsService);

13 changes: 13 additions & 0 deletions awesome_dashboard/static/src/dashboard_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component, xml } from "@odoo/owl";
import {LazyComponent } from "@web/core/assets";
import { registry } from "@web/core/registry";

export class AwesomeDashboardLoader extends Component {
static components = { LazyComponent };
static template = xml`
<LazyComponent bundle="'awesome_dashboard.dashboard'" Component="'AwesomeDashboard'" />
`;
}

registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader);

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

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

static props = {
title: String,
content:{
type: String,
optional: true,
},
slots:Object, // I added this to allow slots inside cards
};

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

ontoggleVisibility() {
this.state.open = !this.state.open;
}

}

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" owl="1">
<header>
<button t-on-click="ontoggleVisibility"/>
</header>
<t t-if="state.open">
<div class="card d-inline-block m-2">
<div class="card-body">
<h5 class="card-title"><t t-esc="props.title"/></h5>
<p class="card-text">
<t t-slot="default"/>
</p>
</div>
</div>
</t>
</t>

</templates>

22 changes: 22 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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();
}
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/counter/counter.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_owl.Counter" owl="1">
<div class="p-3">
<p>Counter: <t t-esc="state.value"/></p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>

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

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

export class Playground extends Component {
static template = "awesome_owl.playground";
static components = { Card , Counter, TodoList };
setup() {
this.htmlContent = markup("<div class='text-primary'>some content</div>");
this.state = useState({ sum : 0 });
this.incrementSum = this.incrementSum.bind(this);
}

incrementSum() {
this.state.sum ++;
}

}

Loading