Skip to content
Draft
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
6 changes: 5 additions & 1 deletion awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
],
'assets': {
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
'awesome_dashboard/static/src/dashboard_loader.js',
],

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

132 changes: 132 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/** @odoo-module **/
import { Component, useState, onWillStart } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { Layout } from "@web/search/layout";
import { useService } from "@web/core/utils/hooks";
import { Dialog } from "@web/core/dialog/dialog";
import { CheckBox } from "@web/core/checkbox/checkbox";
import { browser } from "@web/core/browser/browser";
import { PieChart } from "./pie_chart/pie_chart"
// import { rpc } from "@web/core/network/rpc"
// import { items } from "./dashboard_item";


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

setup() {
this.myService = useService("awesome_dashboard_service");
this.action = useService("action");
this.statistics = useService("awesome_dashboard.statistics");
this.dialogService = useService("dialog");
// this.items = items;
this.items = registry.category("awesome_dashboard.items").getAll();


// stats for statistics cards
this.stats = useState(this.statistics);

// Local Storage Data
const savedDisabled =
browser.localStorage
.getItem("disabledDashboardItems")
?.split(",") || [];

this.ui = useState({
disabledItems: savedDisabled,
});

//rpc calls every time means reopeing dashboard refreshes value
// onWillStart(async () => {
// this.stats.stats = await rpc("/awesome_dashboard/statistics", {})
// });

//memoize means reopeing dashboard will not refreshes, value will store in cache
// onWillStart(async () => {
// this.stats.stats = await this.statistics.loadStatistics();
// });

}

inc() {
this.myService.inc();
this.render(); // simple way to refresh UI for now
}

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

openLeads() {
this.action.doAction({
type: "ir.actions.act_window",
res_model: "crm.lead",
views: [
[false, "list"],
[false, "form"]
],
});
}
openConfiguration() {
this.dialogService.add(ConfigurationDialog, {
items: this.items,
disabledItems: this.ui.disabledItems,
onUpdateConfiguration: this.updateConfiguration.bind(this),
});
}

updateConfiguration(newDisabledItems) {
this.ui.disabledItems = newDisabledItems;
}

openOrdersBySize(size) {
this.action.doAction({
type: "ir.actions.act_window",
name: "Orders",
res_model: "sale.order",
views: [[false, "list"], [false, "form"]],
domain: [["order_line.product_id.product_template_attribute_value_ids.name", "=", size.toUpperCase()]],
});
}

}

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

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

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

onChange(checked, changedItem) {
changedItem.enabled = checked;

const newDisabledItems = this.items
.filter((item) => !item.enabled)
.map((item) => item.id);

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

this.props.onUpdateConfiguration(newDisabledItems);
}
}


// registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
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: beige; // gray
}
90 changes: 90 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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="control-panel-create-button">
<button class="btn btn-primary me-2" t-on-click="openCustomers">
Customers
</button>
<button class="btn btn-secondary" 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>

<t t-if="stats.data">
<div class="d-flex flex-wrap gap-3 mt-3">
<t t-foreach="items" t-as="item" t-key="item.id">
<t t-if="!ui.disabledItems.includes(item.id)">
<div class="col-12 col-md-6 col-lg-4 mb-3">
<t t-set="itemProps" t-value="item.props ? item.props(stats,{openOrdersBySize: openOrdersBySize.bind(this)}) : { data: stats }"/>
<t t-component="item.Component" t-props="itemProps"/>
</div>
</t>
</t>

<div class="card p-3" style="width: 18rem;">
<div class="fw-bold">Average amount of t-shirt by order this month</div>
<div class="display-6 text-success">
<t t-esc="stats.data.average_quantity"/>
</div>
</div>

<div class="card p-3" style="width: 18rem;">
<div class="fw-bold">Number of cancelled orders this month</div>
<div class="display-6 text-success">
<t t-esc="stats.data.nb_cancelled_orders"/>
</div>
</div>

<div class="card p-3" style="width: 18rem;">
<div class="fw-bold">Average time from 'new' to 'sent'/'cancelled'</div>
<div class="display-6 text-success">
<t t-esc="stats.data.average_time"/>
</div>
</div>
<!-- <div class="card p-3 mt-3" style="width: 40rem;">
<div class="fw-bold mb-2">Shirt orders by size</div>
<PieChart data="stats.data.orders_by_size" size="260"/>
</div> -->

</div>
</t>

<t t-else="">
<div class="mt-3 text-muted">Loading statistics...</div>
</t>


<div>
hello dashboard
</div>
<br/>

<div>
<p>Service Counter: <t t-esc="myService.get()"/>
</p>
<button class="btn btn-primary" t-on-click="inc">Increase</button>
</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>
76 changes: 76 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/** @odoo-module **/

import { registry } from "@web/core/registry";
import { StandardItem } from "./standard_item/standard_item";
import { PieChart } from "./pie_chart/pie_chart";
import { _t } from "@web/core/l10n/translation";

const dashboardItemRegistry =
registry.category("awesome_dashboard.items");

dashboardItemRegistry.add("total_amount", {
id: "total_amount",
description: "Total amount",
Component: StandardItem,
props: (stats) => ({
title: _t("Total amount of new orders this month"),
value: stats.data?.total_amount ?? 0,
}),
});

dashboardItemRegistry.add("new_orders", {
id: "new_orders",
description: "New orders",
Component: StandardItem,
props: (stats) => ({
title: _t("Number of new orders this month"),
value: stats.data?.nb_new_orders ?? 0,
}),
});

dashboardItemRegistry.add("pie_chart", {
id: "pie_chart",
description: "Orders by size",
Component: PieChart,
size: 2,
props: (stats, {openOrdersBySize}) => ({
title: _t("Shirt orders by size"),
data: stats.data?.orders_by_size ?? 0,
onSliceClick: openOrdersBySize,
}),
});

// Below code is exporting items in a list

// export const items = [
// {
// id: "total_amount",
// description: "Total amount",
// Component: StandardItem,
// size: 1,
// props: (stats) => ({
// title: "Total amount of new orders this month",
// value: stats.data?.total_amount,
// }),
// },
// {
// id: "new_orders",
// description: "New orders",
// Component: StandardItem,
// size: 1,
// props: (stats) => ({
// title: "Number of new orders this month",
// value: stats.data?.nb_new_orders,
// }),
// },
// {
// id: "pie_chart",
// description: "Orders by size",
// Component: PieChart,
// size: 2,
// props: (stats) => ({
// data: stats.data?.orders_by_size,
// }),
// },

// ];
20 changes: 20 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";

const dashboardService = {
start() {
let counter = 0;

return {
get() {
return counter;
},
inc() {
counter += 1;
return counter;
},
};
},
};

registry.category("services").add("awesome_dashboard_service", dashboardService);
Loading