From db30831d3e413a6a7810c5df14f9a77028f3a29d Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Fri, 26 Jul 2019 10:41:46 +0200 Subject: [PATCH] Add better change detection to MediaFiles There was a chance that the file browser did not update after creating or renaming a folder. --- .../list-view-table/list-view-table.component.ts | 4 ++-- .../global-spinner/global-spinner.component.ts | 6 +++--- .../config-field/config-field.component.ts | 16 ++++++++-------- .../mediafile-list/mediafile-list.component.ts | 7 +++++-- 4 files changed, 18 insertions(+), 15 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 d1a6cb1ef..d1fdfeda3 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 @@ -268,11 +268,11 @@ export class ListViewTableComponent { if (mobile !== this.isMobile) { - this.ref.markForCheck(); + this.cd.markForCheck(); } this.isMobile = mobile; }); 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 f020ac001..0fb8211a7 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 @@ -39,12 +39,12 @@ export class GlobalSpinnerComponent implements OnInit, OnDestroy { * * @param spinnerService Reference to the service for this spinner. * @param translate Service to get translations for the messages. - * @param detector Service to manual initiate a change of the UI. + * @param cd Service to manual initiate a change of the UI. */ public constructor( private spinnerService: SpinnerService, protected translate: TranslateService, - private detector: ChangeDetectorRef + private cd: ChangeDetectorRef ) {} /** @@ -59,7 +59,7 @@ export class GlobalSpinnerComponent implements OnInit, OnDestroy { if (!this.text) { this.text = this.LOADING; } - this.detector.detectChanges(); + this.cd.detectChanges(); }); } 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 782e91c1d..bff41ceb5 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 @@ -97,7 +97,7 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit { * @param titleService Title * @param translate TranslateService * @param formBuilder FormBuilder - * @param cdRef ChangeDetectorRef + * @param cd ChangeDetectorRef * @param repo ConfigRepositoryService * @param dateTimeAdapter DateTimeAdapter */ @@ -105,7 +105,7 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit { protected titleService: Title, protected translate: TranslateService, private formBuilder: FormBuilder, - private cdRef: ChangeDetectorRef, + private cd: ChangeDetectorRef, public repo: ConfigRepositoryService ) { super(titleService, translate); @@ -160,7 +160,7 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit { this.debounceTimeout = setTimeout(() => { this.update(value); }, this.configItem.getDebouncingTimeout()); - this.cdRef.detectChanges(); + this.cd.detectChanges(); } /** @@ -194,22 +194,22 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit { this.updateSuccessIconTimeout = setTimeout(() => { this.updateSuccessIcon = false; if (!this.wasViewDestroyed()) { - this.cdRef.detectChanges(); + this.cd.detectChanges(); } }, 2000); this.updateSuccessIcon = true; if (!this.wasViewDestroyed()) { - this.cdRef.detectChanges(); + this.cd.detectChanges(); } } /** - * @returns true, if the veiw was destroyed. Note: This + * @returns true, if the view was destroyed. Note: This * needs to access internal attributes from the change detection * reference. */ private wasViewDestroyed(): boolean { - return (this.cdRef).destroyed; + return (this.cd).destroyed; } /** @@ -218,7 +218,7 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit { private setError(error: string): void { this.error = error; this.form.setErrors({ error: true }); - this.cdRef.detectChanges(); + this.cd.detectChanges(); } /** 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 e18804405..a56e442fd 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 @@ -5,7 +5,8 @@ import { TemplateRef, OnDestroy, ViewEncapsulation, - ChangeDetectionStrategy + ChangeDetectionStrategy, + ChangeDetectorRef } from '@angular/core'; import { BehaviorSubject, Subscription } from 'rxjs'; import { FormGroup, Validators, FormBuilder } from '@angular/forms'; @@ -188,7 +189,8 @@ export class MediafileListComponent extends BaseViewComponent implements OnInit, private dialog: MatDialog, private fb: FormBuilder, private formBuilder: FormBuilder, - private groupRepo: GroupRepositoryService + private groupRepo: GroupRepositoryService, + private cd: ChangeDetectorRef ) { super(titleService, translate, matSnackBar); @@ -255,6 +257,7 @@ export class MediafileListComponent extends BaseViewComponent implements OnInit, this.dataSource = createDS() .onTrigger(() => mediafiles) .create(); + this.cd.detectChanges(); } });