PR CI / flow (pull_request) Successful in 3s
PR CI / ledger (pull_request) Successful in 3s
PR CI / ui (pull_request) Successful in 17s
PR CI / test (lowest) (pull_request) Successful in 47s
PR CI / test (stable) (pull_request) Successful in 51s
PR CI / security (pull_request) Successful in 53s
PR CI / pr-ci (pull_request) Successful in 1s
PR CI / release-automerge (pull_request) Successful in 3s
67 lines
3.0 KiB
Vue
67 lines
3.0 KiB
Vue
<script setup lang="ts">
|
|
import { onMounted, ref } from 'vue';
|
|
import { api, boot } from '../api';
|
|
import { t } from '../i18n';
|
|
import { flash, reload } from '../state';
|
|
|
|
// The history of a post, a page or another record: what was saved when and by whom, and a way back.
|
|
const props = defineProps<{ type: string; id: number }>();
|
|
|
|
interface Revision { id: number; created_at: string; user: string | null; changed: string[]; current: boolean; values: Record<string, string> }
|
|
|
|
const revisions = ref<Revision[]>([]);
|
|
const canRestore = ref(false);
|
|
const open = ref<number | null>(null);
|
|
const loading = ref(true);
|
|
const base = `${boot.base}/revisions/${props.type}/${props.id}`;
|
|
|
|
onMounted(async () => {
|
|
try {
|
|
const data = await api.get(base);
|
|
revisions.value = data.revisions;
|
|
canRestore.value = data.can_restore;
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
});
|
|
|
|
async function restore(revision: Revision): Promise<void> {
|
|
if (!window.confirm(t('Put this version back? The text now is kept in the history.'))) {
|
|
return;
|
|
}
|
|
|
|
await api.post(`${base}/${revision.id}/restore`);
|
|
flash(t('The earlier version is back.'));
|
|
await reload();
|
|
}
|
|
|
|
const when = (value: string) => new Date(value).toLocaleString(boot.locale || undefined);
|
|
</script>
|
|
|
|
<template>
|
|
<section class="m-card mt-6 max-w-3xl p-5">
|
|
<h2 class="font-display text-lg font-bold">{{ t('History') }}</h2>
|
|
<p v-if="loading" class="mt-2 text-sm text-muted">{{ t('Loading…') }}</p>
|
|
<p v-else-if="!revisions.length" class="mt-2 text-sm text-muted">{{ t('Nothing here yet.') }}</p>
|
|
<ul v-else class="mt-3 divide-y divide-line">
|
|
<li v-for="revision in revisions" :key="revision.id" class="py-3">
|
|
<div class="flex flex-wrap items-center justify-between gap-2">
|
|
<button type="button" class="text-left text-sm" :aria-expanded="open === revision.id" @click="open = open === revision.id ? null : revision.id">
|
|
<span class="font-semibold">{{ when(revision.created_at) }}</span>
|
|
<span v-if="revision.user" class="text-muted"> · {{ revision.user }}</span>
|
|
<span v-if="revision.current" class="m-badge ml-2">{{ t('Now') }}</span>
|
|
<span class="block text-xs text-muted">{{ revision.changed.join(', ') }}</span>
|
|
</button>
|
|
<button v-if="canRestore && !revision.current" type="button" class="m-btn m-btn-secondary" @click="restore(revision)">{{ t('Put back') }}</button>
|
|
</div>
|
|
<dl v-if="open === revision.id" class="mt-2 space-y-2 text-sm">
|
|
<div v-for="(value, key) in revision.values" :key="key">
|
|
<dt class="text-xs font-semibold uppercase tracking-wide text-muted">{{ key }}</dt>
|
|
<dd class="whitespace-pre-wrap break-words">{{ value }}</dd>
|
|
</div>
|
|
</dl>
|
|
</li>
|
|
</ul>
|
|
</section>
|
|
</template>
|