From f503af8aff122e61d55aa46c63a264999b1853f0 Mon Sep 17 00:00:00 2001 From: ibrahim Date: Wed, 14 Aug 2024 02:11:04 +0300 Subject: [PATCH] feat: update study settings logic based on study type --- .../template/template_configuration.dart | 4 + .../template/template_configuration.g.dart | 2 + .../study/settings/study_settings_dialog.dart | 84 ++++++++++--------- .../study_settings_form_controller.dart | 21 ++++- 4 files changed, 69 insertions(+), 42 deletions(-) diff --git a/core/lib/src/models/template/template_configuration.dart b/core/lib/src/models/template/template_configuration.dart index a9a5322be..7c411c643 100644 --- a/core/lib/src/models/template/template_configuration.dart +++ b/core/lib/src/models/template/template_configuration.dart @@ -7,6 +7,7 @@ class TemplateConfiguration { final bool lockPublisherInformation; final bool lockEnrollmentType; final bool lockStudySchedule; + final bool lockStudySettings; /// The title of the parent template final String? title; @@ -18,6 +19,7 @@ class TemplateConfiguration { this.lockPublisherInformation = false, this.lockEnrollmentType = false, this.lockStudySchedule = false, + this.lockStudySettings = false, this.title, this.description, }); @@ -26,6 +28,7 @@ class TemplateConfiguration { bool? lockPublisherInformation, bool? lockEnrollmentType, bool? lockStudySchedule, + bool? lockStudySettings, String? title, String? description, }) => @@ -34,6 +37,7 @@ class TemplateConfiguration { lockPublisherInformation ?? this.lockPublisherInformation, lockEnrollmentType: lockEnrollmentType ?? this.lockEnrollmentType, lockStudySchedule: lockStudySchedule ?? this.lockStudySchedule, + lockStudySettings: lockStudySettings ?? this.lockStudySettings, title: title ?? this.title, description: description ?? this.description, ); diff --git a/core/lib/src/models/template/template_configuration.g.dart b/core/lib/src/models/template/template_configuration.g.dart index d16c71f28..a561501c3 100644 --- a/core/lib/src/models/template/template_configuration.g.dart +++ b/core/lib/src/models/template/template_configuration.g.dart @@ -13,6 +13,7 @@ TemplateConfiguration _$TemplateConfigurationFromJson( json['lockPublisherInformation'] as bool? ?? false, lockEnrollmentType: json['lockEnrollmentType'] as bool? ?? false, lockStudySchedule: json['lockStudySchedule'] as bool? ?? false, + lockStudySettings: json['lockStudySettings'] as bool? ?? false, title: json['title'] as String?, description: json['description'] as String?, ); @@ -23,6 +24,7 @@ Map _$TemplateConfigurationToJson( 'lockPublisherInformation': instance.lockPublisherInformation, 'lockEnrollmentType': instance.lockEnrollmentType, 'lockStudySchedule': instance.lockStudySchedule, + 'lockStudySettings': instance.lockStudySettings, }; void writeNotNull(String key, dynamic value) { diff --git a/designer_v2/lib/features/study/settings/study_settings_dialog.dart b/designer_v2/lib/features/study/settings/study_settings_dialog.dart index 336ca2b7b..dbdc8a8d9 100644 --- a/designer_v2/lib/features/study/settings/study_settings_dialog.dart +++ b/designer_v2/lib/features/study/settings/study_settings_dialog.dart @@ -22,51 +22,57 @@ class StudySettingsDialog extends StudyPageWidget { child: StandardDialog( titleText: tr.study_settings, body: Column( - crossAxisAlignment: CrossAxisAlignment.start, children: [ - const SizedBox(height: 12.0), - FormSectionHeader( - title: tr.navlink_public_studies, - showLock: formViewModel.study.value?.isStandalone != true, - lockControl: formViewModel.lockPublishSettingsControl, - lockHelpText: tr.form_section_publish_lock_help, - lockedStateText: tr.form_section_publish_lock_locked, - unlockedStateText: tr.form_section_publish_lock_unlocked, - ), - const SizedBox(height: 6.0), - TextParagraph(text: tr.navlink_public_studies_description), - const SizedBox(height: 24.0), ReactiveFormConsumer( builder: (context, form, child) { - return FormTableLayout( - rows: [ - FormTableRow( - label: tr.study_settings_publish_study, - labelHelpText: tr.study_settings_publish_study_tooltip, - input: Align( - alignment: Alignment.centerRight, - child: ReactiveSwitch( - formControl: - formViewModel.isPublishedToRegistryControl, - ), - ), + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 12.0), + FormSectionHeader( + title: tr.navlink_public_studies, + showLock: formViewModel.study.value?.isStandalone != true, + lockControl: formViewModel.lockPublishSettingsControl, + lockHelpText: tr.form_section_publish_lock_help, + lockedStateText: tr.form_section_publish_lock_locked, + unlockedStateText: tr.form_section_publish_lock_unlocked, ), - FormTableRow( - label: tr.study_settings_publish_results, - labelHelpText: tr.study_settings_publish_results_tooltip, - input: Align( - alignment: Alignment.centerRight, - child: ReactiveSwitch( - formControl: - formViewModel.isPublishedToRegistryResultsControl, + const SizedBox(height: 6.0), + TextParagraph(text: tr.navlink_public_studies_description), + const SizedBox(height: 24.0), + FormTableLayout( + rows: [ + FormTableRow( + label: tr.study_settings_publish_study, + labelHelpText: + tr.study_settings_publish_study_tooltip, + input: Align( + alignment: Alignment.centerRight, + child: ReactiveSwitch( + formControl: + formViewModel.isPublishedToRegistryControl, + ), + ), ), - ), - ), + FormTableRow( + label: tr.study_settings_publish_results, + labelHelpText: + tr.study_settings_publish_results_tooltip, + input: Align( + alignment: Alignment.centerRight, + child: ReactiveSwitch( + formControl: formViewModel + .isPublishedToRegistryResultsControl, + ), + ), + ), + ], + columnWidths: const { + 0: IntrinsicColumnWidth(), + 1: FlexColumnWidth(), + }, + ) ], - columnWidths: const { - 0: IntrinsicColumnWidth(), - 1: FlexColumnWidth(), - }, ); }, ), diff --git a/designer_v2/lib/features/study/settings/study_settings_form_controller.dart b/designer_v2/lib/features/study/settings/study_settings_form_controller.dart index b65dc1b79..ccc1936f4 100644 --- a/designer_v2/lib/features/study/settings/study_settings_form_controller.dart +++ b/designer_v2/lib/features/study/settings/study_settings_form_controller.dart @@ -29,24 +29,34 @@ class StudySettingsFormViewModel extends FormViewModel { FormControl(value: defaultPublishedToRegistry); final FormControl isPublishedToRegistryResultsControl = FormControl(value: defaultPublishedToRegistryResults); - final FormControl lockPublishSettingsControl = - FormControl(value: true, disabled: true); + final FormControl lockPublishSettingsControl = FormControl(); @override late final FormGroup form = FormGroup({ 'isPublishedToRegistry': isPublishedToRegistryControl, 'isPublishedToRegistryResults': isPublishedToRegistryResultsControl, + 'lockStudySettings': lockPublishSettingsControl, }); @override void setControlsFrom(Study data) { isPublishedToRegistryControl.value = data.publishedToRegistry; isPublishedToRegistryResultsControl.value = data.publishedToRegistryResults; + lockPublishSettingsControl.value = + data.templateConfiguration?.lockStudySettings ?? false; - if (data.isSubStudy) { + //disable editing registry controls if study is template and running OR if study is sub-study and publish settings are locked + //in other words template studies cannot change its registry settings while running and sub-studies cannot change its registry settings if publish settings are locked + if ((data.isTemplate && data.status == StudyStatus.running) || + (data.isSubStudy && lockPublishSettingsControl.value == true)) { isPublishedToRegistryControl.markAsDisabled(); isPublishedToRegistryResultsControl.markAsDisabled(); } + + if (data.isTemplate && data.status == StudyStatus.running || + data.isSubStudy) { + lockPublishSettingsControl.markAsDisabled(); + } } @override @@ -57,6 +67,9 @@ class StudySettingsFormViewModel extends FormViewModel { study.resultSharing = (isPublishedToRegistryResultsControl.value!) ? ResultSharing.public : ResultSharing.private; + study.templateConfiguration = study.templateConfiguration?.copyWith( + lockStudySettings: lockPublishSettingsControl.value, + ); return study; } @@ -89,6 +102,8 @@ class StudySettingsFormViewModel extends FormViewModel { isPublishedToRegistryControl.value = defaultPublishedToRegistry; isPublishedToRegistryResultsControl.value = defaultPublishedToRegistryResults; + + lockPublishSettingsControl.value = false; } }