Skip to content

Commit dceda6c

Browse files
[IMP] awesome_owl: Web Framework Finished Chapter 1 Part 1-8
1 parent e70a0b6 commit dceda6c

File tree

11 files changed

+136
-5
lines changed

11 files changed

+136
-5
lines changed

awesome_owl/controllers/controllers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from odoo import http
22
from odoo.http import request, route
33

4+
45
class OwlPlayground(http.Controller):
56
@http.route(['/awesome_owl'], type='http', auth='public')
67
def show_playground(self):
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Component, useState } from "@odoo/owl";
2+
3+
export class TodoItem extends Component
4+
{
5+
static template = 'awesome_owl.TodoItem';
6+
static props = {
7+
todo : {
8+
type: Object,
9+
shape:{
10+
id: {type : Number},
11+
description: {type : String},
12+
isCompleted: {type: Boolean}}}
13+
14+
};
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.TodoItem">
5+
<div class="m-2 p-2 border d-inline-block" t-att-class="{'text-muted text-decoration-line-through' : props.todo.isCompleted};">
6+
7+
<p>ID : <t t-esc="props.todo.id"/></p>
8+
<p>Desc : <t t-esc="props.todo.description"/></p>
9+
</div>
10+
</t>
11+
</templates>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Component, useState } from "@odoo/owl";
2+
import { TodoItem } from "../TodoItem/TodoItem";
3+
4+
export class TodoList extends Component
5+
{
6+
static template = 'awesome_owl.TodoList';
7+
static components = { TodoItem };
8+
setup()
9+
{
10+
this.todos = useState([
11+
{id: 3, description: "buy milk", isCompleted: false },
12+
{id: 4, description: "buy milk 2", isCompleted: false },
13+
{id: 5, description: "buy milk -1", isCompleted: true }
14+
]);
15+
}
16+
}
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.TodoList">
5+
<t t-foreach="todos" t-as="todo" t-key="todo.id">
6+
<TodoItem todo="todo"/>
7+
</t>
8+
</t>
9+
</templates>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Component, useState } from "@odoo/owl";
2+
3+
export class Card extends Component {
4+
static template = "awesome_owl.Card";
5+
static props = {
6+
title: String,
7+
content: String,
8+
html: String
9+
};
10+
11+
}
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+
<h5 class="card-title"><t t-esc="props.title"/></h5>
7+
<p class="card-text">
8+
<t t-esc="props.content"/>
9+
<t t-out="props.html"/>
10+
</p>
11+
</div>
12+
</div>
13+
</t>
14+
</templates>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { Component, useState } from "@odoo/owl";
2+
3+
export class Counter extends Component
4+
{
5+
static template = 'awesome_owl.counter';
6+
static props = {
7+
onChange: {type : Function}
8+
};
9+
setup()
10+
{
11+
this.state = useState({value: 0});
12+
}
13+
14+
increment()
15+
{
16+
this.state.value++;
17+
if(this.props.onChange)
18+
{
19+
this.props.onChange();
20+
}
21+
}
22+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="awesome_owl.counter">
5+
<div class="m-2 p-2 border d-inline-block">
6+
<p>Counter : <t t-esc="state.value"/></p>
7+
<button class='btn btn-primary' t-on-click='increment'>
8+
Increment
9+
</button>
10+
</div>
11+
</t>
12+
</templates>
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1-
import { Component } from "@odoo/owl";
1+
import { Component, useState, markup } from "@odoo/owl";
2+
import { Counter } from "./counter/counter";
3+
import { Card } from "./card/card";
4+
import { TodoList } from "./TodoList/TodoList"
25

36
export class Playground extends Component {
47
static template = "awesome_owl.playground";
8+
static components = { Counter, Card, TodoList };
9+
todo= {id: 3, description: "buy milk", isCompleted: false };
10+
html = markup("<h1> Hi </h1>");
11+
12+
setup()
13+
{
14+
this.sum = useState({value: 0});
15+
}
16+
incrementSum()
17+
{
18+
console.log("test this");
19+
this.sum.value ++;
20+
}
21+
22+
523
}

0 commit comments

Comments
 (0)