From 852d4ec9541550e07d40781790d1e8b767e0c3d2 Mon Sep 17 00:00:00 2001 From: Adsumus Date: Sun, 26 Apr 2020 22:50:26 +0300 Subject: [PATCH] WIP on es support --- ui-ngx/src/app/core/utils.ts | 16 ++++++--- .../components/widget/lib/maps/map-widget2.ts | 35 ++++++++++--------- ui-ngx/src/tslint.json | 6 +++- 3 files changed, 34 insertions(+), 23 deletions(-) diff --git a/ui-ngx/src/app/core/utils.ts b/ui-ngx/src/app/core/utils.ts index 5ee772a0c1..1f57ea2910 100644 --- a/ui-ngx/src/app/core/utils.ts +++ b/ui-ngx/src/app/core/utils.ts @@ -510,14 +510,13 @@ export function safeExecute(func: Function, params = []) { return res; } -export function parseFunction(source: any, params: string[] = []): Function { +export function parseFunction(source: any, params: string[] = ['def']): Function { let res = null; if (source?.length) { try { res = new Function(...params, source); } catch (err) { - console.error(err); res = null; } } @@ -537,17 +536,24 @@ export function parseTemplate(template: string, data: object, translateFn?: (key template = template.replace(match, translateFn(match.match(translateRegexp)[1])); }); } + /* const expressions = template.match(/\{(.*?)\}/g); if (expressions) { - const clearMatches = template.match(/(.)/g); + const clearMatches = template.match(/\$\{([^}]*?)\}/g); for (const key in data) { if (!key.includes('|')) - variables += `let ${key} = '${clearMatches[key] ? padValue(data[key], +clearMatches[key]) : data[key]}';`; + variables += `var ${key} = '${clearMatches[key] ? padValue(data[key], +clearMatches[key]) : data[key]}';`; } template = template.replace(/\:\d+\}/g, '}'); + const interpolator = new Interpolator({delimeter: ['${', '}']}); + interpolator.parse(template, data); res = safeExecute(parseFunction(variables + ' return' + '`' + template + '`')); } - else res = template; + else res = template;*/ + const compiled = _.template(template, { + interpolate: /${([\s\S]+?)}/g + }); + res = compiled(data) } catch (ex) { console.log(ex, variables, template) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts index 10f643e618..41d683fe63 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts @@ -42,7 +42,7 @@ import { AttributeScope } from '@shared/models/telemetry/telemetry.models'; import { AttributeService } from '@core/http/attribute.service'; import { Type } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; -import { UtilsService } from '@app/core/services/utils.service'; +import { UtilsService } from '@core/services/utils.service'; // @dynamic export class MapWidgetController implements MapWidgetInterface { @@ -85,26 +85,27 @@ export class MapWidgetController implements MapWidgetInterface { public static getProvidersSchema(mapProvider: MapProviders) { mapProviderSchema.schema.properties.provider.default = mapProvider; return mergeSchemes([mapProviderSchema, - ...Object.values(providerSets)?.map( - (setting: IProvider) => addCondition(setting?.schema, `model.provider === '${setting.name}'`))]); + ...Object.keys(providerSets)?.map( + (key: string) => { const setting = providerSets[key]; return addCondition(setting?.schema, `model.provider === '${setting.name}'`) })]); } public static settingsSchema(mapProvider: MapProviders, drawRoutes: boolean): JsonSettingsSchema { const schema = initSchema(); addToSchema(schema, this.getProvidersSchema(mapProvider)); - if(mapProvider!=='image-map'){ + if (mapProvider !== 'image-map') { addGroupInfo(schema, 'Map Provider Settings'); - addToSchema(schema, mergeSchemes([commonMapSettingsSchema, addCondition(mapPolygonSchema, 'model.showPolygon === true')])); - addGroupInfo(schema, 'Common Map Settings'); - if (drawRoutes) { - addToSchema(schema, routeMapSettingsSchema); - addGroupInfo(schema, 'Route Map Settings'); - } else if (mapProvider !== 'image-map') { - const clusteringSchema = mergeSchemes([markerClusteringSettingsSchema, - addCondition(markerClusteringSettingsSchemaLeaflet, `model.useClusterMarkers === true`)]) - addToSchema(schema, clusteringSchema); - addGroupInfo(schema, 'Markers Clustering Settings'); - }} + addToSchema(schema, mergeSchemes([commonMapSettingsSchema, addCondition(mapPolygonSchema, 'model.showPolygon === true')])); + addGroupInfo(schema, 'Common Map Settings'); + if (drawRoutes) { + addToSchema(schema, routeMapSettingsSchema); + addGroupInfo(schema, 'Route Map Settings'); + } else if (mapProvider !== 'image-map') { + const clusteringSchema = mergeSchemes([markerClusteringSettingsSchema, + addCondition(markerClusteringSettingsSchemaLeaflet, `model.useClusterMarkers === true`)]) + addToSchema(schema, clusteringSchema); + addGroupInfo(schema, 'Markers Clustering Settings'); + } + } return schema; } @@ -125,7 +126,7 @@ export class MapWidgetController implements MapWidgetInterface { }; } - translate = (key: string, defaultTranslation?: string):string => { + translate = (key: string, defaultTranslation?: string): string => { return (this.ctx.$injector.get(UtilsService).customTranslation(key, defaultTranslation || key) || this.ctx.$injector.get(TranslateService).instant(key)); } @@ -143,7 +144,7 @@ export class MapWidgetController implements MapWidgetInterface { } private onCustomAction(descriptor: WidgetActionDescriptor, $event: any) { - if ($event & $event.stopPropagation) { + if ($event && $event.stopPropagation) { $event?.stopPropagation(); } // safeExecute(parseFunction(descriptor.customFunction, ['$event', 'widgetContext']), [$event, this.ctx]) diff --git a/ui-ngx/src/tslint.json b/ui-ngx/src/tslint.json index 839fcd0d77..3bccc99f12 100644 --- a/ui-ngx/src/tslint.json +++ b/ui-ngx/src/tslint.json @@ -12,6 +12,10 @@ "element", "tb", "kebab-case" - ] + ], + "import-blacklist": [ + true, + ["^.*/public-api$"] + ] } }