2019-03-01 16:16:21 +01:00
|
|
|
import { Status } from "../../../core/common/enum/Status";
|
|
|
|
import { ProjectListingModel } from "../../../core/model/project/project-listing";
|
|
|
|
import { ValidationContext } from "../../../common/forms/validation/validation-context";
|
|
|
|
import { FormGroup, FormBuilder, Validators } from "@angular/forms";
|
|
|
|
import { BackendErrorValidator } from "../../../common/forms/validation/custom-validator";
|
|
|
|
import { ValidationErrorModel } from "../../../common/forms/validation/error-model/validation-error-model";
|
2019-03-05 12:21:04 +01:00
|
|
|
import { ValidJsonValidator } from "../../../library/auto-complete/auto-complete-custom-validator";
|
2019-03-01 16:16:21 +01:00
|
|
|
|
|
|
|
export class ProjectEditorWizardModel {
|
|
|
|
public id: string;
|
|
|
|
public label: string;
|
|
|
|
public status: Status = Status.Active;
|
|
|
|
public description: String;
|
2019-03-05 12:21:04 +01:00
|
|
|
public existProject: ProjectListingModel;
|
2019-03-01 16:16:21 +01:00
|
|
|
public validationErrorModel: ValidationErrorModel = new ValidationErrorModel();
|
|
|
|
|
|
|
|
|
|
|
|
fromModel(item: ProjectListingModel): ProjectEditorWizardModel {
|
|
|
|
this.id = item.id;
|
|
|
|
this.label = item.label;
|
|
|
|
this.status = item.status;
|
|
|
|
this.description = item.description;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
|
|
|
|
if (context == null) { context = this.createValidationContext(); }
|
|
|
|
|
|
|
|
const formGroup = new FormBuilder().group({
|
|
|
|
id: [{ value: this.id, disabled: disabled }, context.getValidation('id').validators],
|
|
|
|
label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators],
|
|
|
|
status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators],
|
|
|
|
description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators],
|
2019-03-05 12:21:04 +01:00
|
|
|
existProject: [{ value: this.existProject, disabled: disabled }, context.getValidation('existProject').validators],
|
2019-03-01 16:16:21 +01:00
|
|
|
});
|
|
|
|
return formGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
createValidationContext(): ValidationContext {
|
|
|
|
const baseContext: ValidationContext = new ValidationContext();
|
|
|
|
baseContext.validation.push({ key: 'id', validators: [] });
|
|
|
|
baseContext.validation.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'label')] });
|
|
|
|
baseContext.validation.push({ key: 'status', validators: [] });
|
|
|
|
baseContext.validation.push({ key: 'description', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'description')] });
|
2019-03-05 12:21:04 +01:00
|
|
|
baseContext.validation.push({ key: 'existProject', validators: [Validators.required, ValidJsonValidator, BackendErrorValidator(this.validationErrorModel, 'existProject')] });
|
2019-03-01 16:16:21 +01:00
|
|
|
return baseContext;
|
|
|
|
}
|
2019-03-05 12:21:04 +01:00
|
|
|
|
|
|
|
|
2019-03-01 16:16:21 +01:00
|
|
|
}
|
2019-03-05 12:21:04 +01:00
|
|
|
|