Skip to content

Commit 549c84e

Browse files
committed
[IMP] awesome_owl: add counter, card components and todo lists
-Made estate module user-friendly UI -Added counter and card component and display in awesome owl module -Added todo list in awesome_owl
1 parent cc9415c commit 549c84e

File tree

20 files changed

+232
-11
lines changed

20 files changed

+232
-11
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# -*- coding: utf-8 -*-
2-
3-
from . import controllers
1+
from . import controllers

awesome_dashboard/controllers/controllers.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
import logging
42
import random
53

@@ -33,4 +31,3 @@ def get_statistics(self):
3331
},
3432
'total_amount': random.randint(100, 1000)
3533
}
36-
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 Card extends Component {
4+
static template = "awesome_owl.Card";
5+
static props = {
6+
title: String,
7+
slots: {
8+
type: Object,
9+
shape: {
10+
default: true
11+
},
12+
}
13+
};
14+
15+
setup() {
16+
this.state = useState({ isOpen: true });
17+
}
18+
19+
toggleContent() {
20+
this.state.isOpen = !this.state.isOpen;
21+
}
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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">
7+
<t t-out="props.title"/>
8+
<button class="btn" t-on-click="toggleContent">Toggle</button>
9+
</h5>
10+
<p class="card-text" t-if="state.isOpen">
11+
<t t-slot="default"/>
12+
</p>
13+
</div>
14+
</div>
15+
</t>
16+
</templates>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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.state = useState({ value: 1 });
11+
}
12+
13+
increment() {
14+
this.state.value = this.state.value + 1;
15+
if (this.props.onChange) {
16+
this.props.onChange();
17+
}
18+
}
19+
}
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="m-2 p-2 border d-inline-block">
5+
<span class="me-2">Counter: <t t-esc="state.value"/></span>
6+
<button class="btn btn-primary" t-on-click="increment">Increment</button>
7+
</div>
8+
</t>
9+
</templates>

awesome_owl/static/src/main.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ const config = {
99

1010
// Mount the Playground component when the document.body is ready
1111
whenReady(() => mountComponent(Playground, document.body, config));
12-
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
import { Component } from "@odoo/owl";
1+
import { Component, markup, 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.str1 = "<div class='text-primary'>some content</div>";
12+
this.str2 = markup("<div class='text-primary'>some content</div>");
13+
this.sum = useState({ value: 2 });
14+
}
15+
16+
incrementSum() {
17+
this.sum.value++;
18+
}
519
}

awesome_owl/static/src/playground.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@
44
<t t-name="awesome_owl.playground">
55
<div class="p-3">
66
hello world
7+
<Counter onChange.bind="incrementSum" />
8+
<Counter onChange.bind="incrementSum" />
9+
<div>The sum is: <t t-esc="sum.value"/></div>
710
</div>
11+
<div>
12+
<Card title="'card 1'">
13+
content of card 1
14+
</Card>
15+
<Card title="'card 2'">
16+
<Counter />
17+
</Card>
18+
</div>
19+
<TodoList />
820
</t>
921

1022
</templates>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Component } from "@odoo/owl";
2+
3+
export class TodoItem extends Component {
4+
static template = "awesome_owl.TodoItem";
5+
static props = {
6+
todo: {
7+
type: Object,
8+
shape: { id: Number, description: String, isCompleted: Boolean }
9+
},
10+
toggleState: Function,
11+
removeTodo: Function,
12+
};
13+
14+
onChange() {
15+
this.props.toggleState(this.props.todo.id);
16+
}
17+
18+
onRemove() {
19+
this.props.removeTodo(this.props.todo.id);
20+
}
21+
}

0 commit comments

Comments
 (0)