zwischenstand
This commit is contained in:
13
frontend/src/lib/functions/eventBus.ts
Normal file
13
frontend/src/lib/functions/eventBus.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
const eventCallbacks: { [key: string]: any } = {}
|
||||
|
||||
export const registerEventCallback = (event: string | number, id: string | number, callback: any) => {
|
||||
if (!eventCallbacks[event]) eventCallbacks[event] = {}
|
||||
eventCallbacks[event][id] = callback
|
||||
}
|
||||
|
||||
export const unregisterEventCallback = (event: string | number, id: string | number) => {
|
||||
delete eventCallbacks[event][id]
|
||||
}
|
||||
export const getEventCallbacks = (event: string) => {
|
||||
return eventCallbacks[event]
|
||||
}
|
||||
16
frontend/src/lib/functions/fetch/loadContentAndSetStores.ts
Normal file
16
frontend/src/lib/functions/fetch/loadContentAndSetStores.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { api } from "../../../api"
|
||||
import { pages, content, rerender } from "../../store"
|
||||
export async function loadContentAndSetStores(): Promise<null> {
|
||||
const contentRes = await api<Content[]>("content", {})
|
||||
const contentStore: { [id: string]: Content } = {}
|
||||
const pagesStore: { [path: string]: Content } = {}
|
||||
contentRes.data.forEach((e: Content) => {
|
||||
contentStore[e.id] = e
|
||||
if (e.type === "page") {
|
||||
pagesStore[e.path] = e
|
||||
}
|
||||
})
|
||||
content.set(contentStore)
|
||||
pages.set(pagesStore)
|
||||
return null
|
||||
}
|
||||
12
frontend/src/lib/functions/fetch/loadLibraryAndSetStores.ts
Normal file
12
frontend/src/lib/functions/fetch/loadLibraryAndSetStores.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { api } from "../../../api"
|
||||
import { mediaLibrary } from "../../store"
|
||||
|
||||
export async function loadLibraryAndSetStore(): Promise<null> {
|
||||
const libraryRes = await api<MediaLibrary[]>("medialib", {})
|
||||
const libStore: { [id: string]: MediaLibrary } = {}
|
||||
libraryRes.data.forEach((el: MediaLibrary) => {
|
||||
libStore[el.id] = el
|
||||
})
|
||||
mediaLibrary.set(libStore)
|
||||
return null
|
||||
}
|
||||
11
frontend/src/lib/functions/fetch/loadModules.ts
Normal file
11
frontend/src/lib/functions/fetch/loadModules.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { api } from "../../../api"
|
||||
import { modules } from "../../store"
|
||||
export async function loadModulesAndSetStore(): Promise<{ [id: string]: Module }> {
|
||||
const module = await api<Module[]>("module", {})
|
||||
const moduleStore: { [id: string]: Module } = {}
|
||||
module.data.forEach((e: Module) => {
|
||||
moduleStore[e.id] = e
|
||||
})
|
||||
modules.set(moduleStore)
|
||||
return moduleStore
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { api } from "../../../api"
|
||||
import { navigation, serviceNavigation } from "../../store"
|
||||
export async function loadNavigationAndSetStores(): Promise<null> {
|
||||
const navigations = await api<Navigation[]>("navigation", {})
|
||||
let navigationStore: NavElement[] = []
|
||||
let serviceNavigationStore: NavElement[] = []
|
||||
navigations.data.forEach((nav: Navigation) => {
|
||||
if (nav.tree == 0) navigationStore = nav.elements
|
||||
else if (nav.tree == 1) serviceNavigationStore = nav.elements
|
||||
})
|
||||
navigation.set(navigationStore)
|
||||
serviceNavigation.set(serviceNavigationStore)
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -20,7 +20,10 @@ export function validateFields(fieldsArray: ValueEntry[]): (string | (() => void
|
||||
}
|
||||
|
||||
fieldsArray.forEach(([field, value]) => {
|
||||
|
||||
|
||||
if (field === "blockGroups" || (typeof field === "string" && field.includes("numberLabel"))) {
|
||||
// number label benötigt gesonderte Validierung
|
||||
if (!field.includes("numberLabel")) return
|
||||
// @ts-ignore
|
||||
let [elementValue, element, group, boolean] = value
|
||||
|
||||
14
frontend/src/lib/functions/utils.ts
Normal file
14
frontend/src/lib/functions/utils.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { getEventCallbacks } from "./eventBus"
|
||||
import { navigate } from "../../../../vendor/svelte-routing"
|
||||
|
||||
export function navigateWrapper(path: string, props: any = null) {
|
||||
if (getEventCallbacks("navigate")) {
|
||||
let callbacks = Object.values(getEventCallbacks("navigate"))
|
||||
for (let i = 0; i < callbacks?.length; i++) {
|
||||
// do not navigate if false is returned
|
||||
if ((callbacks[i] as Function)(path, props) === false) return
|
||||
}
|
||||
}
|
||||
if (props) navigate(path, props)
|
||||
else navigate(path)
|
||||
}
|
||||
Reference in New Issue
Block a user