code improvements

This commit is contained in:
VLE2FE
2020-09-03 15:51:53 +02:00
parent 1440e9a6fc
commit c38d0be457
73 changed files with 276 additions and 1686 deletions

View File

@ -16,7 +16,7 @@ export class DataService {
private api: ApiService
) { }
private collectionMap = {
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'},
@ -36,7 +36,7 @@ export class DataService {
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'};
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
@ -46,7 +46,11 @@ export class DataService {
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);
.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);
}
@ -59,9 +63,10 @@ export class DataService {
}
}
// 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') {
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