Files
frontend/app/components/ObjectTable.vue
andreas.dinauer 970fd76190 Bulk-Delete für Objects
Checkboxen in der ObjectTable für Mehrfachauswahl, dazu eine
Aktionsleiste sobald was markiert ist. Löschen läuft über
deleteObjects() in useS3Client (parallel via Promise.allSettled,
S3 kann bei uns keinen echten Batch-Delete). Bestätigung läuft
über das vorhandene ConfirmPopup, bei Teilfehlern gibt's eine
klare Fehlermeldung statt stillem Datenverlust.
2026-09-12 21:21:16 +02:00

210 lines
7.5 KiB
Vue

<template>
<div class="flex-1 overflow-auto">
<div
v-if="selected.size"
class="sticky top-0 z-10 flex items-center justify-between gap-3 border-b border-border bg-surface px-4 py-2 text-sm"
>
<span class="text-text">{{ selected.size }} ausgewählt</span>
<div class="flex items-center gap-2">
<button
type="button"
class="rounded-md border border-border px-2.5 py-1 text-xs font-medium text-text transition-colors hover:bg-surface-raised"
@click="clearSelection"
>
Auswahl aufheben
</button>
<button
type="button"
class="flex items-center gap-1.5 rounded-md bg-red-500 px-3 py-1.5 text-xs font-medium text-white transition-opacity hover:opacity-90"
@click="$emit('bulk-delete', selectedObjects)"
>
<span class="material-symbols-outlined !text-[16px]">delete</span>
Löschen
</button>
</div>
</div>
<table v-if="loading || objects.length" class="w-full border-collapse text-sm">
<thead class="sticky top-0 bg-bg">
<tr class="border-b border-border text-left text-xs tracking-[0.08em] text-muted">
<th class="w-10 px-4 py-2.5 font-medium">
<input
type="checkbox"
class="size-3.5 cursor-pointer accent-accent"
:checked="allSelected"
:disabled="!sortedObjects.length"
@change="toggleSelectAll"
>
</th>
<th class="px-4 py-2.5 font-medium">
<SortHeader :active="sortKey === 'key' ? sortDir : null" @click="toggleSort('key')">KEY</SortHeader>
</th>
<th class="px-4 py-2.5 font-medium">
<SortHeader :active="sortKey === 'size' ? sortDir : null" @click="toggleSort('size')">SIZE</SortHeader>
</th>
<th class="px-4 py-2.5 font-medium">
<SortHeader :active="sortKey === 'lastModified' ? sortDir : null" @click="toggleSort('lastModified')">MODIFIED</SortHeader>
</th>
</tr>
</thead>
<tbody>
<template v-if="loading">
<tr v-for="n in 5" :key="n" class="border-b border-border/60">
<td class="px-4 py-3" colspan="4">
<div class="h-4 w-2/3 animate-pulse rounded bg-surface-raised" />
</td>
</tr>
</template>
<tr
v-for="object in sortedObjects"
v-else
:key="object.key"
class="cursor-pointer border-b border-border/60 transition-colors hover:bg-surface-raised/35"
:class="{ 'bg-surface-raised/50': selected.has(object.key) }"
@click="$emit('select', object)"
>
<td class="px-4 py-[5px]" @click.stop>
<input
type="checkbox"
class="size-3.5 cursor-pointer accent-accent"
:checked="selected.has(object.key)"
@change="toggleSelected(object.key)"
>
</td>
<td class="px-4 py-[5px]">
<div class="flex items-center gap-2.5">
<FileTypeBadge :filename="object.key" />
<PathBreadcrumb :path="object.key" />
</div>
</td>
<td class="px-4 py-[5px] font-mono tabular-nums text-muted">{{ formatBytes(object.size) }}</td>
<td class="px-4 py-[5px] font-mono tabular-nums text-muted">
<div class="flex items-center gap-2">
<span>{{ formatDate(object.lastModified) }} {{ formatTime(object.lastModified) }}</span>
<span
v-if="isToday(object.lastModified)"
class="rounded bg-surface-raised px-1 py-0.5 font-sans text-[11.5px] font-medium normal-case tracking-normal text-muted"
>Heute</span>
</div>
</td>
</tr>
</tbody>
</table>
<div v-else class="flex h-full flex-col items-center justify-center gap-3 px-6 text-center">
<template v-if="error">
<span class="material-symbols-outlined !text-[40px] text-accent">error</span>
<p class="text-text">Objekte konnten nicht geladen werden</p>
<p class="max-w-xs text-sm text-muted">{{ error }}</p>
<button
type="button"
class="mt-1 flex items-center gap-1.5 rounded-md border border-border px-3 py-1.5 text-sm font-medium text-text transition-colors hover:bg-surface-raised"
@click="$emit('retry')"
>
<span class="material-symbols-outlined !text-[18px]">refresh</span>
Erneut versuchen
</button>
</template>
<template v-else>
<span class="material-symbols-outlined !text-[40px] text-muted">{{ hasSearch ? 'search_off' : 'inventory_2' }}</span>
<p class="text-text">{{ hasSearch ? 'Keine Treffer' : 'Dieser Bucket ist leer' }}</p>
<p class="max-w-xs text-sm text-muted">
{{ hasSearch
? `Keine Objekte passen zu "${searchTerm}".`
: 'Objekte, die du hier hochlädst, tauchen in dieser Liste auf.' }}
</p>
<button
v-if="!hasSearch"
type="button"
class="mt-1 flex items-center gap-1.5 rounded-md bg-accent px-3 py-1.5 text-sm font-medium text-white transition-opacity hover:opacity-90"
@click="$emit('upload')"
>
<span class="material-symbols-outlined !text-[18px]">upload</span>
Hochladen
</button>
</template>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import { formatBytes, formatTime, formatDate, isToday } from '~/utils/format'
import type { S3Object } from '~/utils/s3xml'
const props = defineProps<{
objects: S3Object[]
loading: boolean
hasSearch: boolean
searchTerm: string
error?: string | null
}>()
defineEmits<{ select: [object: S3Object]; upload: []; retry: []; 'bulk-delete': [objects: S3Object[]] }>()
type SortKey = 'key' | 'size' | 'lastModified'
const selected = ref<Set<string>>(new Set())
const selectedObjects = computed(() => props.objects.filter((object) => selected.value.has(object.key)))
const allSelected = computed(() => sortedObjects.value.length > 0 && sortedObjects.value.every((object) => selected.value.has(object.key)))
function toggleSelected(key: string) {
const next = new Set(selected.value)
if (next.has(key)) {
next.delete(key)
}
else {
next.add(key)
}
selected.value = next
}
function toggleSelectAll() {
if (allSelected.value) {
selected.value = new Set()
return
}
selected.value = new Set(sortedObjects.value.map((object) => object.key))
}
function clearSelection() {
selected.value = new Set()
}
defineExpose({ clearSelection })
watch(() => props.objects, (objects) => {
const keys = new Set(objects.map((object) => object.key))
const next = new Set([...selected.value].filter((key) => keys.has(key)))
if (next.size !== selected.value.size) {
selected.value = next
}
})
const sortKey = ref<SortKey>('lastModified')
const sortDir = ref<'asc' | 'desc'>('desc')
function toggleSort(key: SortKey) {
if (sortKey.value === key) {
sortDir.value = sortDir.value === 'asc' ? 'desc' : 'asc'
return
}
sortKey.value = key
sortDir.value = 'asc'
}
const sortedObjects = computed(() => {
const factor = sortDir.value === 'asc' ? 1 : -1
return [...props.objects].sort((a, b) => {
if (sortKey.value === 'key') {
return a.key.localeCompare(b.key) * factor
}
if (sortKey.value === 'size') {
return (a.size - b.size) * factor
}
return (new Date(a.lastModified).getTime() - new Date(b.lastModified).getTime()) * factor
})
})
</script>