1
1
<template >
2
2
<DialogComponent
3
- v-model =" showDialog"
3
+ v-model:showDialog =" showDialog"
4
+ v-model:history =" history"
4
5
@emitSubmit =" emitAddOrEdit"
5
6
@emitSaveDraft =" saveDraft"
6
7
:hideDraftBtn =" editQueue ? true : false"
8
+ :showHistoryToggle =" editQueue && !Object.hasOwn(editQueue, 'payload')"
9
+ :disableConfirm =" history"
7
10
>
8
11
<template #title >
9
12
<label id =" modalTitle" >
10
13
{{editQueue ? 'Edit Queue' : 'Register Queue'}}
11
14
</label >
12
15
</template >
13
- <div class =" row items-center" >
14
- <label class =" col-3 q-mb-lg" id =" queueName" >
15
- Queue Name:
16
- </label >
17
- <q-input
18
- class =" col q-mb-xs"
19
- outlined
20
- dense
21
- v-model.trim =" name"
22
- autofocus
23
- :rules =" [requiredRule]"
24
- aria-labelledby =" queueName"
25
- aria-required =" true"
26
- />
27
- </div >
28
- <div class =" row items-center q-mb-xs" >
29
- <label class =" col-3 q-mb-lg" id =" pluginGroup" >
30
- Group:
31
- </label >
32
- <q-select
33
- class =" col"
34
- outlined
35
- v-model =" group"
36
- :options =" store.groups"
37
- option-label =" name"
38
- option-value =" id"
39
- emit-value
40
- map-options
41
- dense
42
- :rules =" [requiredRule]"
43
- aria-labelledby =" pluginGroup"
44
- aria-required =" true"
45
- />
46
- </div >
47
- <div class =" row items-center" >
48
- <label class =" col-3" id =" description" >
49
- Description:
50
- </label >
51
- <q-input
52
- class =" col"
53
- v-model.trim =" description"
54
- outlined
55
- type =" textarea"
56
- aria-labelledby =" description"
57
- />
16
+ <div class =" row no-wrap" >
17
+ <!-- this is the form col -->
18
+ <div
19
+ style =" width : 500px ;"
20
+ :style =" {
21
+ pointerEvents: history ? 'none' : 'auto',
22
+ opacity: history ? .65 : 1,
23
+ cursor: history ? 'not-allowed' : 'default'
24
+ }"
25
+ >
26
+ <div class =" row items-center" >
27
+ <label class =" col-3 q-mb-lg" id =" queueName" >
28
+ Queue Name:
29
+ </label >
30
+ <q-input
31
+ class =" col q-mb-xs"
32
+ outlined
33
+ dense
34
+ v-model.trim =" name"
35
+ autofocus
36
+ :rules =" [requiredRule]"
37
+ aria-labelledby =" queueName"
38
+ aria-required =" true"
39
+ />
40
+ </div >
41
+ <div class =" row items-center q-mb-xs" >
42
+ <label class =" col-3 q-mb-lg" id =" pluginGroup" >
43
+ Group:
44
+ </label >
45
+ <q-select
46
+ class =" col"
47
+ outlined
48
+ v-model =" group"
49
+ :options =" store.groups"
50
+ option-label =" name"
51
+ option-value =" id"
52
+ emit-value
53
+ map-options
54
+ dense
55
+ :rules =" [requiredRule]"
56
+ aria-labelledby =" pluginGroup"
57
+ aria-required =" true"
58
+ />
59
+ </div >
60
+ <div class =" row items-center" >
61
+ <label class =" col-3" id =" description" >
62
+ Description:
63
+ </label >
64
+ <q-input
65
+ class =" col"
66
+ v-model.trim =" description"
67
+ outlined
68
+ type =" textarea"
69
+ aria-labelledby =" description"
70
+ />
71
+ </div >
72
+ <!-- <q-inner-loading :showing="history" size="0px" /> -->
73
+ </div >
74
+ <!-- this is the history col -->
75
+ <q-card
76
+ v-if =" history"
77
+ style =" width : 240px ; max-height : 263px ; overflow : auto ;"
78
+ flat
79
+ bordered
80
+ class =" q-ml-sm col"
81
+ >
82
+ <q-list bordered separator >
83
+ <q-item
84
+ v-for =" (snapshot, i) in snapshots"
85
+ tag =" label"
86
+ v-ripple
87
+ dense
88
+ clickable
89
+ @click =" loadSnapshot(snapshot, i)"
90
+ @keydown =" keydown"
91
+ :class =" `${getSelectedColor(selectedSnapshotIndex === i)} cursor-pointer` "
92
+ >
93
+ <!-- <q-item-section avatar>
94
+ <q-radio
95
+ v-model="selectedSnapshot"
96
+ :val="snapshot"
97
+ @update:model-value="loadSnapshot(snapshot)"
98
+ />
99
+ </q-item-section> -->
100
+ <q-item-section >
101
+ <q-item-label >
102
+ {{
103
+ new Intl.DateTimeFormat('en-US', {
104
+ year: '2-digit',
105
+ month: '2-digit',
106
+ day: '2-digit',
107
+ hour: 'numeric',
108
+ minute: 'numeric',
109
+ hour12: true
110
+ }).format(new Date(snapshot.snapshotCreatedOn))
111
+ }}
112
+ <q-chip
113
+ v-if =" snapshot.latestSnapshot"
114
+ label =" latest"
115
+ size =" md"
116
+ dense
117
+ color =" orange"
118
+ text-color =" white"
119
+ />
120
+ </q-item-label >
121
+ </q-item-section >
122
+ </q-item >
123
+ </q-list >
124
+ </q-card >
58
125
</div >
59
126
</DialogComponent >
60
127
</template >
61
128
62
129
<script setup>
63
- import { ref , watch } from ' vue'
130
+ import { ref , watch , computed } from ' vue'
64
131
import DialogComponent from ' ./DialogComponent.vue'
65
132
import { useLoginStore } from ' @/stores/LoginStore.ts'
133
+ import * as api from ' @/services/dataApi'
134
+ import { useQuasar } from ' quasar'
66
135
67
136
const store = useLoginStore ()
68
137
79
148
const group = ref (' ' )
80
149
const description = ref (' ' )
81
150
151
+ function loadSnapshot (snapshot , index ) {
152
+ selectedSnapshotIndex .value = index
153
+ name .value = snapshot .name
154
+ group .value = snapshot .group
155
+ description .value = snapshot .description
156
+ }
157
+
82
158
watch (showDialog, (newVal ) => {
83
159
if (newVal) {
84
160
name .value = props .editQueue .name
88
164
else {
89
165
name .value = ' '
90
166
description .value = ' '
167
+ history .value = false
168
+ snapshots .value = []
91
169
}
92
170
})
93
171
109
187
emit (' saveDraft' , name .value , description .value , props .editQueue .id )
110
188
}
111
189
190
+ const history = ref (false )
191
+
192
+ const snapshots = ref ([])
193
+ const selectedSnapshot = ref ()
194
+ const selectedSnapshotIndex = ref ()
195
+
196
+ async function getSnapshots () {
197
+ try {
198
+ const res = await api .getSnapshots (' queues' , props .editQueue .id )
199
+ snapshots .value = res .data .data .reverse ()
200
+ selectedSnapshot .value = snapshots .value [0 ]
201
+ selectedSnapshotIndex .value = 0
202
+ loadSnapshot (snapshots .value [0 ], 0 )
203
+ } catch (err) {
204
+ console .warn (err)
205
+ }
206
+ }
207
+
208
+ watch (history, (newVal ) => {
209
+ if (newVal) {
210
+ getSnapshots ()
211
+ } else {
212
+ selectedSnapshotIndex .value = 0
213
+ name .value = props .editQueue .name
214
+ description .value = props .editQueue .description
215
+ group .value = props .editQueue .group
216
+ }
217
+ })
218
+
219
+ const $q = useQuasar ()
220
+
221
+ const darkMode = computed (() => {
222
+ if ($q .dark .mode === ' auto' ) {
223
+ return window .matchMedia (' (prefers-color-scheme: dark)' ).matches
224
+ }
225
+ return $q .dark .mode
226
+ })
227
+
228
+ function getSelectedColor (selected ) {
229
+ if (darkMode .value && selected) return ' bg-deep-purple-10'
230
+ else if (selected) return ' bg-blue-grey-2'
231
+ }
232
+
233
+ function keydown (event ) {
234
+ if (event .key === ' ArrowUp' && selectedSnapshotIndex .value > 0 ) {
235
+ const newIndex = selectedSnapshotIndex .value - 1
236
+ loadSnapshot (snapshots .value [newIndex], newIndex)
237
+ }
238
+ else if (event .key === ' ArrowDown' && selectedSnapshotIndex .value < snapshots .value .length - 1 ) {
239
+ const newIndex = selectedSnapshotIndex .value + 1
240
+ loadSnapshot (snapshots .value [newIndex], newIndex)
241
+ }
242
+ }
243
+
112
244
113
245
</script >
0 commit comments