diff --git a/dmp-frontend/src/app/ui/description/editor/form-progress-indication/form-progress-indication.component.ts b/dmp-frontend/src/app/ui/description/editor/form-progress-indication/form-progress-indication.component.ts index 1b62dc6ea..7e6a867d8 100644 --- a/dmp-frontend/src/app/ui/description/editor/form-progress-indication/form-progress-indication.component.ts +++ b/dmp-frontend/src/app/ui/description/editor/form-progress-indication/form-progress-indication.component.ts @@ -3,6 +3,8 @@ import { AbstractControl, UntypedFormArray, UntypedFormControl, UntypedFormGroup import { VisibilityRulesService } from '@app/ui/description/editor/description-form/visibility-rules/visibility-rules.service'; import { BaseComponent } from '@common/base/base.component'; import { takeUntil } from 'rxjs/operators'; +import { DescriptionEditorModel } from '../description-editor.model'; +import { nameof } from 'ts-simple-nameof'; @Component({ selector: 'app-form-progress-indication', @@ -43,12 +45,22 @@ export class FormProgressIndicationComponent extends BaseComponent implements On } calculateValueForProgressbar() { - this.progressSoFar = this.countRequiredFields(this.formGroup.get('properties'), this.checkVisibility, true); - this.total = this.countRequiredFields(this.formGroup.get('properties'), this.checkVisibility); + this.progressSoFar = this.countCompletedRequiredBaseFields(this.formGroup) + this.countRequiredFields(this.formGroup.get('properties'), this.checkVisibility, true); + this.total = 2 + this.countRequiredFields(this.formGroup.get('properties'), this.checkVisibility); // main info contains two required fields: label and descriptionTemplateId this.percent = (this.progressSoFar / this.total) * 100; this.value = Number.parseFloat(this.percent.toPrecision(this.progressValueAccuracy)); } + countCompletedRequiredBaseFields(formControl: AbstractControl): number { + let count = 0; + const baseInfoControlNames: string[] = [nameof(x => x.label), nameof(x => x.descriptionTemplateId)]; + baseInfoControlNames.forEach((name: string) => { + if (this.formGroup.get(name)?.valid) count += 1; + }); + + return count; + } + countRequiredFields(formControl: AbstractControl, checkVisibility = false, countCompletedFields = false): number { let valueCurrent = 0; if (formControl instanceof UntypedFormGroup) {