clean up description editor progress bar

This commit is contained in:
Sofia Papacharalampous 2024-04-29 13:41:01 +03:00
parent 2180bebc7f
commit 88ba79c406
1 changed files with 13 additions and 46 deletions

View File

@ -16,7 +16,6 @@ export class FormProgressIndicationComponent extends BaseComponent implements On
determinateProgressValue: number;
progressSoFar: number;
total: number;
totalIds: string[] = [];
percent: number;
fieldTypes: string[] = ['dateValue', 'externalIdentifier.identifier', 'externalIdentifier.type', 'reference', 'references', 'textListValue', 'textValue'];
@ -44,80 +43,48 @@ export class FormProgressIndicationComponent extends BaseComponent implements On
}
calculateValueForProgressbar() {
this.progressSoFar = this.countCompletedFields(this.formGroup.get('properties'), this.checkVisibility);
this.total = this.countTotalRequiredFields(this.formGroup.get('properties'), this.checkVisibility);
this.progressSoFar = this.countRequiredFields(this.formGroup.get('properties'), this.checkVisibility, true);
this.total = this.countRequiredFields(this.formGroup.get('properties'), this.checkVisibility);
this.percent = (this.progressSoFar / this.total) * 100;
this.value = Number.parseFloat(this.percent.toPrecision(this.progressValueAccuracy));
}
countTotalRequiredFields(formControl: AbstractControl, checkVisibility = false): number {
countRequiredFields(formControl: AbstractControl, checkVisibility = false, countCompletedFields = false): number {
let valueCurrent = 0;
if (formControl instanceof UntypedFormGroup) {
if(!checkVisibility || (!formControl.get('id')?.value || (this.visibilityRulesService.isVisibleMap[formControl.get('id').value] ?? true))) {
Object.keys(formControl.controls).forEach(item => {
const control = formControl.get(item);
valueCurrent = valueCurrent + this.countTotalRequiredFields(control, checkVisibility);
valueCurrent = valueCurrent + this.countRequiredFields(control, checkVisibility, countCompletedFields);
});
}
} else if (formControl instanceof UntypedFormArray) {
formControl.controls.forEach(item => {
valueCurrent = valueCurrent + this.countTotalRequiredFieldsByFieldset(item.get('ordinal').value, item.get('fields') as UntypedFormGroup);
valueCurrent = valueCurrent + this.countRequiredFieldsByFieldset(item.get('ordinal').value, item.get('fields') as UntypedFormGroup, countCompletedFields);
});
}
return valueCurrent;
}
countTotalRequiredFieldsByFieldset(ordinal: number, fieldsFormGroup: UntypedFormGroup): number {
let requiredFieldsCount: number = 0;
countRequiredFieldsByFieldset(ordinal: number, fieldsFormGroup: UntypedFormGroup, filterValid: boolean = false): number {
let fieldsCount: number = 0;
const fieldNames = Object.keys(fieldsFormGroup.controls);
for(let item of fieldNames) {
if (!this.checkVisibility || this.visibilityRulesService.isVisible(item, ordinal)) {
const fieldControl = fieldsFormGroup.get(item);
for (let fieldType of this.fieldTypes) {
const typedControl = fieldControl.get(fieldType);
if (this.controlRequired(typedControl) && this.controlEnabled(typedControl)) {
requiredFieldsCount ++;
let controlFilter: boolean = this.controlRequired(typedControl) && this.controlEnabled(typedControl);
if (filterValid) controlFilter = controlFilter && typedControl.valid;
if (controlFilter) {
fieldsCount ++;
break;
}
}
}
}
return requiredFieldsCount;
}
countCompletedFields(formControl: AbstractControl, checkVisibility=false): number {
let completedFieldsCount: number = 0;
if (formControl instanceof UntypedFormGroup) {
if(!checkVisibility || (!formControl.get('id')?.value || (this.visibilityRulesService.isVisibleMap[formControl.get('id').value] ?? true))) {
Object.keys(formControl.controls).forEach(item => {
const control = formControl.get(item);
completedFieldsCount = completedFieldsCount + this.countCompletedFields(control, checkVisibility);
});
}
} else if (formControl instanceof UntypedFormArray) {
formControl.controls.forEach(item => {
completedFieldsCount = completedFieldsCount + this.countCompletedRequiredFieldsByFieldset(item.get('ordinal').value, item.get('fields') as UntypedFormGroup);
});
}
return completedFieldsCount;
}
countCompletedRequiredFieldsByFieldset(ordinal: number, fieldsFormGroup: UntypedFormGroup): number {
let completedFieldsCount: number = 0;
const fieldNames = Object.keys(fieldsFormGroup.controls);
for(let item of fieldNames) {
if (!this.checkVisibility || this.visibilityRulesService.isVisible(item, ordinal)) {
const fieldControl = fieldsFormGroup.get(item);
for (let fieldType of this.fieldTypes) {
const typedControl = fieldControl.get(fieldType);
if (this.controlRequired(typedControl) && this.controlEnabled(typedControl) && typedControl.valid) {
completedFieldsCount ++;
break;
}
}
}
}
return completedFieldsCount;
return fieldsCount;
}
//////////////////////////////////////////////////////////////////////