argos/dmp-frontend/src/app/entities/DataModel.ts

63 lines
1.5 KiB
TypeScript

import { GroupBase } from '../form/dynamic-form-group/group-base';
import { FieldBase } from '../form/fields/field-base';
import { Attribute } from './model/attribute';
import { Source } from './model/source';
export class DataModel {
private fIndex : Map<string, FieldBase<any>>;
private fIndSources : Map<string, Source>;
groups: GroupBase<any>[] = [];
fields: FieldBase<any>[] = [];
semanticAttr: Attribute[];
//need to add more class fields to describe the remaining elements of the json object fetched from the service.
//e.g. the current dataset's metadata information, the DataRepository description information, etc
constructor(){
}
public buildIndex(){
this.fIndex = new Map<string, FieldBase<any>>();
this.fIndSources = new Map<string, Source>();
this.fields.forEach((field) => {
console.log("fieldid:" +field.key);
this.fIndex.set(field.key, field);
});
this.groups.forEach((group) => {
group.groupFields.forEach((field) => {
console.log("groupid: "+group.key + "fieldid:" +field.key);
this.fIndex.set(field.key, field);
});
});
this.semanticAttr.forEach((attr) => {
attr.sources.forEach(src => {
this.fIndSources.set(attr.id, src);
console.log("fieldid: "+attr.id + "attr:" +src);
});
});
}
public getFieldByKey(key){
return this.fIndex.get(key);
}
}