Skip to content

Commit 33f4f9c

Browse files
committed
[IMP] awesome_owl: chapter 1 of owl training
Implemented all OWL features mentioned in Chapter 1. Added tutorials covering hooks, reactivity, and reusable components. Provides a basic understanding of core OWL concepts.
1 parent 918a82c commit 33f4f9c

File tree

10 files changed

+223
-2
lines changed

10 files changed

+223
-2
lines changed

awesome_owl/static/src/card/card.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState } from "@odoo/owl";
4+
5+
export class Card extends Component {
6+
static template = "awesome_owl.card";
7+
static props = {
8+
title: {type: String},
9+
content: {type: String},
10+
slots: {type:Object}
11+
}
12+
13+
14+
}

awesome_owl/static/src/card/card.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.card">
5+
6+
<div class="card d-inline-block m-2" style="width: 18rem;">
7+
<div class="card-body">
8+
<h5 class="card-title">
9+
<t t-esc="props.title" />
10+
</h5>
11+
<p class="card-text">
12+
<t t-out="props.content" />
13+
14+
</p>
15+
16+
<t t-slot="counter" />
17+
</div>
18+
</div>
19+
</t>
20+
21+
</templates>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState } from "@odoo/owl";
4+
5+
export class Counter extends Component {
6+
static template = "awesome_owl.counter";
7+
static props ={
8+
incrementsum:{type:Function}
9+
}
10+
11+
setup() {
12+
this.state = useState({ value: 0 });
13+
}
14+
15+
16+
increment() {
17+
this.state.value++;
18+
this.props.incrementsum();
19+
}
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.counter">
5+
<div class="p-3">
6+
<p>Counter: <t t-esc="state.value" />
7+
</p>
8+
<button class="btn btn-outline-primary" t-on-click="increment">Increment</button>
9+
</div>
10+
11+
</t>
12+
13+
</templates>

awesome_owl/static/src/playground.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
/** @odoo-module **/
22

3-
import { Component } from "@odoo/owl";
3+
import {markup, Component , useState } from "@odoo/owl";
4+
import { Counter } from "./counter/counter";
5+
import { Card } from "./card/card";
6+
import { Todolist } from "./todo/todo_list";
47

58
export class Playground extends Component {
69
static template = "awesome_owl.playground";
10+
static props ={
11+
12+
}
13+
value2 = markup("<div>some text 2</div>");
14+
static components = { Counter , Card , Todolist};
15+
16+
state= useState({
17+
sum:0,
18+
card1:false,
19+
card2:false
20+
})
21+
incrementsum= ()=> {
22+
this.state.sum++;
23+
}
24+
inccard1= ()=> {
25+
this.state.card1= !this.state.card1;
26+
27+
}
28+
inccard2= ()=> {
29+
this.state.card2= !this.state.card2;
30+
31+
}
732
}

awesome_owl/static/src/playground.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,31 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_owl.playground">
5+
<div>
6+
<button class="btn btn-outline-primary" t-on-click="inccard1">card1</button>
7+
<button class="btn btn-outline-primary" t-on-click="inccard2">card2</button>
8+
9+
</div>
10+
<t t-if="this.state.card1">
11+
<Card title="'counter-1'" content="'counter -1 '">
12+
<t t-set-slot="counter">
13+
<Counter incrementsum="incrementsum" />
14+
</t>
15+
16+
</Card>
17+
</t>
18+
<t t-if="this.state.card2">
19+
<Card title="'counter-2'" content="value2">
20+
<t t-set-slot="counter">
21+
<Counter incrementsum="incrementsum" />
22+
</t>
23+
</Card>
24+
</t>
525
<div class="p-3">
6-
hello world
26+
<p>sum: <t t-esc="state.sum" />
27+
</p>
728
</div>
29+
<Todolist />
830
</t>
931

1032
</templates>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/** @odoo-module **/
2+
3+
import { Component } from "@odoo/owl";
4+
5+
export class Todoitem extends Component {
6+
static template = "awesome_owl.todoitem";
7+
static props = {
8+
item: {type: Object
9+
},
10+
delete: {type: Function
11+
}
12+
}
13+
check = () =>{
14+
this.props.item.isCompleted = !this.props.item.isCompleted
15+
}
16+
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.todoitem">
5+
<div >
6+
7+
<li class="list-group-item" t-att-class="{'text-muted text-decoration-line-through':props.item.isCompleted}">
8+
<input type="checkbox" t-att-checked="props.item.isCompleted" t-on-change="check" />
9+
<t t-esc="props.item.name" />
10+
<span class="fa fa-remove" t-on-click="()=> props.delete(props.item)" />
11+
12+
</li>
13+
14+
</div>
15+
16+
</t>
17+
18+
</templates>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState, onMounted, useRef } from "@odoo/owl";
4+
import { Todoitem } from "./todo_item";
5+
export class Todolist extends Component {
6+
static template = "awesome_owl.todolist";
7+
static props ={
8+
9+
}
10+
setup() {
11+
this.inputRef = useRef('input');
12+
onMounted(() => {
13+
this.inputRef.el.focus()
14+
});
15+
this.todo= useState([{
16+
id:1,
17+
name:"ch1-owl",
18+
isCompleted: false
19+
},
20+
{
21+
id:2,
22+
name:"ch2-owl",
23+
isCompleted: false
24+
},
25+
{
26+
id:3,
27+
name:"estate",
28+
isCompleted: true
29+
}])
30+
}
31+
32+
addtodo = (e) => {
33+
if(e.key=="Enter" && e.target.value){
34+
this.todo.push({
35+
id: this.todo.length +2,
36+
name: e.target.value,
37+
isCompleted: false
38+
39+
})
40+
e.target.value=""
41+
42+
}
43+
}
44+
45+
delete=(e)=>{
46+
const index = this.todo.findIndex((todo) => todo.id === e.id);
47+
if (index >= 0) {
48+
this.todo.splice(index, 1);
49+
}
50+
}
51+
52+
static components = {Todoitem}
53+
54+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.todolist">
5+
<div class="m-3">
6+
<input class="form-control m-3" t-ref="input" t-on-keyup="addtodo" />
7+
<ul class="list-group">
8+
<t t-foreach="todo" t-as="item" t-key="item.id">
9+
10+
<Todoitem item="item" delete="delete" />
11+
</t>
12+
</ul>
13+
</div>
14+
15+
</t>
16+
17+
</templates>

0 commit comments

Comments
 (0)