-
Notifications
You must be signed in to change notification settings - Fork 1
/
Endpoint.vue
188 lines (166 loc) · 5.15 KB
/
Endpoint.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
181
182
183
184
185
186
187
188
<script setup>
import Tile from "@/components/Tile.vue";
import CommandParameter from "@/components/CommandParameter.vue";
import { useRoute, RouterLink } from "vue-router";
//import { store } from "@/store";
import { alert, request, debounce } from "@/helper";
import { settingsStore } from "../store.js";
const settings = settingsStore();
</script>
<script>
import { mapActions } from "pinia";
import { itemStore } from "../store.js";
const store = itemStore();
export default {
components: {
Tile,
RouterLink,
CommandParameter
},
data() {
return {
data: {
},
};
},
mounted() {
let $route = useRoute();
this.data = Array.from(store.endpoints).find((item) => {
return item._id === $route.params._id;
});
},
methods: {
//getRoomNameById,
...mapActions(itemStore, ["getRoomNameById", "getDeviceNameById"]),
alert,
trigger: debounce(function (_id, event) {
console.log("Aasdflaksdfleila")
let command = this.data.commands.find((obj) => {
return obj._id === _id;
});
if (!command) {
console.warn("Could not find command with _id: ", _id);
return;
}
console.log("command.params", command.params)
let body = [];
if (command.params) {
body = command.params.map(({ key, value }) => {
return {
key,
value
};
});
}
request(`/api/endpoints/${this.data._id}/commands/${_id}`, {
method: "POST",
headers: {
"content-type": "application/json"
},
body: JSON.stringify(body)
}, (err, result) => {
console.log(err, result);
});
}, 10),
repeat(cmd) {
this.trigger(cmd._id);
},
},
computed: {
commands() {
return this.data.commands?.length || 0;
},
states() {
return this.data.states?.length || 0;
},
/*
scenes() {
return Math.round(Math.random() * 10);
},*/
},
};
</script>
<template>
<div class="container-fluid">
<!-- HEADER -->
<div class="row py-4" style="border-top: 1px solid #000; border-bottom: 1px solid #000">
<!-- LEFT -->
<div class="col">
<div class="d-inline-flex">
<div class="me-2 pt-1">
<i :class="data.icon || 'fa-solid fa-circle-question'" class="fa-3x"></i>
</div>
<div class="">
<h3 class="mb-0">
{{ data.name }}
<!--<sup class="text-secondary">•</sup>-->
</h3>
<span class="text-secondary fw-light d-block">
{{ getRoomNameById(data.room) }}
</span>
</div>
</div>
</div>
<!-- LEFT -->
<!-- RIGHT -->
<div class="col text-end" style="font-size: 14px" v-if="settings.showCommandStatesCounter">
<span class="text-secondary fw-light d-block">
<!--Commands: {{ Math.round(Math.random() * 10) }}-->
Commands: {{ commands }}
</span>
<span class="text-secondary fw-light d-block">
States: {{ states }}
</span>
<!--
<span class="text-secondary fw-light d-block">
Scenes: {{ scenes }}
</span>
-->
</div>
<!-- RIGHT -->
</div>
<!-- HEADER -->
<!-- COMMANDS/STATES/SCENES -->
<div class="row display-flex text-center" style="height: calc(100% - 109px)">
<!-- COMMANDS -->
<div class="p-0 col-6 col-md-3 col-xl-2" v-bind:key="command._id" v-for="command in data.commands">
<RouterLink custom :to="{
name: '/endpoints/:_id/commands/:_command',
params: {
_id: $route.params._id,
_command: command._id,
},
}" v-slot="{ href, navigate }" v-if="command.params?.length > 0 && !settings.showParameterInCommands">
<Tile style="background: transparent; border: 1px solid rgb(0, 0, 0)" :href="href" @click="navigate">
<template #title>
<i :class="command.icon || 'fa-regular fa-circle-question'"></i>
</template>
{{ command.name }}
</Tile>
</RouterLink>
<Tile v-else style="background: transparent; border: 1px solid rgb(0, 0, 0)" @click="trigger(command._id, $event)"
v-repeat="{ handler: repeat, interval: 300, command }">
<template #title>
<i :class="command.icon || 'fa-regular fa-circle-question'"></i>
</template>
<div>
{{ command.name }}
</div>
<CommandParameter :param="param" v-for="param in command.params" @changed="trigger(command._id, $event)">
</CommandParameter>
</Tile>
</div>
<!-- COMMANDS -->
<!-- STATES -->
<div class="p-0 col-6 col-md-3 col-xl-2" v-bind:key="state._id" v-for="state in data.states">
<Tile style="background: transparent; border: 1px solid rgb(0, 0, 0)">
<!--<h3><i :class="state.icon || 'fa-regular fa-circle-question'"></i></h3>-->
<div>{{ state.name }}</div>
<i>{{ state.value }}</i>
</Tile>
</div>
<!-- STATES -->
</div>
<!-- COMMANDS/STATES/SCENES -->
</div>
</template>