Skip to content

[IMP] awesome_owl : Adding Counter + Adding Card + Adding TodoList #797

New issue

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

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

Already on GitHub? # to your account

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

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

import { _t } from "@web/core/l10n/translation";
import { Layout } from "@web/search/layout"
import { Component, useState } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";

import { DashboardItem } from "./dashboard_item/dashboard_item";
import { NumberCard } from "./dashboard_item/cards/number_card";
import { PieChartCard } from "./dashboard_item/cards/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 template = "awesome_dashboard.AwesomeDashboard";
static components = { Layout, DashboardItem, NumberCard, PieChartCard, Dialog }

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

this.statistics = useState(this.statisticsService);

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

this.state = useState({
disabledItems: browser.localStorage.getItem("disabledDashboardItems")?.split(",") || []
});

this.dialogService = useService("dialog");
}

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

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

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

openDialog() {
this.dialog = this.dialogService.add(ConfigurationDialog, {
title: _t("Dashboard items configuration"),
contentHeader: _t("Which cards do you want to see ?"),
items: this.items,
disabledItemsIds: this.state.disabledItems,
updateConfiguration: (newDisabledItems) => this.updateConfiguration(newDisabledItems)
});
}
}

class ConfigurationDialog extends Component {
static template = "awesome_dashboard.ConfigurationDialog";
static components = { Dialog, CheckBox }

static props = {
title: { type: String, optional: true },
contentHeader: { type: String, optional: true },
items: Object,
disabledItemsIds: Object,
updateConfiguration: Function,
close: { type: Function }
}

static defaultProps = {
title: _t("Dashboard items configuration"),
contentHeader: _t("Which cards do you want to see ?"),
}

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

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

onApply() {
const disabledItems = this.items.filter((item) => !item.enabled).map((item) => item.id);

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

this.props.updateConfiguration(disabledItems);

this.props.close();
}
}

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: gray;
}
40 changes: 40 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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 type="button" class="btn btn-primary" t-on-click="openCustomers">Customers</button>
<button type="button" class="btn btn-primary" t-on-click="openLeads">Leads</button>
</t>
<t t-set-slot="control-panel-additional-actions">
<button t-on-click="openDialog" class="btn p-0 ms-1 border-0">
<i class="fa fa-cog"></i>
</button>
</t>
<div class="d-flex flex-wrap" t-if="statistics.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(statistics) : {'data': statistics}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</div>
</Layout>
</t>
<t t-name="awesome_dashboard.ConfigurationDialog">
<Dialog title="props.title">
<t t-esc="props.contentHeader" />
<div>
<t t-foreach="items" t-as="item" t-key="item.id">
<CheckBox id="item.id" value="item.enabled" onChange="(ev) => this.onChange(ev, item)">
<t t-esc="item.description" />
</CheckBox>
</t>
</div>
<t t-set-slot="footer">
<button class="btn btn-primary" t-on-click="onApply">Done</button>
</t>
</Dialog>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component } from "@odoo/owl";

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

static props = {
title: { type: String },
number: { type: Number },
};

setup() {

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.number_card">
<div class="card-title">
<t t-esc="props.title" />
</div>
<div class="card-body fs-1 fw-bold text-success text-center">
<t t-esc="props.number"/>
</div>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component } from "@odoo/owl";
import { PieChart } from "../charts/pie_chart";

export class PieChartCard extends Component {
static template = "awesome_dashboard.pie_chart_card";
static components = { PieChart };

static props = {
label: String,
data: { type: Object }
};

setup() {

}
}

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.pie_chart_card">
<div class="card-title">
<t t-esc="props.label" />
</div>
<PieChart data="props.data" />
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

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


export class PieChart extends Component {
static template = "awesome_dashboard.pie_chart"

static props = {
data: { type: Object, optional: true }
}

setup() {
this.canvasRef = useRef("canvas");
this.chart = null

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


onMounted(() => this.renderChart());

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

onWillUpdateProps(() => this.renderChart());
}

renderChart() {
if (this.chart) {
this.chart.destroy();
}

if (this.props.data) {
let data = {
datasets: [{
data: Object.values(this.props.data)
}],
labels: Object.keys(this.props.data)
}

this.chart = new Chart(this.canvasRef.el, {
type: 'pie',
data: data
});
}
}
}
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.pie_chart">
<div class="h-100" t-ref="root">
<div class="h-100 position-relative" t-ref="container">
<canvas t-ref="canvas" />
</div>
</div>
</t>
</templates>
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.dashboard_item";

static props = {
size: { type: Number, default: 1, optional: true },
slots: Object,
};

static defaultProps = {
size: 1,
};

setup() {

}
}

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.dashboard_item">
<div class="card d-inline-block m-2" t-attf-style="width: {{18*props.size}}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>
</templates>
Loading