|
| 1 | +<!-- |
| 2 | +// Copyright 2022-2026 Tobias Anker <tobias.anker@kitsunemimi.moe> |
| 3 | +
|
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +
|
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | +--> |
| 16 | + |
| 17 | +<template> |
| 18 | + <div class="modal-overlay" @click.self="cancel"> |
| 19 | + <div class="modal task-delete-modal"> |
| 20 | + <div class="modal-topbar"> |
| 21 | + <span>Abort task</span> |
| 22 | + </div> |
| 23 | + <div class="modal-content"> |
| 24 | + <p>Are you sure you want to abort?</p> |
| 25 | + <strong>Task: {{ task?.uuid }}</strong> |
| 26 | + </div> |
| 27 | + |
| 28 | + <div class="modal-bottombar"> |
| 29 | + <div class="modal-actions"> |
| 30 | + <button |
| 31 | + class="icon-button" |
| 32 | + @click="handleAccept(task?.uuid, model_uuid, torii_port)" |
| 33 | + > |
| 34 | + <img :src="icons.acceptIcon" alt="Accept" /> |
| 35 | + </button> |
| 36 | + <button class="icon-button" @click="cancel"> |
| 37 | + <img :src="icons.cancelIcon" alt="Cancel" /> |
| 38 | + </button> |
| 39 | + </div> |
| 40 | + </div> |
| 41 | + </div> |
| 42 | + </div> |
| 43 | + <div v-if="errorPopupMsg" class="error-popup"> |
| 44 | + <button class="error-close-btn" @click="errorPopupMsg = ''">✕</button> |
| 45 | + {{ errorPopupMsg }} |
| 46 | + </div> |
| 47 | +</template> |
| 48 | + |
| 49 | +<script lang="ts" setup> |
| 50 | +import { ref } from "vue"; |
| 51 | +import axios from "axios"; |
| 52 | +
|
| 53 | +import { getAuthContext } from "@/auth_context"; |
| 54 | +import { handleAxiosError } from "@/handleAxiosError"; |
| 55 | +
|
| 56 | +interface Props { |
| 57 | + model_uuid: string; |
| 58 | + torii_port: number; |
| 59 | + task: { uuid: string } | null; |
| 60 | + icons: { acceptIcon: string; cancelIcon: string }; |
| 61 | +} |
| 62 | +defineProps<Props>(); |
| 63 | +const emit = defineEmits<{ |
| 64 | + (e: "accept"): void; |
| 65 | + (e: "cancel"): void; |
| 66 | +}>(); |
| 67 | +const errorPopupMsg = ref<string>(""); |
| 68 | +
|
| 69 | +async function handleAccept(task_uuid: string, model_uuid: string, torii_port: number) { |
| 70 | + if (!task_uuid) return; |
| 71 | + try { |
| 72 | + const authContext = getAuthContext(); |
| 73 | + const sakura_api = axios.create({ |
| 74 | + baseURL: `${authContext.torii_base_address}:${torii_port}`, |
| 75 | + }); |
| 76 | +
|
| 77 | + await sakura_api.put(`/v1alpha/model/${model_uuid}/task/${task_uuid}/abort`, {}, { |
| 78 | + headers: { Authorization: `Bearer ${authContext.token}` }, |
| 79 | + }); |
| 80 | +
|
| 81 | + emit("accept"); |
| 82 | + } catch (err) { |
| 83 | + errorPopupMsg.value = handleAxiosError(err, "Failed to delete task"); |
| 84 | + } |
| 85 | +} |
| 86 | +
|
| 87 | +function cancel() { |
| 88 | + emit("cancel"); |
| 89 | +} |
| 90 | +</script> |
| 91 | + |
| 92 | +<style scoped> |
| 93 | +.task-delete-modal { |
| 94 | + width: 30rem; |
| 95 | +} |
| 96 | +</style> |
0 commit comments