diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index ad800af06..ac1daf84b 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -986,5 +986,6 @@
"addFearedEvent": "Add feared event",
"addEbiosRMstudy": "Add Ebios RM Study",
"noAuthor": "No author assigned",
- "noReviewer": "No reviewer assigned"
+ "noReviewer": "No reviewer assigned",
+ "selectAudit": "Select audit"
}
diff --git a/frontend/src/lib/components/Modals/UpdateModal.svelte b/frontend/src/lib/components/Modals/UpdateModal.svelte
new file mode 100644
index 000000000..5ce8a4626
--- /dev/null
+++ b/frontend/src/lib/components/Modals/UpdateModal.svelte
@@ -0,0 +1,66 @@
+
+
+{#if $modalStore[0]}
+
+{/if}
diff --git a/frontend/src/lib/components/ModelTable/ModelTable.svelte b/frontend/src/lib/components/ModelTable/ModelTable.svelte
index bf9ecab79..ff2e98a0f 100644
--- a/frontend/src/lib/components/ModelTable/ModelTable.svelte
+++ b/frontend/src/lib/components/ModelTable/ModelTable.svelte
@@ -259,9 +259,13 @@
{#if pagination && rowsPerPage}
{/if}
- {#if canCreateObject}
-
- {/if}
+
+
+ {#if canCreateObject}
+
+ {/if}
+
+
{
const deleteForm = await superValidate(zod(schema));
const URLModel = 'compliance-assessments';
const createSchema = modelSchema(URLModel);
+ const updateSchema = modelSchema('ebios-rm')
const initialData = {
ebios_rm_studies: [params.id]
};
+ const updatedModel: ModelInfo = getModelInfo('ebios-rm');
const createForm = await superValidate(initialData, zod(createSchema), { errors: false });
+ const objectEndpoint = `${BASE_API_URL}/${updatedModel.endpointUrl}/${params.id}/object/`;
+ const objectResponse = await fetch(objectEndpoint);
+ const object = await objectResponse.json();
+ const updateForm = await superValidate(object, zod(updateSchema), { errors: false });
const model: ModelInfo = getModelInfo(URLModel);
const foreignKeyFields = urlParamModelForeignKeyFields(URLModel);
+ const updateForeignKeyFields = urlParamModelForeignKeyFields('ebios-rm');
const selectFields = model.selectFields;
const foreignKeys: Record = {};
@@ -46,6 +53,25 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
model['foreignKeys'] = foreignKeys;
+ const updateForeignKeys: Record = {};
+
+ for (const keyField of updateForeignKeyFields) {
+ const model = getModelInfo(keyField.urlModel);
+ const queryParams = keyField.urlParams ? `?${keyField.urlParams}` : '';
+ const url = model.endpointUrl
+ ? `${BASE_API_URL}/${model.endpointUrl}/${queryParams}`
+ : `${BASE_API_URL}/${model.urlModel}/${queryParams}`;
+ const response = await fetch(url);
+ if (response.ok) {
+ updateForeignKeys[keyField.field] = await response.json().then((data) => data.results);
+ }
+ else {
+ console.error(`Failed to fetch data for ${keyField.field}: ${response.statusText}`);
+ }
+ }
+
+ updatedModel['foreignKeys'] = updateForeignKeys
+
const selectOptions: Record = {};
if (selectFields) {
@@ -91,7 +117,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
meta: data // metaData
};
- return { createForm, deleteForm, model, URLModel, table };
+ return { createForm, deleteForm, model, URLModel, table, updateForm, updatedModel, object };
};
export const actions: Actions = {
@@ -106,5 +132,8 @@ export const actions: Actions = {
},
delete: async (event) => {
return defaultDeleteFormAction({ event, urlModel: 'compliance-assessments' });
+ },
+ update: async (event) => {
+ return defaultWriteFormAction({ event, urlModel: 'ebios-rm', action: 'edit' });
}
};
diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/baseline/+page.svelte b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/baseline/+page.svelte
index 08ebedae8..65ceaf1c7 100644
--- a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/baseline/+page.svelte
+++ b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/baseline/+page.svelte
@@ -8,6 +8,7 @@
import MissingConstraintsModal from '$lib/components/Modals/MissingConstraintsModal.svelte';
import { checkConstraints } from '$lib/utils/crud';
import * as m from '$paraglide/messages.js';
+ import UpdateModal from '$lib/components/Modals/UpdateModal.svelte';
const modalStore: ModalStore = getModalStore();
@@ -50,9 +51,58 @@
}
modalStore.trigger(modal);
}
+
+ function modalUpdateForm(): void {
+ let modalComponent: ModalComponent = {
+ ref: UpdateModal,
+ props: {
+ form: data.updateForm,
+ model: data.updatedModel,
+ object: data.object,
+ foreignKeys: data.updatedModel.foreignKeys,
+ }
+ };
+ let modal: ModalSettings = {
+ type: 'component',
+ component: modalComponent,
+ // Data
+ title: m.selectAudit()
+ };
+ if (
+ checkConstraints(
+ data.updateForm.constraints,
+ Object.fromEntries(
+ Object.entries(data.updatedModel.foreignKeys).filter(([key]) => key !== 'risk_matrix')
+ )
+ ).length > 0
+ ) {
+ modalComponent = {
+ ref: MissingConstraintsModal
+ };
+ modal = {
+ type: 'component',
+ component: modalComponent,
+ title: m.warning(),
+ body: safeTranslate('add-' + data.updatedModel.localName).toLowerCase(),
+ value: checkConstraints(data.updateForm.constraints, data.updatedModel.foreignKeys)
+ };
+ }
+ modalStore.trigger(modal);
+ }
+
+
+
+
+