diff --git a/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte b/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte index 1a5f2d850..edbfe6f8d 100644 --- a/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte +++ b/frontend/src/lib/components/Forms/ModelForm/RiskAssessmentForm.svelte @@ -65,6 +65,7 @@ bind:cachedValue={formDataCache['risk_matrix']} label={m.riskMatrix()} helpText={m.riskAssessmentMatrixHelpText()} + hidden={initialData.risk_matrix} /> { + return await loadDetail({ event, model: getModelInfo('ebios-rm'), id: event.params.id }); +}; diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.server.ts b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.server.ts index cb361f306..52f5ce694 100644 --- a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.server.ts +++ b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.server.ts @@ -1,7 +1,45 @@ -import { loadDetail } from '$lib/utils/load'; +import { defaultDeleteFormAction, defaultWriteFormAction } from '$lib/utils/actions'; +import { BASE_API_URL } from '$lib/utils/constants'; +import { + getModelInfo, + urlParamModelForeignKeyFields, + urlParamModelSelectFields +} from '$lib/utils/crud'; +import { modelSchema } from '$lib/utils/schemas'; +import type { ModelInfo } from '$lib/utils/types'; +import { type Actions } from '@sveltejs/kit'; +import { superValidate } from 'sveltekit-superforms'; +import { zod } from 'sveltekit-superforms/adapters'; import type { PageServerLoad } from './$types'; -import { getModelInfo } from '$lib/utils/crud'; -export const load: PageServerLoad = async (event) => { - return await loadDetail({ event, model: getModelInfo('ebios-rm'), id: event.params.id }); +export const load: PageServerLoad = async ({ params, fetch }) => { + const URLModel = 'ebios-rm'; + const model: ModelInfo = getModelInfo(URLModel); + + const endpoint = model.endpointUrl + ? `${BASE_API_URL}/${model.endpointUrl}/${params.id}/` + : `${BASE_API_URL}/${model.urlModel}/${params.id}/`; + const res = await fetch(endpoint); + const data = await res.json(); + + const initialData = { + risk_matrix: data.risk_matrix.id + } + + const createSchema = modelSchema('risk-assessments'); + const createRiskAnalysisForm = await superValidate(initialData, zod(createSchema), { errors: false }); + + return { createRiskAnalysisForm, model: getModelInfo('risk-assessments') }; }; + +export const actions: Actions = { + create: async (event) => { + // const redirectToWrittenObject = Boolean(event.params.model === 'entity-assessments'); + return defaultWriteFormAction({ + event, + urlModel: 'risk-assessments', + action: 'create' + // redirectToWrittenObject: redirectToWrittenObject + }); + }, +}; \ No newline at end of file diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.svelte b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.svelte index fdda99e68..b9b5514d1 100644 --- a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.svelte +++ b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.svelte @@ -5,11 +5,19 @@ import { page } from '$app/stores'; import type { PageData } from './$types'; import { breadcrumbObject } from '$lib/utils/stores'; + import type { ModalComponent, ModalSettings, ModalStore } from '@skeletonlabs/skeleton'; + import { getModalStore } from '@skeletonlabs/skeleton'; + import CreateModal from '$lib/components/Modals/CreateModal.svelte'; + import MissingConstraintsModal from '$lib/components/Modals/MissingConstraintsModal.svelte'; + import { checkConstraints } from '$lib/utils/crud'; + const modalStore: ModalStore = getModalStore(); export let data: PageData; $: breadcrumbObject.set(data.data); + const riskAnalysisCreated: boolean = data.data.risk_assessments.length > 0; + const dummydata = { ws1: [ { @@ -68,13 +76,46 @@ } ], ws5: [ - { title: safeTranslate(m.ebiosWs5_1()), status: 'done', href: '#' }, + { title: safeTranslate(m.ebiosWs5_1()), status: riskAnalysisCreated ? 'done' : 'to_do', href: '#' }, { title: safeTranslate(m.ebiosWs5_2()), status: 'done', href: '#' }, { title: safeTranslate(m.ebiosWs5_3()), status: 'to_do', href: '#' }, { title: safeTranslate(m.ebiosWs5_4()), status: 'to_do', href: '#' }, { title: safeTranslate(m.ebiosWs5_5()), status: 'done', href: '#' } ] }; + + function modalCreateForm(): void { + let modalComponent: ModalComponent = { + ref: CreateModal, + props: { + form: data.createRiskAnalysisForm, + model: data.model + } + }; + let modal: ModalSettings = { + type: 'component', + component: modalComponent, + // Data + title: safeTranslate('add-' + data.model.localName) + }; + if ( + checkConstraints( + data.createRiskAnalysisForm.constraints, data.model.foreignKeys) + .length > 0 + ) { + modalComponent = { + ref: MissingConstraintsModal + }; + modal = { + type: 'component', + component: modalComponent, + title: m.warning(), + body: safeTranslate('add-' + data.model.localName).toLowerCase(), + value: checkConstraints(data.createRiskAnalysisForm.constraints, data.model.foreignKeys) + }; + } + modalStore.trigger(modal); + }
@@ -85,7 +126,19 @@ - + +
+ +
+
diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/Tile.svelte b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/Tile.svelte index 00fe2faee..766d33520 100644 --- a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/Tile.svelte +++ b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/Tile.svelte @@ -7,6 +7,7 @@ export let meta = null; export let href = '#'; export let accent_color = ''; + export let createRiskAnalysis = false;
@@ -42,15 +43,19 @@ {:else}
  • - - - - -

    {m.activity()} {i + 1}

    -

    {step.title}

    -
    + {#if createRiskAnalysis && i == 0} + + {:else} + + + + +

    {m.activity()} {i + 1}

    +

    {step.title}

    +
    + {/if}
  • {/if} {/each}