refactor: update openstapps/api

This commit is contained in:
Rainer Killinger
2021-02-23 12:34:31 +01:00
parent ccf8b1a5cc
commit e9978a2d93
5 changed files with 801 additions and 689 deletions

View File

@@ -116,7 +116,7 @@ export class ContextMenuComponent {
getTranslatedPropertyName(property: string, onlyForType?: SCThingType): string {
return (this.translator
// tslint:disable-next-line:no-any
.translatedPropertyNames(typeof onlyForType !== 'undefined' ? onlyForType : SCThingType.AcademicEvent) as any)[property];
.translatedPropertyNames(onlyForType ?? SCThingType.AcademicEvent) as any)[property];
}
/**

View File

@@ -19,13 +19,8 @@ import {Injectable} from '@angular/core';
export abstract class ThingTranslateParser {
/**
* Gets a value from an object by composed key
* parser.getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA') ==> 'valueI'
*/
abstract getValue(target: unknown, key: string): string;
/**
* TODO
* Gets a value from an object given a keypath
* paser.getValueFromKeyPath(anObject, 'property.subarray[42].etc');
*/
abstract getValueFromKeyPath(instance: object, keypath: string): unknown;
}
@@ -33,34 +28,9 @@ export abstract class ThingTranslateParser {
@Injectable()
export class ThingTranslateDefaultParser extends ThingTranslateParser {
/**
* TODO
*
*/
getValue(target: unknown, key: string): string {
const keys = typeof key === 'string' ? key.split('.') : [key];
let aKey = '';
// tslint:disable-next-line: no-any
let newTarget = target as any;
do {
aKey += keys.shift();
if (isDefined(newTarget) && isDefined(newTarget[aKey]) && (typeof newTarget[aKey] === 'object' || keys.length === 0)) {
newTarget = newTarget[aKey];
aKey = '';
} else if (keys.length === 0) {
newTarget = undefined;
} else {
aKey += '.';
}
} while (keys.length > 0);
return newTarget;
}
getValueFromKeyPath(instance: object, keypath: string): unknown {
// keypath = aproperty[0].anotherproperty["arrayproperty"][42].finalproperty
let path = keypath.replace(/(?:\"|\')'"/gmi, '');
let path = keypath.replace(/(?:\"|\')'"/gmi, '.');
// path = aproperty[0].anotherproperty[.arrayproperty.][42].finalproperty
path = path.replace(/(?:\[|\])/gmi, '.');
// path = aproperty.0..anotherproperty..arrayproperty...42..finalproperty
@@ -80,7 +50,6 @@ export class ThingTranslateDefaultParser extends ThingTranslateParser {
}
}
// tslint:disable-next-line: no-any
export function isDefined(value: any): boolean {
export function isDefined<T>(value?: T | null): value is T {
return typeof value !== 'undefined' && value !== null;
}

View File

@@ -42,7 +42,7 @@ export class ThingTranslatePipe implements PipeTransform, OnDestroy {
this.value = this.thingTranslate.get(thing, key);
}
transform(query: string, thing: SCThings): unknown {
transform(query: unknown, thing: SCThings): unknown {
if (typeof query !== 'string' || query.length <= 0) {
return query;
}
@@ -99,7 +99,6 @@ export class ThingPropertyNameTranslatePipe implements PipeTransform, OnDestroy
onLangChange: Subscription;
constructor(private readonly translate: TranslateService,
// private readonly _ref: ChangeDetectorRef,
private readonly thingTranslate: ThingTranslateService) {
}
@@ -107,7 +106,7 @@ export class ThingPropertyNameTranslatePipe implements PipeTransform, OnDestroy
this.value = this.thingTranslate.getPropertyName(type as SCThingType, key);
}
transform(query: string, thingOrType: SCThings | string): unknown {
transform(query: unknown, thingOrType: SCThings | string | unknown): unknown {
if (typeof query !== 'string' || query.length <= 0) {
return query;
}