From f8520d2bc1bceafe7d8b1f861dc8a3973c3e86c0 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Thu, 20 Jun 2019 15:47:02 +0200 Subject: [PATCH] Field ordering fixed. --- .../Areas/Api/Controllers/Schemas/Models/FieldDto.cs | 6 ++++-- .../Areas/Api/Controllers/Schemas/Models/SchemaDto.cs | 2 +- .../app/features/schemas/pages/schema/field.component.ts | 2 +- .../features/schemas/pages/schema/schema-page.component.ts | 2 +- src/Squidex/app/shared/services/schemas.service.spec.ts | 4 ++-- src/Squidex/app/shared/services/schemas.service.ts | 4 ++-- src/Squidex/app/shared/state/schemas.state.spec.ts | 4 ++-- src/Squidex/app/shared/state/schemas.state.ts | 2 +- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Squidex/Areas/Api/Controllers/Schemas/Models/FieldDto.cs b/src/Squidex/Areas/Api/Controllers/Schemas/Models/FieldDto.cs index 16ad30e3c..bc583bb03 100644 --- a/src/Squidex/Areas/Api/Controllers/Schemas/Models/FieldDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Schemas/Models/FieldDto.cs @@ -88,9 +88,11 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models if (Properties is ArrayFieldPropertiesDto) { - AddPostLink("fields/add", controller.Url(x => nameof(x.PostNestedField), values)); + var parentValues = new { app, name = schema, parentId = FieldId }; - AddPutLink("order", controller.Url(x => nameof(x.PutNestedFieldOrdering), values)); + AddPostLink("fields/add", controller.Url(x => nameof(x.PostNestedField), parentValues)); + + AddPutLink("fields/order", controller.Url(x => nameof(x.PutNestedFieldOrdering), parentValues)); } AddPutLink("lock", controller.Url(x => nameof(x.LockField), values)); diff --git a/src/Squidex/Areas/Api/Controllers/Schemas/Models/SchemaDto.cs b/src/Squidex/Areas/Api/Controllers/Schemas/Models/SchemaDto.cs index 7a48b73d9..35fafd420 100644 --- a/src/Squidex/Areas/Api/Controllers/Schemas/Models/SchemaDto.cs +++ b/src/Squidex/Areas/Api/Controllers/Schemas/Models/SchemaDto.cs @@ -119,7 +119,7 @@ namespace Squidex.Areas.Api.Controllers.Schemas.Models if (allowUpdate) { - AddPutLink("order", controller.Url(x => nameof(x.PutSchemaFieldOrdering), values)); + AddPutLink("fields/order", controller.Url(x => nameof(x.PutSchemaFieldOrdering), values)); AddPutLink("update", controller.Url(x => nameof(x.PutSchema), values)); AddPutLink("update/category", controller.Url(x => nameof(x.PutCategory), values)); diff --git a/src/Squidex/app/features/schemas/pages/schema/field.component.ts b/src/Squidex/app/features/schemas/pages/schema/field.component.ts index db2288385..848aef0f8 100644 --- a/src/Squidex/app/features/schemas/pages/schema/field.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/field.component.ts @@ -95,7 +95,7 @@ export class FieldComponent implements OnChanges { } public sortFields(fields: NestedFieldDto[]) { - this.schemasState.sortFields(this.schema, fields, this.field).subscribe(); + this.schemasState.orderFields(this.schema, fields, this.field).subscribe(); } public lockField() { diff --git a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts index abc5b1f46..d9957a1f0 100644 --- a/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts +++ b/src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts @@ -87,7 +87,7 @@ export class SchemaPageComponent extends ResourceOwner implements OnInit { } public sortFields(fields: FieldDto[]) { - this.schemasState.sortFields(this.schema, fields).subscribe(); + this.schemasState.orderFields(this.schema, fields).subscribe(); } public trackByField(index: number, field: FieldDto) { diff --git a/src/Squidex/app/shared/services/schemas.service.spec.ts b/src/Squidex/app/shared/services/schemas.service.spec.ts index 0daacd8e9..cec206ce2 100644 --- a/src/Squidex/app/shared/services/schemas.service.spec.ts +++ b/src/Squidex/app/shared/services/schemas.service.spec.ts @@ -236,7 +236,7 @@ describe('SchemasService', () => { const resource: Resource = { _links: { - ['update/urls'] { method: 'PUT', href: '/api/apps/my-app/schemas/my-schema/preview-urls' } + ['update/urls']: { method: 'PUT', href: '/api/apps/my-app/schemas/my-schema/preview-urls' } } }; @@ -387,7 +387,7 @@ describe('SchemasService', () => { const resource: Resource = { _links: { - order: { method: 'PUT', href: '/api/apps/my-app/schemas/my-schema/fields/ordering' } + ['fields/order']: { method: 'PUT', href: '/api/apps/my-app/schemas/my-schema/fields/ordering' } } }; diff --git a/src/Squidex/app/shared/services/schemas.service.ts b/src/Squidex/app/shared/services/schemas.service.ts index d74774141..e02391b2a 100644 --- a/src/Squidex/app/shared/services/schemas.service.ts +++ b/src/Squidex/app/shared/services/schemas.service.ts @@ -385,11 +385,11 @@ export class SchemasService { } public putFieldOrdering(appName: string, resource: Resource, dto: number[], version: Version): Observable { - const link = resource._links['order']; + const link = resource._links['fields/order']; const url = this.apiUrl.buildUrl(link.href); - return HTTP.requestVersioned(this.http, link.method, url, version, dto).pipe( + return HTTP.requestVersioned(this.http, link.method, url, version, { fieldIds: dto }).pipe( map(({ version: newVersion, payload }) => { return parseSchemaWithDetails(payload.body, newVersion); }), diff --git a/src/Squidex/app/shared/state/schemas.state.spec.ts b/src/Squidex/app/shared/state/schemas.state.spec.ts index 394599074..8668a17f8 100644 --- a/src/Squidex/app/shared/state/schemas.state.spec.ts +++ b/src/Squidex/app/shared/state/schemas.state.spec.ts @@ -373,7 +373,7 @@ describe('SchemasState', () => { schemasService.setup(x => x.putFieldOrdering(app, schema1, [schema.fields[1].fieldId, schema.fields[2].fieldId], version)) .returns(() => of(updated)).verifiable(); - schemasState.sortFields(schema1, [schema.fields[1], schema.fields[2]]).subscribe(); + schemasState.orderFields(schema1, [schema.fields[1], schema.fields[2]]).subscribe(); const schema1New = schemasState.snapshot.schemas.at(0); @@ -387,7 +387,7 @@ describe('SchemasState', () => { schemasService.setup(x => x.putFieldOrdering(app, schema.fields[0], [schema.fields[1].fieldId, schema.fields[2].fieldId], version)) .returns(() => of(updated)).verifiable(); - schemasState.sortFields(schema1, [schema.fields[1], schema.fields[2]], schema.fields[0]).subscribe(); + schemasState.orderFields(schema1, [schema.fields[1], schema.fields[2]], schema.fields[0]).subscribe(); const schema1New = schemasState.snapshot.schemas.at(0); diff --git a/src/Squidex/app/shared/state/schemas.state.ts b/src/Squidex/app/shared/state/schemas.state.ts index 3cdc39c85..68c3ea6d5 100644 --- a/src/Squidex/app/shared/state/schemas.state.ts +++ b/src/Squidex/app/shared/state/schemas.state.ts @@ -233,7 +233,7 @@ export class SchemasState extends State { shareMapSubscribed(this.dialogs, x => getField(x, request, parent), { silent: true })); } - public sortFields(schema: SchemaDto, fields: any[], parent?: RootFieldDto): Observable { + public orderFields(schema: SchemaDto, fields: any[], parent?: RootFieldDto): Observable { return this.schemasService.putFieldOrdering(this.appName, parent || schema, fields.map(t => t.fieldId), schema.version).pipe( tap(updated => { this.replaceSchema(updated);