Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e610aa0
[IMP] dashboard: add layout component to dashboard
Mohamed-Dallash Sep 24, 2025
c1be7a0
[IMP] dashboard: add quick navigation buttons
Mohamed-Dallash Sep 24, 2025
ec83700
[ADD] Dashboard Item
Mohamed-Dallash Sep 24, 2025
379d84d
[IMP] Dashboard: add some statistics to the dashboard, get the data f…
Mohamed-Dallash Sep 24, 2025
a652292
[IMP] dashboard: add statistics caching
Mohamed-Dallash Sep 24, 2025
c38b2b8
[IMP] dashboard: add pie chart for shirt orders by size to the dashboard
Mohamed-Dallash Sep 24, 2025
f8818ed
[IMP] dashboard: periodically update statistics
Mohamed-Dallash Sep 24, 2025
670399f
[IMP] dashboard: lazy load the dashboard
Mohamed-Dallash Sep 25, 2025
704adb3
[IMP] dashboard: make the dashboard generic
Mohamed-Dallash Sep 25, 2025
aec9520
[IMP] dashbaord: make the dashboard estensible
Mohamed-Dallash Sep 25, 2025
10d91f0
[IMP] dashboard: add and remove dashboard items
Mohamed-Dallash Sep 26, 2025
62a0dcb
[IMP] dashboard: add new lines to files that didn't have it at the en…
Mohamed-Dallash Sep 26, 2025
93eba2e
[IMP] dashboard: allow variable chart type
Mohamed-Dallash Sep 29, 2025
bbd55c6
[IMP] dashboard: update formatting in configuration_dialog
Mohamed-Dallash Sep 29, 2025
9c6d675
[IMP] dashboard: remove unnecessary browser import
Mohamed-Dallash Sep 29, 2025
e490a77
[IMP] dashboard: make titles translatable
Mohamed-Dallash Sep 29, 2025
55a69a3
[I18N] dashboard: add arabic translations
Mohamed-Dallash Sep 29, 2025
f66adc5
[IMP] dashboard: store user dashboard preferences in the DB instead …
Mohamed-Dallash Sep 29, 2025
a7e1441
[IMP] dashboard: tidy up the get disabled items function
Mohamed-Dallash Sep 30, 2025
dc5abeb
[IMP] dashboard: use more concise naming for disabled items variable
Mohamed-Dallash Sep 30, 2025
d8b2a2c
[IMP] dashboard: remove unnecessary default string, unnecessary array…
Mohamed-Dallash Sep 30, 2025
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
1 change: 1 addition & 0 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'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.

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


export class ConfigurationDialog extends Component {
static template = "awesome_dashboard.ConfigurationDialog";
static components = { Dialog, CheckBox };
static props = {
items: { type: Array },
disabledItems: {
type: Array,
element: {
type: { String },
}
},
onUpdateConfig: Function,
close: Function,
}

setup() {
this.items = useState(this.props.items.map((item) => {
return {
id: item.id,
description: item.description,
enabled: !this.props.disabledItems.includes(item.id),
}
}));
}

onChange(checked, item) {
item.enabled = checked;
const updatedDisabledItems = Object.values(this.items).filter(
(item) => !item.enabled
).map((item) => item.id);
this.props.onUpdateConfig(updatedDisabledItems);
}

done() {
this.props.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="awesome_dashboard.ConfigurationDialog">
<Dialog size="'md'" title="'Dashboard items configuration'">
Which cards do you wish to see?
<t t-foreach="items" t-as="item" t-key="item.id">
<CheckBox value="item.enabled" onChange="(ev) => this.onChange(ev,item)">
<t t-esc="item.description"/>
</CheckBox>
</t>
<t t-set-slot="footer">
<button class="btn btn-primary" t-on-click="done">
Done
</button>
</t>
</Dialog>
</t>
</templates>
55 changes: 55 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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 { ConfigurationDialog } from "./configuration_dialog/configuration_dialog";
import { browser } from "@web/core/browser/browser";


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

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

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

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

updateConfig(newDisabledItems) {
this.disabledItems.values = newDisabledItems;
browser.localStorage.setItem("disabledDashboardItems", newDisabledItems);
}

openConfig() {
this.dialog.add(ConfigurationDialog, {
items: this.items,
disabledItems: this.disabledItems.values,
onUpdateConfig: this.updateConfig.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: gray;
}
26 changes: 26 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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="openCustomers">Customers</button>
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
</t>
<t t-set-slot="control-panel-additional-actions">
<button class="btn p-0 ms-1 border-0" t-on-click="openConfig">
<i class="fa fa-cog"/>
</button>
</t>
<div class="d-flex flex-wrap" t-if="statistics.isReady">
<t t-foreach="items" t-as="item" t-key="item.id">
<DashboardItem t-if="!disabledItems.values.includes(item.id)" size="item.size">
<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>
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: Object,
size: {
type: Number,
optional: true,
}
}
static defaultProps = {
size: 1,
}
}
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 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>
65 changes: 65 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { NumberCard } from "./number_card/number_card";
import { PieChartCard } from "./pie_chart_card/pie_chart_card";
import { registry } from "@web/core/registry";

export const items = [
{
id: "average_quantity",
description: "Average amount of t-shirt",
Component: NumberCard,
props: (data) => ({
title: "Average amount of t-shirt by order this month",
value: data.average_quantity,
}),
},
{
id: "average_time",
description: "Average time for order",
Component: NumberCard,
props: (data) => ({
title: "Average time for an order to go from 'new' to 'sent' of 'cancelled'",
value: data.average_time,
}),
},
{
id: "nb_new_orders",
description: "Number of new orders",
Component: NumberCard,
props: (data) => ({
title: "Number of new orders this month",
value: data.nb_new_orders,
}),
},
{
id: "nb_cancelled_orders",
description: "Number of cancelled orders",
Component: NumberCard,
props: (data) => ({
title: "Number of cancelled orders this month",
value: data.nb_cancelled_orders,
}),
},
{
id: "total_amount",
description: "Number of new orders",
Component: NumberCard,
props: (data) => ({
title: "Total amount of new orders this month",
value: data.total_amount,
}),
},
{
id: "orders_by_size",
description: "Shirt orders by size",
Component: PieChartCard,
size: 2,
props: (data) => ({
title: "Shirt orders by size",
value: data['orders_by_size'],
}),
},
]

items.forEach(item => {
registry.category("awesome_dashboard").add(item.id, item);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Component } from "@odoo/owl";

export class NumberCard extends Component {
static template = "awesome_dashboard.NumberCard";
static props = {
title: String,
value: 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="fs-1 fw-bold text-success text-center">
<t t-esc="props.value"/>
</div>
</t>

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

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

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

renderChart() {
this.chart?.destroy();
const config = {
type: "pie",
data: {
labels: Object.keys(this.props.data),
datasets: [{
label: this.props.label,
data: Object.values(this.props.data)

}],
}

};
this.chart = new Chart(this.canvasRef.el, config);
}
}
10 changes: 10 additions & 0 deletions awesome_dashboard/static/src/dashboard/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 class="canvas-container mt-auto d-flex align-items-end">
<canvas t-ref="canvas"/>
</div>
</t>

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

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

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

const fetchStatistics = () => {
return rpc("/awesome_dashboard/statistics");
}

export const statisticsService = {
start() {
const statistics = reactive({ isReady: false });
const updateData = async () => {
Object.assign(statistics, await fetchStatistics(), { isReady: true });
}
updateData();
setInterval(updateData, 1000 * 60 * 10);
return statistics;
},
}

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

export class DashboardLoader extends Component {
static components = { LazyComponent };
static template = "awesome_dashboard.Loader";
}

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