Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,30 +260,44 @@ export function ValidationStoreSetSimpleTypeValid(path: string, isValid: boolean
export function createSimpleComponentValidationItem(path: string, label: string, required: boolean, simpleComponent: any): SimpleComponentData {
let simpleComponentValidationItem: SimpleComponentData = { label: label, path: path, required: required, isValid: false };

let item = simpleComponent.properties['#text'];

// set regex if defined
if (simpleComponent.properties['#text'].pattern && simpleComponent.properties['#text'].pattern != undefined && simpleComponent.properties['#text'].pattern != null && simpleComponent.properties['#text'].pattern != '') {
simpleComponentValidationItem.regex = simpleComponent.properties['#text'].pattern;
if (item.pattern && item.pattern != undefined && item.pattern != null && item.pattern != '') {
simpleComponentValidationItem.regex = item.pattern;
}
// set minLength if defined
if (simpleComponent.properties['#text'].minLength && simpleComponent.properties['#text'].minLength != undefined && simpleComponent.properties['#text'].minLength != null && simpleComponent.properties['#text'].minLength != '') {
simpleComponentValidationItem.minLength = simpleComponent.properties['#text'].minLength;
if (item.minLength && item.minLength != undefined && item.minLength != null && item.minLength != '') {
simpleComponentValidationItem.minLength = item.minLength;
}
// set maxLength if defined
if (simpleComponent.properties['#text'].maxLength && simpleComponent.properties['#text'].maxLength != undefined && simpleComponent.properties['#text'].maxLength != null && simpleComponent.properties['#text'].maxLength != '') {
simpleComponentValidationItem.maxLength = simpleComponent.properties['#text'].maxLength;
if (item.maxLength && item.maxLength != undefined && item.maxLength != null && item.maxLength != '') {
simpleComponentValidationItem.maxLength = item.maxLength;
}
// set domainList if defined
if (simpleComponent.properties['#text'].domainList && simpleComponent.properties['#text'].domainList != undefined && simpleComponent.properties['#text'].domainList != null && simpleComponent.properties['#text'].domainList.length > 0) {
simpleComponentValidationItem.domainList = simpleComponent.properties['#text'].domainList;
if (item.domainList && item.domainList != undefined && item.domainList != null && item.domainList.length > 0) {
simpleComponentValidationItem.domainList = item.domainList;
}
// set lowerBound if defined
if (simpleComponent.properties['#text'].lowerBound && simpleComponent.properties['#text'].lowerBound != undefined && simpleComponent.properties['#text'].lowerBound != null && simpleComponent.properties['#text'].lowerBound.length != '') {
simpleComponentValidationItem.lowerBound = simpleComponent.properties['#text'].lowerBound;
if (item.lowerBound && item.lowerBound != undefined && item.lowerBound != null && item.lowerBound.length != '') {
simpleComponentValidationItem.lowerBound = item.lowerBound;
}
// set upperBound if defined
if (simpleComponent.properties['#text'].upperBound && simpleComponent.properties['#text'].upperBound != undefined && simpleComponent.properties['#text'].upperBound != null && simpleComponent.properties['#text'].upperBound.length != '') {
simpleComponentValidationItem.upperBound = simpleComponent.properties['#text'].upperBound;
if (item.upperBound && item.upperBound != undefined && item.upperBound != null && item.upperBound.length != '') {
simpleComponentValidationItem.upperBound = item.upperBound;
}

// type secific validation criteria
// set minium if if defined
if ((item.minimum && item.minimum != undefined && item.minimum != null && item.minimum != '') || item.minimum == 0) {

simpleComponentValidationItem.minimum = item.minimum;
}

if (item.maximum && item.maximum != undefined && item.maximum != null && item.maximum != '') {
simpleComponentValidationItem.maximum = item.maximum;
}


return simpleComponentValidationItem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface SimpleComponentData {
domainList?: string[];
minLength?: number;
maxLength?: number;
minimum?: number;
maximum?: number;
isValid: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script lang="ts">
import { toggleShow } from '../../../../lib/components/utils/metadata/metadataComponentUtils';
import { convertDisplayName } from '../../metadataShared';

import { faPlus, faChevronUp, faChevronDown } from '@fortawesome/free-solid-svg-icons';
import Fa from 'svelte-fa';

import { hideStore } from '../../../../lib/components/utils/metadata/stores';

export let required: boolean = false;
export let path: string;
export let p:string = '';

let label: string = path.split('.').length > 1 ? path.split('.')[path.split('.').length - 1] : path;

const togglePath = p!=='' ? p : path;

</script>



<div class="card flex bg-primary-300 dark:bg-primary-800 pl-5 grid grid-cols-2">
<div class="text-left grow pt-1">

{#if required}
<h4 class="h4">{convertDisplayName(label, true)} *</h4>
{:else}
<h4 class="h4">{convertDisplayName(label, true)}</h4>
{/if}

</div>
<div class="text-left flex justify-end w-2 px-2">
{#if !$hideStore.includes(path)}
<button
class="btn h-9 w-10 text-right"
title="Open or close {convertDisplayName(label, true)}"
on:click={() => toggleShow(togglePath)}><Fa icon={faChevronUp} /></button
>
{:else}
<button
class="btn h-9 w-10 text-right"
title="Open or close {convertDisplayName(label, true)}"
on:click={() => toggleShow(togglePath)}><Fa icon={faChevronDown} /></button
>
{/if}
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import * as apiCalls from '../../services/apiCalls';
import { helpStore, Spinner } from '@bexis2/bexis2-core-ui';

import { Page } from '@bexis2/bexis2-core-ui';
// import { Page } from '@bexis2/bexis2-core-ui';
import { schemaToJson, setConfigStore, setMetadataStore } from '../../../../lib/components/utils/metadata/metadataComponentUtils';

// import configJson from './customComponents/config.json';

//export let schemaId: number = 3;
Expand All @@ -17,15 +18,10 @@
let schema: any = s;
$: schema = s;


let container

async function load() {
// read id from url
//datasetId = Number(new URLSearchParams(window.location.search).get('id'));
console.log('Loading metadata for datasetId:', datasetId);


if (datasetId > 0) {
const datasetInfos = await apiCalls.GetDatasetInfoById(datasetId);
s = await apiCalls.GetMetadataSchema(datasetInfos.metadataStructureId);
Expand All @@ -36,6 +32,7 @@
setMetadataStore(m);
const configJson = await apiCalls.GetComponentConfig(datasetInfos.entityTemplateId, "edit");
setConfigStore(configJson);

}
}
</script>
Expand All @@ -49,7 +46,7 @@
</div>

<button
class="btn variant-filled-primary m-2"
class="btn variant-filled-secondary m-2"
on:click={async () => {
try {
console.log('Saving metadata:', datasetId, m);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { slide, fade } from 'svelte/transition';
import { hideStore } from '../../../../lib/components/utils/metadata/stores';
import { convertDisplayName } from './../../metadataShared';
import Header from './MetadataComponentHeader.svelte';

export let arrayComponent: any;
export let path: string;
Expand Down Expand Up @@ -63,34 +64,17 @@
{#key render}
{#if arrayComponent.items.type === 'object' && arrayComponent.items.properties && !arrayComponent.items.properties['#text']}
<div class="grid grid-cols-1 gap-0">
<div class="card bg-primary-300 dark:bg-primary-800 pl-5 py-2 grid grid-cols-2">
<div class="text-left w-4/5">
<h3 class="h3">{convertDisplayName(label, true)}</h3>
</div>
<div class="text-right">
{#if !$hideStore.includes(path)}
<button
class="h-9 w-10 text-right"
title="Open or close {convertDisplayName(label, true)}"
on:click={() => toggleShow(path)}><Fa icon={faChevronUp} /></button
>
{:else}
<button
class="h-9 w-10 text-right"
title="Open or close {convertDisplayName(label, true)}"
on:click={() => toggleShow(path)}><Fa icon={faChevronDown} /></button
>
{/if}
</div>
</div>

<Header path={path} required={requiredList.includes(label)} />

{#if !$hideStore.includes(path)}
<div in:slide out:slide class="card pl-5 py-4" id={path}>
<div in:slide out:slide class="card pl-5 py-2" id={path}>
{#if value && value.length > 0}
{#each value as item, index}
<div in:slide out:slide class="pl-5 py-5 card mb-2">
<div class="grid grid-cols-2 gap-2">
<div>
<h3 class="h3 text-primary-500">{convertDisplayName(label, true)} {index+1}</h3>
<h4 class="h4 text-primary-500">{convertDisplayName(label, true)} {index+1}</h4>
</div>
<div class="text-right w-full pr-2">
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import { faChevronUp, faChevronDown } from '@fortawesome/free-solid-svg-icons';
import Fa from 'svelte-fa';
import { slide } from 'svelte/transition';
import Header from './MetadataComponentHeader.svelte';

export let choiceComponent: any;
export let path: string;
Expand Down Expand Up @@ -49,26 +50,8 @@
</script>

<div class="grid grid-cols-1 gap-0 m-2">
<div class="card bg-primary-300 dark:bg-primary-800 px-5 py-2 grid grid-cols-2">
<div class="text-left w-4/5">
<h3 class="h3">{label}</h3>
</div>
<div class="text-right">
{#if !$hideStore.includes(path)}
<button
class="h-9 w-10 text-right"
title="Open or close {label}"
on:click={() => toggleShow(path)}><Fa icon={faChevronUp} /></button
>
{:else}
<button
class="h-9 w-10 text-right"
title="Open or close {label}"
on:click={() => toggleShow(path)}><Fa icon={faChevronDown} /></button
>
{/if}
</div>
</div>
<Header {path} />

{#if !$hideStore.includes(path)}
<div in:slide out:slide class="card px-5 py-4" id={path}>
{#if choiceComponent.anyOf}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,70 +1,41 @@
<script lang="ts">
import { onMount } from 'svelte';
import {
TextInput,
NumberInput,
TextArea,
DropdownKVP,
helpStore,
CodeEditor
} from '@bexis2/bexis2-core-ui';
import ComplexComponent from './complexComponentWrapper.svelte';
import SimpleComponent from './simpleComponentWrapper.svelte';
import ArrayComponent from './arrayComponentWrapper.svelte';
import ChoiceComponent from './choiceComponentWrapper.svelte';
import { faPlus, faChevronUp, faChevronDown } from '@fortawesome/free-solid-svg-icons';
import Fa from 'svelte-fa';

import { slide, fade } from 'svelte/transition';
import { hideStore } from '../../../../lib/components/utils/metadata/stores';
import { toggleShow } from '../../../../lib/components/utils/metadata/metadataComponentUtils';
import { convertDisplayName } from './../../metadataShared';
import Header from './MetadataComponentHeader.svelte';


export let complexComponent: any;
export let path: string;
export let required: boolean = false;

let label: string =
path.split('.').length > 1 ? path.split('.')[path.split('.').length - 1] : path;

let requiredList =
complexComponent && complexComponent.type === 'object' && complexComponent.required
? complexComponent.required
: [];

</script>

{#if complexComponent && complexComponent.type === 'object' && complexComponent.properties}
{#each Object.entries(complexComponent.properties) as [key, value]}
{@const p = path = path ? path + '.' + key : key}
{@const l = label = key}

{#if value.type === 'object' && value.properties && !value.properties['#text']}
{#if value.oneOf || value.anyOf || value.allOf}
<ChoiceComponent choiceComponent={value} {path} />
{:else}
<div class="grid grid-cols-1 gap-0 ">
<div class="card flex bg-primary-300 dark:bg-primary-800 pl-5 py-2 grid grid-cols-2">
<div class="text-left grow">
{#if required}
<h4 class="h4">{convertDisplayName(label, true)} *</h4>
{:else}
<h4 class="h4">{convertDisplayName(label, true)}</h4>
{/if}

</div>
<div class="text-left flex justify-end w-2 px-5">
{#if !$hideStore.includes(path)}
<button
class="h-9 w-10 text-right"
title="Open or close {convertDisplayName(label, true)}"
on:click={() => toggleShow(p)}><Fa icon={faChevronUp} /></button
>
{:else}
<button
class="h-9 w-10 text-right"
title="Open or close {convertDisplayName(label, true)}"
on:click={() => toggleShow(p)}><Fa icon={faChevronDown} /></button
>
{/if}
</div>
</div>

<Header {required} {path} {p} />

{#if !$hideStore.includes(path)}
<div in:slide out:slide class="card pl-5 py-4" id={path}>
<ComplexComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
}
// create validation item and add to store
let simpleComponentValidationItem: SimpleComponentData = createSimpleComponentValidationItem(path, label, required, simpleComponent);

// add to validation store
ValidationStoreAddSimpleComponent(simpleComponentValidationItem);
config = getConfigStore();
Expand Down Expand Up @@ -93,7 +94,7 @@
<!-- Simple Component Rendering -->
{#if isVisible && !isAnchor}
{#if path && simpleComponent.properties}
<div class="pl-5 pr-2" id={path + '.item'}>
<div class="pr-2" id={path + '.item'}>
<!-- Handle different formats and types -->
{#if simpleComponent.properties['#text'].format !== undefined && simpleComponent.properties['#text'].format !== null}
<!-- Handle date format -->
Expand Down Expand Up @@ -228,6 +229,7 @@
invalid={res.hasErrors(path)}
feedback={res.getErrors(path)}
description={simpleComponent.description}
size="sm"
>{label}</SlideToggle>
{/if}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const suite = create((data: any, fieldName: string) => {

});
}

// Validate maximum length if defined
if(item.maxLength != null && item.maxLength != undefined){
console.log('Validating maxLength for field:', item.path);
Expand All @@ -36,6 +37,22 @@ const suite = create((data: any, fieldName: string) => {

});
}

// Validate minimum if defined
if(item.minimum != null && item.minimum != undefined){
console.log('Validating minimum for field:', item.path);
test( item.path, `${item.label} must have a minimum length of ${item.minimum}`, () => {
enforce(data).greaterThanOrEquals(item.minimum);
});
}

// Validate maximum if defined
if(item.maximum != null && item.maximum != undefined){
console.log('Validating maximum for field:', item.path);
test( item.path, `${item.label} must have a maximum length of ${item.maximum}`, () => {
enforce(data).lessThanOrEquals(item.maximum);
});
}
// Validate regex pattern if defined
if(item.regex != '' && item.regex != null && item.regex != undefined){
console.log('Validating regex pattern for field:', item.path);
Expand Down
Loading