Browse Source

Autosave improvements.

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

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

@ -7,7 +7,7 @@
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; 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 { Observable, of } from 'rxjs';
import { filter, map, tap } from 'rxjs/operators'; import { filter, map, tap } from 'rxjs/operators';
import { ContentReferencesComponent } from './references/content-references.component'; 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 { export class ContentPageComponent extends ResourceOwner implements CanComponentDeactivate, OnInit {
private isLoadingContent: boolean;
private autoSaveKey: AutoSaveKey; private autoSaveKey: AutoSaveKey;
@ViewChild(ContentReferencesComponent) @ViewChild(ContentReferencesComponent)
@ -126,9 +125,13 @@ export class ContentPageComponent extends ResourceOwner implements CanComponentD
})); }));
this.own( this.own(
this.contentForm.valueChanges.pipe(filter(_ => !this.isLoadingContent && this.contentForm.form.enabled)) this.contentForm.valueChanges.pipe(filter(_ => this.contentForm.form.enabled))
.subscribe(value => { .subscribe(value => {
this.autoSaveService.set(this.autoSaveKey, 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) { private loadContent(data: any, isInitial: boolean) {
this.isLoadingContent = true; this.autoSaveService.remove(this.autoSaveKey);
try {
this.autoSaveService.remove(this.autoSaveKey); this.contentForm.load(data, isInitial);
this.contentForm.setEnabled(!this.content || this.content.canUpdate);
this.contentForm.load(data, isInitial);
this.contentForm.setEnabled(!this.content || this.content.canUpdate);
} finally {
this.isLoadingContent = false;
}
} }
} }

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

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

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

@ -7,7 +7,7 @@
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { debounceTimeSafe, Form, getRawValue, Types, UndefinableFormArray, UndefinableFormGroup, valueAll$ } from '@app/framework'; 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 { AppLanguageDto } from './../services/app-languages.service';
import { LanguageDto } from './../services/languages.service'; import { LanguageDto } from './../services/languages.service';
import { FieldDto, RootFieldDto, SchemaDto, TableField } from './../services/schemas.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); 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.valueChange$.next(value);
this.updateState(value); this.updateState(value);

Loading…
Cancel
Save