added templates component

This commit is contained in:
VLE2FE
2020-07-27 17:52:03 +02:00
parent 15aeeb27ee
commit 55248e25ef
42 changed files with 862 additions and 57 deletions

View File

@ -9,7 +9,10 @@ import {Observable} from 'rxjs';
})
export class LoginService implements CanActivate {
private maintainPaths = ['templates'];
private loggedIn;
private level;
constructor(
private api: ApiService,
@ -27,6 +30,7 @@ export class LoginService implements CanActivate {
if (!error) {
if (data.status === 'Authorization successful') {
this.loggedIn = true;
this.level = data.level;
resolve(true);
} else {
this.loggedIn = false;
@ -49,14 +53,21 @@ export class LoginService implements CanActivate {
canActivate(route: ActivatedRouteSnapshot = null, state: RouterStateSnapshot = null): Observable<boolean> {
return new Observable<boolean>(observer => {
if (this.loggedIn === undefined) {
this.login().then(res => {
observer.next(res as any);
const isMaintainPath = this.maintainPaths.indexOf(route.url[0].path) >= 0;
if (!isMaintainPath || (isMaintainPath && this.isMaintain)) {
if (this.loggedIn === undefined) {
this.login().then(res => {
observer.next(res as any);
observer.complete();
});
}
else {
observer.next(this.loggedIn);
observer.complete();
});
}
}
else {
observer.next(this.loggedIn);
observer.next(false);
observer.complete();
}
});
@ -66,6 +77,10 @@ export class LoginService implements CanActivate {
return this.loggedIn;
}
get isMaintain() {
return this.level === 'maintain' || this.level === 'admin';
}
get username() {
return atob(this.storage.get('basicAuth')).split(':')[0];
}

View File

@ -121,4 +121,53 @@ export class ValidationService {
}
return {ok: true, error: ''};
}
parameterName(data) {
const {ignore, error} = Joi.string()
.max(128)
.invalid('condition_template', 'material_template')
.pattern(/^[^.]+$/)
.required()
.messages({'string.pattern.base': 'name must not contain a dot'})
.validate(data);
if (error) {
return {ok: false, error: error.details[0].message};
}
return {ok: true, error: ''};
}
parameterRange(data) {
if (data) {
try {
const {ignore, error} = Joi.object({
values: Joi.array()
.min(1),
min: Joi.number(),
max: Joi.number(),
type: Joi.string()
.valid('array')
})
.oxor('values', 'min')
.oxor('values', 'max')
.oxor('type', 'values')
.oxor('type', 'min')
.oxor('type', 'max')
.required()
.validate(JSON.parse(data));
if (error) {
return {ok: false, error: error.details[0].message};
}
}
catch (e) {
return {ok: false, error: `no valid JSON`};
}
return {ok: true, error: ''};
}
else {
return {ok: false, error: `no valid value`};
}
}
}