Skip to content

Commit b2ac76c

Browse files
committed
[ADD] awesome_owl: Add Card, TodoList, and Counter components
Introduced new Owl components in the awesome_owl module, including interactive Cards, a dynamic TodoList with task management, and a reactive Counter. These components demonstrate the usage of Owl's reactive framework and enhance the UI with reusable and interactive widgets for frontend development in Odoo.
1 parent 1ea3e17 commit b2ac76c

File tree

10 files changed

+135
-2
lines changed

10 files changed

+135
-2
lines changed

awesome_owl/static/src/card/card.js

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

awesome_owl/static/src/card/card.xml

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+
<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-out="props.title"/></h5>
7+
<p class="card-text"><t t-out="props.content"/></p>
8+
</div>
9+
</div>
10+
</t>
11+
</templates>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {Component, useState} from "@odoo/owl"
2+
3+
4+
export class Counter extends Component{
5+
static template = "awesome_owl.Counter";
6+
7+
static props = {
8+
onChange: { type: Function, optional: true }
9+
}
10+
11+
setup(){
12+
this.state = useState({value: 1});
13+
}
14+
15+
increment(){
16+
this.state.value++;
17+
if (this.props.onChange) {
18+
this.props.onChange(this.state.value);
19+
}
20+
}
21+
}
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+
<t t-name="awesome_owl.Counter">
4+
<div class="d-inline-flex align-items-center gap-2 m-3 p-3 border">
5+
<p>Counter: <t t-esc="state.value"/></p>
6+
<button class="btn btn-primary" t-on-click="increment" style="background-color: pink; color: white;">Increment</button>
7+
</div>
8+
</t>
9+
</templates>

awesome_owl/static/src/playground.js

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

3-
import { Component } from "@odoo/owl";
3+
import { useState, Component } from "@odoo/owl";
4+
import { Counter } from "./counter/counter";
5+
import { Card } from "./card/card";
6+
import { TodoList } from "./todo/todolist";
7+
48

59
export class Playground extends Component {
610
static template = "awesome_owl.playground";
11+
static components = {Counter, Card, TodoList};
12+
setup() {
13+
this.state = useState({ sum: 2 });
14+
}
15+
16+
incrementSum(value) {
17+
this.state.sum += 1;
18+
}
19+
720
}

awesome_owl/static/src/playground.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33

44
<t t-name="awesome_owl.playground">
55
<div class="p-3">
6-
hello world
6+
<span>hello world</span>
7+
<Counter onChange.bind="incrementSum" />
8+
<Counter onChange.bind="incrementSum" />
79
</div>
10+
<div>
11+
<p>The Sum is: <t t-esc="state.sum" /></p>
12+
</div>
13+
<Card title="'my title'" content="'some content'"/>
14+
<Card title="'my title 1'" content="'some content 2'"/>
15+
16+
<TodoList/>
817
</t>
918

1019
</templates>
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, xml } from "@odoo/owl";
4+
5+
6+
export class TodoItem extends Component {
7+
static template = "awesome_owl.TodoItem";
8+
static props = {
9+
todo: {
10+
type: Object,
11+
shape: {
12+
id: Number,
13+
description: String,
14+
isCompleted: Boolean,
15+
},
16+
optional: false,
17+
},
18+
};
19+
}
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>
6+
<t t-esc="props.todo.id"/> .
7+
<t t-esc="props.todo.description" />
8+
</div>
9+
</t>
10+
11+
</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, useState, xml } from "@odoo/owl";
4+
import { TodoItem } from "./todoitem";
5+
6+
7+
export class TodoList extends Component {
8+
static template = "awesome_owl.TodoList";
9+
static components = { TodoItem };
10+
11+
setup() {
12+
this.todos = useState([
13+
{ id: 3, description: "buy milk", isCompleted: false },
14+
{ id: 4, description: "complete assignment", isCompleted: false },
15+
]);
16+
}
17+
}
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.TodoList">
5+
<div class="todo-item mb-2 p-2 border rounded">
6+
<h4>Todo List</h4>
7+
<div t-foreach="todos" t-as="todo" t-key="todo.id">
8+
<TodoItem todo="todo" />
9+
</div>
10+
</div>
11+
</t>
12+
13+
</templates>

0 commit comments

Comments
 (0)