Skip to content

Commit

Permalink
feat: update study settings logic based on study type
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimozkn committed Aug 13, 2024
1 parent cf95529 commit f503af8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 42 deletions.
4 changes: 4 additions & 0 deletions core/lib/src/models/template/template_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +19,7 @@ class TemplateConfiguration {
this.lockPublisherInformation = false,
this.lockEnrollmentType = false,
this.lockStudySchedule = false,
this.lockStudySettings = false,
this.title,
this.description,
});
Expand All @@ -26,6 +28,7 @@ class TemplateConfiguration {
bool? lockPublisherInformation,
bool? lockEnrollmentType,
bool? lockStudySchedule,
bool? lockStudySettings,
String? title,
String? description,
}) =>
Expand All @@ -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,
);
Expand Down
2 changes: 2 additions & 0 deletions core/lib/src/models/template/template_configuration.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 45 additions & 39 deletions designer_v2/lib/features/study/settings/study_settings_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
},
);
},
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,34 @@ class StudySettingsFormViewModel extends FormViewModel<Study> {
FormControl(value: defaultPublishedToRegistry);
final FormControl<bool> isPublishedToRegistryResultsControl =
FormControl(value: defaultPublishedToRegistryResults);
final FormControl<bool> lockPublishSettingsControl =
FormControl(value: true, disabled: true);
final FormControl<bool> 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
Expand All @@ -57,6 +67,9 @@ class StudySettingsFormViewModel extends FormViewModel<Study> {
study.resultSharing = (isPublishedToRegistryResultsControl.value!)
? ResultSharing.public
: ResultSharing.private;
study.templateConfiguration = study.templateConfiguration?.copyWith(
lockStudySettings: lockPublishSettingsControl.value,
);

return study;
}
Expand Down Expand Up @@ -89,6 +102,8 @@ class StudySettingsFormViewModel extends FormViewModel<Study> {
isPublishedToRegistryControl.value = defaultPublishedToRegistry;
isPublishedToRegistryResultsControl.value =
defaultPublishedToRegistryResults;

lockPublishSettingsControl.value = false;
}
}

Expand Down

0 comments on commit f503af8

Please sign in to comment.