Skip to content

[ADD] AwesomeOwl: OWL Tutorial PR #798

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

Open
wants to merge 3 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[ADD] AwesomeOwl: Add playground and base components
Added the base structure for the AwesomeOwl module.
Introduced main components and sub-components (Playground, Counter, and Card).
Implemented props validation and callback handling (e.g., sum case).
This commit covers the first chapter (tasks 1 to 6) of the Web Framework section from Odoo's official documentation.
  • Loading branch information
karygauss03 committed May 26, 2025
commit 1184064b07261c8687dff7d9e79114eb08f4bf6a
12 changes: 12 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Component } from "@odoo/owl";

export class Card extends Component {
static template = "awesome_owl.card";
static props = {
"title": {
type: String,
validate: s => s.startsWith("[Odoo]")
},
"content": String
}
}
10 changes: 10 additions & 0 deletions awesome_owl/static/src/card/card.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_owl.card">
<div>
<span>Title: <t t-out="props.title"/></span>
<span>Content: <t t-out="props.content"/></span>
</div>
</t>
</templates>
21 changes: 21 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 });
}

increment() {
this.state.value++;
if (this.props.onChange) {
this.props.onChange();
}
}
}
10 changes: 10 additions & 0 deletions awesome_owl/static/src/counter/counter.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_owl.counter">
<div>
<button t-on-click="increment">Increment</button>
<span>Counter: <t t-esc="state.value"/></span>
</div>
</t>
</templates>
15 changes: 14 additions & 1 deletion awesome_owl/static/src/playground.js
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 { Counter } from "./counter/counter";

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

setup() {
this.title = "[Odoo] New version here!!!";
this.content = markup("<div><span>19.0</span></div>");
this.sum = useState({value: 0});
}

incrementSum() {
this.sum.value++;
}
}
8 changes: 7 additions & 1 deletion awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<Counter onChange.bind="incrementSum"></Counter>
<br/>
<Counter onChange.bind="incrementSum"></Counter>
</div>
<span>Total counter sum: <t t-out="sum.value"></t></span>
<div>
<Card title="title" content="content"/>
</div>
</t>

</templates>