From 17c48aa1a20707b187686cdc76804763ab24efe0 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Thu, 5 Dec 2024 17:04:06 +0100 Subject: [PATCH 1/6] Rename base route to baseline --- .../src/routes/(app)/(internal)/ebios-rm/[id=uuid]/+page.svelte | 2 +- .../[id=uuid]/workshop-one/{base => baseline}/+page.server.ts | 0 .../[id=uuid]/workshop-one/{base => baseline}/+page.svelte | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/{base => baseline}/+page.server.ts (100%) rename frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/{base => baseline}/+page.svelte (100%) 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 af9816e3d..21df4f60f 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 @@ -30,7 +30,7 @@ { title: safeTranslate(m.ebiosWs1_4()), status: 'to_do', - href: `${$page.url.pathname}/workshop-one/base?next=${$page.url.pathname}` + href: `${$page.url.pathname}/workshop-one/baseline?next=${$page.url.pathname}` } ], ws2: [ diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/base/+page.server.ts b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/baseline/+page.server.ts similarity index 100% rename from frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/base/+page.server.ts rename to frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/baseline/+page.server.ts diff --git a/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/base/+page.svelte b/frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/baseline/+page.svelte similarity index 100% rename from frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/base/+page.svelte rename to frontend/src/routes/(app)/(internal)/ebios-rm/[id=uuid]/workshop-one/baseline/+page.svelte From 6e269749f493295b3845fae9573f8045a9f1920c Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Thu, 5 Dec 2024 17:14:29 +0100 Subject: [PATCH 2/6] Add risk_matrix property and endpoint to feared events --- backend/ebios_rm/models.py | 4 ++++ backend/ebios_rm/views.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index f51d4fc8b..0d03410e2 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -137,6 +137,10 @@ def save(self, *args, **kwargs): self.folder = self.ebios_rm_study.folder super().save(*args, **kwargs) + @property + def risk_matrix(self): + return self.ebios_rm_study.risk_matrix + class RoTo(AbstractBaseModel, FolderMixin): class RiskOrigin(models.TextChoices): diff --git a/backend/ebios_rm/views.py b/backend/ebios_rm/views.py index 1ca61f709..20a4424cf 100644 --- a/backend/ebios_rm/views.py +++ b/backend/ebios_rm/views.py @@ -1,3 +1,4 @@ +from core.serializers import RiskMatrixReadSerializer from core.views import BaseModelViewSet as AbstractBaseModelViewSet from .models import ( EbiosRMStudy, @@ -39,6 +40,11 @@ class FearedEventViewSet(BaseModelViewSet): "ebios_rm_study", ] + @action(detail=True, name="Get risk matrix", url_path="risk-matrix") + def risk_matrix(self, request, pk=None): + feared_event = self.get_object() + return Response(RiskMatrixReadSerializer(feared_event.risk_matrix).data) + class RoToViewSet(BaseModelViewSet): model = RoTo From 052c06740d63577ff84e3418bce37949ec3ca70b Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Thu, 5 Dec 2024 17:21:01 +0100 Subject: [PATCH 3/6] Add gravity choices endpoint for feared events --- backend/ebios_rm/models.py | 4 ++++ backend/ebios_rm/views.py | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/backend/ebios_rm/models.py b/backend/ebios_rm/models.py index 0d03410e2..a2d050858 100644 --- a/backend/ebios_rm/models.py +++ b/backend/ebios_rm/models.py @@ -141,6 +141,10 @@ def save(self, *args, **kwargs): def risk_matrix(self): return self.ebios_rm_study.risk_matrix + @property + def parsed_matrix(self): + return self.risk_matrix.parse_json_translated() + class RoTo(AbstractBaseModel, FolderMixin): class RiskOrigin(models.TextChoices): diff --git a/backend/ebios_rm/views.py b/backend/ebios_rm/views.py index 20a4424cf..47cfac6b2 100644 --- a/backend/ebios_rm/views.py +++ b/backend/ebios_rm/views.py @@ -45,6 +45,20 @@ def risk_matrix(self, request, pk=None): feared_event = self.get_object() return Response(RiskMatrixReadSerializer(feared_event.risk_matrix).data) + @method_decorator(cache_page(60 * LONG_CACHE_TTL)) + @action(detail=True, name="Get gravity choices") + def gravity(self, request, pk): + feared_event: FearedEvent = self.get_object() + undefined = dict([(-1, "--")]) + _choices = dict( + zip( + list(range(0, 64)), + [x["name"] for x in feared_event.parsed_matrix["impact"]], + ) + ) + choices = undefined | _choices + return Response(choices) + class RoToViewSet(BaseModelViewSet): model = RoTo From 7f03d85446907b0f128cbaa68424c39373cc30da Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Thu, 5 Dec 2024 17:48:03 +0100 Subject: [PATCH 4/6] Internationalize gravity field --- frontend/messages/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/messages/en.json b/frontend/messages/en.json index ca6cab15a..77a6d510b 100644 --- a/frontend/messages/en.json +++ b/frontend/messages/en.json @@ -929,5 +929,6 @@ "impacts": "Impacts", "ebiosRmStudies": "Ebios RM studies", "bringTheEvidences": "Bring the evidences", - "bringTheEvidencesHelpText": "If disabled, the object will be duplicated without its evidences" + "bringTheEvidencesHelpText": "If disabled, the object will be duplicated without its evidences", + "gravity": "Gravity" } From 981bb3439fda21c6d217df7782ad8d164b2b7f45 Mon Sep 17 00:00:00 2001 From: Nassim Tabchiche Date: Thu, 5 Dec 2024 17:48:15 +0100 Subject: [PATCH 5/6] Add gravity field to feared event form --- .../lib/components/Forms/ModelForm/FearedEventForm.svelte | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/frontend/src/lib/components/Forms/ModelForm/FearedEventForm.svelte b/frontend/src/lib/components/Forms/ModelForm/FearedEventForm.svelte index d3548da56..9580233a3 100644 --- a/frontend/src/lib/components/Forms/ModelForm/FearedEventForm.svelte +++ b/frontend/src/lib/components/Forms/ModelForm/FearedEventForm.svelte @@ -32,6 +32,14 @@ cacheLock={cacheLocks['ref_id']} bind:cachedValue={formDataCache['ref_id']} /> +