Add better change detection to MediaFiles

There was a chance that the file browser did not update after creating or renaming a folder.
This commit is contained in:
Sean Engelhardt 2019-07-26 10:41:46 +02:00
parent ec853e5aba
commit db30831d3e
4 changed files with 18 additions and 15 deletions

View File

@ -268,11 +268,11 @@ export class ListViewTableComponent<V extends BaseViewModel, M extends BaseModel
private operator: OperatorService, private operator: OperatorService,
vp: ViewportService, vp: ViewportService,
private store: StorageService, private store: StorageService,
private ref: ChangeDetectorRef private cd: ChangeDetectorRef
) { ) {
vp.isMobileSubject.subscribe(mobile => { vp.isMobileSubject.subscribe(mobile => {
if (mobile !== this.isMobile) { if (mobile !== this.isMobile) {
this.ref.markForCheck(); this.cd.markForCheck();
} }
this.isMobile = mobile; this.isMobile = mobile;
}); });

View File

@ -39,12 +39,12 @@ export class GlobalSpinnerComponent implements OnInit, OnDestroy {
* *
* @param spinnerService Reference to the service for this spinner. * @param spinnerService Reference to the service for this spinner.
* @param translate Service to get translations for the messages. * @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( public constructor(
private spinnerService: SpinnerService, private spinnerService: SpinnerService,
protected translate: TranslateService, protected translate: TranslateService,
private detector: ChangeDetectorRef private cd: ChangeDetectorRef
) {} ) {}
/** /**
@ -59,7 +59,7 @@ export class GlobalSpinnerComponent implements OnInit, OnDestroy {
if (!this.text) { if (!this.text) {
this.text = this.LOADING; this.text = this.LOADING;
} }
this.detector.detectChanges(); this.cd.detectChanges();
}); });
} }

View File

@ -97,7 +97,7 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit {
* @param titleService Title * @param titleService Title
* @param translate TranslateService * @param translate TranslateService
* @param formBuilder FormBuilder * @param formBuilder FormBuilder
* @param cdRef ChangeDetectorRef * @param cd ChangeDetectorRef
* @param repo ConfigRepositoryService * @param repo ConfigRepositoryService
* @param dateTimeAdapter DateTimeAdapter * @param dateTimeAdapter DateTimeAdapter
*/ */
@ -105,7 +105,7 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit {
protected titleService: Title, protected titleService: Title,
protected translate: TranslateService, protected translate: TranslateService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private cdRef: ChangeDetectorRef, private cd: ChangeDetectorRef,
public repo: ConfigRepositoryService public repo: ConfigRepositoryService
) { ) {
super(titleService, translate); super(titleService, translate);
@ -160,7 +160,7 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit {
this.debounceTimeout = <any>setTimeout(() => { this.debounceTimeout = <any>setTimeout(() => {
this.update(value); this.update(value);
}, this.configItem.getDebouncingTimeout()); }, this.configItem.getDebouncingTimeout());
this.cdRef.detectChanges(); this.cd.detectChanges();
} }
/** /**
@ -194,22 +194,22 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit {
this.updateSuccessIconTimeout = <any>setTimeout(() => { this.updateSuccessIconTimeout = <any>setTimeout(() => {
this.updateSuccessIcon = false; this.updateSuccessIcon = false;
if (!this.wasViewDestroyed()) { if (!this.wasViewDestroyed()) {
this.cdRef.detectChanges(); this.cd.detectChanges();
} }
}, 2000); }, 2000);
this.updateSuccessIcon = true; this.updateSuccessIcon = true;
if (!this.wasViewDestroyed()) { 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 * needs to access internal attributes from the change detection
* reference. * reference.
*/ */
private wasViewDestroyed(): boolean { private wasViewDestroyed(): boolean {
return (<any>this.cdRef).destroyed; return (<any>this.cd).destroyed;
} }
/** /**
@ -218,7 +218,7 @@ export class ConfigFieldComponent extends BaseComponent implements OnInit {
private setError(error: string): void { private setError(error: string): void {
this.error = error; this.error = error;
this.form.setErrors({ error: true }); this.form.setErrors({ error: true });
this.cdRef.detectChanges(); this.cd.detectChanges();
} }
/** /**

View File

@ -5,7 +5,8 @@ import {
TemplateRef, TemplateRef,
OnDestroy, OnDestroy,
ViewEncapsulation, ViewEncapsulation,
ChangeDetectionStrategy ChangeDetectionStrategy,
ChangeDetectorRef
} from '@angular/core'; } from '@angular/core';
import { BehaviorSubject, Subscription } from 'rxjs'; import { BehaviorSubject, Subscription } from 'rxjs';
import { FormGroup, Validators, FormBuilder } from '@angular/forms'; import { FormGroup, Validators, FormBuilder } from '@angular/forms';
@ -188,7 +189,8 @@ export class MediafileListComponent extends BaseViewComponent implements OnInit,
private dialog: MatDialog, private dialog: MatDialog,
private fb: FormBuilder, private fb: FormBuilder,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private groupRepo: GroupRepositoryService private groupRepo: GroupRepositoryService,
private cd: ChangeDetectorRef
) { ) {
super(titleService, translate, matSnackBar); super(titleService, translate, matSnackBar);
@ -255,6 +257,7 @@ export class MediafileListComponent extends BaseViewComponent implements OnInit,
this.dataSource = createDS<ViewMediafile>() this.dataSource = createDS<ViewMediafile>()
.onTrigger(() => mediafiles) .onTrigger(() => mediafiles)
.create(); .create();
this.cd.detectChanges();
} }
}); });