Commit eda23bbffcb1fd3ab79a6450e4aff0967e56783f

Authored by Igor Kulikov
1 parent 9c5e3c76

Propagate UI changes

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