|
14 | 14 | <BButton variant="success" @click="newShowModal?.show()">Setup New Show</BButton> |
15 | 15 | </template> |
16 | 16 | <template #cell(btn)="data"> |
17 | | - <BButton |
18 | | - variant="primary" |
19 | | - :disabled=" |
20 | | - isSubmittingLoad || (currentShow != null && currentShow.id === data.item.id) |
21 | | - " |
22 | | - @click="loadShow(data.item)" |
23 | | - > |
24 | | - {{ |
25 | | - currentShow != null && currentShow.id === data.item.id ? 'Loaded' : 'Load Show' |
26 | | - }} |
27 | | - </BButton> |
| 17 | + <BButtonGroup> |
| 18 | + <BButton |
| 19 | + variant="primary" |
| 20 | + :disabled=" |
| 21 | + isSubmittingLoad || (currentShow != null && currentShow.id === data.item.id) |
| 22 | + " |
| 23 | + @click="loadShow(data.item)" |
| 24 | + > |
| 25 | + {{ |
| 26 | + currentShow != null && currentShow.id === data.item.id ? 'Loaded' : 'Load Show' |
| 27 | + }} |
| 28 | + </BButton> |
| 29 | + <BButton |
| 30 | + variant="danger" |
| 31 | + :disabled="isDeleting || (currentShow != null && currentShow.id === data.item.id)" |
| 32 | + @click="deleteShow(data.item)" |
| 33 | + > |
| 34 | + <BSpinner v-if="isDeleting && deletingId === data.item.id" small /> |
| 35 | + Delete |
| 36 | + </BButton> |
| 37 | + </BButtonGroup> |
28 | 38 | </template> |
29 | 39 | </BTable> |
30 | 40 | <BPagination |
@@ -118,18 +128,22 @@ import log from 'loglevel'; |
118 | 128 | import { makeURL } from '@/js/utils'; |
119 | 129 | import { useSystemStore } from '@/stores/system'; |
120 | 130 | import { useShowStore } from '@/stores/show'; |
| 131 | +import { useConfirm } from '@/composables/useConfirm'; |
121 | 132 | import { toast } from '@/js/toast'; |
122 | 133 | import type { Show } from '@/types/api/show'; |
123 | 134 |
|
124 | 135 | const systemStore = useSystemStore(); |
125 | 136 | const showStore = useShowStore(); |
126 | 137 | const { availableShows, currentShow } = storeToRefs(systemStore); |
127 | 138 | const { scriptModes } = storeToRefs(showStore); |
| 139 | +const { confirm } = useConfirm(); |
128 | 140 |
|
129 | 141 | const loaded = ref(false); |
130 | 142 | const newShowModal = ref<InstanceType<typeof BModal>>(); |
131 | 143 | const isSubmittingLoad = ref(false); |
132 | 144 | const isSubmittingShow = ref(false); |
| 145 | +const isDeleting = ref(false); |
| 146 | +const deletingId = ref<number | null>(null); |
133 | 147 | const currentPage = ref(1); |
134 | 148 | const rowsPerPage = 15; |
135 | 149 |
|
@@ -250,6 +264,34 @@ async function loadShow(show: Show): Promise<void> { |
250 | 264 | } |
251 | 265 | } |
252 | 266 |
|
| 267 | +async function deleteShow(show: Show): Promise<void> { |
| 268 | + const confirmed = await confirm( |
| 269 | + `Are you sure you want to delete ${show.name}? This will delete all data associated with this show and cannot be undone.`, |
| 270 | + { title: 'Delete Show', okVariant: 'danger', okTitle: 'Delete' } |
| 271 | + ); |
| 272 | + if (!confirmed) return; |
| 273 | +
|
| 274 | + isDeleting.value = true; |
| 275 | + deletingId.value = show.id; |
| 276 | + try { |
| 277 | + const params = new URLSearchParams({ id: String(show.id) }); |
| 278 | + const response = await fetch(`${makeURL('/api/v1/show')}?${params}`, { method: 'DELETE' }); |
| 279 | + if (response.ok) { |
| 280 | + await systemStore.getAvailableShows(); |
| 281 | + toast.success('Deleted show!'); |
| 282 | + } else { |
| 283 | + log.error('Unable to delete show'); |
| 284 | + toast.error('Unable to delete show'); |
| 285 | + } |
| 286 | + } catch (err) { |
| 287 | + log.error('Error deleting show:', err); |
| 288 | + toast.error('Unable to delete show'); |
| 289 | + } finally { |
| 290 | + isDeleting.value = false; |
| 291 | + deletingId.value = null; |
| 292 | + } |
| 293 | +} |
| 294 | +
|
253 | 295 | onMounted(async () => { |
254 | 296 | await Promise.all([systemStore.getAvailableShows(), showStore.getScriptModes()]); |
255 | 297 | loaded.value = true; |
|
0 commit comments