Skip to content

18.0 owl tutorials abye #804

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 10 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
25 changes: 25 additions & 0 deletions awesome_owl/static/src/card/card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/** @odoo-module **/

import { Component, markup } from "@odoo/owl";

export class Card extends Component {
static template = "awesome_owl.card";

static props = {
title: {
type: String,
optional: true,
},
content: {
type: String,
optional: true,
},
};

get content() {
if (this.props.content) {
return markup(this.props.content);
}
return undefined;
}
}
15 changes: 15 additions & 0 deletions awesome_owl/static/src/card/card.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<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"/></h5>
<p class="card-text"><t t-out="this.content"/></p>
</div>
</div>

</t>

</templates>
25 changes: 25 additions & 0 deletions awesome_owl/static/src/counter/counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/** @odoo-module **/

import { Component, useState } from "@odoo/owl";

export class Counter extends Component {
static template = "awesome_owl.counter";

static props = {
callback: {
type: Function,
optional: true,
}
}

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

increment() {
this.count.value += 1;
if (this.props.callback) {
this.props.callback();
}
}
}
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 style="border: 1px solid #ccc; padding: 15px; margin: 10px; width: fit-content; height:fit-content; display: inline">
<label style="margin:10px">Counter: <t t-esc="count.value"/></label>
<button class="btn" t-on-click="increment" style="background-color: purple; color: white">Increment</button>
</div>
</t>

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

import { Component } from "@odoo/owl";
import { Component, 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.content1 = "<u>Card Content 1</u>";
this.content2 = "<u>Card Content 2</u>";
this.state = useState({
sum: 0,
});
}

incrementSum() {
this.state.sum += 1;
}
}
26 changes: 23 additions & 3 deletions awesome_owl/static/src/playground.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.playground">
<div class="p-3">
hello world
<p>◇─◇─ welcome to the Owl Playground! ─◇─◇</p>
<p>Here you can experiment with Owl components and see how they work.</p>
<p>Feel free to modify the code and see the changes in real-time.</p>
<p>Use the buttons below to interact with the components.</p>
<h2>Have fun!</h2>
<h4>love u 🫶🏻💓</h4>
</div>
<div style="border: 1px solid #ccc; padding: 10px; margin: 10px; width: fit-content;">
<div style="display:inline">
<Counter callback.bind="incrementSum"/>
<Counter callback.bind="incrementSum"/>
</div>
<br />
<br />
<p style="padding: 0 10px"> The sum is <t t-esc="state.sum"/> </p>
</div>
</t>

<div style="border: 1px solid #ccc; padding: 10px; margin: 10px; width: fit-content;">
<h3>Todo List</h3>
<TodoList />
</div>

</t>

</templates>
14 changes: 14 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item/todo_item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @odoo-module **/

import { Component } from "@odoo/owl";

export class TodoItem extends Component {
static template = "awesome_owl.todo_item";

static props = {
todo: {
type: Object,
optional: true,
}
};
}
10 changes: 10 additions & 0 deletions awesome_owl/static/src/todo_list/todo_item/todo_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.todo_item">
<p class="card-text" t-att-class="props.todo.isCompleted ? 'text-decoration-line-through text-muted' : '' ">
<t t-esc="props.todo.id"/>. <t t-esc="props.todo.description"/>
</p>
</t>

</templates>
36 changes: 36 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,36 @@
/** @odoo-module **/

import { Component, useState } from "@odoo/owl";
import { TodoItem } from "./todo_item/todo_item";

export class TodoList extends Component {
static template = "awesome_owl.todo_list";

static components = {
TodoItem,
};

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

static props = {
todos: {
type: Array,
optional: true,
default: () => [],
},
};

addTodo(ev){
let input_val = ev.target.value;
if (ev.keyCode === 13 && input_val != "") {
this.todos.push({
id: this.todos.length + 1,
description: input_val,
isCompleted: false,
});
ev.target.value = "";
}
}
}
17 changes: 17 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,17 @@
<?xml version="1.0"?>
<templates xml:space="preserve">

<t t-name="awesome_owl.todo_list">
<div class="container">
<div class="col">
<input type="text" placeholder="Add a new todo..." t-on-keyup="addTodo"/>
<div class="card-body">
<t t-foreach="todos" t-as="todo" t-key="todo.id">
<TodoItem todo="todo" />
</t>
</div>
</div>
</div>
</t>

</templates>