From de5aff38cec35af13d2a9f9850c234d9aebe56a7 Mon Sep 17 00:00:00 2001 From: Mohamed-Hacene Date: Thu, 4 Apr 2024 14:57:19 +0200 Subject: [PATCH 1/8] feat: add warning if mandatory objects are missing --- .../Modals/MissingConstraintsModal.svelte | 33 +++++++++++++++++++ frontend/src/lib/utils/crud.ts | 10 ++++++ .../(app)/[model=urlmodel]/+page.svelte | 18 ++++++++-- 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 frontend/src/lib/components/Modals/MissingConstraintsModal.svelte diff --git a/frontend/src/lib/components/Modals/MissingConstraintsModal.svelte b/frontend/src/lib/components/Modals/MissingConstraintsModal.svelte new file mode 100644 index 000000000..969a97f39 --- /dev/null +++ b/frontend/src/lib/components/Modals/MissingConstraintsModal.svelte @@ -0,0 +1,33 @@ + + +{#if $modalStore[0]} + {@const value = $modalStore[0].value} + +{/if} diff --git a/frontend/src/lib/utils/crud.ts b/frontend/src/lib/utils/crud.ts index d9560e716..c8ec94b36 100644 --- a/frontend/src/lib/utils/crud.ts +++ b/frontend/src/lib/utils/crud.ts @@ -13,6 +13,16 @@ type GetOptionsParams = { extra_fields: (string[] | string)[]; }; +export function checkConstraints(constraints: { [key: string]: any }, foreignKeys: any) { + const emptyConstraintsList = []; + for (const [key, constraint] of Object.entries(constraints)) { + if (constraint.required && foreignKeys[key]) + if (foreignKeys[key].length === 0) + emptyConstraintsList.push(key); + } + return emptyConstraintsList; +} + function getValue(object: {[key: string]: any},keys: string[]) { if (typeof keys === "string") { return object[keys]; diff --git a/frontend/src/routes/(app)/[model=urlmodel]/+page.svelte b/frontend/src/routes/(app)/[model=urlmodel]/+page.svelte index 21d2e4c71..a763f045d 100644 --- a/frontend/src/routes/(app)/[model=urlmodel]/+page.svelte +++ b/frontend/src/routes/(app)/[model=urlmodel]/+page.svelte @@ -1,5 +1,6 @@