Skip to content
Open
Show file tree
Hide file tree
Changes from 20 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
5 changes: 5 additions & 0 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
'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.

44 changes: 44 additions & 0 deletions awesome_dashboard/static/src/dashboard/config_dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Component, useState } from "@odoo/owl";
import { Dialog } from "@web/core/dialog/dialog";
import { items } from "./dashboard_items";
import { registry } from "@web/core/registry";
import { CheckBox } from "@web/core/checkbox/checkbox";
import { browser } from "@web/core/browser/browser";


export class ConfigDialog extends Component {
static template = "awesome_dashboard.ConfigDialog";
static components = { Dialog, CheckBox };
static props = ["close", "items", "disabledItems", "onUpdateConfigs"];
setup() {
// create object for each item with an enabled property
this.items = useState(this.props.items.map((item) => {
return {
...item,
enabled: !this.props.disabledItems.includes(item.id),
}
}));

}

// adds the unchecked item to the disabled list
onChange(checkedItems, Item) {
Item.enabled = checkedItems;

const updatedDisabledItems = Object.values(this.items).filter(
(item) => !item.enabled
).map((item) => item.id);

browser.localStorage.setItem(
"disabledItems", updatedDisabledItems,
);

this.props.onUpdateConfigs(updatedDisabledItems);
}

done() {
this.props.close();
}

}

21 changes: 21 additions & 0 deletions awesome_dashboard/static/src/dashboard/config_dialog.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_dashboard.ConfigDialog" >
<Dialog title="'Dashboard items configuration'">
Which cards do you whish 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>

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;
}

51 changes: 51 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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 { ConfigDialog } from "./config_dialog";
import { browser } from "@web/core/browser/browser";
import { _t } from "@web/core/l10n/translation";

class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";
static components = { Layout, DashboardItem }
setup() {
this.action = useService("action");
this.result = useState(useService("awesome_dashboard.statistics"));
this.items = registry.category("awesome_dashboard").getAll();
this.dialog = useService("dialog");
// retreive disabled items
this.state = useState({
disabledItems: browser.localStorage.getItem("disabledItems")?.split(",") || []
});
}
openCustomers() {
this.action.doAction("base.action_partner_form");
}
openConfigs() {
this.dialog.add(ConfigDialog, {
items: this.items,
disabledItems: this.state.disabledItems,
onUpdateConfigs: this.updateConfigs.bind(this),
});
}
// update the list of disabeled items
updateConfigs(newDisabledItems) {
this.state.disabledItems = newDisabledItems;
}

openLeads() {

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

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

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

<t t-name="awesome_dashboard.AwesomeDashboard" >
<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>
<button t-on-click="openConfigs" class="btn p-0 ms-1 border-0">
<i class="fa fa-cog"></i>
</button>
</t>
<t t-set-slot="default">
<div class="o-awesome-dashboard-content" t-if="result.isReady">
<t t-foreach="items" t-as="item" t-key="item.id">
<DashboardItem t-if="!state.disabledItems.includes(item.id)" size="item.size || 1">
<t t-set="itemProp" t-value="item.props ? item.props(result) : {'data': result}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</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.DashboardItem";
static defaultProps = { size: 1};
static props = {
size: {
type: Number,
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.DashboardItem">
<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>

72 changes: 72 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { NumberCard } from "./numbercard/number_card";
import { PieChartCard } from "./piechartcard/piechart_card";
import { registry } from "@web/core/registry";
import { _t } from "@web/core/l10n/translation";

export const items = [
{
id: "average_quantity",
description: _t("Average amount of t-shirt"),
Component: NumberCard,
props: (data) => ({
title: _t("Average amount of tees ordered this month"),
value: data.average_quantity,
})
},

{
id: "average_time",
description: _t("Average time of an order"),
Component: NumberCard,
props: (data) => ({
title: _t("Average time for an order to go from 'new' to 'sent' or 'cancelled'"),
value: data.average_time,
})
},

{
id: "nb_new_orders",
description: _t("Number of new orders this month"),
Component: NumberCard,
props: (data) => ({
title: _t("Number of new orders this month"),
value: data.nb_new_orders,
})
},

{
id: "nb_cancelled_orders",
description: _t("Number of cancelled orders this month"),
Component: NumberCard,
props: (data) => ({
title: _t("Number of cancelled orders this month"),
value: data.nb_cancelled_orders,
})
},

{
id: "total_amount",
description: _t("Total amount of new orders this month"),
Component: NumberCard,
props: (data) => ({
title: _t("Total amount of new orders this month"),
value: data.total_amount,
})
},

{
id: "orders_pie_chart",
description: _t("Shirt order by size"),
Component: PieChartCard,
props: (data) => ({
title: _t("Shirt order by size"),
data: data.orders_by_size,
})
},

]

items.forEach(item => {
registry.category("awesome_dashboard").add(item.id, item);
})

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

export class NumberCard extends Component {
static template = "awesome_dashboard.NumberCard";
static props = {
title: {
type: String,
},
value: {
type: Number,
},
};
}

14 changes: 14 additions & 0 deletions awesome_dashboard/static/src/dashboard/numbercard/number_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_dashboard.NumberCard" owl='1'>
<div class="d-flex flex-wrap">
<t t-esc="props.title"/>
<div class="fs-1 fw-bold text-success text-center">
<t t-esc="props.value"/>
</div>
</div>
</t>

</templates>

43 changes: 43 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,43 @@
import { Component, onWillStart,useRef, onMounted, onWillUnmount } from "@odoo/owl";
import { loadJS } from "@web/core/assets";


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

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

}

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/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.PieChart" >
<div t-att-class="'h-100 ' + props.class">
<div class="h-100 position-relative">
<canvas t-ref="canvas_pie" />
</div>
</div>
</t>

</templates>

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

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

Loading