forked from openWB/openwb-ui-settings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenwbNestedList.vue
180 lines (166 loc) · 3.33 KB
/
OpenwbNestedList.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<template>
<draggable
class="dragArea w-100 mb-0"
tag="ul"
:list="list"
:group="{ name: 'g1' }"
item-key="id"
handle=".handle"
>
<template #item="{ element }">
<li>
<div class="element-titel" :class="classes(element)">
<span>
<font-awesome-icon
class="handle"
fixed-width
:icon="['fas', 'arrows-alt']"
/>
<font-awesome-icon
v-if="getElementIcon(element)"
fixed-width
:icon="getElementIcon(element)"
/>
{{ getElementLabel(element.id) }}
</span>
<!-- <span class="element-actions">
<font-awesome-icon
fixed-width
:icon="['fas', 'edit']"
@click="elementEdit(element.id)"
/>
</span> -->
</div>
<openwb-nested-list
v-model="element.children"
:labels="labels"
/>
</li>
</template>
</draggable>
</template>
<script>
import draggable from "vuedraggable";
import { library } from "@fortawesome/fontawesome-svg-core";
import {
faArrowsAlt as fasArrowsAlt,
faChargingStation as fasChargingStation,
faCarBattery as fasCarBattery,
faSolarPanel as fasSolarPanel,
faGaugeHigh as fasGaugeHigh,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
library.add(
fasArrowsAlt,
fasChargingStation,
fasCarBattery,
fasSolarPanel,
fasGaugeHigh,
);
export default {
name: "OpenwbNestedList",
props: {
list: { type: Object },
labels: { type: Object },
},
components: {
draggable,
FontAwesomeIcon,
},
methods: {
classes(element) {
var myClasses = "";
switch (element.type) {
case "bat":
myClasses += "battery";
break;
case "cp":
myClasses += "charge-point";
break;
default:
myClasses += element.type;
break;
}
return myClasses;
},
getElementLabel(elementId) {
if (this.labels && elementId in this.labels) {
return this.labels[elementId];
}
return elementId;
},
getElementIcon(element) {
switch (element.type) {
case "bat":
return ["fas", "car-battery"];
case "counter":
return ["fas", "gauge-high"];
case "cp":
return ["fas", "charging-station"];
case "inverter":
return ["fas", "solar-panel"];
default:
return undefined;
}
},
// elementEdit(id) {
// console.log("edit Element:", id);
// },
},
};
</script>
<style scoped>
.dragArea {
min-height: 40px;
color: #e9ecef;
list-style-type: none;
border: 1px solid var(--secondary);
border-radius: 3px;
padding: 0px;
}
.dragArea ul {
background-color: var(--light);
}
.dragArea li {
position: relative;
top: 0px;
left: 0px;
padding-left: 40px;
margin: 5px;
border: 1px solid var(--dark);
border-radius: 3px;
background-color: var(--dark);
}
.handle {
float: left;
background-position: center center;
background-repeat: no-repeat;
margin-left: -35px;
margin-right: 5px;
font-size: 1.1em;
color: var(--light);
cursor: pointer;
}
.element-titel {
display: flex;
justify-content: space-between;
padding: 7px;
background: var(--info);
}
.element-titel.counter {
background-color: var(--danger);
}
.element-titel.charge-point {
background-color: var(--primary);
}
.element-titel.inverter {
background-color: var(--success);
}
.element-titel.battery {
background-color: var(--warning);
color: var(--dark);
}
.element-actions {
cursor: pointer;
}
</style>