/
App.vue
329 lines (302 loc) · 10.6 KB
/
App.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
<template>
<v-app>
<v-main>
<Dialog v-model:show="showMainMenu">
<div class="flex flex-col items-center justify-around">
<v-btn
v-if="route.name === 'widgets-view'"
prepend-icon="mdi-pencil"
class="w-full m-1 text-white action-button bg-slate-500 hover:bg-slate-400"
@click="widgetStore.editingMode = !widgetStore.editingMode"
>
Edit mode
</v-btn>
<v-btn
v-if="route.name !== 'widgets-view'"
prepend-icon="mdi-send"
class="w-full m-1 text-white action-button bg-slate-500 hover:bg-slate-400"
to="/"
>
Flight
</v-btn>
<v-btn
v-if="route.name !== 'Mission planning'"
prepend-icon="mdi-map-marker-radius"
class="w-full m-1 text-white action-button bg-slate-500 hover:bg-slate-400"
to="/mission-planning"
>
Mission planning
</v-btn>
<v-btn
prepend-icon="mdi-cog"
class="w-full m-1 text-white action-button bg-slate-500 hover:bg-slate-400"
@click="showConfigurationMenu = true"
>
Configuration
</v-btn>
<v-btn
:prepend-icon="fullScreenToggleIcon"
class="w-full m-1 text-white action-button bg-slate-500 hover:bg-slate-400"
@click="toggleFullscreen"
>
{{ isFullscreen ? 'Exit fullscreen' : 'Enter fullscreen' }}
</v-btn>
</div>
</Dialog>
<teleport to="body">
<v-dialog v-model="showConfigurationMenu" transition="dialog-bottom-transition" width="100%" height="100%">
<ConfigurationMenu />
</v-dialog>
</teleport>
<teleport to="body">
<v-dialog v-model="showMissionOptionsDialog" width="50%">
<v-card class="pa-2">
<v-card-title>Mission configuration</v-card-title>
<v-card-text>
<div class="flex">
<v-text-field
v-model="store.missionName"
label="Mission name"
append-inner-icon="mdi-restore"
@click:append-inner="store.missionName = store.lastMissionName"
/>
</div>
</v-card-text>
</v-card>
</v-dialog>
</teleport>
<div ref="routerSection" class="router-view">
<div class="main-view" :class="{ 'edit-mode': widgetStore.editingMode }">
<div id="mainTopBar" class="z-[60] w-full h-12 bg-slate-600/50 absolute flex backdrop-blur-[2px]">
<button class="flex items-center justify-center h-full aspect-square" @click="openMainMenu()">
<span class="text-3xl transition-all mdi mdi-menu text-slate-300 hover:text-slate-50" />
</button>
<div
class="flex items-center justify-start h-full px-4 ml-3 mr-1 transition-all cursor-pointer hover:bg-slate-200/30 min-w-[20%] select-none"
@click="showMissionOptionsDialog = true"
>
<div class="flex items-center overflow-hidden text-lg font-medium text-white whitespace-nowrap">
<p v-if="store.missionName" class="overflow-x-hidden text-ellipsis">{{ store.missionName }}</p>
<p v-else class="overflow-x-hidden text-ellipsis">
{{ randomMissionName }}
<FontAwesomeIcon icon="fa-pen-to-square" size="1x" class="ml-2 text-slate-200/30" />
</p>
</div>
</div>
<div class="grow" />
<Alerter class="max-w-sm min-w-fit" />
<div class="grow" />
<div class="flex-1">
<MiniWidgetContainer
:container="widgetStore.currentMiniWidgetsProfile.containers[0]"
:allow-editing="widgetStore.editingMode"
align="end"
/>
</div>
<div
class="flex items-center justify-center m-2 text-sm font-bold text-center text-white select-none min-w-[80px]"
>
{{ format(timeNow, 'E LLL do HH:mm') }}
</div>
</div>
<AltitudeSlider />
<Transition name="fade">
<div v-if="showBottomBarNow" class="bottom-container">
<SlideToConfirm />
<div class="bottom-bar h-12">
<MiniWidgetContainer
:container="widgetStore.currentView.miniWidgetContainers[0]"
:allow-editing="widgetStore.editingMode"
align="start"
/>
<div />
<MiniWidgetContainer
:container="widgetStore.currentView.miniWidgetContainers[1]"
:allow-editing="widgetStore.editingMode"
align="center"
/>
<div />
<MiniWidgetContainer
:container="widgetStore.currentView.miniWidgetContainers[2]"
:allow-editing="widgetStore.editingMode"
align="end"
/>
</div>
</div>
</Transition>
<router-view />
</div>
<EditMenu v-model:edit-mode="widgetStore.editingMode" />
</div>
</v-main>
</v-app>
</template>
<script setup lang="ts">
import { onClickOutside, useDebounceFn, useFullscreen, useTimestamp } from '@vueuse/core'
import { format } from 'date-fns'
import Swal from 'sweetalert2'
import {
// type AsyncComponentLoader,
computed,
onBeforeUnmount,
// defineAsyncComponent,
ref,
watch,
} from 'vue'
import { useRoute } from 'vue-router'
import ConfigurationMenu from '@/components/ConfigurationMenu.vue'
import { coolMissionNames } from '@/libs/funny-name/words'
import {
availableCockpitActions,
registerActionCallback,
unregisterActionCallback,
} from '@/libs/joystick/protocols/cockpit-actions'
import { useMissionStore } from '@/stores/mission'
import AltitudeSlider from './components/AltitudeSlider.vue'
import Dialog from './components/Dialog.vue'
import EditMenu from './components/EditMenu.vue'
import MiniWidgetContainer from './components/MiniWidgetContainer.vue'
import SlideToConfirm from './components/SlideToConfirm.vue'
import Alerter from './components/widgets/Alerter.vue'
import { datalogger } from './libs/sensors-logging'
import { useMainVehicleStore } from './stores/mainVehicle'
import { useWidgetManagerStore } from './stores/widgetManager'
const widgetStore = useWidgetManagerStore()
const vehicleStore = useMainVehicleStore()
const showConfigurationMenu = ref(false)
// Main menu
const showMainMenu = ref(false)
// When a isVehicleArmed change its value a watcher call Swal.close, this flag is
// used to avoid closing others Swal instances instead of the one intended
let requestDisarmConfirmationPopup = false
const openMainMenu = (): void => {
if (!vehicleStore.isArmed) {
showMainMenu.value = true
return
}
requestDisarmConfirmationPopup = true
Swal.fire({
title: 'Be careful',
text: 'The vehicle is currently armed, it is not recommended to open the main menu.',
icon: 'warning',
showCancelButton: true,
showConfirmButton: true,
cancelButtonText: 'Continue anyway',
confirmButtonText: 'Disarm vehicle',
}).then((result) => {
// Opens the main menu only after disarming by the slider is confirmed
if (result.isConfirmed && vehicleStore.isArmed) {
vehicleStore.disarm().then(() => {
showMainMenu.value = true
})
} else if (result.dismiss === Swal.DismissReason.cancel) {
showMainMenu.value = true
}
requestDisarmConfirmationPopup = false
})
}
const isVehicleArmed = computed(() => vehicleStore.isArmed)
watch(isVehicleArmed, (isArmed) => {
if (requestDisarmConfirmationPopup && !isArmed) {
Swal.close()
}
})
const mainMenu = ref()
onClickOutside(mainMenu, () => (showMainMenu.value = false))
const route = useRoute()
const routerSection = ref()
// Full screen toggling
const { isFullscreen, toggle: toggleFullscreen } = useFullscreen()
const debouncedToggleFullScreen = useDebounceFn(() => toggleFullscreen(), 10)
const fullScreenCallbackId = registerActionCallback(
availableCockpitActions.toggle_full_screen,
debouncedToggleFullScreen
)
onBeforeUnmount(() => unregisterActionCallback(fullScreenCallbackId))
const fullScreenToggleIcon = computed(() => (isFullscreen.value ? 'mdi-fullscreen-exit' : 'mdi-overscan'))
// Mission identification
const store = useMissionStore()
const showMissionOptionsDialog = ref(false)
const randomMissionName = coolMissionNames.random()
// Clock
const timeNow = useTimestamp({ interval: 1000 })
// Control showing mouse
let hideMouseTimeoutId: ReturnType<typeof setInterval>
const hideMouse = (): void => {
document.body.classList.add('hide-cursor')
}
const resetHideMouseTimeout = (): void => {
clearTimeout(hideMouseTimeoutId)
document.body.classList.remove('hide-cursor')
hideMouseTimeoutId = setTimeout(hideMouse, 5000)
}
document.addEventListener('mousemove', resetHideMouseTimeout)
// Control bottom bar momentary hiding
const showBottomBarNow = ref(widgetStore.currentView.showBottomBarOnBoot)
watch([() => widgetStore.currentView, () => widgetStore.currentView.showBottomBarOnBoot], () => {
showBottomBarNow.value = widgetStore.currentView.showBottomBarOnBoot
})
const debouncedToggleBottomBar = useDebounceFn(() => (showBottomBarNow.value = !showBottomBarNow.value), 25)
const bottomBarToggleCallbackId = registerActionCallback(
availableCockpitActions.toggle_bottom_bar,
debouncedToggleBottomBar
)
onBeforeUnmount(() => unregisterActionCallback(bottomBarToggleCallbackId))
// Start datalogging
datalogger.startLogging()
</script>
<style>
html,
body {
/* Removes the scrollbar */
overflow: hidden !important;
}
body.hide-cursor {
cursor: none;
}
.router-view {
width: 100%;
height: 100%;
position: relative;
}
.main-view {
transition: all 0.2s;
width: 100%;
height: 100%;
position: absolute;
right: 0%;
top: 0%;
}
.main-view.edit-mode {
transform: scale(0.8);
right: -10%;
top: -10%;
}
.swal2-container {
z-index: 10000;
}
.fade-enter-active,
.fade-leave-active {
transition: all 0.3s cubic-bezier(0.55, 0, 0.1, 1);
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
transform: translate(0, 100px);
}
.bottom-container {
position: absolute;
bottom: 0;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
z-index: 60; /* Adjust z-index as needed */
}
.bottom-bar {
width: 100%;
background: rgba(108, 117, 125, 0.5);
display: flex;
justify-content: space-between;
}
</style>