-
Notifications
You must be signed in to change notification settings - Fork 2.6k
18.0 onboarding owl hasaa #974
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
base: 18.0
Are you sure you want to change the base?
Changes from 14 commits
874a1e0
32c21b4
21928ba
f8be1b7
41e82cc
a4fc171
0ecf95d
a5fc2c2
abb7b5e
ef33a66
34ffcc5
abb94b6
8c7d448
3dbc265
3f92bd4
f4f128c
350d4cf
d1388b1
8262cb2
fff2bf5
8dd8fcc
bce32b6
3a7ac6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Run (Update)", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"python": "/usr/bin/python3", | ||
"program": "/home/odoo/odoo/odoo-bin", | ||
"console": "integratedTerminal", | ||
"args": [ | ||
"--database", "rd-demo", | ||
"--dev", "xml", | ||
// "-u", "we_guarantee", | ||
"--addons-path", "/home/odoo/enterprise,/home/odoo/odoo/addons,/home/odoo/tutorials", | ||
"--log-level", "info", | ||
"--limit-time-real=0", | ||
"--limit-time-cpu=0", | ||
], | ||
"variablePresentation": {}, | ||
}, | ||
] | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.o_dashboard { | ||
background-color: #f0f0f0; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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 { PieChart } from "./pie_chart"; | ||
|
||
class AwesomeDashboard extends Component { | ||
static template = "awesome_dashboard.AwesomeDashboard"; | ||
static components = { Layout, DashboardItem, PieChart } | ||
setup() { | ||
this.action = useService("action"); | ||
this.statistics = useService("awesome_dashboard.statistics"); | ||
this.result = useState(this.statistics); | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
openCustomers() { | ||
this.action.doAction("base.action_partner_form"); | ||
} | ||
openLeads() { | ||
this.action.doAction({ | ||
type: 'ir.actions.act_window', | ||
name: 'CRM Leads', | ||
|
||
target: 'current', | ||
res_model: 'crm.lead', | ||
views: [[false,'list'],[false, 'form']], | ||
}); | ||
} | ||
} | ||
|
||
registry.category("lazy_components").add("AwesomeDashboard", AwesomeDashboard); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_dashboard.AwesomeDashboard" owl="1"> | ||
<Layout className="'o_dashboard h-100'" display="{ controlPanel: {} }"> | ||
<t t-set-slot="layout-buttons"> | ||
<button class="btn btn-primary" t-on-click="openCustomers">Customers</button> | ||
<button class="btn btn-secondary" t-on-click="openLeads">Leads</button> | ||
</t> | ||
<t t-set-slot="default"> | ||
<div class="o-awesome-dashboard-content" t-if="statistics.isReady"> | ||
|
||
<DashboardItem> | ||
Average amount of t-shirt by order this month | ||
<div class="fs-1 fw-bold text-success text-center"> | ||
<t t-esc="result.average_quantity"/> | ||
</div> | ||
</DashboardItem> | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
<DashboardItem> | ||
Average time for an order to go from 'new' to 'sent' or 'cancelled' | ||
<div class="fs-1 fw-bold text-success text-center"> | ||
<t t-esc="result.average_time"/> | ||
</div> | ||
</DashboardItem> | ||
<DashboardItem> | ||
Number of new orders this month | ||
<div class="fs-1 fw-bold text-success text-center"> | ||
<t t-esc="result.nb_new_orders"/> | ||
</div> | ||
</DashboardItem> | ||
<DashboardItem> | ||
Number of cancelled orders this month | ||
<div class="fs-1 fw-bold text-success text-center"> | ||
<t t-esc="result.nb_cancelled_orders"/> | ||
</div> | ||
</DashboardItem> | ||
<DashboardItem> | ||
Total amount of new orders this month | ||
<div class="fs-1 fw-bold text-success text-center"> | ||
<t t-esc="result.total_amount"/> | ||
</div> | ||
</DashboardItem> | ||
<DashboardItem> | ||
Shirt order by size | ||
<PieChart label="'Orders By Size'" data="result.orders_by_size"/> | ||
</DashboardItem> | ||
</div> | ||
</t> | ||
</Layout> | ||
</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, | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
optional: true, | ||
}, | ||
slots: { | ||
type: Object, | ||
}, | ||
}; | ||
get Width() { | ||
return 18*this.props.size | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_dashboard.dashboard_item" owl='1'> | ||
<div class="card d-inline-block m-2" t-attf-style="width: {{Width}}rem;"> | ||
<div class="card-body"> | ||
<t t-slot="default"/> | ||
</div> | ||
</div> | ||
</t> | ||
|
||
</templates> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Component, onWillStart,useRef, onMounted, onWillUnmount } from "@odoo/owl"; | ||
import { loadJS } from "@web/core/assets"; | ||
|
||
|
||
export class PieChart extends Component { | ||
static template = "awesome_dashboard.pie_chart"; | ||
static props = { | ||
label: String, | ||
data : Object, | ||
} | ||
setup(){ | ||
this.canvasRef = useRef("canvas_pie"); | ||
onWillStart(async () => loadJS("/web/static/lib/Chart/Chart.js")); | ||
onMounted(()=> { | ||
this.renderChart(); | ||
} | ||
); | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
onWillUnmount(()=> { | ||
this.chart.destroy(); | ||
|
||
}); | ||
|
||
|
||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
renderChart(){ | ||
this.chart = new Chart(this.canvasRef.el,{ | ||
type: 'pie', | ||
data : { | ||
labels : Object.keys(this.props.data), | ||
datasets:[ | ||
{ | ||
label: this.props.label, | ||
data : Object.values(this.props.data), | ||
}, | ||
], | ||
} | ||
}) | ||
|
||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_dashboard.pie_chart" owl='1'> | ||
<div t-att-class="'h-100 ' + props.class"> | ||
<div class="h-100 position-relative"> | ||
<canvas t-ref="canvas_pie" /> | ||
</div> | ||
</div> | ||
</t> | ||
|
||
</templates> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { registry } from "@web/core/registry"; | ||
import { rpc } from "@web/core/network/rpc"; | ||
import { reactive } from "@odoo/owl" | ||
|
||
|
||
const statisticsService = { | ||
start() { | ||
|
||
const statistics = reactive({isReady : false}); | ||
|
||
async function loadingData() { | ||
const data = await rpc("/awesome_dashboard/statistics"); | ||
Object.assign(statistics,data,{isReady : true}); | ||
setInterval(loadingData, 10*60*1000); | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
loadingData(); | ||
return statistics; | ||
}, | ||
}; | ||
|
||
registry.category("services").add("awesome_dashboard.statistics", statisticsService); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Component, xml } from "@odoo/owl"; | ||
import {LazyComponent } from "@web/core/assets"; | ||
import { registry } from "@web/core/registry"; | ||
|
||
export class AwesomeDashboardLoader extends Component { | ||
static components = { LazyComponent }; | ||
static template = xml` | ||
<LazyComponent bundle="'awesome_dashboard.dashboard'" Component="'AwesomeDashboard'" /> | ||
`; | ||
} | ||
|
||
registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboardLoader); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Component, useState } from "@odoo/owl"; | ||
|
||
export class Card extends Component { | ||
static template = "awesome_owl.Card" | ||
|
||
static props = { | ||
title: String, | ||
content:{ | ||
type: String, | ||
optional: true, | ||
}, | ||
slots:Object, // I added this to allow slots inside cards | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}; | ||
|
||
setup(){ | ||
this.state = useState({open : true}); | ||
} | ||
|
||
ontoggleVisibility() { | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
this.state.open = !this.state.open; | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<templates xml:space="preserve"> | ||
|
||
<t t-name="awesome_owl.Card" owl="1"> | ||
<header> | ||
<button t-on-click="ontoggleVisibility"/> | ||
</header> | ||
<t t-if="state.open"> | ||
<div class="card d-inline-block m-2"> | ||
<div class="card-body"> | ||
<h5 class="card-title"><t t-esc="props.title"/></h5> | ||
<p class="card-text"> | ||
<t t-slot="default"/> | ||
</p> | ||
</div> | ||
</div> | ||
</t> | ||
</t> | ||
|
||
</templates> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Component , useState} from "@odoo/owl"; | ||
|
||
export class Counter extends Component { | ||
static template = "awesome_owl.Counter"; | ||
static props = { | ||
onChange: { | ||
type: Function, | ||
optional: true, | ||
} | ||
}; | ||
|
||
setup() { | ||
this.state =useState({ value: 0 }); | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
increment() { | ||
this.state.value ++; | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
if (this.props.onChange){ | ||
this.props.onChange(); | ||
} | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} |
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_owl.Counter" owl="1"> | ||
<div class="p-3"> | ||
<p>Counter: <t t-esc="state.value"/></p> | ||
<button class="btn btn-primary" t-on-click="increment">Increment</button> | ||
</div> | ||
</t> | ||
|
||
</templates> | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
/** @odoo-module **/ | ||
|
||
import { Component } from "@odoo/owl"; | ||
import { Component, markup , useState} from "@odoo/owl"; | ||
import { Card } from "./card/card"; // Import the Card component | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
import { Counter } from "./counter/counter"; | ||
import { TodoList } from "./todo/todo_list"; | ||
|
||
export class Playground extends Component { | ||
static template = "awesome_owl.playground"; | ||
static components = { Card , Counter, TodoList }; | ||
setup() { | ||
this.htmlContent = markup("<div class='text-primary'>some content</div>"); | ||
this.state = useState({ sum : 0 }); | ||
this.incrementSum = this.incrementSum.bind(this); | ||
} | ||
|
||
incrementSum() { | ||
this.state.sum ++; | ||
hasaa-odoo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't push anything inside .vscode 💢