Commit 906b5d47f496b81674993397c9ea67fa981cd965

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