Skip to content

18.0 estate ibmo #818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 18.0
Choose a base branch
from
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: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/tutorials.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +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'
}
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.

94 changes: 94 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/** @odoo-module **/

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 { items } from "./dashboard_items";
import { NumberCard } from "./number_card";
import { PieChartCard } from "./pie_chart_card";
import { Dialog } from "@web/core/dialog/dialog";
import { CheckBox } from "@web/core/checkbox/checkbox";
import { browser } from "@web/core/browser/browser";



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

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

openConfiguration() {
this.dialog.add(ConfigurationDialog, {
items: this.items,
disabledItems: this.state.disabledItems,
onUpdateConfiguration: this.updateConfiguration.bind(this),
})
}

updateConfiguration(disabledItems) {
this.state.disabledItems = disabledItems;
}

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

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


class ConfigurationDialog extends Component {
static components = { Dialog, CheckBox };
static template = "awesome_dashboard.ConfigurationDialog";
static props = ["close", "items", "disabledItems", "onUpdateConfiguration"];

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

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

onChange(checked, changedItem) {
changedItem.enabled = checked;
const newDisabledItems = Object.values(this.items).filter(
(item) => !item.enabled
).map((item) => item.id)

browser.localStorage.setItem(
"disabledDashboardItems",
newDisabledItems,
);

this.props.onUpdateConfiguration(newDisabledItems);
}
}


registry.category("lazy_components").add("awesome_dashboard.dashboard", 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;
}
42 changes: 42 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="awesome_dashboard.AwesomeDashboard">
<div class="mb-4 d-flex gap-1">
<button class="btn btn-primary" t-on-click="openCustomers">Customers</button>
<button class="btn btn-outline-secondary" t-on-click="openLeads">Leads</button>
<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>
<Layout className="'o_dashboard h-100'" display="{controlPanel: {} }">
<div class="dashboard grid">
<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="itemProps" t-value="item.props ? item.props(statistics) : {'data': statistics}" />
<t t-component="item.Component" t-props="itemProps" />
</DashboardItem>
</t>
</div>
</Layout>
</t>

<t t-name="awesome_dashboard.ConfigurationDialog">
<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>
8 changes: 8 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @odoo-module **/

import { Component } from "@odoo/owl";

export class DashboardItem extends Component {
static props = {size: {type: Number, default: 1}, slots: {type: Object}}
static template = "awesome_dashboard.dashboard_item";
}
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.dashboard_item">
<div class="card d-inline-block m-2" t-attf-style="width: ${18 * this.props.size}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>

</templates>
41 changes: 41 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/** @odoo-module **/

import { NumberCard } from "./number_card";
import { PieChartCard } from "./pie_chart_card";
import { registry } from "@web/core/registry";

const items = [
{
id: "cancelled_orders",
description: "Cancelled orders this month",
Component: NumberCard,
props: (data) => ({
title: "Number of cancelled orders this month",
value: data.nb_cancelled_orders,
})
},
{
id: "amount_new_orders",
description: "amount orders this month",
Component: NumberCard,
props: (data) => ({
title: "Total amount of new orders this month",
value: data.total_amount,
})
},
{
id: "pie_chart",
description: "Shirt orders by size",
Component: PieChartCard,
size: 2,
props: (data) => ({
title: "Shirt orders by size",
values: data.orders_by_size,
})
},
];


items.forEach(item => {
registry.category("awesome_dashboard").add(item.id, item);
});
12 changes: 12 additions & 0 deletions awesome_dashboard/static/src/dashboard/number_card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/** @odoo-module **/

import { Component } from "@odoo/owl";


export class NumberCard extends Component {
static template = "awesome_dashboard.number_card";
static props = {
title: {type: String},
value: {type: Number},
};
}
9 changes: 9 additions & 0 deletions awesome_dashboard/static/src/dashboard/number_card.xml
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.number_card">
<label><t t-esc="props.title"/></label>
<h1 style="color: green;"><t t-esc="props.value"/></h1>
</t>

</templates>
58 changes: 58 additions & 0 deletions awesome_dashboard/static/src/dashboard/pie_chart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/** @odoo-module **/

import { Component, onWillStart, onMounted, onWillUpdateProps } from "@odoo/owl";
import { loadJS } from "@web/core/assets";


export class PieChart extends Component {
static props = {sizes: {type: Object}}
static template = "awesome_dashboard.pie_chart";

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

onWillUpdateProps((props) => {
this.chart.destroy();
this.renderChart(props);
});

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

renderChart(props) {
const ctx = document.getElementById('myChart');
const sizeData = props.sizes; // Assumes response like { sizes: { S: 100, M: 80, ... } }
const labels = Object.keys(sizeData);
const data = Object.values(sizeData);

this.chart = new Chart(ctx, {
type: "pie",
data: {
labels: labels,
datasets: [{
data: data,
backgroundColor: [
"#FF6384", "#36A2EB", "#FFCE56", "#4BC0C0", "#9966FF"
],
}],
},
options: {
responsive: true,
plugins: {
legend: {
position: "bottom",
},
title: {
display: true,
text: "T-Shirt Sizes Sold",
},
},
},
});
}

}
Loading