Files
frontend/app/components/ObjectTable.vue
andreas.dinauer 33c3670ba7 Bulk-Move für Objects
Mehrfachauswahl in der Objekttabelle (Checkboxen + Alle-auswählen),
neues Popup zum Verschieben in einen anderen Bucket, Move via
Copy+Delete gegen die bestehende S3-Schnittstelle. sigv4 kann jetzt
zusätzliche Header signieren (x-amz-copy-source), sonst nix am
Backend angefasst wie gewünscht.
2026-09-12 21:32:41 +02:00

158 lines
6.0 KiB
Vue

<template>
<div class="flex-1 overflow-auto">
<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-4 cursor-pointer accent-accent"
:checked="allSelected"
:indeterminate="someSelected"
@click.stop
@change="$emit('toggle-all')"
>
</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-accent-dim/40': selectedKeys.has(object.key) }"
@click="$emit('select', object)"
>
<td class="px-4 py-[5px]" @click.stop>
<input
type="checkbox"
class="size-4 cursor-pointer accent-accent"
:checked="selectedKeys.has(object.key)"
@change="$emit('toggle', 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 } 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
selectedKeys: Set<string>
}>()
defineEmits<{
select: [object: S3Object]
upload: []
retry: []
toggle: [key: string]
'toggle-all': []
}>()
const allSelected = computed(() => props.objects.length > 0 && props.objects.every((object) => props.selectedKeys.has(object.key)))
const someSelected = computed(() => !allSelected.value && props.objects.some((object) => props.selectedKeys.has(object.key)))
type SortKey = 'key' | 'size' | 'lastModified'
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>