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

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

import { _t } from "@web/core/l10n/translation";
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 "../dashboarditem/dashboarditem";
import { PieChart } from "../piechart/piechart";

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

setup() {
const { status } = owl;
this.action = useService("action");
this.state = useState({ items: [], chart: {} });
this.statisticsService = useService('statistics');
this.loadStatisticsData();
}


async loadStatisticsData() {
let result = await this.statisticsService.loadStatistics();
this.state.items = [
{
id: 1,
title: 'Number of new orders this month',
value: result.nb_new_orders
},
{
id: 2,
title: 'Total amount of new orders this month',
value: result.nb_new_orders
},
{
id: 3,
title: 'Average amount of t-shirt by order this month',
value: result.nb_new_orders
},
{
id: 4,
title: 'Number of cancelled orders this month',
value: result.nb_cancelled_orders
},
{
id: 5,
title: "Average time for an order to go from β€˜new’ to β€˜sent’ or β€˜cancelled`",
value: result.average_time
}
];
this.state.chart = result.orders_by_size;

}

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]
});
}
}

registry.category("actions").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;
}
26 changes: 26 additions & 0 deletions awesome_dashboard/static/src/dashboard/dashboard.xml
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.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-foreach="state.items" t-as="item" t-key="item_index">
<DashboardItem size="2">
<h2 class="text-lg-center">
<t t-esc="item.title"/>
</h2>
<div class="text-success text-bold text-lg-center" style="font-size: 38px; font-weight: bold">
<t t-esc="item.value"/>
</div>
</DashboardItem>
</t>
<DashboardItem>
<PieChart t-props='{
key_value: state.chart
}' />
</DashboardItem>
</Layout>
</t>
</templates>
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 black;`" t-att-class="'m-3 p-3 d-inline-block'">
<t t-slot="default"/>
</div>
</t>
</templates>
45 changes: 45 additions & 0 deletions awesome_dashboard/static/src/piechart/piechart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use strict";
import { Component, onWillStart, useRef, useEffect } from '@odoo/owl'
import { AssetsLoadingError, loadJS } from '@web/core/assets';

export class PieChart extends Component {

static template = "awesome_dashboard.pieChart";
static components = {}
static props = {
key_value: 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");
this.chart = new Chart(ctx, {
type: "pie",
data: {
labels: Object.keys(this.props.key_value), //["S", "M", "L", "XL", "XXL"],
datasets: [{
data: Object.values(this.props.key_value), // [10, 20, 15, 5, 2]
}],
},
options: {
responsive: true,
},
});
}
}
6 changes: 6 additions & 0 deletions awesome_dashboard/static/src/piechart/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.pieChart">
<canvas t-ref="canvas" width="300" height="300"></canvas>
</t>
</templates>
16 changes: 16 additions & 0 deletions awesome_dashboard/static/src/services/statistics_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { registry } from '@web/core/registry';
import { rpc } from "@web/core/network/rpc";
import { memoize } from "@web/core/utils/functions";

const loadStatistics = memoize(async () => {
return await rpc("/awesome_dashboard/statistics");
});

export const statisticsService = {
dependencies: [],
start() {
return { loadStatistics };
},
};

registry.category("services").add("statistics", statisticsService);
1 change: 1 addition & 0 deletions awesome_owl/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
('include', 'web._assets_core'),
'web/static/src/libs/fontawesome/css/font-awesome.css',
'awesome_owl/static/src/**/*',
'awesome_owl/static/css/**'
],
},
'license': 'AGPL-3'
Expand Down
10 changes: 10 additions & 0 deletions awesome_owl/static/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.fade-in {
opacity: 0;
transform: translateY(-10px);
transition: opacity 0.5s ease, transform 0.5s ease;
}

.fade-in.show {
opacity: 1;
transform: translateY(0);
}
21 changes: 21 additions & 0 deletions awesome_owl/static/src/components/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component, markup, useState } from '@odoo/owl'

export class Card extends Component {
static template = "awesome_owl.Card"
static components = {}
static props = {
title: { type: String, default: "Card Title", required: true },
slots: { type: Object },
visit: { type: String, default: "Visit us", optional: true }
}

setup() {
super.setup();
this.state = useState({ isOpen: true })
this.markup_visit = markup(this.props.visit)
}

toggleCard() {
this.state.isOpen = !this.state.isOpen;
}
}
28 changes: 28 additions & 0 deletions awesome_owl/static/src/components/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<template xml:space="preserve">
<t t-name="awesome_owl.Card">
<div class="card d-inline-block m-2" style="width: 28rem;">
<div class="card-body">
<div class="d-flex mb-3" style="justify-content: space-between">
<h5 class="card-title"><t t-esc="props.title"/></h5>
<button class="btn btn-sm text-bg-light" t-on-click="toggleCard">
<t t-if="state.isOpen">
Close
</t>
<t t-else="">
Open
</t>
</button>
</div>
<div t-if="state.isOpen">
<p class="card-text">
<t t-slot="default"/>
</p>
<t t-if="props.visit">
<t t-out="markup_visit"></t>
</t>
</div>
</div>
</div>
</t>
</template>
23 changes: 23 additions & 0 deletions awesome_owl/static/src/components/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Component, useState } from "@odoo/owl";

export class Counter extends Component {

static template = "awesome_owl.Counter";
static components = {}
static props = {
onChange: {
type: Function,
optional: true
}
}

setup() {
super.setup();
this.state = useState({ value: 1 })
}

increment() {
this.state.value++;
this.props.onChange?.(this.state.value);
}
}
14 changes: 14 additions & 0 deletions awesome_owl/static/src/components/counter/counter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<template xml:space="preserve">
<t t-name="awesome_owl.Counter">
<div class="card shadow-sm">
<div class="card-body">
<h2 class="card-title">Counter</h2>
<div class="d-flex" style="align-items: center; justify-content: space-between">
<button class="btn text-bg-success" t-on-click="increment" style="background-color: 'blue'">Increment</button>
<p class="card-text">Value: <t t-esc="state.value"/></p>
</div>
</div>
</div>
</t>
</template>
58 changes: 58 additions & 0 deletions awesome_owl/static/src/components/playground/playground.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/** @odoo-module **/

import { Component, useEffect, useState } from "@odoo/owl";
import { Counter } from "../counter/counter";
import { Card } from "../card/card";
import { TodoList } from "../todo/todolist/todolist";

export class Playground extends Component {
static template = "awesome_owl.Playground";
static components = { Counter, Card, TodoList }
static props = {}

setup() {
super.setup();
this.state = useState({ counters: 2, sum: 2 });

useEffect(() => {
this.state.sum += this.state.counters;
},()=>[this.state.counters]);

this.cards = [
{
title: "Discover the Stars",
body: "Explore the mysteries of the universe and learn about constellations and galaxies.",
visit: "<a href='https://nasa.gov' target='_blank'>https://nasa.gov</a>"
},
{
title: "Healthy Living Tips",
body: "Simple and effective ways to improve your health and boost your energy every day.",
visit: "<a href='https://www.healthline.com' target='_blank'>https://www.healthline.com</a>"
},
{
title: "Travel on a Budget",
body: "Find out how to see the world without breaking the bank β€” travel smart and save money.",
visit: "<a href='https://www.nomadicmatt.com' target='_blank'>https://www.nomadicmatt.com</a>"
},
{
title: "Mastering JavaScript",
body: "Step-by-step guide to becoming proficient in JavaScript and building dynamic web apps.",
visit: "<a href='https://javascript.info' target='_blank'>https://javascript.info</a>"
},
{
title: "Cooking Made Easy",
body: "Delicious and quick recipes for busy people who love home-cooked meals.",
visit: "<a href='https://www.budgetbytes.com' target='_blank'>https://www.budgetbytes.com</a>"
},
{
title: "Mindfulness & Meditation",
body: "Learn techniques to reduce stress and enhance your mental wellbeing through mindfulness.",
visit: "<a href='https://www.headspace.com' target='_blank'>https://www.headspace.com</a>"
}
];
}

incrementSum() {
this.state.sum++;
}
}
Loading