Properly indent all source files
This commit is contained in:
@ -8,77 +8,77 @@ import {ModelItemModel} from '../models/model-item.model';
|
||||
import {ModelFileModel} from '../models/model-file.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DataService {
|
||||
|
||||
constructor(
|
||||
private api: ApiService
|
||||
) { }
|
||||
constructor(
|
||||
private api: ApiService
|
||||
) { }
|
||||
|
||||
private collectionMap = { // List of available collections
|
||||
materials: {path: '/materials?status[]=validated&status[]=new', model: MaterialModel, type: 'idArray'},
|
||||
materialSuppliers: {path: '/material/suppliers', model: null, type: 'idArray'},
|
||||
materialGroups: {path: '/material/groups', model: null, type: 'idArray'},
|
||||
materialTemplates: {path: '/template/materials', model: TemplateModel, type: 'template'},
|
||||
measurementTemplates: {path: '/template/measurements', model: TemplateModel, type: 'template'},
|
||||
conditionTemplates: {path: '/template/conditions', model: TemplateModel, type: 'template'},
|
||||
sampleNotesFields: {path: '/sample/notes/fields', model: TemplateModel, type: 'idArray'},
|
||||
users: {path: '/users', model: UserModel, type: 'idArray'},
|
||||
modelGroups: {path: '/model/groups', model: ModelItemModel, type: 'array'},
|
||||
modelFiles: {path: '/model/files', model: ModelFileModel, type: 'array'},
|
||||
user: {path: '/user', model: UserModel, type: 'string'},
|
||||
userKey: {path: '/user/key', model: BaseModel, type: 'string'}
|
||||
};
|
||||
private collectionMap = { // List of available collections
|
||||
materials: {path: '/materials?status[]=validated&status[]=new', model: MaterialModel, type: 'idArray'},
|
||||
materialSuppliers: {path: '/material/suppliers', model: null, type: 'idArray'},
|
||||
materialGroups: {path: '/material/groups', model: null, type: 'idArray'},
|
||||
materialTemplates: {path: '/template/materials', model: TemplateModel, type: 'template'},
|
||||
measurementTemplates: {path: '/template/measurements', model: TemplateModel, type: 'template'},
|
||||
conditionTemplates: {path: '/template/conditions', model: TemplateModel, type: 'template'},
|
||||
sampleNotesFields: {path: '/sample/notes/fields', model: TemplateModel, type: 'idArray'},
|
||||
users: {path: '/users', model: UserModel, type: 'idArray'},
|
||||
modelGroups: {path: '/model/groups', model: ModelItemModel, type: 'array'},
|
||||
modelFiles: {path: '/model/files', model: ModelFileModel, type: 'array'},
|
||||
user: {path: '/user', model: UserModel, type: 'string'},
|
||||
userKey: {path: '/user/key', model: BaseModel, type: 'string'}
|
||||
};
|
||||
|
||||
arr: {[key: string]: any[]} = {}; // Array of data
|
||||
latest: {[key: string]: any[]} = {}; // Array of latest template versions
|
||||
id: {[key: string]: {[id: string]: any}} = {}; // Data in format _id: data
|
||||
d: {[key: string]: any} = {}; // Data not in array format
|
||||
arr: {[key: string]: any[]} = {}; // Array of data
|
||||
latest: {[key: string]: any[]} = {}; // Array of latest template versions
|
||||
id: {[key: string]: {[id: string]: any}} = {}; // Data in format _id: data
|
||||
d: {[key: string]: any} = {}; // Data not in array format
|
||||
|
||||
contact = {name: 'CR/APS1-Lingenfelser', mail: 'dominic.lingenfelser@bosch.com'}; // Global contact data
|
||||
contact = {name: 'CR/APS1-Lingenfelser', mail: 'dominic.lingenfelser@bosch.com'}; // Global contact data
|
||||
|
||||
load(collection, f = () => {}) { // Load data
|
||||
if (this.arr[collection]) { // Data already loaded
|
||||
f();
|
||||
}
|
||||
else { // Load data
|
||||
this.api.get<any>(this.collectionMap[collection].path, data => {
|
||||
if (this.collectionMap[collection].type !== 'string') { // Array data
|
||||
this.arr[collection] = data
|
||||
.map(
|
||||
e => this.collectionMap[collection].model ?
|
||||
new this.collectionMap[collection].model().deserialize(e) : e
|
||||
);
|
||||
// Load ids
|
||||
if (this.collectionMap[collection].type === 'idArray' || this.collectionMap[collection].type === 'template') {
|
||||
this.idReload(collection);
|
||||
}
|
||||
}
|
||||
else { // Not array data
|
||||
this.d[collection] = new this.collectionMap[collection].model().deserialize(data);
|
||||
}
|
||||
f();
|
||||
});
|
||||
}
|
||||
}
|
||||
load(collection, f = () => {}) { // Load data
|
||||
if (this.arr[collection]) { // Data already loaded
|
||||
f();
|
||||
}
|
||||
else { // Load data
|
||||
this.api.get<any>(this.collectionMap[collection].path, data => {
|
||||
if (this.collectionMap[collection].type !== 'string') { // Array data
|
||||
this.arr[collection] = data
|
||||
.map(
|
||||
e => this.collectionMap[collection].model ?
|
||||
new this.collectionMap[collection].model().deserialize(e) : e
|
||||
);
|
||||
// Load ids
|
||||
if (this.collectionMap[collection].type === 'idArray' || this.collectionMap[collection].type === 'template') {
|
||||
this.idReload(collection);
|
||||
}
|
||||
}
|
||||
else { // Not array data
|
||||
this.d[collection] = new this.collectionMap[collection].model().deserialize(data);
|
||||
}
|
||||
f();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Generate id object
|
||||
idReload(collection) {
|
||||
this.id[collection] = this.arr[collection].reduce((s, e) => {s[e._id] = e; return s; }, {});
|
||||
if (this.collectionMap[collection].type === 'template') { // Generate array with latest templates
|
||||
const tmpTemplates = {};
|
||||
this.arr[collection].forEach(template => {
|
||||
if (tmpTemplates[template.first_id]) { // Already found another version
|
||||
if (template.version > tmpTemplates[template.first_id].version) {
|
||||
tmpTemplates[template.first_id] = template;
|
||||
}
|
||||
}
|
||||
else {
|
||||
tmpTemplates[template.first_id] = template;
|
||||
}
|
||||
});
|
||||
this.latest[collection] = Object.values(tmpTemplates);
|
||||
}
|
||||
}
|
||||
// Generate id object
|
||||
idReload(collection) {
|
||||
this.id[collection] = this.arr[collection].reduce((s, e) => {s[e._id] = e; return s; }, {});
|
||||
if (this.collectionMap[collection].type === 'template') { // Generate array with latest templates
|
||||
const tmpTemplates = {};
|
||||
this.arr[collection].forEach(template => {
|
||||
if (tmpTemplates[template.first_id]) { // Already found another version
|
||||
if (template.version > tmpTemplates[template.first_id].version) {
|
||||
tmpTemplates[template.first_id] = template;
|
||||
}
|
||||
}
|
||||
else {
|
||||
tmpTemplates[template.first_id] = template;
|
||||
}
|
||||
});
|
||||
this.latest[collection] = Object.values(tmpTemplates);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user