From 80db56c2eb1d2a5af6a8a885d2e1afe480c7fd6a Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Thu, 12 Sep 2019 15:11:00 +0200 Subject: [PATCH] Fix change detecting dead views --- .../list-view-table.component.ts | 51 ++++++++++++------- .../meta-text-block.component.ts | 1 + .../components/preview/preview.component.ts | 11 +++- .../progress-snack-bar.component.ts | 2 + .../filter-menu/filter-menu.component.html | 2 +- .../filter-menu/filter-menu.component.ts | 11 +++- .../global-spinner.component.ts | 1 + .../config-field/config-field.component.ts | 19 ++++++- .../mediafile-list.component.ts | 1 + 9 files changed, 73 insertions(+), 26 deletions(-) diff --git a/client/src/app/shared/components/list-view-table/list-view-table.component.ts b/client/src/app/shared/components/list-view-table/list-view-table.component.ts index 430305fc8..1404b2cc5 100644 --- a/client/src/app/shared/components/list-view-table/list-view-table.component.ts +++ b/client/src/app/shared/components/list-view-table/list-view-table.component.ts @@ -4,6 +4,7 @@ import { Component, EventEmitter, Input, + OnDestroy, OnInit, Output, ViewChild, @@ -81,7 +82,7 @@ export interface ColumnRestriction { changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None }) -export class ListViewTableComponent implements OnInit { +export class ListViewTableComponent implements OnInit, OnDestroy { /** * Declare the table */ @@ -243,7 +244,9 @@ export class ListViewTableComponent { - return this.repo.getViewModelListObservable(); + if (this.repo) { + return this.repo.getViewModelListObservable(); + } } /** @@ -296,24 +299,27 @@ export class ListViewTableComponent() .onTrigger(() => { let listObservable: Observable; - if (this.filterService && this.sortService) { - // filtering and sorting - this.filterService.initFilters(this.viewModelListObservable); - this.sortService.initSorting(this.filterService.outputObservable); - listObservable = this.sortService.outputObservable; - } else if (this.filterService) { - // only filter service - this.filterService.initFilters(this.viewModelListObservable); - listObservable = this.filterService.outputObservable; - } else if (this.sortService) { - // only sorting - this.sortService.initSorting(this.viewModelListObservable); - listObservable = this.sortService.outputObservable; - } else { - // none of both - listObservable = this.viewModelListObservable; + if (this.repo && this.viewModelListObservable) { + if (this.filterService && this.sortService) { + // filtering and sorting + this.filterService.initFilters(this.viewModelListObservable); + this.sortService.initSorting(this.filterService.outputObservable); + listObservable = this.sortService.outputObservable; + } else if (this.filterService) { + // only filter service + this.filterService.initFilters(this.viewModelListObservable); + listObservable = this.filterService.outputObservable; + } else if (this.sortService) { + // only sorting + this.sortService.initSorting(this.viewModelListObservable); + listObservable = this.sortService.outputObservable; + } else { + // none of both + listObservable = this.viewModelListObservable; + } } - return listObservable; + + return listObservable ? listObservable : []; }) .create(); @@ -394,6 +400,13 @@ export class ListViewTableComponent - + {{ service.getFilterName(filter) | translate }} diff --git a/client/src/app/shared/components/sort-filter-bar/filter-menu/filter-menu.component.ts b/client/src/app/shared/components/sort-filter-bar/filter-menu/filter-menu.component.ts index dc3a1a5b5..b904c8e8f 100644 --- a/client/src/app/shared/components/sort-filter-bar/filter-menu/filter-menu.component.ts +++ b/client/src/app/shared/components/sort-filter-bar/filter-menu/filter-menu.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; +import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewEncapsulation } from '@angular/core'; import { BaseFilterListService, OsFilterOption } from 'app/core/ui-services/base-filter-list.service'; import { BaseViewModel } from 'app/site/base/base-view-model'; @@ -20,7 +20,7 @@ import { BaseViewModel } from 'app/site/base/base-view-model'; styleUrls: ['./filter-menu.component.scss'], encapsulation: ViewEncapsulation.None }) -export class FilterMenuComponent implements OnInit { +export class FilterMenuComponent implements OnInit, OnDestroy { /** * An event emitter to submit a desire to close this component * TODO: Might be an easier way to do this @@ -50,6 +50,13 @@ export class FilterMenuComponent implements OnInit { } } + /** + * + */ + public ngOnDestroy(): void { + this.dismissed.unsubscribe(); + } + /** * Tests for escape key (to colose the sidebar) * @param event diff --git a/client/src/app/site/common/components/global-spinner/global-spinner.component.ts b/client/src/app/site/common/components/global-spinner/global-spinner.component.ts index f7a81d5df..43170f597 100644 --- a/client/src/app/site/common/components/global-spinner/global-spinner.component.ts +++ b/client/src/app/site/common/components/global-spinner/global-spinner.component.ts @@ -75,5 +75,6 @@ export class GlobalSpinnerComponent implements OnInit, OnDestroy { this.isVisible = false; } this.spinnerSubscription = null; + this.cd.detach(); } } diff --git a/client/src/app/site/config/components/config-field/config-field.component.ts b/client/src/app/site/config/components/config-field/config-field.component.ts index 77a98cf06..17f57e39f 100644 --- a/client/src/app/site/config/components/config-field/config-field.component.ts +++ b/client/src/app/site/config/components/config-field/config-field.component.ts @@ -1,4 +1,12 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit, ViewEncapsulation } from '@angular/core'; +import { + ChangeDetectionStrategy, + ChangeDetectorRef, + Component, + Input, + OnDestroy, + OnInit, + ViewEncapsulation +} from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; import { Title } from '@angular/platform-browser'; @@ -28,7 +36,7 @@ import { ViewConfig } from '../../models/view-config'; changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None // to style the date and time pickers }) -export class ConfigFieldComponent extends BaseComponent implements OnInit { +export class ConfigFieldComponent extends BaseComponent implements OnInit, OnDestroy { public configItem: ViewConfig; /** @@ -147,6 +155,13 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit { }); } + /** + * Stops the change detection + */ + public ngOnDestroy(): void { + this.cd.detach(); + } + /** * Helper function to split a unix timestamp into a date as a moment object and a time string in the form of HH:SS * diff --git a/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.ts b/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.ts index a2d7d05b4..5bc87c912 100644 --- a/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.ts +++ b/client/src/app/site/mediafiles/components/mediafile-list/mediafile-list.component.ts @@ -243,6 +243,7 @@ export class MediafileListComponent extends BaseListViewComponent public ngOnDestroy(): void { super.ngOnDestroy(); this.clearSubscriptions(); + this.cd.detach(); } /**