70 lines
3.8 KiB
TypeScript
70 lines
3.8 KiB
TypeScript
import { Serializable } from '../Serializable';
|
|
import { ValidationContext } from '../../utilities/validators/ValidationContext';
|
|
import { FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
|
|
import { BackendErrorValidator } from '../../utilities/validators/BackendErrorValidator';
|
|
import { BaseErrorModel } from '../error/BaseErrorModel';
|
|
import { ExternalSourcesItemModel } from '../external-sources/ExternalSourcesItemModel';
|
|
import { ServiceModel } from '../services/ServiceModel';
|
|
import { JsonSerializer } from '../../utilities/JsonSerializer';
|
|
import { RegisterModel } from '../registers/RegisterModel';
|
|
import { DataRepositoryModel } from '../dataRepositories/DataRepositoryModel';
|
|
|
|
export class DatasetModel implements Serializable<DatasetModel> {
|
|
public id: String;
|
|
public label: String;
|
|
public profile: String;
|
|
public uri: String;
|
|
public status: String;
|
|
public description: String;
|
|
public services: ServiceModel[] = [];
|
|
public registries: RegisterModel[] = [];
|
|
public dataRepositories: DataRepositoryModel[] = [];
|
|
|
|
public errorModel: BaseErrorModel = new BaseErrorModel();
|
|
|
|
fromJSONObject(item: any): DatasetModel {
|
|
this.id = item.id;
|
|
this.label = item.label;
|
|
this.profile = item.profile;
|
|
this.uri = item.uri;
|
|
this.status = item.status;
|
|
this.description = item.description;
|
|
this.services = JsonSerializer.fromJSONArray(item.services, ServiceModel);
|
|
this.registries = JsonSerializer.fromJSONArray(item.registries, RegisterModel);
|
|
this.dataRepositories = JsonSerializer.fromJSONArray(item.dataRepositories, DataRepositoryModel);
|
|
|
|
return this;
|
|
}
|
|
|
|
buildForm(context: ValidationContext = null, disabled: boolean = false): FormGroup {
|
|
if (context == null) { context = this.createValidationContext(); }
|
|
|
|
const formGroup = new FormBuilder().group({
|
|
label: [{ value: this.label, disabled: disabled }, context.getValidation('label').validators],
|
|
profile: [{ value: this.profile, disabled: disabled }, context.getValidation('profile').validators],
|
|
uri: [{ value: this.uri, disabled: disabled }, context.getValidation('uri').validators],
|
|
status: [{ value: this.status, disabled: disabled }, context.getValidation('status').validators],
|
|
description: [{ value: this.description, disabled: disabled }, context.getValidation('description').validators],
|
|
services: [{ value: this.services, disabled: disabled }, context.getValidation('services').validators],
|
|
registries: [{ value: this.registries, disabled: disabled }, context.getValidation('registries').validators],
|
|
dataRepositories: [{ value: this.dataRepositories, disabled: disabled }, context.getValidation('dataRepositories').validators]
|
|
});
|
|
|
|
return formGroup;
|
|
}
|
|
|
|
createValidationContext(): ValidationContext {
|
|
const baseContext: ValidationContext = new ValidationContext();
|
|
baseContext.validation.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'label')] });
|
|
baseContext.validation.push({ key: 'profile', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'profile')] });
|
|
baseContext.validation.push({ key: 'uri', validators: [BackendErrorValidator(this.errorModel, 'uri')] });
|
|
baseContext.validation.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'status')] });
|
|
baseContext.validation.push({ key: 'description', validators: [BackendErrorValidator(this.errorModel, 'description')] });
|
|
baseContext.validation.push({ key: 'services', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'services')] });
|
|
baseContext.validation.push({ key: 'registries', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'registries')] });
|
|
baseContext.validation.push({ key: 'dataRepositories', validators: [Validators.required, BackendErrorValidator(this.errorModel, 'dataRepositories')] });
|
|
|
|
return baseContext;
|
|
}
|
|
}
|