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
This commit is contained in:
		
							parent
							
								
									3f3fca41dc
								
							
						
					
					
						commit
						906b5d47f4
					
				@ -37,6 +37,7 @@ export default class Subscription {
 | 
			
		||||
        this.id = this.ctx.utils.guid();
 | 
			
		||||
        this.cafs = {};
 | 
			
		||||
        this.registrations = [];
 | 
			
		||||
        this.hasResolvedData = false;
 | 
			
		||||
 | 
			
		||||
        var subscription = this;
 | 
			
		||||
        var deferred = this.ctx.$q.defer();
 | 
			
		||||
@ -235,12 +236,16 @@ export default class Subscription {
 | 
			
		||||
        var subscription = this;
 | 
			
		||||
        this.loadStDiff().then(() => {
 | 
			
		||||
            if (!subscription.ctx.aliasController) {
 | 
			
		||||
                subscription.hasResolvedData = true;
 | 
			
		||||
                subscription.configureAlarmsData();
 | 
			
		||||
                deferred.resolve();
 | 
			
		||||
            } else {
 | 
			
		||||
                subscription.ctx.aliasController.resolveAlarmSource(subscription.alarmSource).then(
 | 
			
		||||
                    function success(alarmSource) {
 | 
			
		||||
                        subscription.alarmSource = alarmSource;
 | 
			
		||||
                        if (alarmSource) {
 | 
			
		||||
                            subscription.hasResolvedData = true;
 | 
			
		||||
                        }
 | 
			
		||||
                        subscription.configureAlarmsData();
 | 
			
		||||
                        deferred.resolve();
 | 
			
		||||
                    },
 | 
			
		||||
@ -282,12 +287,16 @@ export default class Subscription {
 | 
			
		||||
        var subscription = this;
 | 
			
		||||
        this.loadStDiff().then(() => {
 | 
			
		||||
            if (!subscription.ctx.aliasController) {
 | 
			
		||||
                subscription.hasResolvedData = true;
 | 
			
		||||
                subscription.configureData();
 | 
			
		||||
                deferred.resolve();
 | 
			
		||||
            } else {
 | 
			
		||||
                subscription.ctx.aliasController.resolveDatasources(subscription.datasources).then(
 | 
			
		||||
                    function success(datasources) {
 | 
			
		||||
                        subscription.datasources = datasources;
 | 
			
		||||
                        if (datasources && datasources.length) {
 | 
			
		||||
                            subscription.hasResolvedData = true;
 | 
			
		||||
                        }
 | 
			
		||||
                        subscription.configureData();
 | 
			
		||||
                        deferred.resolve();
 | 
			
		||||
                    },
 | 
			
		||||
@ -420,6 +429,7 @@ export default class Subscription {
 | 
			
		||||
                        } else {
 | 
			
		||||
                            subscription.rpcEnabled = subscription.ctx.$scope.widgetEditMode ? true : false;
 | 
			
		||||
                        }
 | 
			
		||||
                        subscription.hasResolvedData = subscription.rpcEnabled;
 | 
			
		||||
                        subscription.callbacks.rpcStateChanged(subscription);
 | 
			
		||||
                        deferred.resolve();
 | 
			
		||||
                    } else {
 | 
			
		||||
@ -443,6 +453,7 @@ export default class Subscription {
 | 
			
		||||
            } else {
 | 
			
		||||
                this.rpcEnabled = this.ctx.$scope.widgetEditMode ? true : false;
 | 
			
		||||
            }
 | 
			
		||||
            this.hasResolvedData = true;
 | 
			
		||||
            this.callbacks.rpcStateChanged(this);
 | 
			
		||||
            deferred.resolve();
 | 
			
		||||
        }
 | 
			
		||||
@ -880,6 +891,10 @@ export default class Subscription {
 | 
			
		||||
        return subscriptionsChanged;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    isDataResolved() {
 | 
			
		||||
        return this.hasResolvedData;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    destroy() {
 | 
			
		||||
        this.unsubscribe();
 | 
			
		||||
        for (var cafId in this.cafs) {
 | 
			
		||||
 | 
			
		||||
@ -466,7 +466,7 @@ function CustomActionPrettyEditor($compile, $templateCache, $window, $timeout) {
 | 
			
		||||
            "//            tasks.push(widgetContext.aliasController.getAliasInfo(aliasId));\n" +
 | 
			
		||||
            "//        });\n" +
 | 
			
		||||
            "//        $q.all(tasks).then(function() {\n" +
 | 
			
		||||
            "//            $rootScope.$broadcast('entityAliasesChanged', aliasIds);\n" +
 | 
			
		||||
            "//            $rootScope.$broadcast('widgetForceReInit');\n" +
 | 
			
		||||
            "//        });\n" +
 | 
			
		||||
            "//    }\n" +
 | 
			
		||||
            "//}\n";
 | 
			
		||||
 | 
			
		||||
@ -312,7 +312,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
 | 
			
		||||
 | 
			
		||||
        options.callbacks = {
 | 
			
		||||
            onDataUpdated: function() {
 | 
			
		||||
                widgetTypeInstance.onDataUpdated();
 | 
			
		||||
                if (displayWidgetInstance()) {
 | 
			
		||||
                    widgetTypeInstance.onDataUpdated();
 | 
			
		||||
                }
 | 
			
		||||
            },
 | 
			
		||||
            onDataUpdateError: function(subscription, e) {
 | 
			
		||||
                handleWidgetException(e);
 | 
			
		||||
@ -849,7 +851,11 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
 | 
			
		||||
        if (!widgetContext.inited && isReady()) {
 | 
			
		||||
            widgetContext.inited = true;
 | 
			
		||||
            try {
 | 
			
		||||
                widgetTypeInstance.onInit();
 | 
			
		||||
                if (displayWidgetInstance()) {
 | 
			
		||||
                    widgetTypeInstance.onInit();
 | 
			
		||||
                } else {
 | 
			
		||||
                    $scope.loadingData = false;
 | 
			
		||||
                }
 | 
			
		||||
            } catch (e) {
 | 
			
		||||
                handleWidgetException(e);
 | 
			
		||||
            }
 | 
			
		||||
@ -886,7 +892,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
 | 
			
		||||
                }
 | 
			
		||||
                cafs['resize'] = tbRaf(function() {
 | 
			
		||||
                    try {
 | 
			
		||||
                        widgetTypeInstance.onResize();
 | 
			
		||||
                        if (displayWidgetInstance()) {
 | 
			
		||||
                            widgetTypeInstance.onResize();
 | 
			
		||||
                        }
 | 
			
		||||
                    } catch (e) {
 | 
			
		||||
                        handleWidgetException(e);
 | 
			
		||||
                    }
 | 
			
		||||
@ -916,7 +924,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
 | 
			
		||||
                }
 | 
			
		||||
                cafs['editMode'] = tbRaf(function() {
 | 
			
		||||
                    try {
 | 
			
		||||
                        widgetTypeInstance.onEditModeChanged();
 | 
			
		||||
                        if (displayWidgetInstance()) {
 | 
			
		||||
                            widgetTypeInstance.onEditModeChanged();
 | 
			
		||||
                        }
 | 
			
		||||
                    } catch (e) {
 | 
			
		||||
                        handleWidgetException(e);
 | 
			
		||||
                    }
 | 
			
		||||
@ -935,7 +945,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
 | 
			
		||||
                }
 | 
			
		||||
                cafs['mobileMode'] = tbRaf(function() {
 | 
			
		||||
                    try {
 | 
			
		||||
                        widgetTypeInstance.onMobileModeChanged();
 | 
			
		||||
                        if (displayWidgetInstance()) {
 | 
			
		||||
                            widgetTypeInstance.onMobileModeChanged();
 | 
			
		||||
                        }
 | 
			
		||||
                    } catch (e) {
 | 
			
		||||
                        handleWidgetException(e);
 | 
			
		||||
                    }
 | 
			
		||||
@ -968,7 +980,21 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function displayWidgetInstance() {
 | 
			
		||||
        if (widget.type !== types.widgetType.static.value) {
 | 
			
		||||
            for (var id in widgetContext.subscriptions) {
 | 
			
		||||
                if (widgetContext.subscriptions[id].isDataResolved()) {
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return false;
 | 
			
		||||
        } else {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function onDestroy() {
 | 
			
		||||
        var shouldDestroyWidgetInstance = displayWidgetInstance();
 | 
			
		||||
        for (var id in widgetContext.subscriptions) {
 | 
			
		||||
            var subscription = widgetContext.subscriptions[id];
 | 
			
		||||
            subscription.destroy();
 | 
			
		||||
@ -984,7 +1010,9 @@ export default function WidgetController($scope, $state, $timeout, $window, $ocL
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            try {
 | 
			
		||||
                widgetTypeInstance.onDestroy();
 | 
			
		||||
                if (shouldDestroyWidgetInstance) {
 | 
			
		||||
                    widgetTypeInstance.onDestroy();
 | 
			
		||||
                }
 | 
			
		||||
            } catch (e) {
 | 
			
		||||
                handleWidgetException(e);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user