Browse Source

Autosave improvements.

pull/771/head
Sebastian 4 years ago
parent
commit
3e56fce56f
  1. 14
      frontend/app/features/content/pages/content/content-page.component.ts
  2. 4
      frontend/app/features/content/pages/content/editor/content-section.component.ts
  3. 4
      frontend/app/shared/state/contents.forms.ts

14
frontend/app/features/content/pages/content/content-page.component.ts

@ -7,7 +7,7 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ApiUrlConfig, AppLanguageDto, AppsState, AuthService, AutoSaveKey, AutoSaveService, CanComponentDeactivate, ContentDto, ContentsState, defined, DialogService, EditContentForm, fadeAnimation, LanguagesState, ModalModel, ResourceOwner, SchemaDto, SchemasState, TempService, Version } from '@app/shared';
import { ApiUrlConfig, AppLanguageDto, AppsState, AuthService, AutoSaveKey, AutoSaveService, CanComponentDeactivate, ContentDto, ContentsState, defined, DialogService, EditContentForm, fadeAnimation, LanguagesState, ModalModel, ResourceOwner, SchemaDto, SchemasState, TempService, Types, Version } from '@app/shared';
import { Observable, of } from 'rxjs';
import { filter, map, tap } from 'rxjs/operators';
import { ContentReferencesComponent } from './references/content-references.component';
@ -21,7 +21,6 @@ import { ContentReferencesComponent } from './references/content-references.comp
],
})
export class ContentPageComponent extends ResourceOwner implements CanComponentDeactivate, OnInit {
private isLoadingContent: boolean;
private autoSaveKey: AutoSaveKey;
@ViewChild(ContentReferencesComponent)
@ -126,9 +125,13 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
}));
this.own(
this.contentForm.valueChanges.pipe(filter(_ => !this.isLoadingContent && this.contentForm.form.enabled))
this.contentForm.valueChanges.pipe(filter(_ => this.contentForm.form.enabled))
.subscribe(value => {
if (!Types.equals(value, this.content?.data)) {
this.autoSaveService.set(this.autoSaveKey, value);
} else {
this.autoSaveService.remove(this.autoSaveKey);
}
}));
}
@ -279,15 +282,10 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
}
private loadContent(data: any, isInitial: boolean) {
this.isLoadingContent = true;
try {
this.autoSaveService.remove(this.autoSaveKey);
this.contentForm.load(data, isInitial);
this.contentForm.setEnabled(!this.content || this.content.canUpdate);
} finally {
this.isLoadingContent = false;
}
}
}

4
frontend/app/features/content/pages/content/editor/content-section.component.ts

@ -55,15 +55,19 @@ export class ContentSectionComponent extends StatefulComponent<State> implements
});
this.changes.subscribe(state => {
if (this.formSection?.separator && this.schema) {
this.localStore.setBoolean(this.configKey(), state.isCollapsed);
}
});
}
public ngOnChanges() {
if (this.formSection?.separator && this.schema) {
const isCollapsed = this.localStore.getBoolean(this.configKey());
this.next({ isCollapsed });
}
}
public toggle() {
this.next(s => ({

4
frontend/app/shared/state/contents.forms.ts

@ -7,7 +7,7 @@
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { debounceTimeSafe, Form, getRawValue, Types, UndefinableFormArray, UndefinableFormGroup, valueAll$ } from '@app/framework';
import { BehaviorSubject, Observable } from 'rxjs';
import { BehaviorSubject, distinctUntilChanged, Observable } from 'rxjs';
import { AppLanguageDto } from './../services/app-languages.service';
import { LanguageDto } from './../services/languages.service';
import { FieldDto, RootFieldDto, SchemaDto, TableField } from './../services/schemas.service';
@ -121,7 +121,7 @@ export class EditContentForm extends Form<FormGroup, any> {
return new FieldSection<RootFieldDto, FieldForm>(separator, forms);
});
valueAll$(this.form).pipe(debounceTimeSafe(debounce)).subscribe(value => {
valueAll$(this.form).pipe(debounceTimeSafe(debounce), distinctUntilChanged(Types.equals)).subscribe(value => {
this.valueChange$.next(value);
this.updateState(value);

Loading…
Cancel
Save