From 0ca14eb9283fd3b88ff2fc9e1f682fe394d0d2f1 Mon Sep 17 00:00:00 2001 From: Loup Federico <16464925+Sh099078@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:06:15 +0100 Subject: [PATCH] editoast, front: udpate stdcm_search_environment with the LTVs Co-Authored-By: Younes Khoudli --- editoast/editoast_models/src/tables.rs | 2 ++ .../down.sql | 2 ++ .../up.sql | 2 ++ editoast/openapi.yaml | 7 +++++++ editoast/src/models/fixtures.rs | 11 +++++++++++ editoast/src/models/stdcm_search_environment.rs | 16 ++++++++++++---- editoast/src/views/stdcm_search_environment.rs | 10 ++++++++-- .../src/applications/stdcm/hooks/useStdcmEnv.tsx | 1 + .../applications/stdcm/utils/formatStdcmConf.ts | 4 ++++ front/src/common/api/generatedEditoastApi.ts | 2 ++ front/src/reducers/osrdconf/stdcmConf/index.ts | 4 ++++ front/src/reducers/osrdconf/types.ts | 1 + 12 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 editoast/migrations/2024-11-06-175550_add_temporary_speed_limit_group_to_stdcm_search_environment/down.sql create mode 100644 editoast/migrations/2024-11-06-175550_add_temporary_speed_limit_group_to_stdcm_search_environment/up.sql diff --git a/editoast/editoast_models/src/tables.rs b/editoast/editoast_models/src/tables.rs index 22df341aa3f..87e7ff1fc30 100644 --- a/editoast/editoast_models/src/tables.rs +++ b/editoast/editoast_models/src/tables.rs @@ -608,6 +608,7 @@ diesel::table! { timetable_id -> Int8, search_window_begin -> Timestamptz, search_window_end -> Timestamptz, + temporary_speed_limit_group_id -> Nullable, } } @@ -798,6 +799,7 @@ diesel::joinable!(search_signal -> infra_object_signal (id)); diesel::joinable!(search_study -> study (id)); diesel::joinable!(stdcm_search_environment -> electrical_profile_set (electrical_profile_set_id)); diesel::joinable!(stdcm_search_environment -> infra (infra_id)); +diesel::joinable!(stdcm_search_environment -> temporary_speed_limit_group (temporary_speed_limit_group_id)); diesel::joinable!(stdcm_search_environment -> timetable (timetable_id)); diesel::joinable!(stdcm_search_environment -> work_schedule_group (work_schedule_group_id)); diesel::joinable!(study -> project (project_id)); diff --git a/editoast/migrations/2024-11-06-175550_add_temporary_speed_limit_group_to_stdcm_search_environment/down.sql b/editoast/migrations/2024-11-06-175550_add_temporary_speed_limit_group_to_stdcm_search_environment/down.sql new file mode 100644 index 00000000000..f75eb03a05e --- /dev/null +++ b/editoast/migrations/2024-11-06-175550_add_temporary_speed_limit_group_to_stdcm_search_environment/down.sql @@ -0,0 +1,2 @@ +ALTER TABLE stdcm_search_environment +DROP COLUMN IF EXISTS temporary_speed_limit_group_id; diff --git a/editoast/migrations/2024-11-06-175550_add_temporary_speed_limit_group_to_stdcm_search_environment/up.sql b/editoast/migrations/2024-11-06-175550_add_temporary_speed_limit_group_to_stdcm_search_environment/up.sql new file mode 100644 index 00000000000..2803d3ddb4f --- /dev/null +++ b/editoast/migrations/2024-11-06-175550_add_temporary_speed_limit_group_to_stdcm_search_environment/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE stdcm_search_environment +ADD COLUMN temporary_speed_limit_group_id int8 REFERENCES temporary_speed_limit_group(id); diff --git a/editoast/openapi.yaml b/editoast/openapi.yaml index 35ceb58e161..10691ec2eac 100644 --- a/editoast/openapi.yaml +++ b/editoast/openapi.yaml @@ -9993,6 +9993,9 @@ components: search_window_end: type: string format: date-time + temporary_speed_limit_group_id: + type: integer + format: int64 timetable_id: type: integer format: int64 @@ -10020,6 +10023,10 @@ components: search_window_end: type: string format: date-time + temporary_speed_limit_group_id: + type: integer + format: int64 + nullable: true timetable_id: type: integer format: int64 diff --git a/editoast/src/models/fixtures.rs b/editoast/src/models/fixtures.rs index 1ed01eb9b7b..844ace527fd 100644 --- a/editoast/src/models/fixtures.rs +++ b/editoast/src/models/fixtures.rs @@ -31,6 +31,8 @@ use crate::models::Scenario; use crate::models::Study; use crate::models::Tags; +use super::temporary_speed_limits::TemporarySpeedLimitGroup; + pub fn project_changeset(name: &str) -> Changeset { Project::changeset() .name(name.to_owned()) @@ -296,6 +298,15 @@ pub async fn create_work_schedule_group(conn: &mut DbConnection) -> WorkSchedule .expect("Failed to create empty work schedule group") } +pub async fn create_temporary_speed_limit_group(conn: &mut DbConnection) -> TemporarySpeedLimitGroup { + TemporarySpeedLimitGroup::changeset() + .name("Empty temporary speed limit group".to_string()) + .creation_date(Utc::now().naive_utc()) + .create(conn) + .await + .expect("Failed to create empty temporary speed limit group") +} + pub async fn create_work_schedules_fixture_set( conn: &mut DbConnection, work_schedules: Vec>, diff --git a/editoast/src/models/stdcm_search_environment.rs b/editoast/src/models/stdcm_search_environment.rs index dddfdc63216..0bcf51881d3 100644 --- a/editoast/src/models/stdcm_search_environment.rs +++ b/editoast/src/models/stdcm_search_environment.rs @@ -30,6 +30,9 @@ pub struct StdcmSearchEnvironment { pub timetable_id: i64, pub search_window_begin: NaiveDateTime, pub search_window_end: NaiveDateTime, + #[schema(nullable = false)] + #[serde(skip_serializing_if = "Option::is_none")] + pub temporary_speed_limit_group_id: Option, } impl StdcmSearchEnvironment { @@ -70,8 +73,9 @@ pub mod test { use crate::models::electrical_profiles::ElectricalProfileSet; use crate::models::fixtures::{ create_electrical_profile_set, create_empty_infra, create_timetable, - create_work_schedule_group, + create_work_schedule_group, create_temporary_speed_limit_group, }; + use crate::models::temporary_speed_limits::TemporarySpeedLimitGroup; use crate::models::timetable::Timetable; use crate::models::work_schedules::WorkScheduleGroup; use crate::models::Infra; @@ -80,16 +84,18 @@ pub mod test { pub async fn stdcm_search_env_fixtures( conn: &mut DbConnection, - ) -> (Infra, Timetable, WorkScheduleGroup, ElectricalProfileSet) { + ) -> (Infra, Timetable, WorkScheduleGroup, TemporarySpeedLimitGroup, ElectricalProfileSet) { let infra = create_empty_infra(conn).await; let timetable = create_timetable(conn).await; let work_schedule_group = create_work_schedule_group(conn).await; + let temporary_speed_limit_group = create_temporary_speed_limit_group(conn).await; let electrical_profile_set = create_electrical_profile_set(conn).await; ( infra, timetable, work_schedule_group, + temporary_speed_limit_group, electrical_profile_set, ) } @@ -101,13 +107,14 @@ pub mod test { StdcmSearchEnvironment::count(&mut db_pool.get_ok(), Default::default()) .await .expect("failed to count STDCM envs"); - let (infra, timetable, work_schedule_group, electrical_profile_set) = + let (infra, timetable, work_schedule_group, temporary_speed_limit_group, electrical_profile_set) = stdcm_search_env_fixtures(&mut db_pool.get_ok()).await; let changeset_1 = StdcmSearchEnvironment::changeset() .infra_id(infra.id) .electrical_profile_set_id(Some(electrical_profile_set.id)) .work_schedule_group_id(Some(work_schedule_group.id)) + .temporary_speed_limit_group_id(Some(temporary_speed_limit_group.id)) .timetable_id(timetable.id) .search_window_begin(NaiveDate::from_ymd_opt(2024, 1, 1).unwrap().into()) .search_window_end(NaiveDate::from_ymd_opt(2024, 1, 15).unwrap().into()); @@ -158,13 +165,14 @@ pub mod test { StdcmSearchEnvironment::delete_all(&mut db_pool.get_ok()) .await .expect("failed to delete envs"); - let (infra, timetable, work_schedule_group, electrical_profile_set) = + let (infra, timetable, work_schedule_group, temporary_speed_limit_group, electrical_profile_set) = stdcm_search_env_fixtures(&mut db_pool.get_ok()).await; let too_old = StdcmSearchEnvironment::changeset() .infra_id(infra.id) .electrical_profile_set_id(Some(electrical_profile_set.id)) .work_schedule_group_id(Some(work_schedule_group.id)) + .temporary_speed_limit_group_id(Some(temporary_speed_limit_group.id)) .timetable_id(timetable.id) .search_window_begin(NaiveDate::from_ymd_opt(2024, 1, 1).unwrap().into()) .search_window_end(NaiveDate::from_ymd_opt(2024, 1, 15).unwrap().into()); diff --git a/editoast/src/views/stdcm_search_environment.rs b/editoast/src/views/stdcm_search_environment.rs index f25ced7549b..e6f6525730e 100644 --- a/editoast/src/views/stdcm_search_environment.rs +++ b/editoast/src/views/stdcm_search_environment.rs @@ -40,6 +40,7 @@ struct StdcmSearchEnvironmentCreateForm { infra_id: i64, electrical_profile_set_id: Option, work_schedule_group_id: Option, + temporary_speed_limit_group_id: Option, timetable_id: i64, search_window_begin: NaiveDateTime, // TODO: move to DateTime search_window_end: NaiveDateTime, @@ -56,6 +57,7 @@ impl<'de> Deserialize<'de> for StdcmSearchEnvironmentCreateForm { infra_id: i64, electrical_profile_set_id: Option, work_schedule_group_id: Option, + temporary_speed_limit_group_id: Option, timetable_id: i64, search_window_begin: NaiveDateTime, search_window_end: NaiveDateTime, @@ -74,6 +76,7 @@ impl<'de> Deserialize<'de> for StdcmSearchEnvironmentCreateForm { infra_id: internal.infra_id, electrical_profile_set_id: internal.electrical_profile_set_id, work_schedule_group_id: internal.work_schedule_group_id, + temporary_speed_limit_group_id: internal.temporary_speed_limit_group_id, timetable_id: internal.timetable_id, search_window_begin: internal.search_window_begin, search_window_end: internal.search_window_end, @@ -87,6 +90,7 @@ impl From for Changeset > @@ -79,6 +80,9 @@ export const stdcmConfSlice = createSlice({ if (action.payload.workScheduleGroupId) { state.workScheduleGroupId = action.payload.workScheduleGroupId; } + if (action.payload.temporarySpeedLimitGroupId) { + state.temporarySpeedLimitGroupId = action.payload.temporarySpeedLimitGroupId; + } }, updateOriginArrival( state: Draft, diff --git a/front/src/reducers/osrdconf/types.ts b/front/src/reducers/osrdconf/types.ts index aed1d2783be..a18177a8fef 100644 --- a/front/src/reducers/osrdconf/types.ts +++ b/front/src/reducers/osrdconf/types.ts @@ -25,6 +25,7 @@ export interface OsrdConfState extends InfraState { timetableID?: number; electricalProfileSetId?: number; workScheduleGroupId?: number; + temporarySpeedLimitGroupId?: number; searchDatetimeWindow?: { begin: Date; end: Date }; rollingStockID?: number; speedLimitByTag?: string;