Propagate UI changes
This commit is contained in:
parent
9c5e3c769d
commit
eda23bbffc
@ -259,6 +259,8 @@ export interface IWidgetSubscription {
|
|||||||
|
|
||||||
subscribe(): void;
|
subscribe(): void;
|
||||||
|
|
||||||
|
isDataResolved(): boolean;
|
||||||
|
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
|
|
||||||
update(): void;
|
update(): void;
|
||||||
|
|||||||
@ -112,6 +112,7 @@ export class WidgetSubscription implements IWidgetSubscription {
|
|||||||
init$: Observable<IWidgetSubscription>;
|
init$: Observable<IWidgetSubscription>;
|
||||||
|
|
||||||
cafs: {[cafId: string]: CancelAnimationFrame} = {};
|
cafs: {[cafId: string]: CancelAnimationFrame} = {};
|
||||||
|
hasResolvedData = false;
|
||||||
|
|
||||||
targetDeviceAliasId: string;
|
targetDeviceAliasId: string;
|
||||||
targetDeviceId: string;
|
targetDeviceId: string;
|
||||||
@ -249,6 +250,7 @@ export class WidgetSubscription implements IWidgetSubscription {
|
|||||||
} else {
|
} else {
|
||||||
this.rpcEnabled = this.ctx.utils.widgetEditMode ? true : false;
|
this.rpcEnabled = this.ctx.utils.widgetEditMode ? true : false;
|
||||||
}
|
}
|
||||||
|
this.hasResolvedData = this.rpcEnabled;
|
||||||
this.callbacks.rpcStateChanged(this);
|
this.callbacks.rpcStateChanged(this);
|
||||||
initRpcSubject.next();
|
initRpcSubject.next();
|
||||||
initRpcSubject.complete();
|
initRpcSubject.complete();
|
||||||
@ -275,6 +277,7 @@ export class WidgetSubscription implements IWidgetSubscription {
|
|||||||
} else {
|
} else {
|
||||||
this.rpcEnabled = this.ctx.utils.widgetEditMode ? true : false;
|
this.rpcEnabled = this.ctx.utils.widgetEditMode ? true : false;
|
||||||
}
|
}
|
||||||
|
this.hasResolvedData = true;
|
||||||
this.callbacks.rpcStateChanged(this);
|
this.callbacks.rpcStateChanged(this);
|
||||||
initRpcSubject.next();
|
initRpcSubject.next();
|
||||||
initRpcSubject.complete();
|
initRpcSubject.complete();
|
||||||
@ -286,6 +289,7 @@ export class WidgetSubscription implements IWidgetSubscription {
|
|||||||
const initAlarmSubscriptionSubject = new ReplaySubject(1);
|
const initAlarmSubscriptionSubject = new ReplaySubject(1);
|
||||||
this.loadStDiff().subscribe(() => {
|
this.loadStDiff().subscribe(() => {
|
||||||
if (!this.ctx.aliasController) {
|
if (!this.ctx.aliasController) {
|
||||||
|
this.hasResolvedData = true;
|
||||||
this.configureAlarmsData();
|
this.configureAlarmsData();
|
||||||
initAlarmSubscriptionSubject.next();
|
initAlarmSubscriptionSubject.next();
|
||||||
initAlarmSubscriptionSubject.complete();
|
initAlarmSubscriptionSubject.complete();
|
||||||
@ -293,6 +297,9 @@ export class WidgetSubscription implements IWidgetSubscription {
|
|||||||
this.ctx.aliasController.resolveAlarmSource(this.alarmSource).subscribe(
|
this.ctx.aliasController.resolveAlarmSource(this.alarmSource).subscribe(
|
||||||
(alarmSource) => {
|
(alarmSource) => {
|
||||||
this.alarmSource = alarmSource;
|
this.alarmSource = alarmSource;
|
||||||
|
if (alarmSource) {
|
||||||
|
this.hasResolvedData = true;
|
||||||
|
}
|
||||||
this.configureAlarmsData();
|
this.configureAlarmsData();
|
||||||
initAlarmSubscriptionSubject.next();
|
initAlarmSubscriptionSubject.next();
|
||||||
initAlarmSubscriptionSubject.complete();
|
initAlarmSubscriptionSubject.complete();
|
||||||
@ -313,6 +320,7 @@ export class WidgetSubscription implements IWidgetSubscription {
|
|||||||
const initDataSubscriptionSubject = new ReplaySubject(1);
|
const initDataSubscriptionSubject = new ReplaySubject(1);
|
||||||
this.loadStDiff().subscribe(() => {
|
this.loadStDiff().subscribe(() => {
|
||||||
if (!this.ctx.aliasController) {
|
if (!this.ctx.aliasController) {
|
||||||
|
this.hasResolvedData = true;
|
||||||
this.configureData();
|
this.configureData();
|
||||||
initDataSubscriptionSubject.next();
|
initDataSubscriptionSubject.next();
|
||||||
initDataSubscriptionSubject.complete();
|
initDataSubscriptionSubject.complete();
|
||||||
@ -320,6 +328,9 @@ export class WidgetSubscription implements IWidgetSubscription {
|
|||||||
this.ctx.aliasController.resolveDatasources(this.datasources).subscribe(
|
this.ctx.aliasController.resolveDatasources(this.datasources).subscribe(
|
||||||
(datasources) => {
|
(datasources) => {
|
||||||
this.datasources = datasources;
|
this.datasources = datasources;
|
||||||
|
if (datasources && datasources.length) {
|
||||||
|
this.hasResolvedData = true;
|
||||||
|
}
|
||||||
this.configureData();
|
this.configureData();
|
||||||
initDataSubscriptionSubject.next();
|
initDataSubscriptionSubject.next();
|
||||||
initDataSubscriptionSubject.complete();
|
initDataSubscriptionSubject.complete();
|
||||||
@ -804,6 +815,10 @@ export class WidgetSubscription implements IWidgetSubscription {
|
|||||||
return subscriptionsChanged;
|
return subscriptionsChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isDataResolved(): boolean {
|
||||||
|
return this.hasResolvedData;
|
||||||
|
}
|
||||||
|
|
||||||
destroy(): void {
|
destroy(): void {
|
||||||
this.unsubscribe();
|
this.unsubscribe();
|
||||||
for (const cafId of Object.keys(this.cafs)) {
|
for (const cafId of Object.keys(this.cafs)) {
|
||||||
|
|||||||
@ -352,8 +352,23 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
this.onDestroy();
|
this.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private displayWidgetInstance(): boolean {
|
||||||
|
if (this.widget.type !== widgetType.static) {
|
||||||
|
for (const id of Object.keys(this.widgetContext.subscriptions)) {
|
||||||
|
const subscription = this.widgetContext.subscriptions[id];
|
||||||
|
if (subscription.isDataResolved()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private onDestroy() {
|
private onDestroy() {
|
||||||
if (this.widgetContext) {
|
if (this.widgetContext) {
|
||||||
|
const shouldDestroyWidgetInstance = this.displayWidgetInstance();
|
||||||
for (const id of Object.keys(this.widgetContext.subscriptions)) {
|
for (const id of Object.keys(this.widgetContext.subscriptions)) {
|
||||||
const subscription = this.widgetContext.subscriptions[id];
|
const subscription = this.widgetContext.subscriptions[id];
|
||||||
subscription.destroy();
|
subscription.destroy();
|
||||||
@ -369,7 +384,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.widgetTypeInstance.onDestroy();
|
if (shouldDestroyWidgetInstance) {
|
||||||
|
this.widgetTypeInstance.onDestroy();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.handleWidgetException(e);
|
this.handleWidgetException(e);
|
||||||
}
|
}
|
||||||
@ -471,7 +488,11 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
}
|
}
|
||||||
this.cafs.init = this.raf.raf(() => {
|
this.cafs.init = this.raf.raf(() => {
|
||||||
try {
|
try {
|
||||||
this.widgetTypeInstance.onInit();
|
if (this.displayWidgetInstance()) {
|
||||||
|
this.widgetTypeInstance.onInit();
|
||||||
|
} else {
|
||||||
|
this.loadingData = false;
|
||||||
|
}
|
||||||
this.detectChanges();
|
this.detectChanges();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.handleWidgetException(e);
|
this.handleWidgetException(e);
|
||||||
@ -492,7 +513,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
}
|
}
|
||||||
this.cafs.resize = this.raf.raf(() => {
|
this.cafs.resize = this.raf.raf(() => {
|
||||||
try {
|
try {
|
||||||
this.widgetTypeInstance.onResize();
|
if (this.displayWidgetInstance()) {
|
||||||
|
this.widgetTypeInstance.onResize();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.handleWidgetException(e);
|
this.handleWidgetException(e);
|
||||||
}
|
}
|
||||||
@ -513,7 +536,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
}
|
}
|
||||||
this.cafs.editMode = this.raf.raf(() => {
|
this.cafs.editMode = this.raf.raf(() => {
|
||||||
try {
|
try {
|
||||||
this.widgetTypeInstance.onEditModeChanged();
|
if (this.displayWidgetInstance()) {
|
||||||
|
this.widgetTypeInstance.onEditModeChanged();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.handleWidgetException(e);
|
this.handleWidgetException(e);
|
||||||
}
|
}
|
||||||
@ -532,7 +557,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
}
|
}
|
||||||
this.cafs.mobileMode = this.raf.raf(() => {
|
this.cafs.mobileMode = this.raf.raf(() => {
|
||||||
try {
|
try {
|
||||||
this.widgetTypeInstance.onMobileModeChanged();
|
if (this.displayWidgetInstance()) {
|
||||||
|
this.widgetTypeInstance.onMobileModeChanged();
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.handleWidgetException(e);
|
this.handleWidgetException(e);
|
||||||
}
|
}
|
||||||
@ -781,7 +808,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
|
|||||||
options.callbacks = {
|
options.callbacks = {
|
||||||
onDataUpdated: () => {
|
onDataUpdated: () => {
|
||||||
try {
|
try {
|
||||||
this.widgetTypeInstance.onDataUpdated();
|
if (this.displayWidgetInstance()) {
|
||||||
|
this.widgetTypeInstance.onDataUpdated();
|
||||||
|
}
|
||||||
} catch (e){}
|
} catch (e){}
|
||||||
},
|
},
|
||||||
onDataUpdateError: (subscription, e) => {
|
onDataUpdateError: (subscription, e) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user