Skip to content

18.0 training paay #812

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

Draft
wants to merge 9 commits into
base: 18.0
Choose a base branch
from
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
5 changes: 4 additions & 1 deletion awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
],
'assets': {
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
'awesome_dashboard/static/src/dashboard_action.js',
],
'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.

57 changes: 57 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/** @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/dashboard_item";
import { DashboardSettings } from "./dashboard_settings/dashboard_settings";
import { browser } from "@web/core/browser/browser";

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

setup() {
this.actionService = useService("action");
this.statisticsService = useService("awesome_dashboard.statistics");
this.statistics = useState(this.statisticsService.data);

this.dialogService = useService("dialog");

const dashboardItemsRegistry = registry.category("awesome_dashboard");
this.items = dashboardItemsRegistry.getAll();

this.state = useState({
uncheckedItems: browser.localStorage.getItem("uncheckedItems")?.split(",").filter(id => id) || [],
});
}

updateConfiguration(newUncheckedItems) {
this.state.uncheckedItems.length = 0;
this.state.uncheckedItems.push(...newUncheckedItems);
}

openConfiguration() {
this.dialogService.add(DashboardSettings, {
items: this.items,
initialUncheckedItems: this.state.uncheckedItems,
updateConfiguration: this.updateConfiguration.bind(this),
});
}

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

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

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: grey;
}
28 changes: 28 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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 t-on-click="openCustomers" type="button" class="btn btn-primary me-2" title="Customers">Customers</button>
<button t-on-click="openLeads" type="button" class="btn btn-primary" title="Leads">Leads</button>
</t>

<t t-set-slot="control-panel-additional-actions">
<button class="btn btn-light" title="Dashboard Settings" t-on-click="openConfiguration">
<i class="fa fa-cog"></i>
</button>
</t>
<div class="p-3">
<div class="d-flex flex-wrap">
<t t-foreach="Object.values(items)" t-as="item" t-key="item.id">
<DashboardItem t-if="!state.uncheckedItems.includes(item.id)" 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>
</div>
</div>
</Layout>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @odoo-module **/
import { Component } from "@odoo/owl";

export class DashboardItem extends Component {
static template = "awesome_dashboard.DashboardItem";

static props = {
size: {
type: Number,
optional: true,
default: 1,
},
slots: {
type: Object,
optional: true,
shape: {default: Object}
}
}
}
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.DashboardItem">
<div class="card m-2 d-inline-block shadow-sm" t-attf-style="width: {{(props.size || 1) * 18}}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>
</templates>
67 changes: 67 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/** @odoo-module **/

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

export const items = [
{
id: "nb_new_orders",
description: "Number of new orders this month",
Component: NumberCard,
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,
props: (data) => ({
title: "Total amount of new orders this month",
value: data.total_amount
}),
},
{
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: "nb_cancelled_orders",
description: "Number of cancelled orders this month",
Component: NumberCard,
props: (data) => ({
title: "Number of cancelled orders this month",
value: data.nb_cancelled_orders
}),
},
{
id: "average_time",
description: "Average time for order processing",
Component: NumberCard,
props: (data) => ({
title: "Average time for an order to go from new to sent or cancelled",
value: `${data.average_time} hours`
}),
},
{
id: "orders_by_size_chart",
description: "T-Shirt Sales by Size Chart",
Component: PieChartCard,
size: 2,
props: (data) => ({
title: "T-Shirt Sales by Size",
data: data
}),
},
];

items.forEach((item) => {
registry.category("awesome_dashboard").add(item.id, item)
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/** @odoo-module **/

import { Component, useState } from "@odoo/owl";
import { Dialog } from "@web/core/dialog/dialog";
import { browser } from "@web/core/browser/browser";

export class DashboardSettings extends Component {
static template = "awesome_dashboard.DashboardSettings";
static components = { Dialog };

static props = {
close: { type: Function },
};

setup() {
const items = this.props.items || {};
const initialUncheckedItems = this.props.initialUncheckedItems || [];

this.dialogDisplayItems = useState(
Object.values(items).map((item) => ({
...item,
checked: !initialUncheckedItems.includes(item.id),
}))
);
}

onChange(checked, itemInDialog) {
const targetItem = this.dialogDisplayItems.find(i => i.id === itemInDialog.id);
if (targetItem) {
targetItem.checked = checked;
}
}

confirmChanges() {
const newUncheckedItems = this.dialogDisplayItems.filter((item) => !item.checked).map((item) => item.id);

browser.localStorage.setItem("uncheckedItems", newUncheckedItems.join(","));

if (this.props.updateConfiguration) {
this.props.updateConfiguration(newUncheckedItems);
}
this.props.close();
}
}
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.DashboardSettings">
<Dialog title="'Dashboard Items Configuration'">
<div class="p-3">
<p>Select items to display on your dashboard:</p>
<div t-foreach="dialogDisplayItems" t-as="item" t-key="item.id" class="form-check mb-2">
<input
type="checkbox"
class="form-check-input"
t-att-id="'settings_item_' + item.id"
t-att-checked="item.checked"
t-on-change="(ev) => this.onChange(ev.target.checked, item)"
/>
<label class="form-check-label" t-att-for="'settings_item_' + item.id">
<t t-out="item.description"/>
</label>
</div>
</div>
<t t-set-slot="footer">
<button class="btn btn-primary" t-on-click="confirmChanges">Apply</button>
<button class="btn btn-secondary ms-2" t-on-click="props.close">Cancel</button>
</t>
</Dialog>
</t>
</templates>
11 changes: 11 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,11 @@
/** @odoo-module **/

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

export class NumberCard extends Component {
static template = "awesome_dashboard.NumberCard";
static props = {
title: { type: String },
value: { type: [String, Number] },
};
}
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.NumberCard">
<div>
<h5 t-out="props.title"/>
<p class="fs-4 fw-bold text-success" t-out="props.value"/>
</div>
</t>
</templates>
Loading