Browse Source

WIP on es support

pull/2678/head
Adsumus 7 years ago
parent
commit
852d4ec954
  1. 16
      ui-ngx/src/app/core/utils.ts
  2. 35
      ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts
  3. 6
      ui-ngx/src/tslint.json

16
ui-ngx/src/app/core/utils.ts

@ -510,14 +510,13 @@ export function safeExecute(func: Function, params = []) {
return res; return res;
} }
export function parseFunction(source: any, params: string[] = []): Function { export function parseFunction(source: any, params: string[] = ['def']): Function {
let res = null; let res = null;
if (source?.length) { if (source?.length) {
try { try {
res = new Function(...params, source); res = new Function(...params, source);
} }
catch (err) { catch (err) {
console.error(err);
res = null; res = null;
} }
} }
@ -537,17 +536,24 @@ export function parseTemplate(template: string, data: object, translateFn?: (key
template = template.replace(match, translateFn(match.match(translateRegexp)[1])); template = template.replace(match, translateFn(match.match(translateRegexp)[1]));
}); });
} }
/*
const expressions = template.match(/\{(.*?)\}/g); const expressions = template.match(/\{(.*?)\}/g);
if (expressions) { if (expressions) {
const clearMatches = template.match(/(.)/g); const clearMatches = template.match(/\$\{([^}]*?)\}/g);
for (const key in data) { for (const key in data) {
if (!key.includes('|')) 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, '}'); template = template.replace(/\:\d+\}/g, '}');
const interpolator = new Interpolator({delimeter: ['${', '}']});
interpolator.parse(template, data);
res = safeExecute(parseFunction(variables + ' return' + '`' + template + '`')); 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) { catch (ex) {
console.log(ex, variables, template) console.log(ex, variables, template)

35
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 { AttributeService } from '@core/http/attribute.service';
import { Type } from '@angular/core'; import { Type } from '@angular/core';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { UtilsService } from '@app/core/services/utils.service'; import { UtilsService } from '@core/services/utils.service';
// @dynamic // @dynamic
export class MapWidgetController implements MapWidgetInterface { export class MapWidgetController implements MapWidgetInterface {
@ -85,26 +85,27 @@ export class MapWidgetController implements MapWidgetInterface {
public static getProvidersSchema(mapProvider: MapProviders) { public static getProvidersSchema(mapProvider: MapProviders) {
mapProviderSchema.schema.properties.provider.default = mapProvider; mapProviderSchema.schema.properties.provider.default = mapProvider;
return mergeSchemes([mapProviderSchema, return mergeSchemes([mapProviderSchema,
...Object.values(providerSets)?.map( ...Object.keys(providerSets)?.map(
(setting: IProvider) => addCondition(setting?.schema, `model.provider === '${setting.name}'`))]); (key: string) => { const setting = providerSets[key]; return addCondition(setting?.schema, `model.provider === '${setting.name}'`) })]);
} }
public static settingsSchema(mapProvider: MapProviders, drawRoutes: boolean): JsonSettingsSchema { public static settingsSchema(mapProvider: MapProviders, drawRoutes: boolean): JsonSettingsSchema {
const schema = initSchema(); const schema = initSchema();
addToSchema(schema, this.getProvidersSchema(mapProvider)); addToSchema(schema, this.getProvidersSchema(mapProvider));
if(mapProvider!=='image-map'){ if (mapProvider !== 'image-map') {
addGroupInfo(schema, 'Map Provider Settings'); addGroupInfo(schema, 'Map Provider Settings');
addToSchema(schema, mergeSchemes([commonMapSettingsSchema, addCondition(mapPolygonSchema, 'model.showPolygon === true')])); addToSchema(schema, mergeSchemes([commonMapSettingsSchema, addCondition(mapPolygonSchema, 'model.showPolygon === true')]));
addGroupInfo(schema, 'Common Map Settings'); addGroupInfo(schema, 'Common Map Settings');
if (drawRoutes) { if (drawRoutes) {
addToSchema(schema, routeMapSettingsSchema); addToSchema(schema, routeMapSettingsSchema);
addGroupInfo(schema, 'Route Map Settings'); addGroupInfo(schema, 'Route Map Settings');
} else if (mapProvider !== 'image-map') { } else if (mapProvider !== 'image-map') {
const clusteringSchema = mergeSchemes([markerClusteringSettingsSchema, const clusteringSchema = mergeSchemes([markerClusteringSettingsSchema,
addCondition(markerClusteringSettingsSchemaLeaflet, `model.useClusterMarkers === true`)]) addCondition(markerClusteringSettingsSchemaLeaflet, `model.useClusterMarkers === true`)])
addToSchema(schema, clusteringSchema); addToSchema(schema, clusteringSchema);
addGroupInfo(schema, 'Markers Clustering Settings'); addGroupInfo(schema, 'Markers Clustering Settings');
}} }
}
return schema; 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) return (this.ctx.$injector.get(UtilsService).customTranslation(key, defaultTranslation || key)
|| this.ctx.$injector.get(TranslateService).instant(key)); || this.ctx.$injector.get(TranslateService).instant(key));
} }
@ -143,7 +144,7 @@ export class MapWidgetController implements MapWidgetInterface {
} }
private onCustomAction(descriptor: WidgetActionDescriptor, $event: any) { private onCustomAction(descriptor: WidgetActionDescriptor, $event: any) {
if ($event & $event.stopPropagation) { if ($event && $event.stopPropagation) {
$event?.stopPropagation(); $event?.stopPropagation();
} }
// safeExecute(parseFunction(descriptor.customFunction, ['$event', 'widgetContext']), [$event, this.ctx]) // safeExecute(parseFunction(descriptor.customFunction, ['$event', 'widgetContext']), [$event, this.ctx])

6
ui-ngx/src/tslint.json

@ -12,6 +12,10 @@
"element", "element",
"tb", "tb",
"kebab-case" "kebab-case"
] ],
"import-blacklist": [
true,
["^.*/public-api$"]
]
} }
} }

Loading…
Cancel
Save