Commit 45961519cdecb465f6cc7507a6c8e5d1627d00bf

Authored by Vladyslav_Prykhodko
1 parent c93e661e

UI: Refactoring code

@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 /// limitations under the License. 14 /// limitations under the License.
15 /// 15 ///
16 16
17 -import { Observable, Subject } from 'rxjs'; 17 +import { Observable } from 'rxjs';
18 import { EntityId } from '@app/shared/models/id/entity-id'; 18 import { EntityId } from '@app/shared/models/id/entity-id';
19 import { 19 import {
20 DataSet, 20 DataSet,
@@ -277,7 +277,7 @@ export interface IWidgetSubscription { @@ -277,7 +277,7 @@ export interface IWidgetSubscription {
277 hiddenData?: Array<{data: DataSet}>; 277 hiddenData?: Array<{data: DataSet}>;
278 timeWindowConfig?: Timewindow; 278 timeWindowConfig?: Timewindow;
279 timeWindow?: WidgetTimewindow; 279 timeWindow?: WidgetTimewindow;
280 - widgetTimewindowChanged: Observable<WidgetTimewindow>; 280 + widgetTimewindowChanged$: Observable<WidgetTimewindow>;
281 comparisonEnabled?: boolean; 281 comparisonEnabled?: boolean;
282 comparisonTimeWindow?: WidgetTimewindow; 282 comparisonTimeWindow?: WidgetTimewindow;
283 283
@@ -141,7 +141,7 @@ export class WidgetSubscription implements IWidgetSubscription { @@ -141,7 +141,7 @@ export class WidgetSubscription implements IWidgetSubscription {
141 subscribed = false; 141 subscribed = false;
142 widgetTimewindowChangedSubject: Subject<WidgetTimewindow> = new ReplaySubject<WidgetTimewindow>(); 142 widgetTimewindowChangedSubject: Subject<WidgetTimewindow> = new ReplaySubject<WidgetTimewindow>();
143 143
144 - widgetTimewindowChanged = this.widgetTimewindowChangedSubject.asObservable().pipe( 144 + widgetTimewindowChanged$ = this.widgetTimewindowChangedSubject.asObservable().pipe(
145 distinct() 145 distinct()
146 ); 146 );
147 147
@@ -1124,6 +1124,7 @@ export class WidgetSubscription implements IWidgetSubscription { @@ -1124,6 +1124,7 @@ export class WidgetSubscription implements IWidgetSubscription {
1124 1124
1125 destroy(): void { 1125 destroy(): void {
1126 this.unsubscribe(); 1126 this.unsubscribe();
  1127 + this.widgetTimewindowChangedSubject.complete();
1127 for (const cafId of Object.keys(this.cafs)) { 1128 for (const cafId of Object.keys(this.cafs)) {
1128 if (this.cafs[cafId]) { 1129 if (this.cafs[cafId]) {
1129 this.cafs[cafId](); 1130 this.cafs[cafId]();
@@ -238,6 +238,7 @@ export class DashboardComponent extends PageComponent implements IDashboardCompo @@ -238,6 +238,7 @@ export class DashboardComponent extends PageComponent implements IDashboardCompo
238 if (this.breakpointObserverSubscription) { 238 if (this.breakpointObserverSubscription) {
239 this.breakpointObserverSubscription.unsubscribe(); 239 this.breakpointObserverSubscription.unsubscribe();
240 } 240 }
  241 + this.dashboardTimewindowChangedSubject.complete();
241 this.gridster = null; 242 this.gridster = null;
242 } 243 }
243 244
@@ -188,7 +188,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, @@ -188,7 +188,7 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
188 188
189 private rowStylesInfo: RowStyleInfo; 189 private rowStylesInfo: RowStyleInfo;
190 190
191 - private widgetTimewindowChangedSubscription: Subscription; 191 + private widgetTimewindowChanged$: Subscription;
192 192
193 private searchAction: WidgetAction = { 193 private searchAction: WidgetAction = {
194 name: 'action.search', 194 name: 'action.search',
@@ -247,18 +247,17 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit, @@ -247,18 +247,17 @@ export class AlarmsTableWidgetComponent extends PageComponent implements OnInit,
247 this.ctx.updateWidgetParams(); 247 this.ctx.updateWidgetParams();
248 248
249 if (this.displayPagination) { 249 if (this.displayPagination) {
250 - this.widgetTimewindowChangedSubscription = this.ctx.defaultSubscription.widgetTimewindowChanged.subscribe( 250 + this.widgetTimewindowChanged$ = this.ctx.defaultSubscription.widgetTimewindowChanged$.subscribe(
251 () => this.pageLink.page = 0 251 () => this.pageLink.page = 0
252 ); 252 );
253 } 253 }
254 } 254 }
255 255
256 ngOnDestroy(): void { 256 ngOnDestroy(): void {
257 - if (this.widgetTimewindowChangedSubscription) {  
258 - this.widgetTimewindowChangedSubscription.unsubscribe();  
259 - this.widgetTimewindowChangedSubscription = null; 257 + if (this.widgetTimewindowChanged$) {
  258 + this.widgetTimewindowChanged$.unsubscribe();
  259 + this.widgetTimewindowChanged$ = null;
260 } 260 }
261 - this.ctx.defaultSubscription.widgetTimewindowChangedSubject.complete();  
262 } 261 }
263 262
264 ngAfterViewInit(): void { 263 ngAfterViewInit(): void {
@@ -119,7 +119,6 @@ export class DateRangeNavigatorWidgetComponent extends PageComponent implements @@ -119,7 +119,6 @@ export class DateRangeNavigatorWidgetComponent extends PageComponent implements
119 this.dashboardTimewindowChangedSubscription.unsubscribe(); 119 this.dashboardTimewindowChangedSubscription.unsubscribe();
120 this.dashboardTimewindowChangedSubscription = null; 120 this.dashboardTimewindowChangedSubscription = null;
121 } 121 }
122 - this.ctx.dashboard.dashboardTimewindowChangedSubject.complete();  
123 } 122 }
124 123
125 openNavigatorPanel($event: Event) { 124 openNavigatorPanel($event: Event) {
@@ -139,7 +139,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI @@ -139,7 +139,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI
139 private rowStylesInfo: RowStyleInfo; 139 private rowStylesInfo: RowStyleInfo;
140 140
141 private subscriptions: Subscription[] = []; 141 private subscriptions: Subscription[] = [];
142 - private widgetTimewindowChangedSubscription: Subscription; 142 + private widgetTimewindowChanged$: Subscription;
143 143
144 private searchAction: WidgetAction = { 144 private searchAction: WidgetAction = {
145 name: 'action.search', 145 name: 'action.search',
@@ -172,7 +172,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI @@ -172,7 +172,7 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI
172 this.ctx.updateWidgetParams(); 172 this.ctx.updateWidgetParams();
173 173
174 if (this.displayPagination) { 174 if (this.displayPagination) {
175 - this.widgetTimewindowChangedSubscription = this.ctx.defaultSubscription.widgetTimewindowChanged.subscribe( 175 + this.widgetTimewindowChanged$ = this.ctx.defaultSubscription.widgetTimewindowChanged$.subscribe(
176 () => { 176 () => {
177 this.sources.forEach((source) => { 177 this.sources.forEach((source) => {
178 if (this.displayPagination) { 178 if (this.displayPagination) {
@@ -185,11 +185,10 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI @@ -185,11 +185,10 @@ export class TimeseriesTableWidgetComponent extends PageComponent implements OnI
185 } 185 }
186 186
187 ngOnDestroy(): void { 187 ngOnDestroy(): void {
188 - if (this.widgetTimewindowChangedSubscription) {  
189 - this.widgetTimewindowChangedSubscription.unsubscribe();  
190 - this.widgetTimewindowChangedSubscription = null; 188 + if (this.widgetTimewindowChanged$) {
  189 + this.widgetTimewindowChanged$.unsubscribe();
  190 + this.widgetTimewindowChanged$ = null;
191 } 191 }
192 - this.ctx.defaultSubscription.widgetTimewindowChangedSubject.complete();  
193 } 192 }
194 193
195 ngAfterViewInit(): void { 194 ngAfterViewInit(): void {
@@ -67,7 +67,6 @@ export interface IDashboardComponent { @@ -67,7 +67,6 @@ export interface IDashboardComponent {
67 autofillHeight: boolean; 67 autofillHeight: boolean;
68 dashboardTimewindow: Timewindow; 68 dashboardTimewindow: Timewindow;
69 dashboardTimewindowChanged: Observable<Timewindow>; 69 dashboardTimewindowChanged: Observable<Timewindow>;
70 - dashboardTimewindowChangedSubject: Subject<Timewindow>;  
71 aliasController: IAliasController; 70 aliasController: IAliasController;
72 stateController: IStateController; 71 stateController: IStateController;
73 onUpdateTimewindow(startTimeMs: number, endTimeMs: number, interval?: number, persist?: boolean): void; 72 onUpdateTimewindow(startTimeMs: number, endTimeMs: number, interval?: number, persist?: boolean): void;