Skip to content
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/

ruff.toml
2 changes: 0 additions & 2 deletions awesome_dashboard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# -*- coding: utf-8 -*-

from . import controllers
41 changes: 19 additions & 22 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
# -*- coding: utf-8 -*-
{
'name': "Awesome Dashboard",

'summary': """
"name": "Awesome Dashboard",
"summary": """
Starting module for "Discover the JS framework, chapter 2: Build a dashboard"
""",

'description': """
"description": """
Starting module for "Discover the JS framework, chapter 2: Build a dashboard"
""",

'author': "Odoo",
'website': "https://www.odoo.com/",
'category': 'Tutorials',
'version': '0.1',
'application': True,
'installable': True,
'depends': ['base', 'web', 'mail', 'crm'],

'data': [
'views/views.xml',
],
'assets': {
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
"author": "Odoo",
"website": "https://www.odoo.com/",
"category": "Tutorials",
"version": "0.1",
"application": True,
"installable": True,
"depends": ["base", "web", "mail", "crm"],
"data": ["views/views.xml"],
"assets": {
"web.assets_backend": [
"awesome_dashboard/static/src/statistics_service.js",
"awesome_dashboard/static/src/dashboard_action.js",
"awesome_dashboard/static/src/dashboard/**/*.xml",
"awesome_dashboard/static/src/dashboard/**/*.scss",
],
"awesome_dashboard.dashboard": ["awesome_dashboard/static/src/dashboard/**/*.js"],
},
'license': 'AGPL-3'
"license": "AGPL-3",
}
4 changes: 1 addition & 3 deletions awesome_dashboard/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import controllers
28 changes: 14 additions & 14 deletions awesome_dashboard/controllers/controllers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-

import logging
import random

from odoo import http
from odoo.http import request

logger = logging.getLogger(__name__)


class AwesomeDashboard(http.Controller):
@http.route('/awesome_dashboard/statistics', type='jsonrpc', auth='user')
@http.route("/awesome_dashboard/statistics", type="jsonrpc", auth="user")
def get_statistics(self):
"""
Returns a dict of statistics about the orders:
Expand All @@ -22,15 +20,17 @@ def get_statistics(self):
"""

return {
'average_quantity': random.randint(4, 12),
'average_time': random.randint(4, 123),
'nb_cancelled_orders': random.randint(0, 50),
'nb_new_orders': random.randint(10, 200),
'orders_by_size': {
'm': random.randint(0, 150),
's': random.randint(0, 150),
'xl': random.randint(0, 150),
"average_quantity": random.randint(4, 12),
"average_time": random.randint(4, 123),
"nb_cancelled_orders": random.randint(0, 50),
"nb_new_orders": random.randint(10, 200),
"orders_by_size": {
"xs": random.randint(0, 150),
"s": random.randint(0, 150),
"m": random.randint(0, 150),
"l": random.randint(0, 150),
"xl": random.randint(0, 150),
"xxl": random.randint(0, 150),
},
'total_amount': random.randint(100, 1000)
"total_amount": random.randint(100, 1000),
}

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.

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

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

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

onApply() {
const disabledItems = this.items.filter((item) => !item.enabled).map((item) => item.id);
this.props.onApply(disabledItems);
this.props.close();
}
}
19 changes: 19 additions & 0 deletions awesome_dashboard/static/src/dashboard/configuration_dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="awesome_dashboard.ConfigurationDashboard">
<Dialog title="'Dashboard items configuration'" size="'md'">
<div class="p-3">
<p>Which cards do you wish to see?</p>
<div t-foreach="items" t-as="item" t-key="item.id" class="form-check my-2">
<CheckBox value="item.enabled" onChange="enabled => item.enabled = enabled">
<t t-esc="item.description"/>
</CheckBox>
</div>
</div>
<t t-set-slot="footer">
<button class="btn btn-primary" t-on-click="onApply">Done</button>
<button class="btn btn-secondary" t-on-click="props.close">Cancel</button>
</t>
</Dialog>
</t>
</templates>
3 changes: 3 additions & 0 deletions awesome_dashboard/static/src/dashboard/dahsboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.o_dashboard {
background-color: #bd917a;
}
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 @@
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 { browser } from "@web/core/browser/browser";
import { ConfigurationDashboard } from "./configuration_dashboard";

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

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

const storedConfig = browser.localStorage.getItem("disabledDashboardItems");
this.state = useState({
disabledItems: storedConfig ? JSON.parse(storedConfig) : [],
});
}
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"],
],
});
}
get filteredItems() {
const allItems = registry.category("dashboard_items").getAll();
return allItems.filter((item) => !this.state.disabledItems.includes(item.id));
}
openConfiguration() {
this.dialog.add(ConfigurationDashboard, {
items: registry.category("dashboard_items").getAll(),
disabledItems: this.state.disabledItems,
onApply: (disabledItems) => {
this.state.disabledItems = disabledItems;
browser.localStorage.setItem("disabledDashboardItems", JSON.stringify(disabledItems));
},
});
}
}

registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard);
20 changes: 20 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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>
<button class="btn btn-primary" t-on-click="openConfiguration">Configuration</button>
</t>
<div class="p-3 d-flex flex-wrap gap-3">
<t t-foreach="filteredItems" t-as="item" t-key="item.id">
<DashboardItem 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>
</templates>
12 changes: 12 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from "@odoo/owl";

export class DashboardItem extends Component {
static template = "awesome_dashboard.DashboardItem";
static props = {
slots: { type: Object },
size: { type: Number, optional: true },
};
static defaultProps = {
size: 1,
};
}
8 changes: 8 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.DashboardItem">
<div class="o_dashboard_item border bg-white p-3 d-flex border" t-att-style="'width: ' + (18 * props.size) + 'rem'">
<t t-slot="default"/>
</div>
</t>
</templates>
66 changes: 66 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { NumberCard } from "./number_card";
import { PieChartCard } from "./pie_chart_card";
import { registry } from "@web/core/registry";

const dashboardItemsRegistry = registry.category("dashboard_items");

dashboardItemsRegistry.add("average_quantity", {
id: "average_quantity",
description: "Average amount of t-shirt",
Component: NumberCard,
props: (stats) => ({
title: "Average amount of t-shirts / order",
value: stats.average_quantity,
}),
});

dashboardItemsRegistry.add("average_time", {
id: "average_time",
description: "Average time for an order",
Component: NumberCard,
props: (stats) => ({
title: "Average time for an order (hours)",
value: stats.average_time,
}),
});

dashboardItemsRegistry.add("total_amount", {
id: "total_amount",
description: "Total amount",
Component: NumberCard,
props: (stats) => ({
title: "Total amount of new orders",
value: stats.total_amount,
}),
});

dashboardItemsRegistry.add("nb_cancelled_orders", {
id: "nb_cancelled_orders",
description: "Cancelled orders this month",
Component: NumberCard,
props: (stats) => ({
title: "Number of cancelled orders",
value: stats.nb_cancelled_orders,
}),
});

dashboardItemsRegistry.add("nb_new_orders", {
id: "nb_new_orders",
description: "New orders",
Component: NumberCard,
props: (stats) => ({
title: "Number of new orders",
value: stats.nb_new_orders,
}),
});

dashboardItemsRegistry.add("orders_by_size", {
id: "orders_by_size",
description: "Orders by size",
Component: PieChartCard,
size: 2,
props: (stats) => ({
title: "Shirt orders by size",
data: stats.orders_by_size,
}),
});
9 changes: 9 additions & 0 deletions awesome_dashboard/static/src/dashboard/number_card.js
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,
};
}
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.NumberCard">
<div class="text-center p-2">
<div class="text-uppercase fw-bold text-muted small" t-esc="props.title"/>
<div class="fs-1 fw-bolder text-primary" t-esc="props.value"/>
</div>
</t>
</templates>
Loading