...
|
...
|
@@ -25,6 +25,7 @@ import extensionDialogTemplate from './extension-dialog.tpl.html'; |
25
|
25
|
/* eslint-enable import/no-unresolved, import/default */
|
26
|
26
|
|
27
|
27
|
import ExtensionDialogController from './extension-dialog.controller'
|
|
28
|
+import $ from 'jquery';
|
28
|
29
|
|
29
|
30
|
/*@ngInject*/
|
30
|
31
|
export default function ExtensionTableDirective() {
|
...
|
...
|
@@ -72,6 +73,15 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, |
72
|
73
|
|
73
|
74
|
$scope.$watch("vm.entityId", function(newVal) {
|
74
|
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
|
85
|
reloadExtensions();
|
76
|
86
|
}
|
77
|
87
|
});
|
...
|
...
|
@@ -205,12 +215,18 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, |
205
|
215
|
}
|
206
|
216
|
|
207
|
217
|
function reloadExtensions() {
|
|
218
|
+ vm.subscribed = false;
|
208
|
219
|
vm.allExtensions.length = 0;
|
209
|
220
|
vm.extensions.length = 0;
|
210
|
221
|
vm.extensionsPromise = attributeService.getEntityAttributesValues(vm.entityType, vm.entityId, types.attributesScope.shared.value, ["configuration"]);
|
211
|
222
|
vm.extensionsPromise.then(
|
212
|
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
|
230
|
vm.selectedExtensions = [];
|
215
|
231
|
updateExtensions();
|
216
|
232
|
vm.extensionsPromise = null;
|
...
|
...
|
@@ -238,52 +254,58 @@ function ExtensionTableController($scope, $filter, $document, $translate, types, |
238
|
254
|
vm.extensionsCount = result.length;
|
239
|
255
|
var startIndex = vm.query.limit * (vm.query.page - 1);
|
240
|
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
|
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
|
300
|
function checkForSync() {
|
282
|
|
- if (vm.appliedConfiguration === vm.extensionsJSON) {
|
|
301
|
+ if (vm.appliedConfiguration && vm.extensionsJSON && vm.appliedConfiguration === vm.extensionsJSON) {
|
283
|
302
|
vm.syncStatus = $translate.instant('extension.sync.sync');
|
284
|
303
|
vm.syncLastTime = formatDate();
|
|
304
|
+ $scope.isSync = true;
|
285
|
305
|
} else {
|
286
|
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
|
328
|
return num;
|
307
|
329
|
}
|
308
|
330
|
}
|
309
|
|
-
|
310
|
|
-
|
311
|
|
- //telemetryWebsocketService.subscribe(subscriber);
|
312
|
331
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|