Commit 906b5d47f496b81674993397c9ea67fa981cd965
Committed by
Igor Kulikov
1 parent
3f3fca41
Fix data update in widget on creating a new entity and deleting the last (#1942)
* Fix fullscreen mode for HTML/CSS editors, highlight dividing comments for parts of the sample * Fix data update in widget on creating a new entity and deleting the last
Showing
3 changed files
with
50 additions
and
7 deletions
@@ -37,6 +37,7 @@ export default class Subscription { | @@ -37,6 +37,7 @@ export default class Subscription { | ||
37 | this.id = this.ctx.utils.guid(); | 37 | this.id = this.ctx.utils.guid(); |
38 | this.cafs = {}; | 38 | this.cafs = {}; |
39 | this.registrations = []; | 39 | this.registrations = []; |
40 | + this.hasResolvedData = false; | ||
40 | 41 | ||
41 | var subscription = this; | 42 | var subscription = this; |
42 | var deferred = this.ctx.$q.defer(); | 43 | var deferred = this.ctx.$q.defer(); |
@@ -235,12 +236,16 @@ export default class Subscription { | @@ -235,12 +236,16 @@ export default class Subscription { | ||
235 | var subscription = this; | 236 | var subscription = this; |
236 | this.loadStDiff().then(() => { | 237 | this.loadStDiff().then(() => { |
237 | if (!subscription.ctx.aliasController) { | 238 | if (!subscription.ctx.aliasController) { |
239 | + subscription.hasResolvedData = true; | ||
238 | subscription.configureAlarmsData(); | 240 | subscription.configureAlarmsData(); |
239 | deferred.resolve(); | 241 | deferred.resolve(); |
240 | } else { | 242 | } else { |
241 | subscription.ctx.aliasController.resolveAlarmSource(subscription.alarmSource).then( | 243 | subscription.ctx.aliasController.resolveAlarmSource(subscription.alarmSource).then( |
242 | function success(alarmSource) { | 244 | function success(alarmSource) { |
243 | subscription.alarmSource = alarmSource; | 245 | subscription.alarmSource = alarmSource; |
246 | + if (alarmSource) { | ||
247 | + subscription.hasResolvedData = true; | ||
248 | + } | ||
244 | subscription.configureAlarmsData(); | 249 | subscription.configureAlarmsData(); |
245 | deferred.resolve(); | 250 | deferred.resolve(); |
246 | }, | 251 | }, |
@@ -282,12 +287,16 @@ export default class Subscription { | @@ -282,12 +287,16 @@ export default class Subscription { | ||
282 | var subscription = this; | 287 | var subscription = this; |
283 | this.loadStDiff().then(() => { | 288 | this.loadStDiff().then(() => { |
284 | if (!subscription.ctx.aliasController) { | 289 | if (!subscription.ctx.aliasController) { |
290 | + subscription.hasResolvedData = true; | ||
285 | subscription.configureData(); | 291 | subscription.configureData(); |
286 | deferred.resolve(); | 292 | deferred.resolve(); |
287 | } else { | 293 | } else { |
288 | subscription.ctx.aliasController.resolveDatasources(subscription.datasources).then( | 294 | subscription.ctx.aliasController.resolveDatasources(subscription.datasources).then( |
289 | function success(datasources) { | 295 | function success(datasources) { |
290 | subscription.datasources = datasources; | 296 | subscription.datasources = datasources; |
297 | + if (datasources && datasources.length) { | ||
298 | + subscription.hasResolvedData = true; | ||
299 | + } | ||
291 | subscription.configureData(); | 300 | subscription.configureData(); |
292 | deferred.resolve(); | 301 | deferred.resolve(); |
293 | }, | 302 | }, |
@@ -420,6 +429,7 @@ export default class Subscription { | @@ -420,6 +429,7 @@ export default class Subscription { | ||
420 | } else { | 429 | } else { |
421 | subscription.rpcEnabled = subscription.ctx.$scope.widgetEditMode ? true : false; | 430 | subscription.rpcEnabled = subscription.ctx.$scope.widgetEditMode ? true : false; |
422 | } | 431 | } |
432 | + subscription.hasResolvedData = subscription.rpcEnabled; | ||
423 | subscription.callbacks.rpcStateChanged(subscription); | 433 | subscription.callbacks.rpcStateChanged(subscription); |
424 | deferred.resolve(); | 434 | deferred.resolve(); |
425 | } else { | 435 | } else { |
@@ -443,6 +453,7 @@ export default class Subscription { | @@ -443,6 +453,7 @@ export default class Subscription { | ||
443 | } else { | 453 | } else { |
444 | this.rpcEnabled = this.ctx.$scope.widgetEditMode ? true : false; | 454 | this.rpcEnabled = this.ctx.$scope.widgetEditMode ? true : false; |
445 | } | 455 | } |
456 | + this.hasResolvedData = true; | ||
446 | this.callbacks.rpcStateChanged(this); | 457 | this.callbacks.rpcStateChanged(this); |
447 | deferred.resolve(); | 458 | deferred.resolve(); |
448 | } | 459 | } |
@@ -880,6 +891,10 @@ export default class Subscription { | @@ -880,6 +891,10 @@ export default class Subscription { | ||
880 | return subscriptionsChanged; | 891 | return subscriptionsChanged; |
881 | } | 892 | } |
882 | 893 | ||
894 | + isDataResolved() { | ||
895 | + return this.hasResolvedData; | ||
896 | + } | ||
897 | + | ||
883 | destroy() { | 898 | destroy() { |
884 | this.unsubscribe(); | 899 | this.unsubscribe(); |
885 | for (var cafId in this.cafs) { | 900 | for (var cafId in this.cafs) { |
@@ -466,7 +466,7 @@ function CustomActionPrettyEditor($compile, $templateCache, $window, $timeout) { | @@ -466,7 +466,7 @@ function CustomActionPrettyEditor($compile, $templateCache, $window, $timeout) { | ||
466 | "// tasks.push(widgetContext.aliasController.getAliasInfo(aliasId));\n" + | 466 | "// tasks.push(widgetContext.aliasController.getAliasInfo(aliasId));\n" + |
467 | "// });\n" + | 467 | "// });\n" + |
468 | "// $q.all(tasks).then(function() {\n" + | 468 | "// $q.all(tasks).then(function() {\n" + |
469 | - "// $rootScope.$broadcast('entityAliasesChanged', aliasIds);\n" + | 469 | + "// $rootScope.$broadcast('widgetForceReInit');\n" + |
470 | "// });\n" + | 470 | "// });\n" + |
471 | "// }\n" + | 471 | "// }\n" + |
472 | "//}\n"; | 472 | "//}\n"; |
@@ -312,7 +312,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | @@ -312,7 +312,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | ||
312 | 312 | ||
313 | options.callbacks = { | 313 | options.callbacks = { |
314 | onDataUpdated: function() { | 314 | onDataUpdated: function() { |
315 | - widgetTypeInstance.onDataUpdated(); | 315 | + if (displayWidgetInstance()) { |
316 | + widgetTypeInstance.onDataUpdated(); | ||
317 | + } | ||
316 | }, | 318 | }, |
317 | onDataUpdateError: function(subscription, e) { | 319 | onDataUpdateError: function(subscription, e) { |
318 | handleWidgetException(e); | 320 | handleWidgetException(e); |
@@ -849,7 +851,11 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | @@ -849,7 +851,11 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | ||
849 | if (!widgetContext.inited && isReady()) { | 851 | if (!widgetContext.inited && isReady()) { |
850 | widgetContext.inited = true; | 852 | widgetContext.inited = true; |
851 | try { | 853 | try { |
852 | - widgetTypeInstance.onInit(); | 854 | + if (displayWidgetInstance()) { |
855 | + widgetTypeInstance.onInit(); | ||
856 | + } else { | ||
857 | + $scope.loadingData = false; | ||
858 | + } | ||
853 | } catch (e) { | 859 | } catch (e) { |
854 | handleWidgetException(e); | 860 | handleWidgetException(e); |
855 | } | 861 | } |
@@ -886,7 +892,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | @@ -886,7 +892,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | ||
886 | } | 892 | } |
887 | cafs['resize'] = tbRaf(function() { | 893 | cafs['resize'] = tbRaf(function() { |
888 | try { | 894 | try { |
889 | - widgetTypeInstance.onResize(); | 895 | + if (displayWidgetInstance()) { |
896 | + widgetTypeInstance.onResize(); | ||
897 | + } | ||
890 | } catch (e) { | 898 | } catch (e) { |
891 | handleWidgetException(e); | 899 | handleWidgetException(e); |
892 | } | 900 | } |
@@ -916,7 +924,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | @@ -916,7 +924,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | ||
916 | } | 924 | } |
917 | cafs['editMode'] = tbRaf(function() { | 925 | cafs['editMode'] = tbRaf(function() { |
918 | try { | 926 | try { |
919 | - widgetTypeInstance.onEditModeChanged(); | 927 | + if (displayWidgetInstance()) { |
928 | + widgetTypeInstance.onEditModeChanged(); | ||
929 | + } | ||
920 | } catch (e) { | 930 | } catch (e) { |
921 | handleWidgetException(e); | 931 | handleWidgetException(e); |
922 | } | 932 | } |
@@ -935,7 +945,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | @@ -935,7 +945,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | ||
935 | } | 945 | } |
936 | cafs['mobileMode'] = tbRaf(function() { | 946 | cafs['mobileMode'] = tbRaf(function() { |
937 | try { | 947 | try { |
938 | - widgetTypeInstance.onMobileModeChanged(); | 948 | + if (displayWidgetInstance()) { |
949 | + widgetTypeInstance.onMobileModeChanged(); | ||
950 | + } | ||
939 | } catch (e) { | 951 | } catch (e) { |
940 | handleWidgetException(e); | 952 | handleWidgetException(e); |
941 | } | 953 | } |
@@ -968,7 +980,21 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | @@ -968,7 +980,21 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | ||
968 | } | 980 | } |
969 | } | 981 | } |
970 | 982 | ||
983 | + function displayWidgetInstance() { | ||
984 | + if (widget.type !== types.widgetType.static.value) { | ||
985 | + for (var id in widgetContext.subscriptions) { | ||
986 | + if (widgetContext.subscriptions[id].isDataResolved()) { | ||
987 | + return true; | ||
988 | + } | ||
989 | + } | ||
990 | + return false; | ||
991 | + } else { | ||
992 | + return true; | ||
993 | + } | ||
994 | + } | ||
995 | + | ||
971 | function onDestroy() { | 996 | function onDestroy() { |
997 | + var shouldDestroyWidgetInstance = displayWidgetInstance(); | ||
972 | for (var id in widgetContext.subscriptions) { | 998 | for (var id in widgetContext.subscriptions) { |
973 | var subscription = widgetContext.subscriptions[id]; | 999 | var subscription = widgetContext.subscriptions[id]; |
974 | subscription.destroy(); | 1000 | subscription.destroy(); |
@@ -984,7 +1010,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | @@ -984,7 +1010,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL | ||
984 | } | 1010 | } |
985 | } | 1011 | } |
986 | try { | 1012 | try { |
987 | - widgetTypeInstance.onDestroy(); | 1013 | + if (shouldDestroyWidgetInstance) { |
1014 | + widgetTypeInstance.onDestroy(); | ||
1015 | + } | ||
988 | } catch (e) { | 1016 | } catch (e) { |
989 | handleWidgetException(e); | 1017 | handleWidgetException(e); |
990 | } | 1018 | } |