Commit 852d4ec9541550e07d40781790d1e8b767e0c3d2

Authored by Adsumus
1 parent 3fe468b2

WIP on es support

... ... @@ -510,14 +510,13 @@ export function safeExecute(func: Function, params = []) {
510 510 return res;
511 511 }
512 512
513   -export function parseFunction(source: any, params: string[] = []): Function {
  513 +export function parseFunction(source: any, params: string[] = ['def']): Function {
514 514 let res = null;
515 515 if (source?.length) {
516 516 try {
517 517 res = new Function(...params, source);
518 518 }
519 519 catch (err) {
520   - console.error(err);
521 520 res = null;
522 521 }
523 522 }
... ... @@ -537,17 +536,24 @@ export function parseTemplate(template: string, data: object, translateFn?: (key
537 536 template = template.replace(match, translateFn(match.match(translateRegexp)[1]));
538 537 });
539 538 }
  539 + /*
540 540 const expressions = template.match(/\{(.*?)\}/g);
541 541 if (expressions) {
542   - const clearMatches = template.match(/(.)/g);
  542 + const clearMatches = template.match(/\$\{([^}]*?)\}/g);
543 543 for (const key in data) {
544 544 if (!key.includes('|'))
545   - variables += `let ${key} = '${clearMatches[key] ? padValue(data[key], +clearMatches[key]) : data[key]}';`;
  545 + variables += `var ${key} = '${clearMatches[key] ? padValue(data[key], +clearMatches[key]) : data[key]}';`;
546 546 }
547 547 template = template.replace(/\:\d+\}/g, '}');
  548 + const interpolator = new Interpolator({delimeter: ['${', '}']});
  549 + interpolator.parse(template, data);
548 550 res = safeExecute(parseFunction(variables + ' return' + '`' + template + '`'));
549 551 }
550   - else res = template;
  552 + else res = template;*/
  553 + const compiled = _.template(template, {
  554 + interpolate: /${([\s\S]+?)}/g
  555 + });
  556 + res = compiled(data)
551 557 }
552 558 catch (ex) {
553 559 console.log(ex, variables, template)
... ...
... ... @@ -42,7 +42,7 @@ import { AttributeScope } from '@shared/models/telemetry/telemetry.models';
42 42 import { AttributeService } from '@core/http/attribute.service';
43 43 import { Type } from '@angular/core';
44 44 import { TranslateService } from '@ngx-translate/core';
45   -import { UtilsService } from '@app/core/services/utils.service';
  45 +import { UtilsService } from '@core/services/utils.service';
46 46
47 47 // @dynamic
48 48 export class MapWidgetController implements MapWidgetInterface {
... ... @@ -85,26 +85,27 @@ export class MapWidgetController implements MapWidgetInterface {
85 85 public static getProvidersSchema(mapProvider: MapProviders) {
86 86 mapProviderSchema.schema.properties.provider.default = mapProvider;
87 87 return mergeSchemes([mapProviderSchema,
88   - ...Object.values(providerSets)?.map(
89   - (setting: IProvider) => addCondition(setting?.schema, `model.provider === '${setting.name}'`))]);
  88 + ...Object.keys(providerSets)?.map(
  89 + (key: string) => { const setting = providerSets[key]; return addCondition(setting?.schema, `model.provider === '${setting.name}'`) })]);
90 90 }
91 91
92 92 public static settingsSchema(mapProvider: MapProviders, drawRoutes: boolean): JsonSettingsSchema {
93 93 const schema = initSchema();
94 94 addToSchema(schema, this.getProvidersSchema(mapProvider));
95   - if(mapProvider!=='image-map'){
  95 + if (mapProvider !== 'image-map') {
96 96 addGroupInfo(schema, 'Map Provider Settings');
97   - addToSchema(schema, mergeSchemes([commonMapSettingsSchema, addCondition(mapPolygonSchema, 'model.showPolygon === true')]));
98   - addGroupInfo(schema, 'Common Map Settings');
99   - if (drawRoutes) {
100   - addToSchema(schema, routeMapSettingsSchema);
101   - addGroupInfo(schema, 'Route Map Settings');
102   - } else if (mapProvider !== 'image-map') {
103   - const clusteringSchema = mergeSchemes([markerClusteringSettingsSchema,
104   - addCondition(markerClusteringSettingsSchemaLeaflet, `model.useClusterMarkers === true`)])
105   - addToSchema(schema, clusteringSchema);
106   - addGroupInfo(schema, 'Markers Clustering Settings');
107   - }}
  97 + addToSchema(schema, mergeSchemes([commonMapSettingsSchema, addCondition(mapPolygonSchema, 'model.showPolygon === true')]));
  98 + addGroupInfo(schema, 'Common Map Settings');
  99 + if (drawRoutes) {
  100 + addToSchema(schema, routeMapSettingsSchema);
  101 + addGroupInfo(schema, 'Route Map Settings');
  102 + } else if (mapProvider !== 'image-map') {
  103 + const clusteringSchema = mergeSchemes([markerClusteringSettingsSchema,
  104 + addCondition(markerClusteringSettingsSchemaLeaflet, `model.useClusterMarkers === true`)])
  105 + addToSchema(schema, clusteringSchema);
  106 + addGroupInfo(schema, 'Markers Clustering Settings');
  107 + }
  108 + }
108 109 return schema;
109 110 }
110 111
... ... @@ -125,7 +126,7 @@ export class MapWidgetController implements MapWidgetInterface {
125 126 };
126 127 }
127 128
128   - translate = (key: string, defaultTranslation?: string):string => {
  129 + translate = (key: string, defaultTranslation?: string): string => {
129 130 return (this.ctx.$injector.get(UtilsService).customTranslation(key, defaultTranslation || key)
130 131 || this.ctx.$injector.get(TranslateService).instant(key));
131 132 }
... ... @@ -143,7 +144,7 @@ export class MapWidgetController implements MapWidgetInterface {
143 144 }
144 145
145 146 private onCustomAction(descriptor: WidgetActionDescriptor, $event: any) {
146   - if ($event & $event.stopPropagation) {
  147 + if ($event && $event.stopPropagation) {
147 148 $event?.stopPropagation();
148 149 }
149 150 // safeExecute(parseFunction(descriptor.customFunction, ['$event', 'widgetContext']), [$event, this.ctx])
... ...
... ... @@ -12,6 +12,10 @@
12 12 "element",
13 13 "tb",
14 14 "kebab-case"
15   - ]
  15 + ],
  16 + "import-blacklist": [
  17 + true,
  18 + ["^.*/public-api$"]
  19 + ]
16 20 }
17 21 }
... ...