Browse Source

Minor fixes.

pull/95/head
Sebastian Stehle 9 years ago
parent
commit
a75a40ac30
  1. 2
      src/Squidex/app/features/content/pages/content/content-page.component.ts
  2. 2
      src/Squidex/app/features/content/pages/contents/contents-page.component.ts
  3. 2
      src/Squidex/app/features/content/pages/messages.ts
  4. 2
      src/Squidex/app/features/schemas/pages/messages.ts
  5. 6
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.html
  6. 2
      src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts
  7. 15
      src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts
  8. 28
      src/Squidex/app/framework/utils/immutable-array.spec.ts
  9. 60
      src/Squidex/app/framework/utils/immutable-array.ts
  10. 2
      src/Squidex/app/shared/services/apps.service.spec.ts
  11. 2
      src/Squidex/app/shared/services/assets.service.spec.ts
  12. 4
      src/Squidex/app/shared/services/schemas.service.spec.ts

2
src/Squidex/app/features/content/pages/content/content-page.component.ts

@ -81,7 +81,7 @@ export class ContentPageComponent extends AppComponentBase implements CanCompone
this.contentDeletedSubscription =
this.messageBus.of(ContentDeleted)
.subscribe(message => {
if (message.contentId === this.contentId) {
if (message.content.id === this.contentId) {
this.router.navigate(['../'], { relativeTo: this.route });
}
});

2
src/Squidex/app/features/content/pages/contents/contents-page.component.ts

@ -148,7 +148,7 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy
this.contentItems = this.contentItems.removeAll(x => x.id === content.id);
this.contentsPager = this.contentsPager.decrementCount();
this.messageBus.publish(new ContentDeleted(content.id));
this.messageBus.publish(new ContentDeleted(content));
}, error => {
this.notifyError(error);
});

2
src/Squidex/app/features/content/pages/messages.ts

@ -23,7 +23,7 @@ export class ContentUpdated {
export class ContentDeleted {
constructor(
public readonly contentId: string
public readonly content: ContentDto
) {
}
}

2
src/Squidex/app/features/schemas/pages/messages.ts

@ -16,7 +16,7 @@ export class SchemaUpdated {
export class SchemaDeleted {
constructor(
public readonly schemaId: string
public readonly schema: SchemaDto
) {
}
}

6
src/Squidex/app/features/schemas/pages/schema/schema-page.component.html

@ -30,7 +30,7 @@
</div>
<h3 class="panel-title">
{{schemaInformation | sqxDisplayName}} <i class="schema-edit icon-pencil" (click)="editSchemaDialog.show()"></i>
{{schema | sqxDisplayName:'properties.label':'name'}} <i class="schema-edit icon-pencil" (click)="editSchemaDialog.show()"></i>
</h3>
</div>
@ -40,8 +40,8 @@
</div>
<div class="panel-main">
<div class="panel-content panel-content-scroll" dnd-sortable-container [sortableData]="schemaFields.mutableValues">
<div *ngFor="let field of schemaFields; let i = index" dnd-sortable [sortableIndex]="i" (sqxSorted)="sortFields($event)">
<div class="panel-content panel-content-scroll" dnd-sortable-container [sortableData]="schema.fields">
<div *ngFor="let field of schema.fields; let i = index" dnd-sortable [sortableIndex]="i" (sqxSorted)="sortFields($event)">
<sqx-field [field]="field" [schemas]="schemas"
(disabling)="disableField(field)"
(deleting)="deleteField(field)"

2
src/Squidex/app/features/schemas/pages/schema/schema-page.component.ts

@ -201,7 +201,7 @@ export class SchemaPageComponent extends AppComponentBase implements OnInit {
this.appNameOnce()
.switchMap(app => this.schemasService.deleteSchema(app, this.schema.name, this.schema.version)).retry(2)
.subscribe(() => {
this.messageBus.publish(new SchemaDeleted(this.schema.id));
this.messageBus.publish(new SchemaDeleted(this.schema));
this.router.navigate(['../'], { relativeTo: this.route });
}, error => {

15
src/Squidex/app/features/schemas/pages/schemas/schemas-page.component.ts

@ -80,7 +80,7 @@ export class SchemasPageComponent extends AppComponentBase implements OnDestroy,
this.schemaDeletedSubscription =
this.messageBus.of(SchemaDeleted)
.subscribe(m => {
this.updateSchemas(this.schemas.filter(s => s.id !== m.schemaId));
this.updateSchemas(this.schemas.filter(s => s.id !== m.schema.id));
});
this.load();
@ -111,18 +111,7 @@ export class SchemasPageComponent extends AppComponentBase implements OnDestroy,
schemas = schemas.filter(t => t.name.indexOf(query!) >= 0);
}
schemas =
schemas.sort((a, b) => {
if (a.name < b.name) {
return -1;
}
if (a.name > b.name) {
return 1;
}
return 0;
});
this.schemasFiltered = schemas;
this.schemasFiltered = schemas.sortByStringAsc(x => x.name);
}
}

28
src/Squidex/app/framework/utils/immutable-array.spec.ts

@ -161,6 +161,34 @@ describe('ImmutableArray', () => {
expect(array_2.values).toEqual([1, 2, 3, 4]);
});
it('should sort ascending by numbers', () => {
const array_1 = ImmutableArray.of([{ id: 3 }, { id: 2 }, { id: 1 }]);
const array_2 = array_1.sortByNumberAsc(x => x.id);
expect(array_2.values).toEqual([{ id: 1 }, { id: 2 }, { id: 3 }]);
});
it('should sort descending by numbers', () => {
const array_1 = ImmutableArray.of([{ id: 1 }, { id: 2 }, { id: 3 }]);
const array_2 = array_1.sortByNumberDesc(x => x.id);
expect(array_2.values).toEqual([{ id: 3 }, { id: 2 }, { id: 1 }]);
});
it('should sort ascending by string', () => {
const array_1 = ImmutableArray.of([{ id: '3' }, { id: '2' }, { id: '1' }]);
const array_2 = array_1.sortByStringAsc(x => x.id);
expect(array_2.values).toEqual([{ id: '1' }, { id: '2' }, { id: '3' }]);
});
it('should sort descending by string', () => {
const array_1 = ImmutableArray.of([{ id: '1' }, { id: '2' }, { id: '3' }]);
const array_2 = array_1.sortByStringDesc(x => x.id);
expect(array_2.values).toEqual([{ id: '3' }, { id: '2' }, { id: '1' }]);
});
it('should provide mutable values', () => {
const array_1 = ImmutableArray.of([3, 1, 4, 2]);

60
src/Squidex/app/framework/utils/immutable-array.ts

@ -73,6 +73,66 @@ export class ImmutableArray<T> implements Iterable<T> {
return new ImmutableArray<T>(clone);
}
public sortByStringAsc(filter: (a: T) => string): ImmutableArray<T> {
return this.sort((a, b) => {
const av = filter(a);
const bv = filter(b);
if (av < bv) {
return -1;
}
if (av > bv) {
return 1;
}
return 0;
});
}
public sortByStringDesc(filter: (a: T) => string): ImmutableArray<T> {
return this.sort((a, b) => {
const av = filter(a);
const bv = filter(b);
if (av < bv) {
return 1;
}
if (av > bv) {
return -1;
}
return 0;
});
}
public sortByNumberAsc(filter: (a: T) => number): ImmutableArray<T> {
return this.sort((a, b) => {
const av = filter(a);
const bv = filter(b);
if (av < bv) {
return -1;
}
if (av > bv) {
return 1;
}
return 0;
});
}
public sortByNumberDesc(filter: (a: T) => number): ImmutableArray<T> {
return this.sort((a, b) => {
const av = filter(a);
const bv = filter(b);
if (av < bv) {
return 1;
}
if (av > bv) {
return -1;
}
return 0;
});
}
public pushFront(...items: T[]): ImmutableArray<T> {
if (!items || items.length === 0) {
return this;

2
src/Squidex/app/shared/services/apps.service.spec.ts

@ -79,7 +79,7 @@ describe('AppsService', () => {
let app: AppDto | null = null;
appsService.postApp(dto).subscribe(result => {
appsService.postApp(dto, now).subscribe(result => {
app = result;
});

2
src/Squidex/app/shared/services/assets.service.spec.ts

@ -207,7 +207,7 @@ describe('AssetsService', () => {
let asset: AssetDto | null = null;
assetsService.uploadFile('my-app', null!, user).subscribe(result => {
assetsService.uploadFile('my-app', null!, user, now).subscribe(result => {
asset = <AssetDto>result;
});

4
src/Squidex/app/shared/services/schemas.service.spec.ts

@ -241,7 +241,7 @@ describe('SchemasService', () => {
const dto = new CreateSchemaDto('name');
let schema: SchemaDto | null = null;
let schema: SchemaDetailsDto | null = null;
schemasService.postSchema('my-app', dto, user, now, version).subscribe(result => {
schema = result;
@ -255,7 +255,7 @@ describe('SchemasService', () => {
req.flush({ id: '1' });
expect(schema).toEqual(
new SchemaDto('my-schema', dto.name, new SchemaPropertiesDto(null, null), false, user, user, now, now, version));
new SchemaDetailsDto('1', dto.name, new SchemaPropertiesDto(null, null), false, user, user, now, now, version, []));
}));
it('should make post request to add field',

Loading…
Cancel
Save