added help component, improved prediction with model templates

This commit is contained in:
VLE2FE
2020-08-20 10:42:02 +02:00
parent 9c2095c31a
commit 433572f819
25 changed files with 459 additions and 65 deletions

View File

@ -5,6 +5,7 @@ import {Observable} from 'rxjs';
import {ErrorComponent} from '../error/error.component';
import {ModalService} from '@inst-iot/bosch-angular-ui-components';
// TODO: find solution when client wants to visit subpage but is not logged in to redirect to login without showing request failed errors
@Injectable({
providedIn: 'root'

View File

@ -4,6 +4,7 @@ import {ApiService} from './api.service';
import {MaterialModel} from '../models/material.model';
import {BaseModel} from '../models/base.model';
import {UserModel} from '../models/user.model';
import {ModelItemModel} from '../models/model-item.model';
@Injectable({
providedIn: 'root'
@ -15,14 +16,15 @@ export class DataService {
) { }
private collectionMap = {
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'},
materials: {path: '/materials?status=all', 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: 'array'},
users: {path: '/users', model: UserModel, type: 'array'},
sampleNotesFields: {path: '/sample/notes/fields', model: TemplateModel, type: 'idArray'},
users: {path: '/users', model: UserModel, type: 'idArray'},
modelGroups: {path: '/model/groups', model: ModelItemModel, type: 'array'},
user: {path: '/user', model: UserModel, type: 'string'},
userKey: {path: '/user/key', model: BaseModel, type: 'string'}
};
@ -32,6 +34,8 @@ export class DataService {
id: {[key: string]: {[id: string]: any}} = {}; // data in format _id: data
d: {[key: string]: any} = {}; // data not in array format
contact = 'dominic.lingenfelser@bosch.com';
load(collection, f = () => {}) { // load data
if (this.arr[collection]) { // data already loaded
f();
@ -41,20 +45,8 @@ export class DataService {
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);
if (this.collectionMap[collection].type === 'idArray' || this.collectionMap[collection].type === 'template') {
this.idReload(collection);
}
}
else { // not array data
@ -67,5 +59,19 @@ export class DataService {
idReload(collection) {
this.id[collection] = this.arr[collection].reduce((s, e) => {s[e._id] = e; return s; }, {});
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);
}
}
}

View File

@ -103,6 +103,14 @@ export class ValidationService {
return {ok: true, error: ''};
}
url(data) {
const {ignore, error} = Joi.string().uri().validate(data);
if (error) {
return {ok: false, error: `must be a valid URL`};
}
return {ok: true, error: ''};
}
unique(data, list) {
const {ignore, error} = Joi.string().allow('').invalid(...list.map(e => e.toString())).validate(data);
if (error) {