From 724fd18021d362d29785d6149d9e49d0ae141c9e Mon Sep 17 00:00:00 2001 From: Dominic Kempf Date: Fri, 30 Aug 2024 17:29:25 +0200 Subject: [PATCH] Render objects in popovers unless their mask is whitelisted --- src/App.svelte | 21 ++++++++++- src/components/EasyDBDetailView.svelte | 22 +++-------- src/components/fields/Link.svelte | 37 +++++++++++++++++-- src/components/logic/DetailViewImpl.svelte | 25 +++++++++++++ .../logic/RecursiveEasyDBDetailView.svelte | 2 +- src/lib/apiaccess.js | 2 +- src/lib/stores.js | 20 ++++++++++ 7 files changed, 104 insertions(+), 25 deletions(-) create mode 100644 src/components/logic/DetailViewImpl.svelte diff --git a/src/App.svelte b/src/App.svelte index 6638f9e..e0541a0 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -1,6 +1,6 @@ @@ -27,14 +24,5 @@ Accessing the EasyDB instance... {:then} - {#await easydb_api_object($uuidStore.at(-1), mask) } - - Waiting for API response... - - {:then data } - - - - - {/await} + {/await} diff --git a/src/components/fields/Link.svelte b/src/components/fields/Link.svelte index 904cd73..017cd0a 100644 --- a/src/components/fields/Link.svelte +++ b/src/components/fields/Link.svelte @@ -1,7 +1,7 @@ {#if hasField(data, table, field)} @@ -21,15 +43,22 @@ {/if} {#if standardHasAsset(fdata)} - { pushUUID(fdata._uuid); }}> + {fdata["_standard"]["1"].text[$dataLanguagesStore[0]]} {:else} - { pushUUID(fdata._uuid); }}> + {fdata["_standard"]["1"].text[$dataLanguagesStore[0]]} {/if} {/if} +{#if detailViewComponent } + {#await detailViewComponent then { default : DetailViewImpl }} + + + + {/await} +{/if} \ No newline at end of file diff --git a/src/components/logic/DetailViewImpl.svelte b/src/components/logic/DetailViewImpl.svelte new file mode 100644 index 0000000..8ccfa25 --- /dev/null +++ b/src/components/logic/DetailViewImpl.svelte @@ -0,0 +1,25 @@ + + +{#await easydb_api_object(uuid ? uuid : $uuidStore.at(-1), mask) } + + Waiting for API response... + +{:then data } + + + + +{/await} diff --git a/src/components/logic/RecursiveEasyDBDetailView.svelte b/src/components/logic/RecursiveEasyDBDetailView.svelte index 8768db6..57950d4 100644 --- a/src/components/logic/RecursiveEasyDBDetailView.svelte +++ b/src/components/logic/RecursiveEasyDBDetailView.svelte @@ -177,7 +177,7 @@ {:else if firstField.kind === "link" } {#if firstField.output[output] } {#if (firstField.inline === "standard") || (firstField.inline === "short") } - + {:else if firstField.inline === "text" } {#await loadAdditionalUUID(firstField)} diff --git a/src/lib/apiaccess.js b/src/lib/apiaccess.js index f9e0bf0..6d96563 100644 --- a/src/lib/apiaccess.js +++ b/src/lib/apiaccess.js @@ -19,7 +19,7 @@ export async function easydb_api_object(uuid, mask) { if(response.status != 200) { throw new Error(`Could not fetch the data for uuid: ${uuid}`); } - const response_json = await response.json() + const response_json = await response.json(); return response_json; } diff --git a/src/lib/stores.js b/src/lib/stores.js index 0001161..6ca5763 100644 --- a/src/lib/stores.js +++ b/src/lib/stores.js @@ -96,3 +96,23 @@ export function popUUID() { uuidStore.update(uuids => uuids.slice(0, -1)); viewerPanelStateStore.set("asset"); } + +// A store for the user given choice of which masks to render +export const userGivenMasksToRenderStore = writable([]); + +// The list of masks that should be rendered in the component +export const masksToRenderStore = derived( + [userGivenMasksToRenderStore, easydbInstanceDataStore], + ([$userGivenMasksToRenderStore, $easydbInstanceDataStore]) => { + if ($easydbInstanceDataStore === undefined) { + return []; + } + if ($userGivenMasksToRenderStore.length === 0) { + if ($easydbInstanceDataStore.masks === null) { + return []; + } + return Object.keys($easydbInstanceDataStore.masks); + } + return $userGivenMasksToRenderStore; + } +);