added user status and prediction user

This commit is contained in:
VLE2FE
2020-08-26 19:25:31 +02:00
parent 3e53ef874c
commit 6f95ff4148
17 changed files with 178 additions and 74 deletions

View File

@ -34,7 +34,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 = 'dominic.lingenfelser@bosch.com';
contact = {name: 'CR/APS1-Lingenfelser', mail: 'dominic.lingenfelser@bosch.com'};
load(collection, f = () => {}) { // load data
if (this.arr[collection]) { // data already loaded

View File

@ -3,6 +3,7 @@ import {ApiService} from './api.service';
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
import {LocalStorageService} from 'angular-2-local-storage';
import {Observable} from 'rxjs';
import {DataService} from './data.service';
@Injectable({
providedIn: 'root'
@ -15,12 +16,14 @@ export class LoginService implements CanActivate {
{path: 'users', permission: 'admin'}
];
readonly levels = [
'predict',
'read',
'write',
'dev',
'admin'
];
isLevel: {[level: string]: boolean} = {};
hasPrediction = false; // true if user has prediction models specified
userId = '';
private loggedIn;
@ -28,7 +31,8 @@ export class LoginService implements CanActivate {
constructor(
private api: ApiService,
private storage: LocalStorageService,
private router: Router
private router: Router,
private d: DataService
) {
}
@ -60,6 +64,14 @@ export class LoginService implements CanActivate {
this.loggedIn = true;
this.levels.forEach(level => {
this.isLevel[level] = this.levels.indexOf(data.level) >= this.levels.indexOf(level);
if (this.isLevel.dev) { // set hasPrediction
this.hasPrediction = true;
}
else {
this.d.load('modelGroups', () => {
this.hasPrediction = this.d.arr.modelGroups.length > 0;
});
}
});
this.userId = data.user_id;
resolve(true);
@ -83,6 +95,7 @@ export class LoginService implements CanActivate {
this.levels.forEach(level => {
this.isLevel[level] = false;
});
this.hasPrediction = false;
}
canActivate(route: ActivatedRouteSnapshot = null, state: RouterStateSnapshot = null): Observable<boolean> {