Commit eda23bbffcb1fd3ab79a6450e4aff0967e56783f

Authored by Igor Kulikov
1 parent 9c5e3c76

Propagate UI changes

@@ -259,6 +259,8 @@ export interface IWidgetSubscription { @@ -259,6 +259,8 @@ export interface IWidgetSubscription {
259 259
260 subscribe(): void; 260 subscribe(): void;
261 261
  262 + isDataResolved(): boolean;
  263 +
262 destroy(): void; 264 destroy(): void;
263 265
264 update(): void; 266 update(): void;
@@ -112,6 +112,7 @@ export class WidgetSubscription implements IWidgetSubscription { @@ -112,6 +112,7 @@ export class WidgetSubscription implements IWidgetSubscription {
112 init$: Observable<IWidgetSubscription>; 112 init$: Observable<IWidgetSubscription>;
113 113
114 cafs: {[cafId: string]: CancelAnimationFrame} = {}; 114 cafs: {[cafId: string]: CancelAnimationFrame} = {};
  115 + hasResolvedData = false;
115 116
116 targetDeviceAliasId: string; 117 targetDeviceAliasId: string;
117 targetDeviceId: string; 118 targetDeviceId: string;
@@ -249,6 +250,7 @@ export class WidgetSubscription implements IWidgetSubscription { @@ -249,6 +250,7 @@ export class WidgetSubscription implements IWidgetSubscription {
249 } else { 250 } else {
250 this.rpcEnabled = this.ctx.utils.widgetEditMode ? true : false; 251 this.rpcEnabled = this.ctx.utils.widgetEditMode ? true : false;
251 } 252 }
  253 + this.hasResolvedData = this.rpcEnabled;
252 this.callbacks.rpcStateChanged(this); 254 this.callbacks.rpcStateChanged(this);
253 initRpcSubject.next(); 255 initRpcSubject.next();
254 initRpcSubject.complete(); 256 initRpcSubject.complete();
@@ -275,6 +277,7 @@ export class WidgetSubscription implements IWidgetSubscription { @@ -275,6 +277,7 @@ export class WidgetSubscription implements IWidgetSubscription {
275 } else { 277 } else {
276 this.rpcEnabled = this.ctx.utils.widgetEditMode ? true : false; 278 this.rpcEnabled = this.ctx.utils.widgetEditMode ? true : false;
277 } 279 }
  280 + this.hasResolvedData = true;
278 this.callbacks.rpcStateChanged(this); 281 this.callbacks.rpcStateChanged(this);
279 initRpcSubject.next(); 282 initRpcSubject.next();
280 initRpcSubject.complete(); 283 initRpcSubject.complete();
@@ -286,6 +289,7 @@ export class WidgetSubscription implements IWidgetSubscription { @@ -286,6 +289,7 @@ export class WidgetSubscription implements IWidgetSubscription {
286 const initAlarmSubscriptionSubject = new ReplaySubject(1); 289 const initAlarmSubscriptionSubject = new ReplaySubject(1);
287 this.loadStDiff().subscribe(() => { 290 this.loadStDiff().subscribe(() => {
288 if (!this.ctx.aliasController) { 291 if (!this.ctx.aliasController) {
  292 + this.hasResolvedData = true;
289 this.configureAlarmsData(); 293 this.configureAlarmsData();
290 initAlarmSubscriptionSubject.next(); 294 initAlarmSubscriptionSubject.next();
291 initAlarmSubscriptionSubject.complete(); 295 initAlarmSubscriptionSubject.complete();
@@ -293,6 +297,9 @@ export class WidgetSubscription implements IWidgetSubscription { @@ -293,6 +297,9 @@ export class WidgetSubscription implements IWidgetSubscription {
293 this.ctx.aliasController.resolveAlarmSource(this.alarmSource).subscribe( 297 this.ctx.aliasController.resolveAlarmSource(this.alarmSource).subscribe(
294 (alarmSource) => { 298 (alarmSource) => {
295 this.alarmSource = alarmSource; 299 this.alarmSource = alarmSource;
  300 + if (alarmSource) {
  301 + this.hasResolvedData = true;
  302 + }
296 this.configureAlarmsData(); 303 this.configureAlarmsData();
297 initAlarmSubscriptionSubject.next(); 304 initAlarmSubscriptionSubject.next();
298 initAlarmSubscriptionSubject.complete(); 305 initAlarmSubscriptionSubject.complete();
@@ -313,6 +320,7 @@ export class WidgetSubscription implements IWidgetSubscription { @@ -313,6 +320,7 @@ export class WidgetSubscription implements IWidgetSubscription {
313 const initDataSubscriptionSubject = new ReplaySubject(1); 320 const initDataSubscriptionSubject = new ReplaySubject(1);
314 this.loadStDiff().subscribe(() => { 321 this.loadStDiff().subscribe(() => {
315 if (!this.ctx.aliasController) { 322 if (!this.ctx.aliasController) {
  323 + this.hasResolvedData = true;
316 this.configureData(); 324 this.configureData();
317 initDataSubscriptionSubject.next(); 325 initDataSubscriptionSubject.next();
318 initDataSubscriptionSubject.complete(); 326 initDataSubscriptionSubject.complete();
@@ -320,6 +328,9 @@ export class WidgetSubscription implements IWidgetSubscription { @@ -320,6 +328,9 @@ export class WidgetSubscription implements IWidgetSubscription {
320 this.ctx.aliasController.resolveDatasources(this.datasources).subscribe( 328 this.ctx.aliasController.resolveDatasources(this.datasources).subscribe(
321 (datasources) => { 329 (datasources) => {
322 this.datasources = datasources; 330 this.datasources = datasources;
  331 + if (datasources && datasources.length) {
  332 + this.hasResolvedData = true;
  333 + }
323 this.configureData(); 334 this.configureData();
324 initDataSubscriptionSubject.next(); 335 initDataSubscriptionSubject.next();
325 initDataSubscriptionSubject.complete(); 336 initDataSubscriptionSubject.complete();
@@ -804,6 +815,10 @@ export class WidgetSubscription implements IWidgetSubscription { @@ -804,6 +815,10 @@ export class WidgetSubscription implements IWidgetSubscription {
804 return subscriptionsChanged; 815 return subscriptionsChanged;
805 } 816 }
806 817
  818 + isDataResolved(): boolean {
  819 + return this.hasResolvedData;
  820 + }
  821 +
807 destroy(): void { 822 destroy(): void {
808 this.unsubscribe(); 823 this.unsubscribe();
809 for (const cafId of Object.keys(this.cafs)) { 824 for (const cafId of Object.keys(this.cafs)) {
@@ -352,8 +352,23 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI @@ -352,8 +352,23 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
352 this.onDestroy(); 352 this.onDestroy();
353 } 353 }
354 354
  355 + private displayWidgetInstance(): boolean {
  356 + if (this.widget.type !== widgetType.static) {
  357 + for (const id of Object.keys(this.widgetContext.subscriptions)) {
  358 + const subscription = this.widgetContext.subscriptions[id];
  359 + if (subscription.isDataResolved()) {
  360 + return true;
  361 + }
  362 + }
  363 + return false;
  364 + } else {
  365 + return true;
  366 + }
  367 + }
  368 +
355 private onDestroy() { 369 private onDestroy() {
356 if (this.widgetContext) { 370 if (this.widgetContext) {
  371 + const shouldDestroyWidgetInstance = this.displayWidgetInstance();
357 for (const id of Object.keys(this.widgetContext.subscriptions)) { 372 for (const id of Object.keys(this.widgetContext.subscriptions)) {
358 const subscription = this.widgetContext.subscriptions[id]; 373 const subscription = this.widgetContext.subscriptions[id];
359 subscription.destroy(); 374 subscription.destroy();
@@ -369,7 +384,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI @@ -369,7 +384,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
369 } 384 }
370 } 385 }
371 try { 386 try {
372 - this.widgetTypeInstance.onDestroy(); 387 + if (shouldDestroyWidgetInstance) {
  388 + this.widgetTypeInstance.onDestroy();
  389 + }
373 } catch (e) { 390 } catch (e) {
374 this.handleWidgetException(e); 391 this.handleWidgetException(e);
375 } 392 }
@@ -471,7 +488,11 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI @@ -471,7 +488,11 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
471 } 488 }
472 this.cafs.init = this.raf.raf(() => { 489 this.cafs.init = this.raf.raf(() => {
473 try { 490 try {
474 - this.widgetTypeInstance.onInit(); 491 + if (this.displayWidgetInstance()) {
  492 + this.widgetTypeInstance.onInit();
  493 + } else {
  494 + this.loadingData = false;
  495 + }
475 this.detectChanges(); 496 this.detectChanges();
476 } catch (e) { 497 } catch (e) {
477 this.handleWidgetException(e); 498 this.handleWidgetException(e);
@@ -492,7 +513,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI @@ -492,7 +513,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
492 } 513 }
493 this.cafs.resize = this.raf.raf(() => { 514 this.cafs.resize = this.raf.raf(() => {
494 try { 515 try {
495 - this.widgetTypeInstance.onResize(); 516 + if (this.displayWidgetInstance()) {
  517 + this.widgetTypeInstance.onResize();
  518 + }
496 } catch (e) { 519 } catch (e) {
497 this.handleWidgetException(e); 520 this.handleWidgetException(e);
498 } 521 }
@@ -513,7 +536,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI @@ -513,7 +536,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
513 } 536 }
514 this.cafs.editMode = this.raf.raf(() => { 537 this.cafs.editMode = this.raf.raf(() => {
515 try { 538 try {
516 - this.widgetTypeInstance.onEditModeChanged(); 539 + if (this.displayWidgetInstance()) {
  540 + this.widgetTypeInstance.onEditModeChanged();
  541 + }
517 } catch (e) { 542 } catch (e) {
518 this.handleWidgetException(e); 543 this.handleWidgetException(e);
519 } 544 }
@@ -532,7 +557,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI @@ -532,7 +557,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
532 } 557 }
533 this.cafs.mobileMode = this.raf.raf(() => { 558 this.cafs.mobileMode = this.raf.raf(() => {
534 try { 559 try {
535 - this.widgetTypeInstance.onMobileModeChanged(); 560 + if (this.displayWidgetInstance()) {
  561 + this.widgetTypeInstance.onMobileModeChanged();
  562 + }
536 } catch (e) { 563 } catch (e) {
537 this.handleWidgetException(e); 564 this.handleWidgetException(e);
538 } 565 }
@@ -781,7 +808,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI @@ -781,7 +808,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
781 options.callbacks = { 808 options.callbacks = {
782 onDataUpdated: () => { 809 onDataUpdated: () => {
783 try { 810 try {
784 - this.widgetTypeInstance.onDataUpdated(); 811 + if (this.displayWidgetInstance()) {
  812 + this.widgetTypeInstance.onDataUpdated();
  813 + }
785 } catch (e){} 814 } catch (e){}
786 }, 815 },
787 onDataUpdateError: (subscription, e) => { 816 onDataUpdateError: (subscription, e) => {