Skip to content

[ADD] training: add Real Estate root menu with Advertisements submenu #890

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 4 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
3 changes: 3 additions & 0 deletions awesome_dashboard/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
'web.assets_backend': [
'awesome_dashboard/static/src/**/*',
],
'awesome_dashboard.dashboard': [
'awesome_dashboard/static/src/dashboard/**/*',
]
},
'license': 'AGPL-3'
}
14 changes: 14 additions & 0 deletions awesome_dashboard/static/src/cards/numbercard/numbercard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component } from '@odoo/owl'

export class NumberCard extends Component {
static template = "awesome_dashboard.numberCard"
static components = {}
static props = {
title: {
type: String
},
value: {
type: Number | String
}
}
}
11 changes: 11 additions & 0 deletions awesome_dashboard/static/src/cards/numbercard/numbercard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="awesome_dashboard.numberCard">
<h2 class="text-lg-center">
<t t-esc="props.title"/>
</h2>
<div class="text-success text-bold text-lg-center" style="font-size: 38px; font-weight: bold">
<t t-esc="props.value"/>
</div>
</t>
</templates>
53 changes: 53 additions & 0 deletions awesome_dashboard/static/src/cards/piechartcard/piechart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use strict";
import { Component, onWillStart, useRef, useEffect } from '@odoo/owl'
import { AssetsLoadingError, loadJS } from '@web/core/assets';

export class PieChartCard extends Component {

static template = "awesome_dashboard.pieChartCard";
static components = {}
static props = {
title: {
type: String
},
value: {
type: Object
}
}

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

onWillStart(async () => {
try {
await loadJS(["/web/static/lib/Chart/Chart.js"]);
}
catch (error) {
if (!(error instanceof AssetsLoadingError)) {
throw error;
}
}
})

useEffect(() => this.renderPieChart())
}

renderPieChart() {
const ctx = this.canvasRef.el.getContext("2d");
if (this.chart) {
this.chart.destroy();
}
this.chart = new Chart(ctx, {
type: "pie",
data: {
labels: Object.keys(this.props.value || []), //["S", "M", "L", "XL", "XXL"],
datasets: [{
data: Object.values(this.props.value || []), // [10, 20, 15, 5, 2]
}],
},
options: {
responsive: true,
},
});
}
}
6 changes: 6 additions & 0 deletions awesome_dashboard/static/src/cards/piechartcard/piechart.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-name="awesome_dashboard.pieChartCard">
<canvas t-ref="canvas" width="300" height="300"></canvas>
</t>
</templates>
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.

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

import { Component, useState } from "@odoo/owl";
import { DashboardItem } from "../dashboarditem/dashboarditem";
import { Layout } from '@web/search/layout'
import { PieChartCard } from "../cards/piechartcard/piechart";
import { NumberCard } from "../cards/numbercard/numbercard";
import { ItemConfigurationPopup } from "./item_configuration_popup/item_configuration_popup";
import { _t } from "@web/core/l10n/translation";
import { browser } from "@web/core/browser/browser";
import { registry } from "@web/core/registry";
import { useService } from "@web/core/utils/hooks";

const dashboardRegistry = registry.category("awesome_dashboard.dashboard");

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

setup() {
this.action = useService("action");
this.state = useState({ items: [], chart: {}, itemConfigs: {} });
this.statisticsService = useService('statistics');
this.statsResult = useState(this.statisticsService);
this.dialogService = useService("dialog");
this.getBrowserLocalStorageData();
}

get items() {
return dashboardRegistry.get("awesome_dashboard.items");
}

get chart() {
return this.statsResult.orders_by_size;
}

showDialog() {
this.updateItemConfig = this.updateItemConfig.bind(this);
this.closeWrapper = this.closeWrapper.bind(this);
this.dialogService.add(ItemConfigurationPopup, {
items: this.items,
itemConfigs: this.state.itemConfigs,
closeWrapper: this.closeWrapper,
updateItemConfigCallback: this.updateItemConfig
});
}

openCustomers() {
this.action.doAction("contacts.action_contacts");
}

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

closeWrapper() {
this.getBrowserLocalStorageData();
}

updateItemConfig(updated_itemconfigs) {
this.state.itemConfigs = updated_itemconfigs;
}

getBrowserLocalStorageData() {
let item_configuration_localdata = browser.localStorage.getItem("awesome_dashboard.item_configuration");
if (item_configuration_localdata) {
this.state.itemConfigs = JSON.parse(item_configuration_localdata);
}
else {
let initialToggleState = {};
for (const item of this.items) {
initialToggleState[item.id] = true;
}
this.state.itemConfigs = initialToggleState;
}
}
}

registry.category("lazy_components").add("awesome_dashboard.dashboard", AwesomeDashboard);
4 changes: 4 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.o_dashboard {
display: flex;
flex-wrap: wrap;
}
22 changes: 22 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="awesome_dashboard.AwesomeDashboard">
<Layout className="'o_dashboard'" display="{controlPanel: {}}">
<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="showDialog" class="d-print-none btn" data-hotkey="u" data-tooltip="Actions">
<i class="fa fa-cog"/>
</button>
</t>
<t t-foreach="items" t-as="item" t-key="item_index">
<DashboardItem t-if="state.itemConfigs[item.id]" size="item.size || 1">
<t t-set="itemProp" t-value="item.props ? item.props(statsResult) : {'data': statistics}"/>
<t t-component="item.Component" t-props="itemProp" />
</DashboardItem>
</t>
</Layout>
</t>
</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Component, useState } from '@odoo/owl'
import { Dialog } from "@web/core/dialog/dialog";
import { CheckBox } from "@web/core/checkbox/checkbox";
import { browser } from "@web/core/browser/browser";

export class ItemConfigurationPopup extends Component {
static template = "awesome_dashboard.itemConfigurationDashboard"
static props = {
items: {
type: Object
},
itemConfigs: {
type: Object
},
closeWrapper: {
type: Function
},
updateItemConfigCallback: {
type: Function
}

}
static components = { CheckBox, Dialog }
static defaultProps = {}

setup() {
this.state = useState({
itemConfigs: this.props.itemConfigs
});
}

confirm() {
this.setBrowserLocalStorageData();
this.closeWrapper();
}

toggleItemConfigCard(itemid, checked) {
this.state.itemConfigs[itemid] = checked;
this.props.updateItemConfigCallback(this.state.itemConfigs)
}

setBrowserLocalStorageData() {
browser.localStorage.setItem(
"awesome_dashboard.item_configuration",
JSON.stringify(this.state.itemConfigs)
);
}

closeWrapper() {
this.props.closeWrapper();
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.itemConfigurationDashboard">
<Dialog>
<t t-set-slot="header">
<h4 class="modal-title text-break">
Dashboard Item Configuration
</h4>
<button type="button" class="btn-close" aria-label="Close" t-on-click="closeWrapper"></button>
</t>
<div class="d-inline-grid gap-1 m-2">
<h3>Which card do you wish to see?</h3>
<t t-foreach="props.items" t-as="item" t-key="item_index">
<CheckBox value="state.itemConfigs[item.id]" onChange.bind="(checked) => this.toggleItemConfigCard(item.id, checked)">
<t t-esc="item.description"/>
</CheckBox>
</t>
</div>
<t t-set-slot="footer">
<button class="button btn btn-lg btn-primary" t-on-click="confirm">
Done
</button>
</t>
</Dialog>
</t>
</templates>
11 changes: 11 additions & 0 deletions awesome_dashboard/static/src/dashboard_actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { registry } from '@web/core/registry'
import { Component, xml } from "@odoo/owl";
import { LazyComponent } from '@web/core/assets'

class AwesomeDashboardActions extends Component {
static components = { LazyComponent }
static template = xml`
<LazyComponent bundle="'awesome_dashboard.dashboard_assests'" Component="'awesome_dashboard.dashboard'" />
`;
}
registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardActions);
18 changes: 18 additions & 0 deletions awesome_dashboard/static/src/dashboarditem/dashboarditem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component } from '@odoo/owl';

export class DashboardItem extends Component {
static template = "awesome_dashboard.dashboardItem"
static components = {}
static props = {
size: {
type: Number,
optional: true,
default: 2
},
slots: {
type: Object
}
}

setup() {}
}
8 changes: 8 additions & 0 deletions awesome_dashboard/static/src/dashboarditem/dashboarditem.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 t-att-style="`width: ${18 * props.size}rem; border: 1px solid #d8dadd;`" t-att-class="'m-3 p-3 d-inline-block'">
<t t-slot="default"/>
</div>
</t>
</templates>
Loading