Browse Source

Fix

pull/421/head
Sebastian Stehle 6 years ago
parent
commit
804b96e5b9
  1. 12
      src/Squidex/app/shared/state/contents.forms.spec.ts
  2. 21
      src/Squidex/app/shared/state/contents.forms.ts
  3. 2
      src/Squidex/app/shared/state/contents.state.ts

12
src/Squidex/app/shared/state/contents.forms.spec.ts

@ -707,6 +707,18 @@ describe('ContentForm', () => {
expect(simpleForm.hasChanged()).toBeFalsy();
});
it('should subscribe to values', () => {
simpleForm.form.setValue({ field1: { iv: 'Change' }});
let value: any;
simpleForm.value.subscribe(v => {
value = v;
});
expect(value).toEqual({ field1: { iv: 'Change' }});
});
});
describe('for editing content', () => {

21
src/Squidex/app/shared/state/contents.forms.ts

@ -8,6 +8,7 @@
// tslint:disable:prefer-for-of
import { FormArray, FormBuilder, FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms';
import { BehaviorSubject } from 'rxjs';
import {
DateTime,
@ -15,8 +16,7 @@ import {
formControls,
ImmutableArray,
Types,
ValidatorsEx,
value$
ValidatorsEx
} from '@app/framework';
import { ContentDto, ContentReferencesValue } from '../services/contents.service';
@ -53,8 +53,7 @@ export class SaveQueryForm extends Form<FormGroup, any> {
[
Validators.required
]
],
user: false
]
}));
}
}
@ -346,9 +345,9 @@ export class FieldDefaultValue implements FieldPropertiesVisitor<any> {
const now = this.now || DateTime.now();
if (properties.calculatedDefaultValue === 'Now') {
return `${now.toUTCStringFormat('YYYY-MM-DDTHH:mm:ss')}Z`;
return now.toUTCStringFormat('YYYY-MM-DDTHH:mm:ss') + 'Z';
} else if (properties.calculatedDefaultValue === 'Today') {
return `${now.toUTCStringFormat('YYYY-MM-DD')}T00:00:00Z`;
return now.toUTCStringFormat('YYYY-MM-DD');
} else {
return properties.defaultValue;
}
@ -425,13 +424,17 @@ export class EditContentForm extends Form<FormGroup, any> {
private readonly partitions: PartitionConfig;
private initialData: any;
public value = value$(this.form);
public value = new BehaviorSubject<any>(this.form.value);
constructor(languages: ImmutableArray<AppLanguageDto>,
private readonly schema: SchemaDetailsDto
) {
super(new FormGroup({}));
this.form.valueChanges.subscribe(value => {
this.value.next(value);
});
this.partitions = new PartitionConfig(languages);
for (const field of schema.fields) {
@ -563,6 +566,10 @@ export class EditContentForm extends Form<FormGroup, any> {
if (isInitial) {
this.extractPrevData();
}
this.value.subscribe(x => {
JSON.stringify(x);
});
}
public submitCompleted(options?: { newValue?: any, noReset?: boolean }) {

2
src/Squidex/app/shared/state/contents.state.ts

@ -186,7 +186,7 @@ export abstract class ContentsStateBase extends State<Snapshot> {
public create(request: any, publish: boolean): Observable<ContentDto> {
return this.contentsService.postContent(this.appName, this.schemaName, request, publish).pipe(
tap(payload => {
this.dialogs.notifyInfo('Contents created successfully.');
this.dialogs.notifyInfo('Content created successfully.');
return this.next(s => {
const contents = s.contents.pushFront(payload);

Loading…
Cancel
Save