Skip to content

Commit 4d818f0

Browse files
committed
[IMP] Whatever Squashed
1 parent 3ebd8b1 commit 4d818f0

File tree

6 files changed

+54
-57
lines changed

6 files changed

+54
-57
lines changed

awesome_dashboard/static/src/dashboard/dashboard.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,16 @@ class AwesomeDashboard extends Component {
2929

3030
if (result.length === 0) {
3131
this.items.forEach((item) => {
32-
this.selected.add(item.id);
32+
this.displayedItems.add(item.id);
3333
});
3434
} else {
3535
result.forEach((item) => {
36-
this.selected.add(item);
36+
this.displayedItems.add(item);
3737
});
3838
}
3939
});
4040

41-
//this.saveDashboard([]);
42-
this.selected = useState(reactive(new Set()));
41+
this.displayedItems = useState(reactive(new Set()));
4342
}
4443

4544
openCustomers() {
@@ -59,10 +58,10 @@ class AwesomeDashboard extends Component {
5958

6059
openConfiguration() {
6160
this.dialog.add(DashboardDialog, {
62-
onConfirm: (selected) => {
63-
this.selected.clear();
64-
selected.forEach((id) => this.selected.add(id));
65-
this.saveDashboard(selected);
61+
onConfirm: (displayedItems) => {
62+
this.displayedItems.clear();
63+
displayedItems.forEach((id) => this.displayedItems.add(id));
64+
this.saveDashboard(displayedItems);
6665
},
6766
});
6867
}

awesome_dashboard/static/src/dashboard/dashboard.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<button class="fa fa-cog" t-on-click="openConfiguration"/>
1010
</t>
1111
<div class="d-flex flex-wrap" t-if="statistics">
12-
<t t-foreach="items" t-as="item" t-key="item.id" t-if="selected.has(item.id)">
13-
<DashboardItem size="item.size || 1">
12+
<t t-foreach="items" t-as="item" t-key="item.id" t-if="displayedItems.has(item.id)">
13+
<DashboardItem size="item.size">
1414
<t t-set="itemProp" t-value="item.props ? item.props(statistics) : {'data': statistics}"/>
1515
<t t-component="item.Component" t-props="itemProp" />
1616
</DashboardItem>

awesome_dashboard/static/src/dashboard/dashboard_dialog/dashboard_dialog.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ export class DashboardDialog extends Component {
1313
this.title = _t("Dashboard Configuration");
1414
this.items = registry.category("awesome_dashboard").getAll();
1515
this.state = useState({
16-
selected: new Set(
16+
displayedItems: new Set(
1717
browser.localStorage.getItem("selectedDashboardItems")?.split(",") || []
1818
),
1919
});
20-
if (this.state.selected.size === 0) {
20+
if (this.state.displayedItems.size === 0) {
2121
this.items.forEach((item) => {
22-
this.state.selected.add(item.id);
22+
this.state.displayedItems.add(item.id);
2323
});
2424
}
2525
}
2626

2727
toggleItem(item) {
28-
if (this.state.selected.has(item)) {
29-
this.state.selected.delete(item);
28+
if (this.state.displayedItems.has(item)) {
29+
this.state.displayedItems.delete(item);
3030
} else {
31-
this.state.selected.add(item);
31+
this.state.displayedItems.add(item);
3232
}
3333
}
3434

3535
confirm() {
36-
this.props.onConfirm([...this.state.selected]);
36+
this.props.onConfirm([...this.state.displayedItems]);
3737
this.props.close();
3838
}
3939
}

awesome_dashboard/static/src/dashboard/dashboard_dialog/dashboard_dialog.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<t t-foreach="items" t-as="item" t-key="item.id">
1111
<div>
1212
<label>
13-
<input type="checkbox" t-att-checked="state.selected.has(item.id)" t-on-click="ev => this.toggleItem(item.id)"/>
13+
<input type="checkbox" t-att-checked="state.displayedItems.has(item.id)" t-on-click="ev => this.toggleItem(item.id)"/>
1414
<t t-esc="item.description"/>
1515
</label>
1616
</div>
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import { Component, useState } from "@odoo/owl";
22

33
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-
removeTodo: Function,
11-
};
4+
static template = "awesome_owl.TodoItem";
5+
static props = {
6+
todo: {
7+
type: Object,
8+
shape: { id: Number, description: String, isCompleted: Boolean },
9+
},
10+
removeTodo: Function,
11+
};
1212

13+
delete() {
14+
this.props.removeTodo(this.props.todo.id);
15+
}
1316

14-
delete(){
15-
this.props.removeTodo(this.props.todo.id)
16-
}
17-
18-
toggleState(ev){
19-
this.props.todo.isCompleted = ! this.props.todo.isCompleted
20-
}
17+
toggleState(ev) {
18+
this.props.todo.isCompleted = !this.props.todo.isCompleted;
19+
}
2120
}
Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
import { Component, useState} from "@odoo/owl";
1+
import { Component, useState } from "@odoo/owl";
22
import { useAutofocus } from "../utils";
33
import { TodoItem } from "./todo_item";
44

55
export class TodoList extends Component {
6-
static template = "awesome_owl.TodoList";
7-
static components = { TodoItem };
8-
static props = []
6+
static template = "awesome_owl.TodoList";
7+
static components = { TodoItem };
8+
static props = [];
99

10-
setup() {
11-
this.todos = useState([]);
12-
this.index = 0
13-
useAutofocus('input')
14-
}
10+
setup() {
11+
this.todos = useState([]);
12+
this.index = 0;
13+
useAutofocus("input");
14+
}
1515

16-
addTodo(ev){
17-
if(ev.keyCode === 13 && ev.target.value != ""){
18-
this.todos.push({
19-
id: this.index++,
20-
description: ev.target.value,
21-
isCompleted: false
22-
})
23-
ev.target.value = ""
24-
}
16+
addTodo(ev) {
17+
if (ev.keyCode === 13 && ev.target.value != "") {
18+
this.todos.push({
19+
id: this.index++,
20+
description: ev.target.value,
21+
isCompleted: false,
22+
});
23+
ev.target.value = "";
2524
}
25+
}
2626

27-
removeTodo(elemId){
28-
const index = this.todos.findIndex((elem) => elem.id === elemId);
29-
if (index >= 0) {
30-
this.todos.splice(index, 1);
31-
}
27+
removeTodo(elemId) {
28+
const index = this.todos.findIndex((elem) => elem.id === elemId);
29+
if (index !== -1) {
30+
this.todos.splice(index, 1);
3231
}
33-
32+
}
3433
}

0 commit comments

Comments
 (0)