Skip to content

Commit

Permalink
feat: create risk analysis from ebios detailed view
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Dec 6, 2024
1 parent 87c60c4 commit 90e320f
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
bind:cachedValue={formDataCache['risk_matrix']}
label={m.riskMatrix()}
helpText={m.riskAssessmentMatrixHelpText()}
hidden={initialData.risk_matrix}
/>
<AutocompleteSelect
{form}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { loadDetail } from '$lib/utils/load';
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 });
};
Original file line number Diff line number Diff line change
@@ -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
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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);
}
</script>

<div class="h-full w-full p-8">
Expand All @@ -85,7 +126,19 @@
<Tile title={m.ebiosWs2()} accent_color="bg-fuchsia-900" status="to_do" meta={dummydata.ws2} />
<Tile title={m.ebiosWs3()} accent_color="bg-teal-500" status="to_do" meta={dummydata.ws3} />
<Tile title={m.ebiosWs4()} accent_color="bg-yellow-600" status="to_do" meta={dummydata.ws4} />
<Tile title={m.ebiosWs5()} accent_color="bg-red-500" status="to_do" meta={dummydata.ws5} />
<Tile title={m.ebiosWs5()} accent_color="bg-red-500" status="to_do" meta={dummydata.ws5} createRiskAnalysis={true}>
<div slot="addRiskAnalysis">
<button class="flex flex-col text-left hover:text-purple-800" on:click={modalCreateForm}>
<span
class="absolute flex items-center justify-center w-8 h-8 bg-gray-100 rounded-full -start-4 ring-4 ring-white"
>
<i class="fa-solid fa-clipboard-check"></i>
</span>
<h3 class="font-medium leading-tight">{m.activity()} 1</h3>
<p class="text-sm">{safeTranslate(m.ebiosWs5_1())}</p>
</button>
</div>
</Tile>
<Tile title={m.summary()} accent_color="bg-purple-800" status="to_do" />
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
export let meta = null;
export let href = '#';
export let accent_color = '';
export let createRiskAnalysis = false;
</script>

<div class="p-5 {accent_color}">
Expand Down Expand Up @@ -42,15 +43,19 @@
</li>
{:else}
<li class="mb-10 ms-6">
<a href={step.href} class="hover:text-purple-800">
<span
class="absolute flex items-center justify-center w-8 h-8 bg-gray-100 rounded-full -start-4 ring-4 ring-white"
>
<i class="fa-solid fa-clipboard-check"></i>
</span>
<h3 class="font-medium leading-tight">{m.activity()} {i + 1}</h3>
<p class="text-sm">{step.title}</p>
</a>
{#if createRiskAnalysis && i == 0}
<slot name="addRiskAnalysis"></slot>
{:else}
<a href={step.href} class="hover:text-purple-800">
<span
class="absolute flex items-center justify-center w-8 h-8 bg-gray-100 rounded-full -start-4 ring-4 ring-white"
>
<i class="fa-solid fa-clipboard-check"></i>
</span>
<h3 class="font-medium leading-tight">{m.activity()} {i + 1}</h3>
<p class="text-sm">{step.title}</p>
</a>
{/if}
</li>
{/if}
{/each}
Expand Down

0 comments on commit 90e320f

Please sign in to comment.