fixed description progress-bar
This commit is contained in:
parent
7e58bfdc5f
commit
ca4efbeb49
|
@ -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<DescriptionEditorModel>(x => x.label), nameof<DescriptionEditorModel>(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) {
|
||||
|
|
Loading…
Reference in New Issue