From c157ecc4e78b3e613a620de27591e280deb7dad5 Mon Sep 17 00:00:00 2001 From: Kristan Ntavidi Date: Wed, 5 May 2021 15:50:20 +0300 Subject: [PATCH] Admin template editor. Fix invalid visibility rules case. --- .../admin/rule-editor-model.ts | 2 +- .../dataset-profile-editor-field.component.ts | 13 +-- .../dataset-profile-editor.component.ts | 88 +++++++++++++++++++ dmp-frontend/src/assets/i18n/de.json | 9 ++ dmp-frontend/src/assets/i18n/en.json | 9 ++ dmp-frontend/src/assets/i18n/es.json | 9 ++ dmp-frontend/src/assets/i18n/gr.json | 9 ++ dmp-frontend/src/assets/i18n/pt.json | 9 ++ dmp-frontend/src/assets/i18n/sk.json | 9 ++ dmp-frontend/src/assets/i18n/sr.json | 9 ++ dmp-frontend/src/assets/i18n/tr.json | 9 ++ .../confirmation-dialog.component.scss | 2 +- 12 files changed, 169 insertions(+), 8 deletions(-) diff --git a/dmp-frontend/src/app/ui/admin/dataset-profile/admin/rule-editor-model.ts b/dmp-frontend/src/app/ui/admin/dataset-profile/admin/rule-editor-model.ts index e945cc8c6..6e878666c 100644 --- a/dmp-frontend/src/app/ui/admin/dataset-profile/admin/rule-editor-model.ts +++ b/dmp-frontend/src/app/ui/admin/dataset-profile/admin/rule-editor-model.ts @@ -23,7 +23,7 @@ export class RuleEditorModel extends BaseFormModel { // sourceField: [this.sourceField], target: [{ value: this.target, disabled: (disabled && !skipDisable.includes('RuleEditorModel.target')) }, [Validators.required]], ruleStyle: [{ value: this.ruleStyle, disabled: (disabled && !skipDisable.includes('RuleEditorModel.ruleStyle')) }], - value: [{ value: this.value, disabled: (disabled && !skipDisable.includes('RuleEditorModel.value')) }], + value: [{ value: this.value, disabled: (disabled && !skipDisable.includes('RuleEditorModel.value')) }, [Validators.required]], ruleType: [{ value: this.ruleType, disabled: (disabled && !skipDisable.includes('RuleEditorModel.ruleType')) }], valueType: [{ value: this.valueType, disabled: (disabled && !skipDisable.includes('RuleEditorModel.valueType')) }] }); diff --git a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.ts b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.ts index 18382a245..6ff1de711 100644 --- a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.ts +++ b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/components/field/dataset-profile-editor-field.component.ts @@ -34,13 +34,14 @@ import { AutoCompleteFieldDataEditorModel } from '../../../admin/field-data/auto import { DatasetsAutoCompleteFieldDataEditorModel } from '../../../admin/field-data/datasets-autocomplete-field-data-editor-mode'; import { DatasetProfileComboBoxType } from '@app/core/common/enum/dataset-profile-combo-box-type'; import { Guid } from '@common/types/guid'; -import { ErrorStateMatcher, MatSlideToggleChange } from '@angular/material'; +import { ErrorStateMatcher, MatDialog, MatSlideToggleChange } from '@angular/material'; import { DefaultValueEditorModel } from '../../../admin/default-value-editor-model'; import { EditorCustomValidators } from '../../custom-validators/editor-custom-validators'; import { Field } from '@app/core/model/admin/dataset-profile/dataset-profile'; import { DatasetProfileInternalDmpEntitiesType } from '@app/core/common/enum/dataset-profile-internal-dmp-entities-type'; import { FieldEditorModel } from '../../../admin/field-editor-model'; import { AutoCompleteFieldData, BooleanDecisionFieldData, CheckBoxFieldData, CurrencyFieldData, DataRepositoriesFieldData, DatasetIdentifierFieldData, DatePickerFieldData, DmpsAutoCompleteFieldData, ExternalDatasetsFieldData, FieldDataOption, FreeTextFieldData, OrganizationsFieldData, RadioBoxFieldData, RegistriesFieldData, ResearchersAutoCompleteFieldData, ServicesFieldData, TagsFieldData, TextAreaFieldData, ValidationFieldData, WordListFieldData } from '@app/core/model/dataset-profile-definition/field-data/field-data'; +import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; @Component({ selector: 'app-dataset-profile-editor-field-component', @@ -69,7 +70,8 @@ export class DatasetProfileEditorFieldComponent extends BaseComponent implements constructor( public enumUtils: EnumUtils, - public datasetProfileService: DatasetProfileService + public datasetProfileService: DatasetProfileService, + private dialog: MatDialog ) { super(); } @@ -97,7 +99,8 @@ export class DatasetProfileEditorFieldComponent extends BaseComponent implements // } // } - if(this.form.get('viewStyle').get('renderStyle').value){ + const renderStyle = this.form.get('viewStyle').get('renderStyle').value; + if(renderStyle){ // this.matcher.setReference(this.form); const type = this.form.get('viewStyle').get('renderStyle').value; @@ -164,7 +167,7 @@ export class DatasetProfileEditorFieldComponent extends BaseComponent implements this.viewType = this.viewTypeEnum.Validation; break; } - + } // this.showPreview = true; @@ -390,8 +393,6 @@ export class DatasetProfileEditorFieldComponent extends BaseComponent implements case this.viewTypeEnum.Select: case this.viewTypeEnum.CheckBox: case this.viewTypeEnum.DatePicker: - case this.viewTypeEnum.DataRepositories://TODO FURTHER NOTICE - case this.viewTypeEnum.ExternalDatasets://TODO FURTHER NOTICE return true; } diff --git a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.ts b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.ts index 6fce4a7ab..026434205 100644 --- a/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/dataset-profile/editor/dataset-profile-editor.component.ts @@ -280,7 +280,95 @@ export class DatasetProfileEditorComponent extends BaseComponent implements OnIn }, 400); // this._initializeFormValidity(tocentries); + //Checking invalid visibilty RULES + const fieldsetEntries = this._getAllFieldSets(this.toCEntries); + const fieldSetHavingInvalidVisibilityRules:ToCEntry[] = fieldsetEntries + .filter(entry=>{ + const fieldsFormGroup = entry.form.get('fields'); + const invalid = (fieldsFormGroup as FormArray).controls.filter(field=>{ + return this.hasInvalidVisibilityRule(field as FormGroup); + + }); + if(invalid && invalid.length){ + return true; + } + return false; + }); + + if(fieldSetHavingInvalidVisibilityRules.length){ + const occurences = fieldSetHavingInvalidVisibilityRules.map(record=>record.numbering).join(' , '); + this.dialog.open(ConfirmationDialogComponent, { + data:{ + message: this.language.instant('DATASET-PROFILE-EDITOR.ERRORS.INVALID-VISIBILITY-RULES.MESSAGE-START')+occurences+ this.language.instant('DATASET-PROFILE-EDITOR.ERRORS.INVALID-VISIBILITY-RULES.MESSAGE-END'), + confirmButton: this.language.instant('DATASET-PROFILE-EDITOR.ERRORS.INVALID-VISIBILITY-RULES.CONFIRM-YES'), + cancelButton: this.language.instant('DATASET-PROFILE-EDITOR.ERRORS.INVALID-VISIBILITY-RULES.CONFIRM-NO') + }, + maxWidth:'30em' + }) + .afterClosed() + .subscribe(confirm=>{ + if(confirm){ + this.removeFieldSetVisibilityRules(fieldSetHavingInvalidVisibilityRules); + this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-PROFILE-EDITOR.ERRORS.INVALID-VISIBILITY-RULES.REMOVE-SUCCESS'), SnackBarNotificationLevel.Success); + + }else{ + console.log('User not confirmed'); + } + }) + } + + + } + + private removeFieldSetVisibilityRules(fieldsets:ToCEntry[]){ + + if(!fieldsets || !fieldsets.length) return; + + fieldsets.forEach(fieldset=>{ + if(fieldset.type != ToCEntryType.FieldSet){ + return; + } + const fields = fieldset.form.get('fields') as FormArray; + + fields.controls.forEach(fieldControl=>{ + if(this.hasInvalidVisibilityRule(fieldControl as FormGroup)){ + try{ + (fieldControl.get('visible').get('rules') as FormArray).clear(); + }catch{} + } + }) + + }) + + } + + private hasInvalidVisibilityRule(field: FormGroup):boolean{ + const renderStyle = field.get('viewStyle').get('renderStyle').value; + if(renderStyle && ![ + DatasetProfileFieldViewStyle.TextArea, + DatasetProfileFieldViewStyle.FreeText, + DatasetProfileFieldViewStyle.BooleanDecision, + DatasetProfileFieldViewStyle.RadioBox, + DatasetProfileFieldViewStyle.CheckBox, + DatasetProfileFieldViewStyle.DatePicker, + DatasetProfileFieldViewStyle.ComboBox, + ].includes(renderStyle)){ + if(((renderStyle === DatasetProfileFieldViewStyle) && (field.get('data').get('type').value === DatasetProfileComboBoxType.WordList))){ + return false; + } + try{ + if(field.get('visible').get('rules').value.length){ + return true; + } + return false; + + }catch{ + return false; + } + }else{ + return false; + } } diff --git a/dmp-frontend/src/assets/i18n/de.json b/dmp-frontend/src/assets/i18n/de.json index 044442adc..a26fbb35c 100644 --- a/dmp-frontend/src/assets/i18n/de.json +++ b/dmp-frontend/src/assets/i18n/de.json @@ -532,6 +532,15 @@ }, "FEEDBACK-MESSAGES":{ "SAVE-SUCCESS":"Changes were saved successfully." + }, + "ERRORS":{ + "INVALID-VISIBILITY-RULES":{ + "MESSAGE-START": "There were invalid visibilty rules detected in ", + "MESSAGE-END": ". Would you like to fix them?", + "CONFIRM-YES": "Yes, remove invalid rules", + "CONFIRM-NO": "No, keep them.", + "REMOVE-SUCCESS":"Invalid visibility rules were removed successfully." + } } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/en.json b/dmp-frontend/src/assets/i18n/en.json index 1dde2a135..ac1f9a0f9 100644 --- a/dmp-frontend/src/assets/i18n/en.json +++ b/dmp-frontend/src/assets/i18n/en.json @@ -532,6 +532,15 @@ }, "FEEDBACK-MESSAGES":{ "SAVE-SUCCESS":"Changes were saved successfully." + }, + "ERRORS":{ + "INVALID-VISIBILITY-RULES":{ + "MESSAGE-START": "There were invalid visibilty rules detected in ", + "MESSAGE-END": ". Would you like to fix them?", + "CONFIRM-YES": "Yes, remove invalid rules", + "CONFIRM-NO": "No, keep them.", + "REMOVE-SUCCESS":"Invalid visibility rules were removed successfully." + } } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/es.json b/dmp-frontend/src/assets/i18n/es.json index 65a7c5f23..59a19697c 100644 --- a/dmp-frontend/src/assets/i18n/es.json +++ b/dmp-frontend/src/assets/i18n/es.json @@ -532,6 +532,15 @@ }, "FEEDBACK-MESSAGES":{ "SAVE-SUCCESS":"Changes were saved successfully." + }, + "ERRORS":{ + "INVALID-VISIBILITY-RULES":{ + "MESSAGE-START": "There were invalid visibilty rules detected in ", + "MESSAGE-END": ". Would you like to fix them?", + "CONFIRM-YES": "Yes, remove invalid rules", + "CONFIRM-NO": "No, keep them.", + "REMOVE-SUCCESS":"Invalid visibility rules were removed successfully." + } } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/gr.json b/dmp-frontend/src/assets/i18n/gr.json index 0e43d17bf..d2b82edc5 100644 --- a/dmp-frontend/src/assets/i18n/gr.json +++ b/dmp-frontend/src/assets/i18n/gr.json @@ -532,6 +532,15 @@ }, "FEEDBACK-MESSAGES":{ "SAVE-SUCCESS":"Changes were saved successfully." + }, + "ERRORS":{ + "INVALID-VISIBILITY-RULES":{ + "MESSAGE-START": "There were invalid visibilty rules detected in ", + "MESSAGE-END": ". Would you like to fix them?", + "CONFIRM-YES": "Yes, remove invalid rules", + "CONFIRM-NO": "No, keep them.", + "REMOVE-SUCCESS":"Invalid visibility rules were removed successfully." + } } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/pt.json b/dmp-frontend/src/assets/i18n/pt.json index 165080056..cdb87ee33 100644 --- a/dmp-frontend/src/assets/i18n/pt.json +++ b/dmp-frontend/src/assets/i18n/pt.json @@ -532,6 +532,15 @@ }, "FEEDBACK-MESSAGES":{ "SAVE-SUCCESS":"Changes were saved successfully." + }, + "ERRORS":{ + "INVALID-VISIBILITY-RULES":{ + "MESSAGE-START": "There were invalid visibilty rules detected in ", + "MESSAGE-END": ". Would you like to fix them?", + "CONFIRM-YES": "Yes, remove invalid rules", + "CONFIRM-NO": "No, keep them.", + "REMOVE-SUCCESS":"Invalid visibility rules were removed successfully." + } } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/sk.json b/dmp-frontend/src/assets/i18n/sk.json index 5b88441bb..6d64be223 100644 --- a/dmp-frontend/src/assets/i18n/sk.json +++ b/dmp-frontend/src/assets/i18n/sk.json @@ -532,6 +532,15 @@ }, "FEEDBACK-MESSAGES":{ "SAVE-SUCCESS":"Changes were saved successfully." + }, + "ERRORS":{ + "INVALID-VISIBILITY-RULES":{ + "MESSAGE-START": "There were invalid visibilty rules detected in ", + "MESSAGE-END": ". Would you like to fix them?", + "CONFIRM-YES": "Yes, remove invalid rules", + "CONFIRM-NO": "No, keep them.", + "REMOVE-SUCCESS":"Invalid visibility rules were removed successfully." + } } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/sr.json b/dmp-frontend/src/assets/i18n/sr.json index adcd07e00..37b7ca19b 100644 --- a/dmp-frontend/src/assets/i18n/sr.json +++ b/dmp-frontend/src/assets/i18n/sr.json @@ -532,6 +532,15 @@ }, "FEEDBACK-MESSAGES":{ "SAVE-SUCCESS":"Changes were saved successfully." + }, + "ERRORS":{ + "INVALID-VISIBILITY-RULES":{ + "MESSAGE-START": "There were invalid visibilty rules detected in ", + "MESSAGE-END": ". Would you like to fix them?", + "CONFIRM-YES": "Yes, remove invalid rules", + "CONFIRM-NO": "No, keep them.", + "REMOVE-SUCCESS":"Invalid visibility rules were removed successfully." + } } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/assets/i18n/tr.json b/dmp-frontend/src/assets/i18n/tr.json index ed1ca38c4..7cf2bfd51 100644 --- a/dmp-frontend/src/assets/i18n/tr.json +++ b/dmp-frontend/src/assets/i18n/tr.json @@ -532,6 +532,15 @@ }, "FEEDBACK-MESSAGES":{ "SAVE-SUCCESS":"Changes were saved successfully." + }, + "ERRORS":{ + "INVALID-VISIBILITY-RULES":{ + "MESSAGE-START": "There were invalid visibilty rules detected in ", + "MESSAGE-END": ". Would you like to fix them?", + "CONFIRM-YES": "Yes, remove invalid rules", + "CONFIRM-NO": "No, keep them.", + "REMOVE-SUCCESS":"Invalid visibility rules were removed successfully." + } } }, "GRANT-LISTING": { diff --git a/dmp-frontend/src/common/modules/confirmation-dialog/confirmation-dialog.component.scss b/dmp-frontend/src/common/modules/confirmation-dialog/confirmation-dialog.component.scss index 523155cb4..5bd8b98b0 100644 --- a/dmp-frontend/src/common/modules/confirmation-dialog/confirmation-dialog.component.scss +++ b/dmp-frontend/src/common/modules/confirmation-dialog/confirmation-dialog.component.scss @@ -23,7 +23,7 @@ } .cancel-btn { - width: 101px; + min-width: 101px; height: 43px; background: #ffffff; border: 1px solid #b5b5b5;