Skip to content

Commit 0e8052e

Browse files
committed
[ADD] web: owl components
chapter 1: owl component
1 parent 32a357f commit 0e8052e

File tree

15 files changed

+210
-6
lines changed

15 files changed

+210
-6
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Component } from "@odoo/owl";
22
import { registry } from "@web/core/registry";
3+
import { Layout } from "@web/search/layout";
34

45
class AwesomeDashboard extends Component {
56
static template = "awesome_dashboard.AwesomeDashboard";
7+
static components = { Layout };
68
}
79

810
registry.category("actions").add("awesome_dashboard.dashboard", AwesomeDashboard);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.o_dashboard {
2+
background-color: #f0f0f0;
3+
}

awesome_dashboard/static/src/dashboard.xml

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

44
<t t-name="awesome_dashboard.AwesomeDashboard">
5-
hello dashboard
5+
<Layout display="{controlPanel: {}}" className="'o_dashboard h-100'">
6+
<div class="p-3">
7+
hello dashboard
8+
</div>
9+
</Layout>
610
</t>
711

812
</templates>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
slots: { type: Object, optional: true },
8+
};
9+
10+
setup() {
11+
this.state = useState({ isOpen: true });
12+
}
13+
14+
toggleContent() {
15+
this.state.isOpen = !this.state.isOpen;
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+
<t t-name="awesome_owl.card">
4+
<div class="card d-inline-block align-top m-2" style="width: 18rem;">
5+
<div class="card-body">
6+
<div class="d-flex justify-content-between align-items-center mb-2">
7+
<h5 class="card-title mb-0"><t t-esc="props.title"/></h5>
8+
<button class="btn btn-sm btn-primary" t-on-click="toggleContent">
9+
<i t-attf-class="fa fa-chevron-{{ state.isOpen ? 'up' : 'down' }}"/>
10+
</button>
11+
</div>
12+
<div class="card-text" t-if="state.isOpen">
13+
<t t-slot="default"/>
14+
</div>
15+
</div>
16+
</div>
17+
</t>
18+
</templates>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Component, useState } from "@odoo/owl";
2+
3+
export class Counter extends Component {
4+
static template = "awesome_owl.counter";
5+
static props = {
6+
onChange: { type: Function, optional: true },
7+
};
8+
9+
setup() {
10+
this.count = useState({ value: 0 });
11+
}
12+
13+
increment() {
14+
this.count.value++;
15+
if (this.props.onChange) {
16+
this.props.onChange(this.count.value);
17+
}
18+
}
19+
}
20+
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="border rounded p-2 bg-light">
5+
<div class="mb-2">Counter: <strong><t t-esc="count.value"/></strong></div>
6+
<button class="btn btn-primary btn-sm" t-on-click="increment">Increment</button>
7+
</div>
8+
</t>
9+
</templates>
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
import { Component } from "@odoo/owl";
1+
import { Component, useState } from "@odoo/owl";
2+
import { Counter } from "./counter/counter";
3+
import { Card } from "./card/card";
4+
import { TodoList } from "./todo_list/todo_list";
25

36
export class Playground extends Component {
47
static template = "awesome_owl.playground";
8+
static components = { Counter, Card, TodoList };
9+
10+
setup() {
11+
this.state = useState({ sum: 2 });
12+
}
13+
14+
incrementSum = () => {
15+
this.state.sum++;
16+
}
517
}
Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,34 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<templates xml:space="preserve">
3-
43
<t t-name="awesome_owl.playground">
54
<div class="p-3">
6-
hello world
5+
<div class="mb-4">
6+
<Card title="'Card 1 - Plain Text'">
7+
<p>This is simple text content</p>
8+
</Card>
9+
<Card title="'Card 2 - With Counter'">
10+
<Counter onChange="incrementSum"/>
11+
</Card>
12+
<Card title="'Card 3 - HTML Content'">
13+
<p>This card has <strong>bold</strong> and <em>italic</em> text!</p>
14+
</Card>
15+
</div>
16+
<div class="mb-4">
17+
<h4>Counters</h4>
18+
<div class="d-flex gap-3 mb-2">
19+
<div>
20+
<Counter onChange="incrementSum"/>
21+
</div>
22+
<div>
23+
<Counter onChange="incrementSum"/>
24+
</div>
25+
<div>
26+
<Counter onChange="incrementSum"/>
27+
</div>
28+
</div>
29+
<div class="alert alert-info">Sum: <strong><t t-esc="state.sum"/></strong></div>
30+
</div>
31+
<TodoList/>
732
</div>
833
</t>
9-
1034
</templates>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class TodoItem extends Component {
4+
static template = "awesome_owl.todo_item";
5+
static props = {
6+
todo: {
7+
type: Object,
8+
shape: {
9+
id: Number,
10+
description: String,
11+
isCompleted: Boolean,
12+
},
13+
},
14+
toggleState: Function,
15+
removeTodo: Function,
16+
};
17+
}

0 commit comments

Comments
 (0)