Skip to content

18.0 awesome owl tutorial (OUAA) #800

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 17 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
92c0815
[ADD] awesome_owl: implement counter functionality and integrate into…
oumaima-aarabe May 28, 2025
abd6da5
[FIX] awesome_owl: add duplicate Counter component and maintain alig…
oumaima-aarabe May 28, 2025
010fb2c
[ADD] awesome_owl: create Card component and integrate into Playground
oumaima-aarabe May 28, 2025
35f6d8d
[ADD] awesome_owl: update Card component to use t-out for rendering p…
oumaima-aarabe May 28, 2025
33d9d61
[ADD] awesome_owl: define props for Card and Counter components to en…
oumaima-aarabe May 28, 2025
7caed05
[ADD] awesome_owl: enhance Counter component with onChange prop and i…
oumaima-aarabe May 28, 2025
99ade4c
[ADD] awesome_owl: integrate TodoList component and create TodoItem f…
oumaima-aarabe May 28, 2025
722fa7e
[ADD] awesome_owl: modify TodoItem component to conditionally apply s…
oumaima-aarabe May 28, 2025
86ee055
[ADD] awesome_owl: implement dynamic todo addition in TodoList component
oumaima-aarabe May 28, 2025
cf1b792
[ADD] awesome_owl: implement autofocus utility and integrate it in To…
oumaima-aarabe May 30, 2025
d35d10a
[ADD] awesome_owl: implement toggle and remove functionality in TodoI…
oumaima-aarabe May 30, 2025
73465b9
[ADD] awesome_owl: update Card component to use slots for dynamic con…
oumaima-aarabe May 30, 2025
82ac6ad
[ADD] awesome_owl: enhance Card component with toggle functionality a…
oumaima-aarabe May 30, 2025
1e85def
[ADD] awesome_dashboard: implement layout and buttons for customer an…
oumaima-aarabe Jun 2, 2025
5a048a9
[ADD] awesome_dashboard: add DashboardItem component and integrate it…
oumaima-aarabe Jun 2, 2025
0cd0cbc
[ADD] awesome_dashboard: fetch and display statistics in DashboardIte…
oumaima-aarabe Jun 2, 2025
1ff36c0
[ADD] awesome_dashboard: implement statistics service for loading das…
oumaima-aarabe Jun 2, 2025
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
35 changes: 33 additions & 2 deletions awesome_dashboard/static/src/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
/** @odoo-module **/

import { Component } from "@odoo/owl";
import { Component, onWillStart } 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/dashboard_item"
class AwesomeDashboard extends Component {
static template = "awesome_dashboard.AwesomeDashboard";

static components = { Layout, DashboardItem };

setup() {
this.action = useService("action");
this.statistics = useService("awesome_dashboard.statistics");
this.display = {
controlPanel: {},
};
onWillStart(async () => {
this.statistics = await this.statistics.loadStatistics();
});
}

openCustomerView() {
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"],
],
});
}
}

registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
3 changes: 3 additions & 0 deletions awesome_dashboard/static/src/dashboard.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.o_dashboard {
background-color: rgb(86, 72, 90);
}
29 changes: 28 additions & 1 deletion awesome_dashboard/static/src/dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,34 @@
<templates xml:space="preserve">

<t t-name="awesome_dashboard.AwesomeDashboard">
hello dashboard
<Layout display="display" className="'o_dashboard h-100'">
<t t-set-slot="layout-buttons">
<button class="btn btn-primary" t-on-click="openCustomerView">Customers</button>
<button class="btn btn-primary" t-on-click="openLeads">Leads</button>
</t>
<div class="d-flex flex-wrap">
<DashboardItem>
Number of new orders this month
<t t-esc="statistics.nb_new_orders"/>
</DashboardItem>
<DashboardItem>
Total amount of new orders this month
<t t-esc="statistics.total_amount"/>
</DashboardItem>
<DashboardItem>
Average amount of t-shirt by order this month
<t t-esc="statistics.average_quantity"/>
</DashboardItem>
<DashboardItem>
Number of cancelled orders this month
<t t-esc="statistics.nb_cancelled_orders"/>
</DashboardItem>
<DashboardItem>
Average time for an order to go from ‘new’ to ‘sent’ or ‘cancelled’
<t t-esc="statistics.average_time"/>
</DashboardItem>
</div>
</Layout>
</t>

</templates>
16 changes: 16 additions & 0 deletions awesome_dashboard/static/src/dashboard_item/dashboard_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component } from "@odoo/owl";
export class DashboardItem extends Component {
static template = "awesome_dashboard.DashboardItem"
static props = {
slots: {
type: Object,
optional: true,
default: () => ({}),
},
size: {
type: Number,
default: 1,
optional: true,
},
};
}
10 changes: 10 additions & 0 deletions awesome_dashboard/static/src/dashboard_item/dashboard_item.xml
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.DashboardItem">
<div class="card m-2 border-dark" t-attf-style="width: {{18*props.size}}rem;">
<div class="card-body">
<t t-slot="default"/>
</div>
</div>
</t>
</templates>
14 changes: 14 additions & 0 deletions awesome_dashboard/static/src/statistics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { registry } from "@web/core/registry";
import { memoize } from "@web/core/utils/functions";
import { rpc } from "@web/core/network/rpc";

const statistics = {
async: ["loadStatistics"],
start() {
return {
loadStatistics: memoize(() => rpc("/awesome_dashboard/statistics")),
};
},
};

registry.category("services").add("awesome_dashboard.statistics", statistics);
22 changes: 22 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Component, useState } from "@odoo/owl";

export class Card extends Component {
static template = "awesome_owl.Card";
static props = {
title: { type: String },
slots: {
type: Object,
shape: { default:true },
},
}

setup() {
this.state = useState({ isToggled: true });
}
toggle() {
this.state.isToggled = !this.state.isToggled;
if (this.props.onChange) {
this.props.onChange(this.state.isToggled);
}
}
}
16 changes: 16 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="awesome_owl.Card">
<div class="card d-inline-block m-2" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">
<t t-out="props.title"/>
<button class="btn" t-on-click="toggle">Toggle</button>
</h5>
<p class="card-text" t-if="state.isToggled">
<t t-slot="default"/>
</p>
</div>
</div>
</t>
</templates>
20 changes: 20 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component, useState } from "@odoo/owl";

export class Counter extends Component {
static template = "awesome_owl.Counter";
static props = {
initialValue: { type: Number, optional: true, default: 0, validate: (value) => value >= 0 },
onChange: { type: Function, optional: true },
};

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

increment() {
this.state.value++;
if (this.props.onChange) {
this.props.onChange(this.state.value);
}
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/counter/counter.xml
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">
<div class="d-inline-flex align-items-center gap-2 m-3 p-3 border">
<p>Counter: <t t-esc="state.value"/></p>
<button class="btn btn-primary" t-on-click="increment">Increment</button>
</div>
</t>

</templates>
18 changes: 15 additions & 3 deletions awesome_owl/static/src/playground.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/** @odoo-module **/

import { Component } from "@odoo/owl";
import { Component, markup, useState } from "@odoo/owl";
import { Counter } from "./counter/counter";
import { Card } from "./card/card";
import { TodoList } from "./todo_list/todo_list";

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

setup() {
this.s1 = "<div class='text-primary'>some content</div>";
this.s2 = markup("<div class='text-primary'>some content</div>");
this.sum = useState({ value: 0 });
}

incrementSum() {
this.sum.value++;
}
}
15 changes: 14 additions & 1 deletion awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<Counter onChange.bind="incrementSum"/>
<Counter onChange.bind="incrementSum"/>
<div>The sum is: <t t-esc="sum.value"/></div>
</div>
<div class="p-3">
<Card title="'Card 1'">
<p>This is the content of Card 1.</p>
</Card>
<Card title="'Card 2'">
<Counter onChange.bind="incrementSum"/>
</Card>
</div>
<div class="d-inline-flex p-3 m-3 border">
<TodoList />
</div>
</t>

</templates>
24 changes: 24 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component } from "@odoo/owl";

export class TodoItem extends Component {
static template = "awesome_owl.TodoItem";
static props = {
todo: { type: Object,
shape: {
id: { type: Number, default: 0 },
description: { type: String, default: "" },
isCompleted: { type: Boolean, default: false },
}
},
toggleState: { type: Function, optional: true },
removeTodo: { type: Function, optional: true },
};

onChange() {
this.props.toggleState(this.props.todo.id);
}

onRemove() {
this.props.removeTodo(this.props.todo.id);
}
}
13 changes: 13 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item.xml
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_owl.TodoItem">
<div class="form-check">
<input class="form-check-input" type="checkbox" t-att-id="props.todo.id" t-att-checked="props.todo.isCompleted" t-on-change="onChange"/>
<label t-att-for="props.todo.id" t-att-class="{'text-muted text-decoration-line-through': props.todo.isCompleted, '': !props.todo.isCompleted}">
<t t-esc="props.todo.id"/>
<t t-esc="props.todo.description"/>
</label>
<span role="botton" class="fa fa-remove" t-on-click="onRemove"/>
</div>
</t>
</templates>
38 changes: 38 additions & 0 deletions awesome_owl/static/src/todo_list/todo_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {Component, useState} from "@odoo/owl";
import {TodoItem} from "./todo_item";
import { useAutofocus } from "../utils";

export class TodoList extends Component {
static template = "awesome_owl.TodoList";
static components = {TodoItem};

setup() {
this.todos = useState([]);
useAutofocus("input")
}

addTodo(ev) {
if (ev.keyCode === 13 && ev.target.value.trim() != "") {
const newTodo = {
id: this.todos.length + 1,
description: ev.target.value.trim(),
isCompleted: false,
};
this.todos.push(newTodo);
ev.target.value = "";
}
}
toggleTodo(id) {
const todo = this.todos.find(todo => todo.id === id);
if (todo) {
todo.isCompleted = !todo.isCompleted;
}
}

removeTodo(id) {
const index = this.todos.findIndex(todo => todo.id === id);
if (index !== -1) {
this.todos.splice(index, 1);
}
}
}
11 changes: 11 additions & 0 deletions awesome_owl/static/src/todo_list/todo_list.xml
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.TodoList">
<div class="todo-list align-items-center gap-2 m-3 p-3 border">
<input type="text" class="form-control" placeholder="Add a new todo" t-on-keyup="addTodo" t-ref="input"/>
<t t-foreach="todos" t-as="todo" t-key="todo.id">
<TodoItem todo="todo" toggleState.bind="toggleTodo" removeTodo.bind="removeTodo"/>
</t>
</div>
</t>
</templates>
13 changes: 13 additions & 0 deletions awesome_owl/static/src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {useRef, onMounted} from "@odoo/owl";

export function useAutofocus(input) {
const inputRef = useRef(input);

onMounted(() => {
if (inputRef.el) {
inputRef.el.focus();
}
});

return { inputRef };
}