|
| 1 | +<script setup lang="ts"> |
| 2 | +import { |
| 3 | + faCheckCircle, |
| 4 | + faCloudUploadAlt, |
| 5 | + faExclamationTriangle, |
| 6 | + faInfoCircle, |
| 7 | + faSpinner, |
| 8 | +} from "@fortawesome/free-solid-svg-icons"; |
| 9 | +import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome"; |
| 10 | +import { BAlert } from "bootstrap-vue"; |
| 11 | +import { computed } from "vue"; |
| 12 | +
|
| 13 | +import type { CardAction, CardBadge } from "@/components/Common/GCard.types"; |
| 14 | +import type { ExportRecord } from "@/components/Common/models/exportRecordModel"; |
| 15 | +
|
| 16 | +import GCard from "@/components/Common/GCard.vue"; |
| 17 | +
|
| 18 | +interface Props { |
| 19 | + /** The export record */ |
| 20 | + exportRecord: ExportRecord; |
| 21 | + /** Whether to display the card in a grid view */ |
| 22 | + gridView?: boolean; |
| 23 | +} |
| 24 | +
|
| 25 | +const props = withDefaults(defineProps<Props>(), { |
| 26 | + gridView: false, |
| 27 | +}); |
| 28 | +
|
| 29 | +const emit = defineEmits<{ |
| 30 | + (e: "onGoTo", to: string): void; |
| 31 | +}>(); |
| 32 | +
|
| 33 | +const objectType = computed(() => { |
| 34 | + const type = props.exportRecord.objectType; |
| 35 | + switch (type) { |
| 36 | + case "history": |
| 37 | + return "History"; |
| 38 | + case "invocation": |
| 39 | + return "Workflow Invocation"; |
| 40 | + default: |
| 41 | + return "Object"; |
| 42 | + } |
| 43 | +}); |
| 44 | +
|
| 45 | +const objectId = computed(() => { |
| 46 | + return props.exportRecord.objectId; |
| 47 | +}); |
| 48 | +
|
| 49 | +const title = computed(() => { |
| 50 | + return `Export ${objectType.value} to File Source`; |
| 51 | +}); |
| 52 | +
|
| 53 | +const targetUri = computed(() => { |
| 54 | + return props.exportRecord.importUri || "Unknown destination"; |
| 55 | +}); |
| 56 | +
|
| 57 | +const shortTargetUri = computed(() => { |
| 58 | + const uri = targetUri.value; |
| 59 | + // Extract just the filename from the URI |
| 60 | + const parts = uri.split("/"); |
| 61 | + return parts[parts.length - 1] || uri; |
| 62 | +}); |
| 63 | +
|
| 64 | +const primaryActions = computed(() => { |
| 65 | + const actions: CardAction[] = []; |
| 66 | +
|
| 67 | + if (objectId.value) { |
| 68 | + actions.push({ |
| 69 | + id: "go-to-object", |
| 70 | + label: `Go to ${objectType.value}`, |
| 71 | + icon: faInfoCircle, |
| 72 | + title: `View details for ${objectType.value}`, |
| 73 | + variant: "outline-primary", |
| 74 | + handler: onGoToObject, |
| 75 | + }); |
| 76 | + } |
| 77 | +
|
| 78 | + return actions; |
| 79 | +}); |
| 80 | +
|
| 81 | +const badges = computed<CardBadge[]>(() => { |
| 82 | + const badges: CardBadge[] = []; |
| 83 | +
|
| 84 | + if (props.exportRecord.isPreparing) { |
| 85 | + badges.push({ |
| 86 | + id: "in-progress", |
| 87 | + title: "Export is in progress", |
| 88 | + label: "In Progress", |
| 89 | + variant: "info", |
| 90 | + }); |
| 91 | + } else if (props.exportRecord.isReady) { |
| 92 | + badges.push({ |
| 93 | + id: "completed", |
| 94 | + title: "Export completed successfully", |
| 95 | + label: "Complete", |
| 96 | + variant: "success", |
| 97 | + }); |
| 98 | + } else if (props.exportRecord.hasFailed) { |
| 99 | + badges.push({ |
| 100 | + id: "failed", |
| 101 | + label: "Failed", |
| 102 | + title: "Export failed", |
| 103 | + variant: "danger", |
| 104 | + }); |
| 105 | + } |
| 106 | +
|
| 107 | + return badges; |
| 108 | +}); |
| 109 | +
|
| 110 | +function onGoToObject() { |
| 111 | + const type = props.exportRecord.objectType; |
| 112 | + const id = objectId.value; |
| 113 | + if (!id) { |
| 114 | + return; |
| 115 | + } |
| 116 | +
|
| 117 | + switch (type) { |
| 118 | + case "history": |
| 119 | + emit("onGoTo", `/histories/view?id=${id}`); |
| 120 | + break; |
| 121 | + case "invocation": |
| 122 | + emit("onGoTo", `/workflows/invocations/${id}`); |
| 123 | + break; |
| 124 | + default: |
| 125 | + console.warn(`No specific route defined for object type: ${type}`); |
| 126 | + break; |
| 127 | + } |
| 128 | +} |
| 129 | +</script> |
| 130 | + |
| 131 | +<template> |
| 132 | + <GCard |
| 133 | + :id="exportRecord.id" |
| 134 | + class="remote-export-card" |
| 135 | + :title="title" |
| 136 | + :badges="badges" |
| 137 | + :primary-actions="primaryActions" |
| 138 | + :update-time="exportRecord.date.toISOString()" |
| 139 | + :grid-view="gridView" |
| 140 | + :title-icon="{ |
| 141 | + icon: faCloudUploadAlt, |
| 142 | + title: 'Export to File Source', |
| 143 | + }"> |
| 144 | + <template v-slot:description> |
| 145 | + <p class="text-muted mb-2"><strong>Destination:</strong> {{ shortTargetUri }}</p> |
| 146 | + <p v-if="exportRecord.modelStoreFormat" class="text-muted mb-2"> |
| 147 | + <strong>Format:</strong> {{ exportRecord.modelStoreFormat }} |
| 148 | + </p> |
| 149 | + <BAlert v-if="exportRecord.isPreparing" variant="info" show> |
| 150 | + <FontAwesomeIcon :icon="faSpinner" spin /> |
| 151 | + <span>Exporting to remote file source...</span> |
| 152 | + </BAlert> |
| 153 | + <BAlert v-if="exportRecord.isReady" variant="success" show> |
| 154 | + <FontAwesomeIcon :icon="faCheckCircle" /> |
| 155 | + <span>Export completed successfully to {{ shortTargetUri }}</span> |
| 156 | + </BAlert> |
| 157 | + <BAlert v-if="exportRecord.hasFailed" variant="danger" show> |
| 158 | + <FontAwesomeIcon :icon="faExclamationTriangle" /> |
| 159 | + <span>Export failed.</span> |
| 160 | + <span v-if="exportRecord.errorMessage"> <strong>Error:</strong> {{ exportRecord.errorMessage }} </span> |
| 161 | + </BAlert> |
| 162 | + </template> |
| 163 | + </GCard> |
| 164 | +</template> |
0 commit comments