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

1442
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -53,7 +53,7 @@
"@ionic/storage": "2.2.0", "@ionic/storage": "2.2.0",
"@ngx-translate/core": "11.0.1", "@ngx-translate/core": "11.0.1",
"@ngx-translate/http-loader": "4.0.0", "@ngx-translate/http-loader": "4.0.0",
"@openstapps/api": "0.25.0", "@openstapps/api": "0.26.0",
"@openstapps/configuration": "0.25.0", "@openstapps/configuration": "0.25.0",
"@openstapps/core": "0.42.0", "@openstapps/core": "0.42.0",
"cordova-android": "9.0.0", "cordova-android": "9.0.0",

View File

@@ -116,7 +116,7 @@ export class ContextMenuComponent {
getTranslatedPropertyName(property: string, onlyForType?: SCThingType): string { getTranslatedPropertyName(property: string, onlyForType?: SCThingType): string {
return (this.translator return (this.translator
// tslint:disable-next-line:no-any // 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 { export abstract class ThingTranslateParser {
/** /**
* Gets a value from an object by composed key * Gets a value from an object given a keypath
* parser.getValue({ key1: { keyA: 'valueI' }}, 'key1.keyA') ==> 'valueI' * paser.getValueFromKeyPath(anObject, 'property.subarray[42].etc');
*/
abstract getValue(target: unknown, key: string): string;
/**
* TODO
*/ */
abstract getValueFromKeyPath(instance: object, keypath: string): unknown; abstract getValueFromKeyPath(instance: object, keypath: string): unknown;
} }
@@ -33,34 +28,9 @@ export abstract class ThingTranslateParser {
@Injectable() @Injectable()
export class ThingTranslateDefaultParser extends ThingTranslateParser { 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 { getValueFromKeyPath(instance: object, keypath: string): unknown {
// keypath = aproperty[0].anotherproperty["arrayproperty"][42].finalproperty // 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 = aproperty[0].anotherproperty[.arrayproperty.][42].finalproperty
path = path.replace(/(?:\[|\])/gmi, '.'); path = path.replace(/(?:\[|\])/gmi, '.');
// path = aproperty.0..anotherproperty..arrayproperty...42..finalproperty // 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<T>(value?: T | null): value is T {
export function isDefined(value: any): boolean {
return typeof value !== 'undefined' && value !== null; 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); 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) { if (typeof query !== 'string' || query.length <= 0) {
return query; return query;
} }
@@ -99,7 +99,6 @@ export class ThingPropertyNameTranslatePipe implements PipeTransform, OnDestroy
onLangChange: Subscription; onLangChange: Subscription;
constructor(private readonly translate: TranslateService, constructor(private readonly translate: TranslateService,
// private readonly _ref: ChangeDetectorRef,
private readonly thingTranslate: ThingTranslateService) { private readonly thingTranslate: ThingTranslateService) {
} }
@@ -107,7 +106,7 @@ export class ThingPropertyNameTranslatePipe implements PipeTransform, OnDestroy
this.value = this.thingTranslate.getPropertyName(type as SCThingType, key); 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) { if (typeof query !== 'string' || query.length <= 0) {
return query; return query;
} }