Skip to content

Commit 9226b26

Browse files
committed
Add "Edit page" button on info pages for admins
Fixes #1601
1 parent edc930a commit 9226b26

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

Tekst-Web/i18n/ui/deDE.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ admin:
966966
newPage: Neue Seite
967967
phSelectPage: Seite auswählen
968968
noPage: Bitte wählen Sie eine Info-Seite aus oder erstellen Sie eine neue!
969+
editPage: Diese Seite bearbeiten
969970

970971
search:
971972
quickSearch:

Tekst-Web/i18n/ui/enUS.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ admin:
941941
newPage: New Page
942942
phSelectPage: Select page
943943
noPage: Please select an info page or create a new one!
944+
editPage: Edit this page
944945

945946
search:
946947
quickSearch:

Tekst-Web/src/views/InfoPageView.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import type { ClientSegmentRead } from '@/api';
33
import HydratedHtml from '@/components/generic/HydratedHtml.vue';
44
import IconHeading from '@/components/generic/IconHeading.vue';
55
import { usePlatformData } from '@/composables/platformData';
6-
import { useStateStore } from '@/stores';
7-
import { NSpin } from 'naive-ui';
6+
import { EditIcon } from '@/icons';
7+
import { useAuthStore, useStateStore } from '@/stores';
8+
import { NButton, NIcon, NSpin } from 'naive-ui';
89
import { ref, watchEffect, type Component } from 'vue';
910
import { useRouter } from 'vue-router';
1011
@@ -14,12 +15,17 @@ const props = defineProps<{
1415
}>();
1516
1617
const state = useStateStore();
18+
const auth = useAuthStore();
1719
const loading = ref(false);
1820
const { getSegment } = usePlatformData();
1921
const router = useRouter();
2022
2123
const page = ref<ClientSegmentRead>();
2224
25+
function handleEditClick() {
26+
router.push({ name: 'adminInfoPages', hash: page.value ? `#page=${page.value.id}` : undefined });
27+
}
28+
2329
watchEffect(async () => {
2430
loading.value = true;
2531
page.value = await getSegment(props.pageKey, state.locale);
@@ -35,6 +41,18 @@ watchEffect(async () => {
3541
<template v-else-if="page">
3642
<icon-heading v-if="page.title" level="1" :icon="icon">
3743
{{ page.title }}
44+
<n-button
45+
v-if="!!auth.user?.isSuperuser"
46+
circle
47+
quaternary
48+
size="small"
49+
:title="$t('admin.infoPages.editPage')"
50+
@click="handleEditClick"
51+
>
52+
<template #icon>
53+
<n-icon :component="EditIcon" />
54+
</template>
55+
</n-button>
3856
</icon-heading>
3957
<div class="content-block" style="padding: 1.2rem">
4058
<hydrated-html :html="page.html" />

Tekst-Web/src/views/admin/AdminSystemSegmentsView.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { infoSegmentFormRules, systemSegmentFormRules } from '@/forms/formRules'
1212
import { $t, getLocaleProfile, renderLanguageOptionLabel } from '@/i18n';
1313
import { AddIcon, FileOpenIcon, InfoIcon, SegmentsIcon } from '@/icons';
1414
import { useStateStore } from '@/stores';
15+
import { useUrlSearchParams } from '@vueuse/core';
1516
import { cloneDeep } from 'lodash-es';
1617
import {
1718
NButton,
@@ -27,16 +28,19 @@ import {
2728
type FormInst,
2829
type InputInst,
2930
} from 'naive-ui';
30-
import { computed, nextTick, ref, watch } from 'vue';
31+
import { computed, nextTick, onMounted, ref, watch } from 'vue';
3132
import { useRoute } from 'vue-router';
3233
33-
const props = defineProps<{ segmentType: 'info' | 'system' }>();
34+
const props = defineProps<{
35+
segmentType: 'info' | 'system';
36+
}>();
3437
3538
const state = useStateStore();
3639
const { loadPlatformData, getSegment } = usePlatformData();
3740
const { message } = useMessages();
3841
const dialog = useDialog();
3942
const route = useRoute();
43+
const hashParams = useUrlSearchParams('hash-params');
4044
4145
const loading = ref(false);
4246
const formRef = ref<FormInst | null>(null);
@@ -156,7 +160,14 @@ async function handleChangeSegment(id?: string) {
156160
segmentModel.value = await getSegmentModel(id);
157161
formRef.value?.restoreValidation();
158162
resetModelChanges();
159-
if (!id) nextTick(() => firstInputRef.value?.focus());
163+
if (!id) {
164+
nextTick(() => {
165+
delete hashParams.page;
166+
firstInputRef.value?.focus();
167+
});
168+
} else {
169+
hashParams.page = id;
170+
}
160171
}
161172
162173
async function handleSaveClick() {
@@ -206,6 +217,7 @@ async function createSegment() {
206217
})
207218
);
208219
selectedSegmentId.value = data.id;
220+
hashParams.page = data.id;
209221
segmentModel.value = data;
210222
resetModelChanges();
211223
loadPlatformData();
@@ -275,6 +287,14 @@ watch(
275287
clearForm();
276288
}
277289
);
290+
291+
onMounted(() => {
292+
nextTick(() => {
293+
if (hashParams.page) {
294+
handleChangeSegment(hashParams.page.toString());
295+
}
296+
});
297+
});
278298
</script>
279299

280300
<template>

0 commit comments

Comments
 (0)