Skip to content

Commit

Permalink
Implement pages admin UI logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bkis committed Nov 5, 2023
1 parent b6fc42f commit 715e663
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Tekst-API/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3413,6 +3413,11 @@
},
"ClientSegmentHead": {
"properties": {
"id": {
"type": "string",
"title": "Id",
"example": "5eb7cf5a86d9755df3a6c593"
},
"key": {
"type": "string",
"title": "Key"
Expand Down Expand Up @@ -3446,6 +3451,7 @@
},
"type": "object",
"required": [
"id",
"key"
],
"title": "ClientSegmentHead"
Expand Down
5 changes: 5 additions & 0 deletions Tekst-API/tekst/models/segment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Annotated, Literal

from beanie import PydanticObjectId
from pydantic import BaseModel, Field, StringConstraints, model_validator

from tekst.models.common import DocumentBase, Locale, ModelBase, ModelFactoryMixin
Expand Down Expand Up @@ -60,6 +61,10 @@ class Settings(DocumentBase.Settings):


class ClientSegmentHead(BaseModel):
id: PydanticObjectId
key: str
title: str | None = None
locale: Locale | None = None

class Settings:
projection = {"id": "$_id", "key": 1, "title": 1, "locale": 1}
20 changes: 12 additions & 8 deletions Tekst-Web/src/views/admin/AdminSystemPagesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import FileOpenOutlined from '@vicons/material/FileOpenOutlined';
import DeleteOutlined from '@vicons/material/DeleteOutlined';
import { negativeButtonProps, positiveButtonProps } from '@/components/dialogButtonProps';
const { pfData, loadPlatformData } = usePlatformData();
const { pfData, loadPlatformData, getSegment } = usePlatformData();
const { locale } = useI18n();
const { message } = useMessages();
const dialog = useDialog();
Expand Down Expand Up @@ -82,7 +82,7 @@ const segmentLocaleOptions = computed(() =>
}))
);
function getSegmentModel(segmentId?: string): ClientSegmentUpdate {
async function getSegmentModel(segmentId?: string): Promise<ClientSegmentUpdate> {
if (!segmentId) {
return {
key: undefined,
Expand All @@ -92,24 +92,28 @@ function getSegmentModel(segmentId?: string): ClientSegmentUpdate {
html: '',
};
} else {
const selectedSegment = pfData.value?.systemSegments.find((s) => s.id === segmentId);
const selectedSegmentInfo = pfData.value?.pagesInfo.find((s) => s.id === segmentId);
const selectedSegment = await getSegment(
selectedSegmentInfo?.key,
selectedSegmentInfo?.locale || undefined
);
if (!selectedSegment) {
return getSegmentModel();
return await getSegmentModel();
} else {
return Object.assign({}, selectedSegment);
}
}
}
function handleAddSegmentClick() {
async function handleAddSegmentClick() {
selectedSegmentId.value = null;
segmentModel.value = getSegmentModel();
segmentModel.value = await getSegmentModel();
resetModelChanges();
formRef.value?.restoreValidation();
}
function handleSelectSegment(id: string) {
segmentModel.value = getSegmentModel(id);
async function handleSelectSegment(id: string) {
segmentModel.value = await getSegmentModel(id);
resetModelChanges();
formRef.value?.restoreValidation();
}
Expand Down

0 comments on commit 715e663

Please sign in to comment.