Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
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
8 changes: 0 additions & 8 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.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Component, useState } from "@odoo/owl"
import { Dialog } from "@web/core/dialog/dialog";

export class Configuration extends Component{
static template = "awesome_dashboard.Configuration";
static components = { Dialog };
static props = {
items: {
type: Array,
},
disabledItems: {
type: Array,
},
update: {
type: Function,
},
close: {
type: Function,
},
}

setup(){
console.log(this.props.disabledItems);
}

onChange(itemId){
if(this.props.disabledItems.includes(itemId)){
this.props.disabledItems = this.props.disabledItems.filter(id => id !== itemId);
}
else{
this.props.disabledItems= [...this.props.disabledItems, itemId];
}
this.props.update(this.props.disabledItems);
}
}
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_dashboard.Configuration">
<Dialog title="'Configuration'">
Enabled cards:
<div class="p-3">
<t t-foreach="props.items" t-as="item" t-key="item.id">
<div class="d-flex align-items-center gap-2 mb-2">
<input type="checkbox" class="form-check-input m-0" t-att-checked="!props.disabledItems.includes(item.id)" t-on-change="() => this.onChange(item.id)"/>
<p class="m-0" t-esc="item.description"/>
</div>
</t>
</div>
<t t-set-slot="footer">
<button class="btn btn-primary" t-on-click="props.close">Done</button>
</t>
</Dialog>
</t>

</templates>
54 changes: 54 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Component, useState } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";
import { Layout } from "@web/search/layout";
import { registry } from "@web/core/registry";
import { DashboardItem } from "./dashboard_item/dashboard_item";
import { Configuration } from "./configuration/configuration";
import { browser } from "@web/core/browser/browser";

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

setup(){
this.display = {ControlPanel: {}}
this.action = useService("action");
this.dialog = useService("dialog");
this.statistics = useState(useService("awesome_dashboard.statistics"));
this.items = registry.category("awesome_dashboard").getAll();
this.state = useState({
disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || []
});
}

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'],
],
});
}

updateItems(disabledItems){
this.state.disabledItems = disabledItems;
browser.localStorage.setItem("disabledDashboardItems", disabledItems);
}

openConfiguration() {
this.dialog.add(Configuration, {
items: this.items,
disabledItems: this.state.disabledItems,
update: this.updateItems.bind(this),
});
}
}

registry.category("lazy_components").add("AwesomeDashboard", 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: lightgray;
}
28 changes: 28 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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" t-on-click="openCustomerView">Customers</button>
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
</t>

<t t-set-slot="control-panel-additional-actions">
<button t-on-click="openConfiguration" class="btn p-0 ms-1 border-0">
<i class="fa fa-cog"></i>
</button>
</t>

<div class="d-flex flex-wrap" t-if="statistics.isReady">
<t t-foreach="items" t-as="item" t-key="item.id">
<DashboardItem size="item.size || 1" t-if="!state.disabledItems.includes(item.id)">
<t t-set="itemProp" t-value="item.props? item.props(statistics): {'data': statistics}"/>
<t t-component="item.Component" t-props="itemProp"/>
</DashboardItem>
</t>
</div>
</Layout>
</t>

</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component } from "@odoo/owl";

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

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

static defaultProps = {
size: 1,
}
}
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 m-2 border rounded" t-attf-style="width: {{18 * props.size}}rem; background-color: white;">
<t t-slot="default"/>
</div>
</t>

</templates>
63 changes: 63 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { registry } from "@web/core/registry"
import { NumberCard } from "./number_card/number_card";
import { PieChartCard } from "./pie_chart_card/pie_chart_card";

const dashboard_registry = registry.category("awesome_dashboard")
dashboard_registry.add("average_new_order",{
id: "average_new_order",
description: "Average amount of new orders",
Component: NumberCard,
props: (data) => ({
title: "Average amount of new orders this month",
value: data.total_amount
}),
});
dashboard_registry.add("number_new_order",{
id: "number_new_order",
description: "Total amount of new orders",
Component: NumberCard,
size: 1,
props: (data) => ({
title: "Total amount of new orders this month",
value: data.nb_new_orders
}),
});
dashboard_registry.add("average_quantity",{
id: "average_quantity",
description: "Average amount of t-shirt",
Component: NumberCard,
size: 5,
props: (data) => ({
title: "Average amount of t-shirt by order this month",
value: data.average_quantity
}),
});
dashboard_registry.add("number_cancelled_order",{
id: "number_cancelled_order",
description: "Number of cancelled orders",
Component: NumberCard,
size: 2,
props: (data) => ({
title: "Number of cancelled orders this month",
value: data.nb_cancelled_orders
}),
});
dashboard_registry.add("average_state_change",{
id: "average_state_change",
description: "Average time for state change",
Component: NumberCard,
props: (data) => ({
title: "Average time for an order to go from 'new' to 'sent' or 'cancelled'",
value: data.average_time
}),
});
dashboard_registry.add("pie_chart",{
id: "pie_chart",
description: "Shirt orders by size",
Component: PieChartCard,
size: 3,
props: (data) => ({
title: "Shirt orders by size",
value: data.orders_by_size
}),
});
13 changes: 13 additions & 0 deletions awesome_dashboard/static/src/dashboard/number_card/number_card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component } from "@odoo/owl"

export class NumberCard extends Component{
static template = "awesome_dashboard.NumberCard";
static props = {
title: {
type: String,
},
value: {
type: Number,
}
};
}
11 changes: 11 additions & 0 deletions awesome_dashboard/static/src/dashboard/number_card/number_card.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.NumberCard">
<t t-esc="props.title"/>
<div class="fw-bold text-success text-center">
<t t-esc="props.value"/>
</div>
</t>

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

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

static props = {
label: {
type: String,
},
data: {
type: Object,
},
}

setup(){
this.canvasRef = useRef("canvas")
onWillStart(async () => {
await loadJS("/web/static/lib/Chart/Chart.js");
});
onMounted(()=>{
this.renderChart();
});
onPatched(() => {
this.chart.destroy();
this.renderChart();
});
onWillUnmount(() => {
this.chart.destroy();
});

}

renderChart() {
const labels = Object.keys(this.props.data);
const dataValues = Object.values(this.props.data);

this.chart = new Chart(this.canvasRef.el, {
type: 'pie',
data: {
labels: labels,
datasets: [
{
label: this.props.label,
data: dataValues,
},
]
}
});
}
}
10 changes: 10 additions & 0 deletions awesome_dashboard/static/src/dashboard/pie_chart/pie_chart.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>
<canvas t-ref="canvas"/>
</div>
</t>

</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component } from "@odoo/owl"
import { PieChart } from "../pie_chart/pie_chart";

export class PieChartCard extends Component{
static template = "awesome_dashboard.PieChartCard";
static components = { PieChart }
static props = {
title: {
type: String,
},
value: {
type: Object,
}
};
}
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_dashboard.PieChartCard">
<t t-esc="props.title"/>
<PieChart data="props.value" label="'Shirts'"/>
</t>

</templates>
Loading