feat: clip bearbeiten mit konfliktbehandlung

- Bearbeiten-Ansicht /clips/:id mit Vorschau, Kopieren und Löschen
- bei paralleler Änderung Wahl zwischen anderer und eigener Version
- Warnung vor dem Verlassen mit ungespeicherten Änderungen
- Systemstatus in den Admin-Bereich verschoben

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dbildhauerandClaude Opus 5.5 committed 2026-10-25 11:04:33 +01:00
1 parent 7b16940b96
commit 8a519041f3
4 files changed
+289

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
<script setup lang="ts">
import { onMounted } from 'vue'
import { useHealthStore } from '@/stores/health'
const store = useHealthStore()
onMounted(store.refresh)
</script>
<template>
<section class="card">
<h2>Systemstatus</h2>
<p v-if="store.loading" class="muted">Prüfe …</p>
<p v-else-if="store.error" class="error">Backend nicht erreichbar: {{ store.error }}</p>
<dl v-else-if="store.health">
<dt>Status</dt>
<dd :class="store.health.status">{{ store.health.status }}</dd>
<dt>Datenbank</dt>
<dd :class="store.health.db">{{ store.health.db }}</dd>
<dt>Version</dt>
<dd>{{ store.health.version }}</dd>
</dl>
<button type="button" :disabled="store.loading" @click="store.refresh">Aktualisieren</button>
</section>
</template>
<style scoped>
dl {
display: grid;
grid-template-columns: max-content 1fr;
gap: 0.25rem 1rem;
margin: 0 0 1rem;
}
dt {
color: var(--muted);
}
dd {
margin: 0;
}
</style>
+6
View File
@@ -20,6 +20,12 @@ const router = createRouter({
component: () => import('@/views/LoginView.vue'), component: () => import('@/views/LoginView.vue'),
meta: { public: true }, meta: { public: true },
}, },
{
path: '/clips/:id(\\d+)',
name: 'clip-edit',
component: () => import('@/views/ClipEditView.vue'),
props: true,
},
{ path: '/account', name: 'account', component: () => import('@/views/AccountView.vue') }, { path: '/account', name: 'account', component: () => import('@/views/AccountView.vue') },
{ {
path: '/admin/users', path: '/admin/users',
+3
View File
@@ -3,6 +3,7 @@ import { onMounted, ref } from 'vue'
import { api } from '@/api/client' import { api } from '@/api/client'
import type { Role, User } from '@/api/types' import type { Role, User } from '@/api/types'
import SystemStatus from '@/components/SystemStatus.vue'
import { useAuthStore } from '@/stores/auth' import { useAuthStore } from '@/stores/auth'
import { formatDateTime } from '@/utils/format' import { formatDateTime } from '@/utils/format'
@@ -155,6 +156,8 @@ onMounted(load)
</li> </li>
</ul> </ul>
</section> </section>
<SystemStatus />
</main> </main>
</template> </template>
+237
View File
@@ -0,0 +1,237 @@
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import { onBeforeRouteLeave, useRouter } from 'vue-router'
import { ApiError } from '@/api/client'
import type { Clip, ClipKind } from '@/api/types'
import CopyButton from '@/components/CopyButton.vue'
import { ClipConflictError, useClipsStore } from '@/stores/clips'
import { formatDateTime } from '@/utils/format'
import { detectLanguage, highlight, LANGUAGES } from '@/utils/highlight'
const props = defineProps<{ id: string }>()
const store = useClipsStore()
const router = useRouter()
const clip = ref<Clip | null>(null)
const notFound = ref(false)
const error = ref<string | null>(null)
const busy = ref(false)
const conflict = ref<Clip | null>(null)
// Form state
const title = ref('')
const content = ref('')
const kind = ref<ClipKind>('text')
const language = ref('plaintext')
const baseVersion = ref(0)
function fillForm(source: Clip): void {
clip.value = source
title.value = source.title ?? ''
content.value = source.content
kind.value = source.kind
language.value = source.language ?? detectLanguage(source.content) ?? 'plaintext'
baseVersion.value = source.version
}
const dirty = computed(() => {
const c = clip.value
if (!c) return false
return (
title.value !== (c.title ?? '') ||
content.value !== c.content ||
kind.value !== c.kind ||
(kind.value === 'code' && language.value !== c.language)
)
})
const previewHtml = computed(() =>
kind.value === 'code' ? highlight(content.value, language.value) : null,
)
async function save(version = baseVersion.value): Promise<void> {
if (!clip.value) return
busy.value = true
error.value = null
try {
await store.update(
clip.value.id,
{
title: title.value.trim() || null,
content: content.value,
kind: kind.value,
language: kind.value === 'code' ? language.value : null,
},
version,
)
conflict.value = null
clip.value = null // nothing left to lose; skip the leave guard
await router.push('/')
} catch (e) {
if (e instanceof ClipConflictError) {
conflict.value = e.current
} else {
error.value = e instanceof Error ? e.message : String(e)
}
} finally {
busy.value = false
}
}
function takeTheirs(): void {
if (conflict.value) fillForm(conflict.value)
conflict.value = null
}
async function remove(): Promise<void> {
if (!clip.value || !confirm('Diesen Clip endgültig löschen?')) return
try {
await store.remove(clip.value.id)
clip.value = null
await router.push('/')
} catch (e) {
error.value = e instanceof Error ? e.message : String(e)
}
}
onBeforeRouteLeave(() => !dirty.value || confirm('Ungespeicherte Änderungen verwerfen?'))
onMounted(async () => {
try {
fillForm(await store.fetchOne(Number(props.id)))
} catch (e) {
if (e instanceof ApiError && e.status === 404) notFound.value = true
else error.value = e instanceof Error ? e.message : String(e)
}
})
</script>
<template>
<main class="page">
<h1>Clip bearbeiten</h1>
<p v-if="notFound" class="muted">
Diesen Clip gibt es nicht (mehr). <RouterLink to="/">Zur Übersicht</RouterLink>
</p>
<p v-if="error" class="error" role="alert">{{ error }}</p>
<section v-if="conflict" class="card conflict" role="alert">
<h2>Konflikt</h2>
<p>
Der Clip wurde am {{ formatDateTime(conflict.updated_at) }} auf einem anderen Gerät
geändert. Deine Änderungen sind noch nicht gespeichert.
</p>
<div class="actions">
<button type="button" @click="takeTheirs">Andere Version laden</button>
<button type="button" class="danger" :disabled="busy" @click="save(conflict.version)">
Meine Version speichern
</button>
</div>
</section>
<form v-if="clip" class="card form" @submit.prevent="save()">
<label>
Titel (optional)
<input v-model="title" maxlength="200" />
</label>
<div class="row">
<div class="segmented" role="radiogroup" aria-label="Art">
<button
type="button"
role="radio"
:aria-checked="kind === 'text'"
:class="{ active: kind === 'text' }"
@click="kind = 'text'"
>
Text
</button>
<button
type="button"
role="radio"
:aria-checked="kind === 'code'"
:class="{ active: kind === 'code' }"
@click="kind = 'code'"
>
Code
</button>
</div>
<select v-if="kind === 'code'" v-model="language" aria-label="Sprache" class="language">
<option v-for="l in LANGUAGES" :key="l.id" :value="l.id">{{ l.label }}</option>
</select>
</div>
<textarea
v-model="content"
:class="{ mono: kind === 'code' }"
rows="14"
autocapitalize="off"
spellcheck="false"
@keydown.enter.ctrl.prevent="save()"
@keydown.enter.meta.prevent="save()"
></textarea>
<template v-if="previewHtml !== null">
<span class="muted small">Vorschau</span>
<!-- eslint-disable-next-line vue/no-v-html -- highlight.js output is escaped -->
<pre class="preview"><code class="hljs" v-html="previewHtml"></code></pre>
</template>
<div class="actions">
<button type="submit" class="primary" :disabled="busy || !content.trim()">Speichern</button>
<CopyButton :text="content" />
<RouterLink to="/" class="button-link">Abbrechen</RouterLink>
<div class="spacer"></div>
<button type="button" class="danger" @click="remove">Löschen</button>
</div>
<p class="muted small">
Angelegt {{ formatDateTime(clip.created_at) }} · zuletzt geändert
{{ formatDateTime(clip.updated_at) }}
</p>
</form>
</main>
</template>
<style scoped>
.row,
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 0.5rem;
}
.spacer {
flex: 1;
}
.language {
width: auto;
min-width: 9rem;
}
.small {
font-size: 0.85rem;
}
.conflict {
border-color: var(--error);
}
.preview {
margin: 0;
padding: 0.75rem;
max-height: 24rem;
overflow: auto;
border-radius: calc(var(--radius) - 4px);
background: var(--bg);
font-size: 0.9rem;
}
.preview code.hljs {
padding: 0;
background: transparent;
}
</style>