Commit 32ece471e94be41803528ad796c6891e6e6f4417

Authored by oleg
1 parent 0374641a

fix devices attributes sync label

@@ -71,7 +71,6 @@ @@ -71,7 +71,6 @@
71 <tb-extension-table flex 71 <tb-extension-table flex
72 entity-id="vm.grid.operatingItem().id.id" 72 entity-id="vm.grid.operatingItem().id.id"
73 entity-type="{{vm.types.entityType.device}}"> 73 entity-type="{{vm.types.entityType.device}}">
74 -  
75 </tb-extension-table> 74 </tb-extension-table>
76 </md-tab> 75 </md-tab>
77 </tb-grid> 76 </tb-grid>
@@ -25,6 +25,7 @@ import extensionDialogTemplate from './extension-dialog.tpl.html'; @@ -25,6 +25,7 @@ import extensionDialogTemplate from './extension-dialog.tpl.html';
25 /* eslint-enable import/no-unresolved, import/default */ 25 /* eslint-enable import/no-unresolved, import/default */
26 26
27 import ExtensionDialogController from './extension-dialog.controller' 27 import ExtensionDialogController from './extension-dialog.controller'
  28 +import $ from 'jquery';
28 29
29 /*@ngInject*/ 30 /*@ngInject*/
30 export default function ExtensionTableDirective() { 31 export default function ExtensionTableDirective() {
@@ -72,6 +73,15 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, @@ -72,6 +73,15 @@ function ExtensionTableController($scope, $filter, $document, $translate, types,
72 73
73 $scope.$watch("vm.entityId", function(newVal) { 74 $scope.$watch("vm.entityId", function(newVal) {
74 if (newVal) { 75 if (newVal) {
  76 + if ($scope.subscriber) {
  77 + telemetryWebsocketService.unsubscribe($scope.subscriber);
  78 + }
  79 +
  80 + vm.subscribed = false;
  81 + vm.syncLastTime = $translate.instant('extension.sync.not-available');
  82 +
  83 + subscribeForClientAttributes();
  84 +
75 reloadExtensions(); 85 reloadExtensions();
76 } 86 }
77 }); 87 });
@@ -205,12 +215,18 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, @@ -205,12 +215,18 @@ function ExtensionTableController($scope, $filter, $document, $translate, types,
205 } 215 }
206 216
207 function reloadExtensions() { 217 function reloadExtensions() {
  218 + vm.subscribed = false;
208 vm.allExtensions.length = 0; 219 vm.allExtensions.length = 0;
209 vm.extensions.length = 0; 220 vm.extensions.length = 0;
210 vm.extensionsPromise = attributeService.getEntityAttributesValues(vm.entityType, vm.entityId, types.attributesScope.shared.value, ["configuration"]); 221 vm.extensionsPromise = attributeService.getEntityAttributesValues(vm.entityType, vm.entityId, types.attributesScope.shared.value, ["configuration"]);
211 vm.extensionsPromise.then( 222 vm.extensionsPromise.then(
212 function success(data) { 223 function success(data) {
213 - vm.allExtensions = angular.fromJson(data[0].value); 224 + if (data.length) {
  225 + vm.allExtensions = angular.fromJson(data[0].value);
  226 + } else {
  227 + vm.allExtensions = [];
  228 + }
  229 +
214 vm.selectedExtensions = []; 230 vm.selectedExtensions = [];
215 updateExtensions(); 231 updateExtensions();
216 vm.extensionsPromise = null; 232 vm.extensionsPromise = null;
@@ -238,52 +254,58 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, @@ -238,52 +254,58 @@ function ExtensionTableController($scope, $filter, $document, $translate, types,
238 vm.extensionsCount = result.length; 254 vm.extensionsCount = result.length;
239 var startIndex = vm.query.limit * (vm.query.page - 1); 255 var startIndex = vm.query.limit * (vm.query.page - 1);
240 vm.extensions = result.slice(startIndex, startIndex + vm.query.limit); 256 vm.extensions = result.slice(startIndex, startIndex + vm.query.limit);
241 - vm.extensionsJSON = angular.toJson(vm.extensions);  
242 - }  
243 -  
244 257
  258 + vm.extensionsJSON = angular.toJson(vm.extensions);
  259 + checkForSync()
245 260
246 - if (vm.entityId && vm.entityType) {  
247 - $scope.subscriber = {  
248 - subscriptionCommands: [{  
249 - entityType: vm.entityType,  
250 - entityId: vm.entityId,  
251 - scope: 'CLIENT_SCOPE'  
252 - }],  
253 - type: 'attribute',  
254 - onData: function (data) {  
255 - if (data.data) {  
256 - onSubscriptionData(data.data);  
257 - }  
258 - }  
259 - };  
260 } 261 }
261 - telemetryWebsocketService.subscribe($scope.subscriber);  
262 -  
263 -  
264 - $scope.$on('$destroy', function() {  
265 - telemetryWebsocketService.unsubscribe($scope.subscriber);  
266 - });  
267 -  
268 -  
269 262
  263 + function subscribeForClientAttributes() {
  264 + if (!vm.subscribed) {
  265 + if (vm.entityId && vm.entityType) {
  266 + $scope.subscriber = {
  267 + subscriptionCommands: [{
  268 + entityType: vm.entityType,
  269 + entityId: vm.entityId,
  270 + scope: 'CLIENT_SCOPE'
  271 + }],
  272 + type: 'attribute',
  273 + onData: function (data) {
  274 + if (data.data) {
  275 + onSubscriptionData(data.data);
  276 + }
  277 + vm.subscribed = true;
  278 + }
  279 + };
  280 + }
  281 + telemetryWebsocketService.subscribe($scope.subscriber);
270 282
  283 + }
  284 + }
271 function onSubscriptionData(data) { 285 function onSubscriptionData(data) {
272 - if (data.appliedConfiguration && data.appliedConfiguration[0] && data.appliedConfiguration[0][1]) {  
273 - vm.appliedConfiguration = data.appliedConfiguration[0][1];  
274 - checkForSync();  
275 - $scope.$digest(); 286 +
  287 + if ($.isEmptyObject(data)) {
  288 + vm.appliedConfiguration = undefined;
  289 + } else {
  290 + if (data.appliedConfiguration && data.appliedConfiguration[0] && data.appliedConfiguration[0][1]) {
  291 + vm.appliedConfiguration = data.appliedConfiguration[0][1];
  292 + }
276 } 293 }
  294 +
  295 + updateExtensions();
  296 + $scope.$digest();
277 } 297 }
278 298
279 299
280 - checkForSync();  
281 function checkForSync() { 300 function checkForSync() {
282 - if (vm.appliedConfiguration === vm.extensionsJSON) { 301 + if (vm.appliedConfiguration && vm.extensionsJSON && vm.appliedConfiguration === vm.extensionsJSON) {
283 vm.syncStatus = $translate.instant('extension.sync.sync'); 302 vm.syncStatus = $translate.instant('extension.sync.sync');
284 vm.syncLastTime = formatDate(); 303 vm.syncLastTime = formatDate();
  304 + $scope.isSync = true;
285 } else { 305 } else {
286 vm.syncStatus = $translate.instant('extension.sync.not-sync'); 306 vm.syncStatus = $translate.instant('extension.sync.not-sync');
  307 +
  308 + $scope.isSync = false;
287 } 309 }
288 } 310 }
289 311
@@ -306,7 +328,4 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, @@ -306,7 +328,4 @@ function ExtensionTableController($scope, $filter, $document, $translate, types,
306 return num; 328 return num;
307 } 329 }
308 } 330 }
309 -  
310 -  
311 - //telemetryWebsocketService.subscribe(subscriber);  
312 } 331 }
@@ -83,7 +83,7 @@ @@ -83,7 +83,7 @@
83 <md-input-container flex="50" class="md-block"> 83 <md-input-container flex="50" class="md-block">
84 <label translate>extension.sync.status</label> 84 <label translate>extension.sync.status</label>
85 <input ng-model="vm.syncStatus" 85 <input ng-model="vm.syncStatus"
86 - ng-class="{'extension__syncStatus--green':vm.appliedConfiguration === vm.extensionsJSON, 'extension__syncStatus--red':vm.appliedConfiguration !== vm.extensionsJSON}" 86 + ng-class="{'extension__syncStatus--green':isSync, 'extension__syncStatus--red':!isSync}"
87 disabled 87 disabled
88 > 88 >
89 </md-input-container> 89 </md-input-container>
@@ -766,14 +766,6 @@ export default angular.module('thingsboard.locale', []) @@ -766,14 +766,6 @@ export default angular.module('thingsboard.locale', [])
766 "add-map": "Add mapping element", 766 "add-map": "Add mapping element",
767 "timeseries": "Timeseries", 767 "timeseries": "Timeseries",
768 "add-timeseries": "Add timeseries", 768 "add-timeseries": "Add timeseries",
769 -  
770 - "sync": {  
771 - "status": "Status",  
772 - "sync": "Sync",  
773 - "not-sync": "Not sync",  
774 - "last-sync-time": "Last sync time",  
775 - },  
776 -  
777 "field-required": "Field is required", 769 "field-required": "Field is required",
778 "brokers": "Brokers", 770 "brokers": "Brokers",
779 "add-broker": "Add broker", 771 "add-broker": "Add broker",
@@ -847,6 +839,14 @@ export default angular.module('thingsboard.locale', []) @@ -847,6 +839,14 @@ export default angular.module('thingsboard.locale', [])
847 "opc-keystore-key-password":"Key password", 839 "opc-keystore-key-password":"Key password",
848 "opc-device-node-pattern":"Device node pattern", 840 "opc-device-node-pattern":"Device node pattern",
849 "opc-device-name-pattern":"Device name pattern", 841 "opc-device-name-pattern":"Device name pattern",
  842 +
  843 + "sync": {
  844 + "status": "Status",
  845 + "sync": "Sync",
  846 + "not-sync": "Not sync",
  847 + "last-sync-time": "Last sync time",
  848 + "not-available": "Not available"
  849 + },
850 }, 850 },
851 "fullscreen": { 851 "fullscreen": {
852 "expand": "Expand to fullscreen", 852 "expand": "Expand to fullscreen",