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
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.

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

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

static components = { Layout, DashboardItem };

setup() {
this.items = registry.category('awesome_dashboard.items').getAll();

this.statisticsService = useService('statistics_service');
this.statistics = useState(this.statisticsService.loadStatistics());
}
}

registry
.category('lazy_components')
.add('awesome_dashboard.AwesomeDashboard', AwesomeDashboard);
10 changes: 10 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.o_dashboard {
background-color: #e3e3e3;
color: #1f1f1f;
padding: 1rem;
gap: 2rem;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
// align-items: start;
align-content: start;
}
22 changes: 22 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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" >
<div class="d-inline-flex gap-2 mx-2">
<button class="btn btn-primary">Customers</button>
<button class="btn btn-primary">Leads</button>

</div>
</t>
<t t-foreach="items" t-as="item" t-key="item.id">
<DashboardItem size="item.size || 1">
<t t-set="itemProp" t-value="item.props ? item.props(statistics) : {'data': statistics}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</Layout>
</t>

</templates>
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.dashboard_item';

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

get itemSize() {
return this.props.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.dashboard_item">
<div class="d-flex flex-column justify-content-center align-items-center shadow-lg rounded-3 p-3 w-100 h-100" t-attf-style="grid-column: span {{ itemSize }};">
<t t-slot="default"></t>
</div>
</t>

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

const items = [
{
id: 'nb_new_orders',
description: 'Number of new orders this month',
Component: NumberCard,
size: 1,
props: (data) => ({
title: 'Number of new orders this month',
value: data.nb_new_orders,
}),
},
{
id: 'total_amount',
description: 'Total amount of new orders this month',
Component: NumberCard,
size: 2,
props: (data) => ({
title: 'Total amount of new orders this month',
value: data.total_amount,
}),
},
{
id: 'average_quantity',
description: 'Average amount of t-shirt by order this month',
Component: NumberCard,
size: 3,
props: (data) => ({
title: 'Average amount of t-shirt by order this month',
value: data.average_quantity,
}),
},
{
id: 'nb_cancelled_orders',
description: 'Number of cancelled orders this month',
Component: NumberCard,
size: 2,
props: (data) => ({
title: 'Number of cancelled orders this month',
value: data.nb_cancelled_orders,
}),
},
{
id: 'average_time',
description:
'Average time for an order to go from new to sent or cancelled',
Component: NumberCard,
size: 2,
props: (data) => ({
title:
'Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’',
value: data.average_time,
}),
},
{
id: 'order_by_size',
description: 'Shirt order by size',
Component: PieChartCard,
size: 2,
props: (data) => ({
title: 'Shirt order by size',
dataset: Object.values(data.orders_by_size),
lables: Object.keys(data.orders_by_size),
}),
},
];

for (const item of items) {
registry.category('awesome_dashboard.items').add(item.id, item);
}
10 changes: 10 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,10 @@
import { Component } from '@odoo/owl';

export class NumberCard extends Component {
static template = 'awesome_dashboard.number_card';

static props = {
title: { type: String, optional: true },
value: { type: Number, optional: true },
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.o_dashboard_item_title {
font-size: 0.85rem;
font-weight: 600;
color: #6c757d;
}

.o_dashboard_item_value {
font-size: 2.25rem;
font-weight: 700;
color: #378a00;
}
15 changes: 15 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,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.number_card">
<div class="d-flex flex-column align-items-center">
<div class="o_dashboard_item_title">
<t t-out="props.title"></t>
</div>
<div class="o_dashboard_item_value">
<t t-out="props.value"></t>
</div>
</div>
</t>

</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {
Component,
onMounted,
onWillStart,
onWillUnmount,
useRef,
} from '@odoo/owl';
import { loadJS } from '@web/core/assets';

export class PieChartCard extends Component {
static template = 'awesome_dashboard.pie_chart_card';

static props = {
title: { type: String, optional: true },
dataset: { type: Array, optional: true },
labeles: { type: Array, optional: true },
};

setup() {
this.canvasRef = useRef('canvasRef');
this.chart = null;

onWillStart(async () => {
await loadJS('/web/static/lib/Chart/Chart.js');
});

onMounted(() => {
this.renderChart();
});

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

renderChart() {
const data = {
datasets: [
{
data: this.props.dataset,
},
],
labels: this.props.labels,
};

const options = {};

const ctx = this.canvasRef.el.getContext('2d');

this.chart = new Chart(ctx, {
type: 'pie',
data: data,
options: options,
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.o_dashboard_item_title {
font-size: 0.85rem;
font-weight: 600;
color: #6c757d;
}
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_card">
<div class="d-flex flex-column align-items-center">
<div class="o_dashboard_item_title">
<t t-out="props.title"></t>
</div>
<canvas t-ref="canvasRef"></canvas>
</div>
</t>

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

const statisticsService = {
start(env) {
async function fetchStatistics() {
const result = await rpc('/awesome_dashboard/statistics');
return result;
}

async function updateData() {
const results = await fetchStatistics();

for (const key in data) {
delete data[key];
}

Object.assign(data, results);
}

const data = reactive({});

updateData();
setInterval(updateData, 10000);

return {
loadStatistics() {
return data;
},
};
},
};

registry.category('services').add('statistics_service', statisticsService);
14 changes: 14 additions & 0 deletions awesome_dashboard/static/src/dashboard_action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component, xml } from '@odoo/owl';
import { LazyComponent } from '@web/core/assets';
import { registry } from '@web/core/registry';

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

registry
.category('actions')
.add('awesome_dashboard.dashboard', LazyDashboard);
14 changes: 14 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component, useState } from '@odoo/owl';

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

static props = {
title: String,
slots: { type: Object, optional: true },
};

setup() {
this.state = useState({ isOpen: true });
}
}
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 d-inline-block m-2" style="width: 18rem;">
<div class="card-body">
<div class="d-flex justify-content-between">
<h5 class="card-title">
<t t-out="this.props.title" />
</h5>
<button type="button" class="btn" t-on-click="() => state.isOpen = !state.isOpen">
<span t-if='!state.isOpen' class="fa fa-eye"></span>
<span t-if='state.isOpen' class="fa fa-eye-slash"></span>
</button>
</div>
<div t-if="state.isOpen">
<t t-slot="default"/>
</div>
</div>
</div>
</t>
</templates>
Loading