Commit 45961519cdecb465f6cc7507a6c8e5d1627d00bf

Authored by Vladyslav_Prykhodko
1 parent c93e661e

UI: Refactoring code

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