Skip to content

Commit

Permalink
feat: re-organize ebios rm views
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Dec 11, 2024
1 parent f73904f commit 16f8d35
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 37 deletions.
5 changes: 3 additions & 2 deletions frontend/src/lib/components/Forms/ModelForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
export let suggestions: { [key: string]: any } = {};
export let cancelButton = true;
export let duplicate = false;
export let customNameDescription = false;
const URLModel = model.urlModel as urlModel;
export let schema = modelSchema(URLModel);
Expand Down Expand Up @@ -163,7 +164,7 @@
}}
/>
{/if}
{#if shape.name}
{#if shape.name && !customNameDescription}
<TextField
{form}
field="name"
Expand All @@ -173,7 +174,7 @@
data-focusindex="0"
/>
{/if}
{#if shape.description}
{#if shape.description && !customNameDescription}
<TextArea
{form}
field="description"
Expand Down
44 changes: 36 additions & 8 deletions frontend/src/lib/components/Forms/ModelForm/EbiosRmForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@
});
</script>

{#if context !== 'ebiosRmStudy'}
{#if context != 'selectAudit'}
<TextField
{form}
field="name"
label={m.name()}
cacheLock={cacheLocks['name']}
bind:cachedValue={formDataCache['name']}
data-focusindex="0"
/>
{/if}
{#if context !== 'ebiosRmStudy' && context !== 'selectAudit'}
<TextField
{form}
field="version"
Expand Down Expand Up @@ -72,6 +82,14 @@
>
{m.activityOne()}
</p>
<TextArea
{form}
field="description"
label={m.description()}
cacheLock={cacheLocks['description']}
bind:cachedValue={formDataCache['description']}
data-focusindex="1"
/>
<TextField
{form}
field="version"
Expand All @@ -86,13 +104,6 @@
cacheLock={cacheLocks['ref_id']}
bind:cachedValue={formDataCache['ref_id']}
/>
<TextArea
{form}
field="observation"
label={m.observation()}
cacheLock={cacheLocks['observation']}
bind:cachedValue={formDataCache['observation']}
/>
<AutocompleteSelect
multiple
{form}
Expand Down Expand Up @@ -136,4 +147,21 @@
label={m.assets()}
/>
</div>
<TextArea
{form}
field="observation"
label={m.observation()}
cacheLock={cacheLocks['observation']}
bind:cachedValue={formDataCache['observation']}
/>
{:else}
<AutocompleteSelect
multiple
{form}
options={getOptions({ objects: model.foreignKeys['compliance_assessments'] })}
field="compliance_assessments"
cacheLock={cacheLocks['compliance_assessments']}
bind:cachedValue={formDataCache['compliance_assessments']}
label={m.complianceAssessment()}
/>
{/if}
2 changes: 2 additions & 0 deletions frontend/src/lib/components/Modals/CreateModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const modalStore: ModalStore = getModalStore();
export let form: SuperValidated<AnyZodObject>;
export let customNameDescription = false;
export let model: ModelInfo;
export let duplicate = false;
export let invalidateAll = true; // set to false to keep form data using muliple forms on a page
Expand Down Expand Up @@ -47,6 +48,7 @@
</div>
<ModelForm
{form}
{customNameDescription}
{suggestions}
{parent}
{invalidateAll}
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/lib/components/Modals/UpdateModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
export let model: ModelInfo;
export let invalidateAll = true; // set to false to keep form data using muliple forms on a page
export let formAction = '?/update';
export let context = 'default';
export let object: Record<string, any> = {};
export let context = 'default';
export let object: Record<string, any> = {};
let closeModal = true;
export let suggestions: { [key: string]: any } = {};
export let selectOptions: Record<string, any> = {};
export let foreignKeys: Record<string, any> = {};
export let selectOptions: Record<string, any> = {};
export let foreignKeys: Record<string, any> = {};
// Base Classes
const cBase = 'card p-4 w-modal shadow-xl space-y-4';
Expand Down Expand Up @@ -48,18 +48,19 @@
</div>
</div>
<ModelForm
customNameDescription
{form}
{object}
{object}
{suggestions}
{parent}
action={formAction}
action={formAction}
{invalidateAll}
{model}
{closeModal}
{context}
caching={true}
selectOptions={selectOptions}
foreignKeys={foreignKeys}
{selectOptions}
{foreignKeys}
{debug}
/>
</div>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/lib/components/ModelTable/ModelTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@
<slot name="addButton" />
{/if}
</div>

</header>
<!-- Table -->
<table
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ export const URL_MODEL_MAP: ModelMap = {
{ field: 'assets', urlModel: 'assets' },
{ field: 'authors', urlModel: 'users', urlParams: 'is_third_party=false' },
{ field: 'reviewers', urlModel: 'users', urlParams: 'is_third_party=false' },
{ field: 'folder', urlModel: 'folders', urlParams: 'content_type=DO' }
{ field: 'folder', urlModel: 'folders', urlParams: 'content_type=DO' },
{ field: 'compliance_assessments', urlModel: 'compliance-assessments' }
],
reverseForeignKeyFields: [{ field: 'ebios_rm_studies', urlModel: 'assets' }]
},
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/lib/utils/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ export const ebiosRMSchema = z.object({
reviewers: z.array(z.string().optional()).optional(),
observation: z.string().optional().nullable(),
assets: z.string().uuid().optional().array().optional(),
folder: z.string()
folder: z.string(),
compliance_assessments: z.string().uuid().optional().array().optional()
});

export const fearedEventsSchema = z.object({
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/routes/(app)/(internal)/ebios-rm/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
ref: CreateModal,
props: {
form: data.createForm,
model: data.model
model: data.model,
customNameDescription: true
}
};
let modal: ModalSettings = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
const deleteForm = await superValidate(zod(schema));
const URLModel = 'compliance-assessments';
const createSchema = modelSchema(URLModel);
const updateSchema = modelSchema('ebios-rm')
const updateSchema = modelSchema('ebios-rm');
const initialData = {
ebios_rm_studies: [params.id]
};
Expand Down Expand Up @@ -64,13 +64,12 @@ export const load: PageServerLoad = async ({ params, fetch }) => {
const response = await fetch(url);
if (response.ok) {
updateForeignKeys[keyField.field] = await response.json().then((data) => data.results);
}
else {
} else {
console.error(`Failed to fetch data for ${keyField.field}: ${response.statusText}`);
}
}

updatedModel['foreignKeys'] = updateForeignKeys
updatedModel['foreignKeys'] = updateForeignKeys;

const selectOptions: Record<string, any> = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
model: data.updatedModel,
object: data.object,
foreignKeys: data.updatedModel.foreignKeys,
context: 'selectAudit'
}
};
let modal: ModalSettings = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,6 @@
{/if}
</ul>
</div>
<div class="w-full p-4 bg-gray-50 border rounded-md shadow-sm">
<h3 class="font-semibold text-lg text-gray-700 flex items-center space-x-2">
<i class="fa-solid fa-eye text-gray-500 opacity-75"></i>
<span>{m.observation()}</span>
</h3>
{#if ebiosRmStudy.observation}
<p class="text-gray-600">{ebiosRmStudy.observation}</p>
{:else}
<p class="text-gray-600">{m.noObservation()}</p>
{/if}
</div>
</div>
<div
id="activityTwo"
Expand Down Expand Up @@ -205,5 +194,16 @@
</div>
{/if}
</div>
<div class="w-full p-4 bg-gray-50 border rounded-md shadow-sm">
<h3 class="font-semibold text-lg text-gray-700 flex items-center space-x-2">
<i class="fa-solid fa-eye text-gray-500 opacity-75"></i>
<span>{m.observation()}</span>
</h3>
{#if ebiosRmStudy.observation}
<p class="text-gray-600">{ebiosRmStudy.observation}</p>
{:else}
<p class="text-gray-600">{m.noObservation()}</p>
{/if}
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<div class="card p-4 bg-white shadow-lg">
<ModelForm
customNameDescription
form={data.form}
object={data.object}
selectOptions={data.selectOptions}
Expand Down

0 comments on commit 16f8d35

Please sign in to comment.