fixed some bugs with dialog and viewing docx works again
This commit is contained in:
@@ -69,7 +69,7 @@ const maxWidthClass = computed(() => {
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="open">
|
||||
<DialogContent :class="maxWidthClass">
|
||||
<DialogContent class="overflow-auto max-h-3/4" :class="maxWidthClass">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
<div class="flex items-center gap-2">
|
||||
|
||||
@@ -6,34 +6,40 @@ import {
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@/Components/ui/dialog';
|
||||
import { Button } from '@/Components/ui/button';
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import { faTrashCan, faTriangleExclamation } from '@fortawesome/free-solid-svg-icons';
|
||||
import { ref, watch } from 'vue';
|
||||
} from "@/Components/ui/dialog";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
||||
import { faTrashCan, faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
|
||||
import { ref, watch } from "vue";
|
||||
|
||||
const props = defineProps({
|
||||
show: { type: Boolean, default: false },
|
||||
title: { type: String, default: 'Izbriši' },
|
||||
message: { type: String, default: 'Ali ste prepričani, da želite izbrisati ta element?' },
|
||||
confirmText: { type: String, default: 'Izbriši' },
|
||||
cancelText: { type: String, default: 'Prekliči' },
|
||||
title: { type: String, default: "Izbriši" },
|
||||
message: {
|
||||
type: String,
|
||||
default: "Ali ste prepričani, da želite izbrisati ta element?",
|
||||
},
|
||||
confirmText: { type: String, default: "Izbriši" },
|
||||
cancelText: { type: String, default: "Prekliči" },
|
||||
processing: { type: Boolean, default: false },
|
||||
itemName: { type: String, default: null }, // Optional name to show in confirmation
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:show', 'close', 'confirm']);
|
||||
const emit = defineEmits(["update:show", "close", "confirm"]);
|
||||
|
||||
const open = ref(props.show);
|
||||
|
||||
watch(() => props.show, (newVal) => {
|
||||
open.value = newVal;
|
||||
});
|
||||
watch(
|
||||
() => props.show,
|
||||
(newVal) => {
|
||||
open.value = newVal;
|
||||
}
|
||||
);
|
||||
|
||||
watch(open, (newVal) => {
|
||||
emit('update:show', newVal);
|
||||
emit("update:show", newVal);
|
||||
if (!newVal) {
|
||||
emit('close');
|
||||
emit("close");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -42,7 +48,7 @@ const onClose = () => {
|
||||
};
|
||||
|
||||
const onConfirm = () => {
|
||||
emit('confirm');
|
||||
emit("confirm");
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -59,8 +65,13 @@ const onConfirm = () => {
|
||||
<DialogDescription>
|
||||
<div class="flex items-start gap-4 pt-4">
|
||||
<div class="flex-shrink-0">
|
||||
<div class="flex items-center justify-center h-12 w-12 rounded-full bg-red-100">
|
||||
<FontAwesomeIcon :icon="faTriangleExclamation" class="h-6 w-6 text-red-600" />
|
||||
<div
|
||||
class="flex items-center justify-center h-12 w-12 rounded-full bg-red-100"
|
||||
>
|
||||
<FontAwesomeIcon
|
||||
:icon="faTriangleExclamation"
|
||||
class="h-6 w-6 text-red-600"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-1 space-y-2">
|
||||
@@ -70,9 +81,7 @@ const onConfirm = () => {
|
||||
<p v-if="itemName" class="text-sm font-medium text-gray-900">
|
||||
{{ itemName }}
|
||||
</p>
|
||||
<p class="text-sm text-gray-500">
|
||||
Ta dejanje ni mogoče razveljaviti.
|
||||
</p>
|
||||
<p class="text-sm text-gray-500">Ta dejanje ni mogoče razveljaviti.</p>
|
||||
</div>
|
||||
</div>
|
||||
</DialogDescription>
|
||||
@@ -82,15 +91,10 @@ const onConfirm = () => {
|
||||
<Button variant="outline" @click="onClose" :disabled="processing">
|
||||
{{ cancelText }}
|
||||
</Button>
|
||||
<Button
|
||||
variant="destructive"
|
||||
@click="onConfirm"
|
||||
:disabled="processing"
|
||||
>
|
||||
<Button variant="destructive" @click="onConfirm" :disabled="processing">
|
||||
{{ confirmText }}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ const maxWidthClass = computed(() => {
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="open">
|
||||
<DialogContent :class="maxWidthClass">
|
||||
<DialogContent class="overflow-auto max-h-3/4" :class="maxWidthClass">
|
||||
<DialogHeader>
|
||||
<DialogTitle>
|
||||
<div class="flex items-center gap-2">
|
||||
|
||||
@@ -9,6 +9,8 @@ import {
|
||||
} from "@/Components/ui/dialog";
|
||||
import { Button } from "@/Components/ui/button";
|
||||
import { Badge } from "../ui/badge";
|
||||
import { Loader2 } from "lucide-vue-next";
|
||||
import axios from "axios";
|
||||
|
||||
const props = defineProps({
|
||||
show: { type: Boolean, default: false },
|
||||
@@ -21,6 +23,8 @@ const emit = defineEmits(["close"]);
|
||||
|
||||
const textContent = ref("");
|
||||
const loading = ref(false);
|
||||
const previewGenerating = ref(false);
|
||||
const previewError = ref("");
|
||||
|
||||
const fileExtension = computed(() => {
|
||||
if (props.filename) {
|
||||
@@ -34,6 +38,9 @@ const viewerType = computed(() => {
|
||||
const mime = props.mimeType.toLowerCase();
|
||||
|
||||
if (ext === "pdf" || mime === "application/pdf") return "pdf";
|
||||
// DOCX/DOC files are converted to PDF by backend - treat as PDF viewer
|
||||
if (["doc", "docx"].includes(ext) || mime.includes("word") || mime.includes("msword"))
|
||||
return "docx";
|
||||
if (["jpg", "jpeg", "png", "gif", "webp"].includes(ext) || mime.startsWith("image/"))
|
||||
return "image";
|
||||
if (["txt", "csv", "xml"].includes(ext) || mime.startsWith("text/")) return "text";
|
||||
@@ -45,8 +52,8 @@ const loadTextContent = async () => {
|
||||
if (!props.src || viewerType.value !== "text") return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await fetch(props.src);
|
||||
textContent.value = await response.text();
|
||||
const response = await axios.get(props.src);
|
||||
textContent.value = response.data;
|
||||
} catch (e) {
|
||||
textContent.value = "Napaka pri nalaganju vsebine.";
|
||||
} finally {
|
||||
@@ -54,12 +61,64 @@ const loadTextContent = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// For DOCX files, the backend converts to PDF. If the preview isn't ready yet (202 status),
|
||||
// we poll until it's available.
|
||||
const docxPreviewUrl = ref("");
|
||||
const loadDocxPreview = async () => {
|
||||
if (!props.src || viewerType.value !== "docx") return;
|
||||
|
||||
previewGenerating.value = true;
|
||||
previewError.value = "";
|
||||
docxPreviewUrl.value = "";
|
||||
|
||||
const maxRetries = 15;
|
||||
const retryDelay = 2000; // 2 seconds between retries
|
||||
|
||||
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||
try {
|
||||
const response = await axios.head(props.src, { validateStatus: () => true });
|
||||
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
// Preview is ready
|
||||
docxPreviewUrl.value = props.src;
|
||||
previewGenerating.value = false;
|
||||
return;
|
||||
} else if (response.status === 202) {
|
||||
// Preview is being generated, wait and retry
|
||||
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
||||
} else {
|
||||
// Other error
|
||||
previewError.value = "Napaka pri nalaganju predogleda.";
|
||||
previewGenerating.value = false;
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
previewError.value = "Napaka pri nalaganju predogleda.";
|
||||
previewGenerating.value = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Max retries reached
|
||||
previewError.value = "Predogled ni na voljo. Prosimo poskusite znova kasneje.";
|
||||
previewGenerating.value = false;
|
||||
};
|
||||
|
||||
watch(
|
||||
() => [props.show, props.src],
|
||||
([show]) => {
|
||||
if (show && viewerType.value === "text") {
|
||||
loadTextContent();
|
||||
}
|
||||
if (show && viewerType.value === "docx") {
|
||||
loadDocxPreview();
|
||||
}
|
||||
// Reset states when dialog closes
|
||||
if (!show) {
|
||||
previewGenerating.value = false;
|
||||
previewError.value = "";
|
||||
docxPreviewUrl.value = "";
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
@@ -89,6 +148,35 @@ watch(
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- DOCX Viewer (converted to PDF by backend) -->
|
||||
<template v-else-if="viewerType === 'docx'">
|
||||
<!-- Loading/generating state -->
|
||||
<div
|
||||
v-if="previewGenerating"
|
||||
class="flex flex-col items-center justify-center h-full gap-4"
|
||||
>
|
||||
<Loader2 class="h-8 w-8 animate-spin text-indigo-600" />
|
||||
<span class="text-gray-500">Priprava predogleda dokumenta...</span>
|
||||
</div>
|
||||
<!-- Error state -->
|
||||
<div
|
||||
v-else-if="previewError"
|
||||
class="flex flex-col items-center justify-center h-full gap-4 text-gray-500"
|
||||
>
|
||||
<span>{{ previewError }}</span>
|
||||
<Button as="a" :href="props.src" target="_blank" variant="outline">
|
||||
Prenesi datoteko
|
||||
</Button>
|
||||
</div>
|
||||
<!-- Preview ready -->
|
||||
<iframe
|
||||
v-else-if="docxPreviewUrl"
|
||||
:src="docxPreviewUrl"
|
||||
class="w-full h-full rounded border"
|
||||
type="application/pdf"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- Image Viewer -->
|
||||
<template v-else-if="viewerType === 'image' && props.src">
|
||||
<img
|
||||
|
||||
Reference in New Issue
Block a user