Skip to content

Commit 957f5cf

Browse files
committed
finished first owl course
1 parent 003b221 commit 957f5cf

File tree

11 files changed

+160
-4
lines changed

11 files changed

+160
-4
lines changed

awesome_owl/__manifest__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
'web/static/src/libs/fontawesome/css/font-awesome.css',
3838
'awesome_owl/static/src/**/*',
3939
],
40+
'awesome_owl.assets_counter': [
41+
'awesome_owl/static/src/**/*',
42+
],
43+
'awesome_owl.assets_card': [
44+
'awesome_owl/static/src/**/*',
45+
],
4046
},
4147
'license': 'AGPL-3'
4248
}

awesome_owl/static/src/card.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 = {title: {type: String}, content: {type: String, optional: true}, slots: {type: Object}};
8+
9+
setup() {
10+
this.state = useState({cardIsOpen: false});
11+
}
12+
13+
toggleCard() {
14+
this.state.cardIsOpen = !this.state.cardIsOpen;
15+
}
16+
}

awesome_owl/static/src/card.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_owl.card">
4+
<div class="card d-inline-block m-2" style="width: 18rem;">
5+
<div class="card-body">
6+
<div class="d-flex flex-row gap-3">
7+
<h5 class="card-title"><t t-esc="props.title"/></h5>
8+
<button t-on-click="toggleCard">toggle</button>
9+
</div>
10+
<t t-if="state.cardIsOpen" t-slot="default"/>
11+
</div>
12+
</div>
13+
</t>
14+
</templates>

awesome_owl/static/src/counter.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState } from "@odoo/owl";
4+
5+
export class Counter extends Component {
6+
static props = {callback: {type: Function, optional: true}}
7+
static template = "awesome_owl.counter";
8+
9+
setup() {
10+
this.state = useState({ counter: 0 });
11+
}
12+
13+
increment() {
14+
this.state.counter++;
15+
if (this.props.callBack) {
16+
this.props.callback("A message to pass ;)")
17+
}
18+
}
19+
}

awesome_owl/static/src/counter.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.counter">
5+
<p>Counter: <t t-esc="state.counter"/></p>
6+
<button t-on-click="increment">Increment</button>
7+
</t>
8+
9+
</templates>

awesome_owl/static/src/playground.js

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

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

58
export class Playground extends Component {
9+
static components = {Counter, Card, Todolist};
610
static template = "awesome_owl.playground";
711
}

awesome_owl/static/src/playground.xml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22
<templates xml:space="preserve">
33

44
<t t-name="awesome_owl.playground">
5-
<div class="p-3">
6-
hello world
7-
</div>
5+
<Card title="'Card1'"><Counter/></Card>
6+
<Card title="'Card2'"><p>This is just a test content</p></Card>
7+
<Card title="'Card3'">
8+
<div>
9+
<ul>
10+
<li>Item A</li>
11+
<li>Item B</li>
12+
</ul>
13+
</div>
14+
</Card>
815
</t>
916

1017
</templates>
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 TodoItem extends Component {
6+
static template = "awesome_owl.todo_item";
7+
static props = {
8+
id: {type: Number},
9+
description: {type: String},
10+
isCompleted: {type: Boolean},
11+
onStatusChange: {type: Function},
12+
deleteTodoItem: {type: Function}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-name="awesome_owl.todo_item">
4+
<div class="card d-inline-block m-2" style="width: 18rem;">
5+
<div class="card-body d-flex align-items-center">
6+
<input type="checkbox" class="form-check-input me-3" t-on-change="() => props.onStatusChange(props.id)"/>
7+
<p class="card-text flex-grow-1 mb-0" t-att-class="{'text-muted text-decoration-line-through': props.isCompleted}">
8+
<t t-esc="props.id + '. ' + props.description"/>
9+
</p>
10+
<span class="fa fa-remove ms-3" t-on-click="() => props.deleteTodoItem(props.id)"/>
11+
</div>
12+
</div>
13+
</t>
14+
</templates>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/** @odoo-module **/
2+
3+
import { Component, useState, useRef } from "@odoo/owl";
4+
import { TodoItem } from './todo_item'
5+
6+
export class Todolist extends Component {
7+
static components = {TodoItem};
8+
static template = "awesome_owl.todo_list";
9+
10+
setup() {
11+
this.state = useState({idCounter: 1, todoItems: []})
12+
this.inputRef = useRef('input');
13+
this.addTodo = this.addTodo.bind(this);
14+
this.inputFocus = this.inputFocus.bind(this);
15+
this.onStatusChange = this.onStatusChange.bind(this);
16+
this.deleteTodoItem = this.deleteTodoItem.bind(this);
17+
}
18+
19+
addTodo(ev) {
20+
if (ev.keyCode === 13 && ev.target.value) {
21+
let newTodoItem = {id: this.state.idCounter++, description: ev.target.value, isCompleted: false}
22+
this.state.todoItems = [...this.state.todoItems, newTodoItem];
23+
}
24+
}
25+
26+
inputFocus() {
27+
this.inputRef.el.focus()
28+
}
29+
30+
onStatusChange(id) {
31+
const todoItemToToggle = this.state.todoItems.find(obj => obj.id === id);
32+
todoItemToToggle.isCompleted = !todoItemToToggle.isCompleted;
33+
}
34+
35+
deleteTodoItem(id) {
36+
this.state.todoItems = this.state.todoItems.filter(obj => obj.id !== id);
37+
}
38+
}

0 commit comments

Comments
 (0)