Skip to content

Commit

Permalink
feat: add reference entity field for enterprise ebios
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed-Hacene committed Dec 20, 2024
1 parent e5bc1f3 commit 91ab717
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 4 deletions.
1 change: 1 addition & 0 deletions backend/ebios_rm/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class EbiosRMStudyReadSerializer(BaseModelSerializer):
str = serializers.CharField(source="__str__")
project = FieldsRelatedField(["id", "folder"])
folder = FieldsRelatedField()
reference_entity = FieldsRelatedField()
risk_matrix = FieldsRelatedField()
reference_entity = FieldsRelatedField()
assets = FieldsRelatedField(many=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<script lang="ts">
import type { SuperValidated } from 'sveltekit-superforms';
import type { ModelInfo, CacheLock } from '$lib/utils/types';
import TextField from '$lib/components/Forms/TextField.svelte';
import AutocompleteSelect from '$lib/components/Forms/AutocompleteSelect.svelte';
import * as m from '$paraglide/messages.js';
import { getOptions } from '$lib/utils/crud';
import TextArea from '../TextArea.svelte';
import { page } from '$app/stores';
export let form: SuperValidated<any>;
export let model: ModelInfo;
export let cacheLocks: Record<string, CacheLock> = {};
export let formDataCache: Record<string, any> = {};
export let initialData: Record<string, any> = {};
export let context: string;
let activeActivity: string | null = null;
$page.url.searchParams.forEach((value, key) => {
if (key === 'activity' && value === 'one') {
activeActivity = 'one';
} else if (key === 'activity' && value === 'two') {
activeActivity = 'two';
}
});
</script>

{#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"
label={m.version()}
cacheLock={cacheLocks['version']}
bind:cachedValue={formDataCache['version']}
/>
<TextField
{form}
field="ref_id"
label={m.refId()}
cacheLock={cacheLocks['ref_id']}
bind:cachedValue={formDataCache['ref_id']}
/>
<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['folder'] })}
field="folder"
cacheLock={cacheLocks['folder']}
bind:cachedValue={formDataCache['folder']}
label={m.domain()}
hidden={initialData.folder}
/>
<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['reference_entity'] })}
field="reference_entity"
cacheLock={cacheLocks['reference_entity']}
bind:cachedValue={formDataCache['reference_entity']}
label={m.referenceEntity()}
hidden={initialData.reference_entity}
/>
<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['risk_matrix'] })}
field="risk_matrix"
cacheLock={cacheLocks['risk_matrix']}
bind:cachedValue={formDataCache['risk_matrix']}
label={m.riskMatrix()}
placeholder={m.ebiosRmRiskMatrix()}
helpText={m.ebiosRmMatrixHelpText()}
/>
{:else if context === 'ebiosRmStudy'}
<div
class="relative p-2 space-y-2 rounded-md {activeActivity === 'one'
? 'border-2 border-primary-500'
: 'border-2 border-gray-300 border-dashed'}"
>
<p
class="absolute -top-3 bg-white font-bold {activeActivity === 'one'
? 'text-primary-500'
: 'text-gray-500'}"
>
{m.activityOne()}
</p>
<TextArea
{form}
field="description"
label={m.description()}
cacheLock={cacheLocks['description']}
bind:cachedValue={formDataCache['description']}
data-focusindex="1"
/>
<TextField
{form}
field="version"
label={m.version()}
cacheLock={cacheLocks['version']}
bind:cachedValue={formDataCache['version']}
/>
<TextField
{form}
field="ref_id"
label={m.refId()}
cacheLock={cacheLocks['ref_id']}
bind:cachedValue={formDataCache['ref_id']}
/>
<AutocompleteSelect
{form}
options={getOptions({ objects: model.foreignKeys['reference_entity'] })}
field="reference_entity"
cacheLock={cacheLocks['reference_entity']}
bind:cachedValue={formDataCache['reference_entity']}
label={m.referenceEntity()}
hidden={initialData.reference_entity}
/>
<AutocompleteSelect
multiple
{form}
options={getOptions({ objects: model.foreignKeys['authors'], label: 'email' })}
field="authors"
cacheLock={cacheLocks['authors']}
bind:cachedValue={formDataCache['authors']}
label={m.authors()}
/>
<AutocompleteSelect
multiple
{form}
options={getOptions({ objects: model.foreignKeys['reviewers'], label: 'email' })}
field="reviewers"
cacheLock={cacheLocks['reviewers']}
bind:cachedValue={formDataCache['reviewers']}
label={m.reviewers()}
/>
</div>
<div
class="relative p-2 space-y-2 rounded-md {activeActivity === 'two'
? 'border-2 border-primary-500'
: 'border-2 border-gray-300 border-dashed'}"
>
<p
class="absolute -top-3 bg-white font-bold {activeActivity === 'two'
? 'text-primary-500'
: 'text-gray-500'}"
>
{m.activityTwo()}
</p>
<AutocompleteSelect
multiple
{form}
options={getOptions({
objects: model.foreignKeys['assets'],
extra_fields: [['folder', 'str']],
label: 'auto'
})}
field="assets"
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}
4 changes: 3 additions & 1 deletion frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1018,5 +1018,7 @@
"riskAnalyses": "Risk analyses",
"client": "Client",
"partner": "Partner",
"supplier": "Supplier"
"supplier": "Supplier",
"referenceEntity": "Reference entity",
"referenceEntitySemiColon": "Reference entity:"
}
4 changes: 3 additions & 1 deletion frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1014,5 +1014,7 @@
"addStrategicScenario": "Ajouter un scénario stratégique",
"client": "Client",
"partner": "Partenaire",
"supplier": "Fournisseur"
"supplier": "Fournisseur",
"referenceEntity": "Entité de référence",
"referenceEntitySemiColon": "Entité de référence :"
}
3 changes: 2 additions & 1 deletion frontend/src/lib/utils/crud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ export const URL_MODEL_MAP: ModelMap = {
{ 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: 'compliance_assessments', urlModel: 'compliance-assessments' }
{ field: 'compliance_assessments', urlModel: 'compliance-assessments' },
{ field: 'reference_entity', urlModel: 'entities' }
],
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 @@ -402,7 +402,8 @@ export const ebiosRMSchema = z.object({
observation: z.string().optional().nullable(),
assets: z.string().uuid().optional().array().optional(),
folder: z.string(),
compliance_assessments: z.string().uuid().optional().array().optional()
compliance_assessments: z.string().uuid().optional().array().optional(),
reference_entity: z.string().optional()
});

export const fearedEventsSchema = z.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@
{m.edit()}
</a>
</div>
{#if ebiosRmStudy.reference_entity}
<div class="flex justify-center items-center w-full">
<span class="text-sm text-gray-500"
>{m.referenceEntitySemiColon()}
<a class="anchor" href="/entities/{ebiosRmStudy.reference_entity.id}"
>{ebiosRmStudy.reference_entity.str}</a
>
</span>
</div>
{/if}
<div
id="activityOne"
class="relative p-4 space-y-4 rounded-md w-full flex flex-col items-center
Expand Down

0 comments on commit 91ab717

Please sign in to comment.