fixed material numbers in new dialog
This commit is contained in:
@ -15,19 +15,20 @@ export class DataService {
|
||||
) { }
|
||||
|
||||
private collectionMap = {
|
||||
materials: {path: '/materials?status=all', model: MaterialModel, array: true},
|
||||
materialSuppliers: {path: '/material/suppliers', model: null, array: true},
|
||||
materialGroups: {path: '/material/groups', model: null, array: true},
|
||||
materialTemplates: {path: '/template/materials', model: TemplateModel, array: true},
|
||||
measurementTemplates: {path: '/template/measurements', model: TemplateModel, array: true},
|
||||
conditionTemplates: {path: '/template/conditions', model: TemplateModel, array: true},
|
||||
sampleNotesFields: {path: '/sample/notes/fields', model: TemplateModel, array: true},
|
||||
users: {path: '/users', model: UserModel, array: true},
|
||||
user: {path: '/user', model: UserModel, array: false},
|
||||
userKey: {path: '/user/key', model: BaseModel, array: false}
|
||||
materials: {path: '/materials?status=all', model: MaterialModel, type: 'array'},
|
||||
materialSuppliers: {path: '/material/suppliers', model: null, type: 'array'},
|
||||
materialGroups: {path: '/material/groups', model: null, type: 'array'},
|
||||
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: 'array'},
|
||||
users: {path: '/users', model: UserModel, 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
|
||||
|
||||
@ -37,10 +38,24 @@ export class DataService {
|
||||
}
|
||||
else { // load data
|
||||
this.api.get<any>(this.collectionMap[collection].path, data => {
|
||||
if (this.collectionMap[collection].array) { // array 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);
|
||||
this.idReload(collection);
|
||||
if (this.collectionMap[collection].type === 'template') {
|
||||
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);
|
||||
}
|
||||
}
|
||||
else { // not array data
|
||||
this.d[collection] = new this.collectionMap[collection].model().deserialize(data);
|
||||
|
@ -11,6 +11,7 @@ export class LoginService implements CanActivate {
|
||||
|
||||
private pathPermissions = [
|
||||
{path: 'templates', permission: 'dev'},
|
||||
{path: 'changelog', permission: 'dev'},
|
||||
{path: 'users', permission: 'admin'}
|
||||
];
|
||||
readonly levels = [
|
||||
|
Reference in New Issue
Block a user