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