From ec7ea7042a46e5cbbf460ae25fd9c65b5585bb7b Mon Sep 17 00:00:00 2001 From: Vladyslav Prykhodko Date: Mon, 10 Aug 2020 00:15:09 +0300 Subject: [PATCH] Fixed loading of data used by post-processing function in key settings for map widgets --- ui-ngx/package-lock.json | 46 ++++++++++++++++--- ui-ngx/package.json | 2 +- ui-ngx/src/app/core/utils.ts | 4 ++ .../components/widget/lib/maps/leaflet-map.ts | 6 +-- .../components/widget/lib/maps/maps-utils.ts | 4 +- .../widget/lib/maps/providers/image-map.ts | 4 +- 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/ui-ngx/package-lock.json b/ui-ngx/package-lock.json index 0478e37ac8..443b1e5999 100644 --- a/ui-ngx/package-lock.json +++ b/ui-ngx/package-lock.json @@ -2127,9 +2127,9 @@ } }, "@types/leaflet": { - "version": "1.5.12", - "resolved": "https://registry.npmjs.org/@types/leaflet/-/leaflet-1.5.12.tgz", - "integrity": "sha512-61HRMIng+bWvnnAIqUWLBlrd/TQZc4gU+gN1JL4K47EDtwIrcMEhWgi7PdcpbG1YmpH4F0EfOimkvV82gJIl9w==", + "version": "1.5.17", + "resolved": "https://registry.npmjs.org/@types/leaflet/-/leaflet-1.5.17.tgz", + "integrity": "sha512-2XYq9k6kNjhNI7PaTz8Rdxcc8Vzwu97OaS9CtcrTxnTSxFUGwjlGjTDvhTLJU+JRSfZ4lBwGcl0SjZHALdVr6g==", "dev": true, "requires": { "@types/geojson": "*" @@ -3100,6 +3100,16 @@ "integrity": "sha512-Phlt0plgpIIBOGTT/ehfFnbNlfsDEiqmzE2KRXoX1bLIlir4X/MR+zSyBEkL05ffWgnRSf/DXv+WrUAVr93/ow==", "dev": true }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "dev": true, + "optional": true, + "requires": { + "file-uri-to-path": "1.0.0" + } + }, "blob": { "version": "0.0.5", "resolved": "https://registry.npmjs.org/blob/-/blob-0.0.5.tgz", @@ -5843,6 +5853,13 @@ "tslib": "^1.9.0" } }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "dev": true, + "optional": true + }, "fileset": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/fileset/-/fileset-2.0.3.tgz", @@ -8938,6 +8955,13 @@ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==", "dev": true }, + "nan": { + "version": "2.14.1", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.1.tgz", + "integrity": "sha512-isWHgVjnFjh2x2yuJ/tj3JbwoHu3UC2dX5G/88Cm24yB6YopVgxvBObDY7n5xW6ExmFhJpSEQqFPvq9zaXc8Jw==", + "dev": true, + "optional": true + }, "nanomatch": { "version": "1.2.13", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", @@ -8997,10 +9021,10 @@ "integrity": "sha512-4O3GWAYJaauMCILm07weko2rHA8a4kjn7+8Lg4s1d7SxwS/3IpkVD/GljbRrIJ1c1W/XGJ3GbuK7RyYZEJChhw==" }, "ngx-flowchart": { - "version": "git://github.com/thingsboard/ngx-flowchart.git#7a02f4748b5e7821a883c903107af5f20415d026", + "version": "git://github.com/thingsboard/ngx-flowchart.git#97a77477ca8579becf0e3a07866046b4536fe30a", "from": "git://github.com/thingsboard/ngx-flowchart.git#master", "requires": { - "tslib": "^1.13.0" + "tslib": "^1.10.0" }, "dependencies": { "tslib": { @@ -14065,7 +14089,11 @@ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", "dev": true, - "optional": true + "optional": true, + "requires": { + "bindings": "^1.5.0", + "nan": "^2.12.1" + } }, "is-binary-path": { "version": "1.0.1", @@ -14500,7 +14528,11 @@ "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.13.tgz", "integrity": "sha512-oWb1Z6mkHIskLzEJ/XWX0srkpkTQ7vaopMQkyaEIoq0fmtFVxOthb8cCxeT+p3ynTdkk/RZwbgG4brR5BeWECw==", "dev": true, - "optional": true + "optional": true, + "requires": { + "bindings": "^1.5.0", + "nan": "^2.12.1" + } }, "is-absolute-url": { "version": "3.0.3", diff --git a/ui-ngx/package.json b/ui-ngx/package.json index 9f6b79d24b..8a463512e1 100644 --- a/ui-ngx/package.json +++ b/ui-ngx/package.json @@ -106,7 +106,7 @@ "@types/js-beautify": "^1.8.2", "@types/jstree": "^3.3.40", "@types/jszip": "^3.4.1", - "@types/leaflet": "^1.5.12", + "@types/leaflet": "^1.5.17", "@types/leaflet-markercluster": "^1.0.3", "@types/leaflet-polylinedecorator": "^1.6.0", "@types/lodash": "^4.14.151", diff --git a/ui-ngx/src/app/core/utils.ts b/ui-ngx/src/app/core/utils.ts index e4823664bb..f8ccb6ae61 100644 --- a/ui-ngx/src/app/core/utils.ts +++ b/ui-ngx/src/app/core/utils.ts @@ -89,6 +89,10 @@ export function isDefinedAndNotNull(value: any): boolean { return typeof value !== 'undefined' && value !== null; } +export function isDefinedAndNotEmptyStr(value: any): boolean { + return typeof value !== 'undefined' && value !== ''; +} + export function isFunction(value: any): boolean { return typeof value === 'function'; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet-map.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet-map.ts index 33c36e3ce8..ddb84fc77b 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet-map.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet-map.ts @@ -44,7 +44,7 @@ import { Polygon } from './polygon'; import { createLoadingDiv, createTooltip, parseArray, safeExecute } from '@home/components/widget/lib/maps/maps-utils'; import { WidgetContext } from '@home/models/widget-component.models'; import { DatasourceData } from '@shared/models/widget.models'; -import { deepClone, isDefinedAndNotNull } from '@core/utils'; +import { deepClone, isDefinedAndNotEmptyStr } from '@core/utils'; export default abstract class LeafletMap { @@ -276,7 +276,7 @@ export default abstract class LeafletMap { if (!expression) return null; const lat = expression[this.options.latKeyName]; const lng = expression[this.options.lngKeyName]; - if (!isDefinedAndNotNull(lat) || isNaN(lat) || !isDefinedAndNotNull(lng) || isNaN(lng)) { + if (!isDefinedAndNotEmptyStr(lat) || isNaN(lat) || !isDefinedAndNotEmptyStr(lng) || isNaN(lng)) { return null; } return L.latLng(lat, lng) as L.LatLng; @@ -524,7 +524,7 @@ export default abstract class LeafletMap { const keys: string[] = []; this.polygonsData = deepClone(polyData); polyData.forEach((data: FormattedData) => { - if (data && data.hasOwnProperty(this.options.polygonKeyName) && data[this.options.polygonKeyName] !== null) { + if (data && isDefinedAndNotEmptyStr(data[this.options.polygonKeyName])) { if (typeof (data[this.options.polygonKeyName]) === 'string') { data[this.options.polygonKeyName] = JSON.parse(data[this.options.polygonKeyName]); } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/maps-utils.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/maps-utils.ts index a94144c061..87b99d3499 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/maps-utils.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/maps-utils.ts @@ -341,8 +341,8 @@ export function parseData(input: DatasourceData[]): FormattedData[] { }; entityArray.filter(el => el.data.length).forEach(el => { const indexDate = el?.data?.length ? el.data.length - 1 : 0; - obj[el?.dataKey?.label] = el?.data[indexDate][0] ? el?.data[indexDate][1] : null; - obj[el?.dataKey?.label + '|ts'] = el?.data[indexDate][0] || null; + obj[el?.dataKey?.label] = el?.data[indexDate][1]; + obj[el?.dataKey?.label + '|ts'] = el?.data[indexDate][0]; if (el?.dataKey?.label === 'type') { obj.deviceType = el?.data[indexDate][1]; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts index b8c0a9c82e..82f8120bac 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts @@ -24,7 +24,7 @@ import { WidgetContext } from '@home/models/widget-component.models'; import { DataSet, DatasourceType, widgetType } from '@shared/models/widget.models'; import { DataKeyType } from '@shared/models/telemetry/telemetry.models'; import { WidgetSubscriptionOptions } from '@core/api/widget-api.models'; -import { isDefinedAndNotNull } from '@core/utils'; +import { isDefinedAndNotEmptyStr } from '@core/utils'; const maxZoom = 4;// ? @@ -212,7 +212,7 @@ export class ImageMap extends LeafletMap { convertPosition(expression): L.LatLng { const xPos = expression[this.options.xPosKeyName]; const yPos = expression[this.options.yPosKeyName]; - if (!isDefinedAndNotNull(xPos) || isNaN(xPos) || !isDefinedAndNotNull(yPos) || isNaN(yPos)) { + if (!isDefinedAndNotEmptyStr(xPos) || isNaN(xPos) || !isDefinedAndNotEmptyStr(yPos) || isNaN(yPos)) { return null; } Object.assign(expression, this.posFunction(xPos, yPos));