From 32ece471e94be41803528ad796c6891e6e6f4417 Mon Sep 17 00:00:00 2001 From: oleg Date: Thu, 30 Nov 2017 16:15:18 +0200 Subject: [PATCH] fix devices attributes sync label --- ui/src/app/device/devices.tpl.html | 1 - .../extension/extension-table.directive.js | 89 +++++++++++-------- ui/src/app/extension/extension-table.tpl.html | 2 +- ui/src/app/locale/locale.constant.js | 16 ++-- 4 files changed, 63 insertions(+), 45 deletions(-) diff --git a/ui/src/app/device/devices.tpl.html b/ui/src/app/device/devices.tpl.html index e0760c3c94..bc66a79b8b 100644 --- a/ui/src/app/device/devices.tpl.html +++ b/ui/src/app/device/devices.tpl.html @@ -71,7 +71,6 @@ - diff --git a/ui/src/app/extension/extension-table.directive.js b/ui/src/app/extension/extension-table.directive.js index f4f69c4911..8ad8275c15 100644 --- a/ui/src/app/extension/extension-table.directive.js +++ b/ui/src/app/extension/extension-table.directive.js @@ -25,6 +25,7 @@ import extensionDialogTemplate from './extension-dialog.tpl.html'; /* eslint-enable import/no-unresolved, import/default */ import ExtensionDialogController from './extension-dialog.controller' +import $ from 'jquery'; /*@ngInject*/ export default function ExtensionTableDirective() { @@ -72,6 +73,15 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, $scope.$watch("vm.entityId", function(newVal) { if (newVal) { + if ($scope.subscriber) { + telemetryWebsocketService.unsubscribe($scope.subscriber); + } + + vm.subscribed = false; + vm.syncLastTime = $translate.instant('extension.sync.not-available'); + + subscribeForClientAttributes(); + reloadExtensions(); } }); @@ -205,12 +215,18 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, } function reloadExtensions() { + vm.subscribed = false; vm.allExtensions.length = 0; vm.extensions.length = 0; vm.extensionsPromise = attributeService.getEntityAttributesValues(vm.entityType, vm.entityId, types.attributesScope.shared.value, ["configuration"]); vm.extensionsPromise.then( function success(data) { - vm.allExtensions = angular.fromJson(data[0].value); + if (data.length) { + vm.allExtensions = angular.fromJson(data[0].value); + } else { + vm.allExtensions = []; + } + vm.selectedExtensions = []; updateExtensions(); vm.extensionsPromise = null; @@ -238,52 +254,58 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, vm.extensionsCount = result.length; var startIndex = vm.query.limit * (vm.query.page - 1); vm.extensions = result.slice(startIndex, startIndex + vm.query.limit); - vm.extensionsJSON = angular.toJson(vm.extensions); - } - + vm.extensionsJSON = angular.toJson(vm.extensions); + checkForSync() - if (vm.entityId && vm.entityType) { - $scope.subscriber = { - subscriptionCommands: [{ - entityType: vm.entityType, - entityId: vm.entityId, - scope: 'CLIENT_SCOPE' - }], - type: 'attribute', - onData: function (data) { - if (data.data) { - onSubscriptionData(data.data); - } - } - }; } - telemetryWebsocketService.subscribe($scope.subscriber); - - - $scope.$on('$destroy', function() { - telemetryWebsocketService.unsubscribe($scope.subscriber); - }); - - + function subscribeForClientAttributes() { + if (!vm.subscribed) { + if (vm.entityId && vm.entityType) { + $scope.subscriber = { + subscriptionCommands: [{ + entityType: vm.entityType, + entityId: vm.entityId, + scope: 'CLIENT_SCOPE' + }], + type: 'attribute', + onData: function (data) { + if (data.data) { + onSubscriptionData(data.data); + } + vm.subscribed = true; + } + }; + } + telemetryWebsocketService.subscribe($scope.subscriber); + } + } function onSubscriptionData(data) { - if (data.appliedConfiguration && data.appliedConfiguration[0] && data.appliedConfiguration[0][1]) { - vm.appliedConfiguration = data.appliedConfiguration[0][1]; - checkForSync(); - $scope.$digest(); + + if ($.isEmptyObject(data)) { + vm.appliedConfiguration = undefined; + } else { + if (data.appliedConfiguration && data.appliedConfiguration[0] && data.appliedConfiguration[0][1]) { + vm.appliedConfiguration = data.appliedConfiguration[0][1]; + } } + + updateExtensions(); + $scope.$digest(); } - checkForSync(); function checkForSync() { - if (vm.appliedConfiguration === vm.extensionsJSON) { + if (vm.appliedConfiguration && vm.extensionsJSON && vm.appliedConfiguration === vm.extensionsJSON) { vm.syncStatus = $translate.instant('extension.sync.sync'); vm.syncLastTime = formatDate(); + $scope.isSync = true; } else { vm.syncStatus = $translate.instant('extension.sync.not-sync'); + + $scope.isSync = false; } } @@ -306,7 +328,4 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, return num; } } - - - //telemetryWebsocketService.subscribe(subscriber); } \ No newline at end of file diff --git a/ui/src/app/extension/extension-table.tpl.html b/ui/src/app/extension/extension-table.tpl.html index 3a425768eb..428a14666d 100644 --- a/ui/src/app/extension/extension-table.tpl.html +++ b/ui/src/app/extension/extension-table.tpl.html @@ -83,7 +83,7 @@ diff --git a/ui/src/app/locale/locale.constant.js b/ui/src/app/locale/locale.constant.js index cfad9860b3..089a0f5c51 100644 --- a/ui/src/app/locale/locale.constant.js +++ b/ui/src/app/locale/locale.constant.js @@ -766,14 +766,6 @@ export default angular.module('thingsboard.locale', []) "add-map": "Add mapping element", "timeseries": "Timeseries", "add-timeseries": "Add timeseries", - - "sync": { - "status": "Status", - "sync": "Sync", - "not-sync": "Not sync", - "last-sync-time": "Last sync time", - }, - "field-required": "Field is required", "brokers": "Brokers", "add-broker": "Add broker", @@ -847,6 +839,14 @@ export default angular.module('thingsboard.locale', []) "opc-keystore-key-password":"Key password", "opc-device-node-pattern":"Device node pattern", "opc-device-name-pattern":"Device name pattern", + + "sync": { + "status": "Status", + "sync": "Sync", + "not-sync": "Not sync", + "last-sync-time": "Last sync time", + "not-available": "Not available" + }, }, "fullscreen": { "expand": "Expand to fullscreen",