Browse Source

Cleanup

pull/1/head
Sebastian 10 years ago
parent
commit
8dd4b45b02
  1. 1
      src/Squidex/app/app.component.spec.ts
  2. 2
      src/Squidex/app/components/internal/app/settings/client.component.html
  3. 5
      src/Squidex/app/components/internal/app/settings/client.component.ts
  4. 2
      src/Squidex/app/components/internal/app/settings/clients-page.component.html
  5. 10
      src/Squidex/app/components/internal/app/settings/clients-page.component.ts
  6. 12
      src/Squidex/app/components/internal/app/settings/contributors-page.component.ts
  7. 8
      src/Squidex/app/components/internal/app/settings/languages-page.component.ts
  8. 4
      src/Squidex/app/framework/angular/copy.directive.ts
  9. 2
      src/Squidex/app/framework/angular/date-time.pipes.spec.ts
  10. 4
      src/Squidex/app/framework/declarations.ts
  11. 134
      src/Squidex/app/framework/utils/immutable-array.spec.ts
  12. 136
      src/Squidex/app/framework/utils/immutable-array.ts
  13. 281
      src/Squidex/app/framework/utils/immutable-id-map.spec.ts
  14. 218
      src/Squidex/app/framework/utils/immutable-id-map.ts
  15. 238
      src/Squidex/app/framework/utils/immutable-list.spec.ts
  16. 210
      src/Squidex/app/framework/utils/immutable-list.ts
  17. 158
      src/Squidex/app/framework/utils/immutable-set.spec.ts
  18. 96
      src/Squidex/app/framework/utils/immutable-set.ts
  19. 2
      src/Squidex/app/shared/services/app-clients.service.spec.ts
  20. 2
      src/Squidex/app/shared/services/app-contributors.service.spec.ts
  21. 2
      src/Squidex/app/shared/services/app-languages.service.spec.ts
  22. 4
      src/Squidex/app/shared/services/apps-store.service.spec.ts
  23. 2
      src/Squidex/app/shared/services/apps.service.spec.ts
  24. 2
      src/Squidex/app/shared/services/languages.service.spec.ts
  25. 10
      src/Squidex/app/shared/services/users-provider.service.spec.ts
  26. 2
      src/Squidex/app/shared/services/users.service.spec.ts
  27. 7
      src/Squidex/app/vendor.ts
  28. 1
      src/Squidex/package.json

1
src/Squidex/app/app.component.spec.ts

@ -1,5 +1,6 @@
import { TestBed } from '@angular/core/testing';
/* tslint:disable ordered-imports */
import { RouterModule, provideRoutes } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';

2
src/Squidex/app/components/internal/app/settings/client.component.html

@ -39,7 +39,7 @@
<tr>
<td>Client Id:</td>
<td>
<input readonly class="form-control" #inputId [attr.value]="clientName" #inputName />
<input readonly class="form-control" #inputId [attr.value]="clientId" #inputName />
</td>
<td>
<button type="button" class="btn btn-primary btn-link" [sqxCopy]="inputName">

5
src/Squidex/app/components/internal/app/settings/client.component.ts

@ -34,6 +34,9 @@ export class ClientComponent implements Ng2.OnChanges {
@Ng2.Input()
public client: AppClientDto;
@Ng2.Input()
public appName: string;
public modalDialog = new ModalView();
public get clientName() {
@ -41,7 +44,7 @@ export class ClientComponent implements Ng2.OnChanges {
}
public get clientId() {
return this.client.id + ':' + this.client.secret;
return this.appName + ':' + this.client.id;
}
public get clientSecret() {

2
src/Squidex/app/components/internal/app/settings/clients-page.component.html

@ -16,7 +16,7 @@
</div>
<div *ngFor="let client of appClients">
<sqx-client [client]="client" (renamed)="renameClient(client, $event)"></sqx-client>
<sqx-client [client]="client" [appName]="appName() | async" (renamed)="renameClient(client, $event)"></sqx-client>
</div>
<div class="table-items-footer">

10
src/Squidex/app/components/internal/app/settings/clients-page.component.ts

@ -14,7 +14,7 @@ import {
AppComponentBase,
AppsStoreService,
CreateAppClientDto,
ImmutableList,
ImmutableArray,
NotificationService,
UpdateAppClientDto,
UsersProviderService
@ -30,7 +30,7 @@ function rename(client: AppClientDto, name: string) {
template
})
export class ClientsPageComponent extends AppComponentBase implements Ng2.OnInit {
public appClients: ImmutableList<AppClientDto>;
public appClients: ImmutableArray<AppClientDto>;
public createForm =
this.formBuilder.group({
@ -57,7 +57,7 @@ export class ClientsPageComponent extends AppComponentBase implements Ng2.OnInit
this.appName()
.switchMap(app => this.appClientsService.getClients(app).retry(2))
.subscribe(dtos => {
this.appClients = new ImmutableList<AppClientDto>(dtos);
this.appClients = ImmutableArray.of(dtos);
}, error => {
this.notifyError(error);
});
@ -77,7 +77,7 @@ export class ClientsPageComponent extends AppComponentBase implements Ng2.OnInit
this.appName()
.switchMap(app => this.appClientsService.updateClient(app, client.id, new UpdateAppClientDto(name)))
.subscribe(() => {
this.appClients = this.appClients.update(client, c => rename(c, name));
this.appClients = this.appClients.replace(client, rename(client, name));
}, error => {
this.notifyError(error);
});
@ -94,7 +94,7 @@ export class ClientsPageComponent extends AppComponentBase implements Ng2.OnInit
this.appName()
.switchMap(app => this.appClientsService.postClient(app, dto))
.subscribe(dto => {
this.appClients = this.appClients.add(dto);
this.appClients = this.appClients.push(dto);
this.reset();
}, error => {
this.notifyError(error);

12
src/Squidex/app/components/internal/app/settings/contributors-page.component.ts

@ -17,7 +17,7 @@ import {
AuthService,
AutocompleteItem,
AutocompleteSource,
ImmutableList,
ImmutableArray,
NotificationService,
UserDto,
UsersProviderService,
@ -61,7 +61,7 @@ function changePermission(contributor: AppContributorDto, permission: string): A
template
})
export class ContributorsPageComponent extends AppComponentBase implements Ng2.OnInit {
public appContributors = new ImmutableList<AppContributorDto>();
public appContributors = ImmutableArray.empty<AppContributorDto>();
public currentUserId: string;
@ -95,7 +95,7 @@ export class ContributorsPageComponent extends AppComponentBase implements Ng2.O
this.appName()
.switchMap(app => this.appContributorsService.getContributors(app).retry(2))
.subscribe(dtos => {
this.appContributors = new ImmutableList<AppContributorDto>(dtos);
this.appContributors = ImmutableArray.of(dtos);
}, error => {
this.notifyError(error);
});
@ -114,7 +114,7 @@ export class ContributorsPageComponent extends AppComponentBase implements Ng2.O
this.appName()
.switchMap(app => this.appContributorsService.postContributor(app, contributor))
.subscribe(() => {
this.appContributors = this.appContributors.add(contributor);
this.appContributors = this.appContributors.push(contributor);
}, error => {
this.notifyError(error);
});
@ -126,7 +126,7 @@ export class ContributorsPageComponent extends AppComponentBase implements Ng2.O
this.appName()
.switchMap(app => this.appContributorsService.postContributor(app, newContributor))
.subscribe(() => {
this.appContributors = this.appContributors.update(contributor, c => newContributor);
this.appContributors = this.appContributors.replace(contributor, newContributor);
}, error => {
this.notifyError(error);
});
@ -136,7 +136,7 @@ export class ContributorsPageComponent extends AppComponentBase implements Ng2.O
this.appName()
.switchMap(app => this.appContributorsService.deleteContributor(app, contributor.contributorId))
.subscribe(() => {
this.appContributors = this.appContributors.add(contributor);
this.appContributors = this.appContributors.remove(contributor);
}, error => {
this.notifyError(error);
});

8
src/Squidex/app/components/internal/app/settings/languages-page.component.ts

@ -13,9 +13,9 @@ import {
AppLanguageDto,
AppLanguagesService,
AppsStoreService,
ImmutableArray,
LanguageDto,
LanguageService,
ImmutableList,
NotificationService,
UpdateAppLanguageDto,
UsersProviderService
@ -28,7 +28,7 @@ import {
})
export class LanguagesPageComponent extends AppComponentBase implements Ng2.OnInit {
public allLanguages: LanguageDto[] = [];
public appLanguages = new ImmutableList<AppLanguageDto>();
public appLanguages = ImmutableArray.empty<AppLanguageDto>();
public selectedLanguage: LanguageDto | null = null;
@ -58,7 +58,7 @@ export class LanguagesPageComponent extends AppComponentBase implements Ng2.OnIn
this.appName()
.switchMap(app => this.appLanguagesService.getLanguages(app).retry(2))
.subscribe(dtos => {
this.appLanguages = new ImmutableList<AppLanguageDto>();
this.appLanguages = ImmutableArray.of(dtos);
}, error => {
this.notifyError(error);
});
@ -68,7 +68,7 @@ export class LanguagesPageComponent extends AppComponentBase implements Ng2.OnIn
this.appName()
.switchMap(app => this.appLanguagesService.postLanguages(app, new AddAppLanguageDto(this.selectedLanguage.iso2Code)))
.subscribe(dto => {
this.appLanguages = this.appLanguages.add(dto);
this.appLanguages = this.appLanguages.push(dto);
}, error => {
this.notifyError(error);
});

4
src/Squidex/app/framework/angular/copy.directive.ts

@ -12,12 +12,12 @@ import * as Ng2 from '@angular/core';
})
export class CopyDirective {
@Ng2.Input('sqxCopy')
public inputElement: Ng2.ElementRef;
public inputElement: any;
@Ng2.HostListener('click')
public onClick() {
if (this.inputElement) {
this.copyToClipbord(this.inputElement.nativeElement);
this.copyToClipbord(this.inputElement);
}
}

2
src/Squidex/app/framework/angular/date-time.pipes.spec.ts

@ -13,7 +13,7 @@ import {
DurationPipe,
MonthPipe,
ShortDatePipe,
ShortTimePipe,
ShortTimePipe
} from './date-time.pipes';
const dateTime = DateTime.parse('2013-10-03T12:13:14.125', DateTime.iso8601());

4
src/Squidex/app/framework/declarations.ts

@ -42,9 +42,7 @@ export * from './utils/color-palette';
export * from './utils/date-helper';
export * from './utils/date-time';
export * from './utils/duration';
export * from './utils/immutable-id-map';
export * from './utils/immutable-list';
export * from './utils/immutable-set';
export * from './utils/immutable-array';
export * from './utils/math-helper';
export * from './utils/modal-view';
export * from './utils/rotation';

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

@ -0,0 +1,134 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { ImmutableArray } from './../';
describe('ImmutableArray', () => {
it('should create empty instance', () => {
const array_1 = ImmutableArray.of();
expect(array_1.length).toBe(0);
});
it('should create same instance for empty arrays', () => {
const array_a = ImmutableArray.of();
const array_b = ImmutableArray.of();
const array_c = ImmutableArray.of([]);
const array_d = ImmutableArray.empty();
expect(array_b).toBe(array_a);
expect(array_c).toBe(array_a);
expect(array_d).toBe(array_a);
});
it('should create non empty instance', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
expect(array_1.length).toBe(3);
expect(array_1.values).toEqual([1, 2, 3]);
});
it('should push items', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.push(4, 5);
expect(array_2.length).toBe(5);
expect(array_2.values).toEqual([1, 2, 3, 4, 5]);
});
it('should return same array if pushing zero items', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.push();
expect(array_2).toBe(array_1);
});
it('should remove item', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.remove(2);
expect(array_2.length).toBe(2);
expect(array_2.values).toEqual([1, 3]);
});
it('should return same array if removing zero items', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.remove();
expect(array_2).toBe(array_1);
});
it('should remove all by predicate', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.removeAll((i: number) => i % 2 === 0);
expect(array_2.values).toEqual([1, 3]);
});
it('should return original if nothing has been removed', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.removeAll((i: number) => i % 200 === 0);
expect(array_2).toEqual(array_1);
});
it('should replace item if found', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.replace(2, 4);
expect(array_2.values).toEqual([1, 4, 3]);
});
it('should not replace item if not found', () => {
const array_1 = ImmutableArray.of([1, 2, 3]);
const array_2 = array_1.replace(5, 5);
expect(array_2).toBe(array_1);
});
it('should replace all by predicate', () => {
const array_1 = ImmutableArray.of([1, 2, 3, 4]);
const array_2 = array_1.replaceAll((i: number) => i % 2 === 0, i => i * 2);
expect(array_2.values).toEqual([1, 4, 3, 8]);
});
it('should return original if nothing has been replace', () => {
const array_1 = ImmutableArray.of([1, 2, 3, 4]);
const array_2 = array_1.replaceAll((i: number) => i % 200 === 0, i => i);
expect(array_2).toBe(array_1);
});
it('should filter items', () => {
const array_1 = ImmutableArray.of([1, 2, 3, 4]);
const array_2 = array_1.filter((i: number) => i % 2 === 0);
expect(array_2.values).toEqual([2, 4]);
});
it('should map items', () => {
const array_1 = ImmutableArray.of([1, 2, 3, 4]);
const array_2 = array_1.map((i: number) => i * 2);
expect(array_2.values).toEqual([2, 4, 6, 8]);
});
it('should find item', () => {
const array_1 = ImmutableArray.of([1, 2, 3, 4]);
const result = array_1.find(i => i >= 2.5);
expect(result).toEqual(3);
});
it('should not return item if not found', () => {
const array_1 = ImmutableArray.of([1, 2, 3, 4]);
const result = array_1.find(i => i >= 4.5);
expect(result).toBeUndefined();
});
});

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

@ -0,0 +1,136 @@
function freeze<T>(items: T[]): T[] {
for (let item of items) {
Object.freeze(item);
}
return items;
}
export class ImmutableArray<T> implements Iterable<T> {
private static readonly EMPTY = new ImmutableArray<any>([]);
private readonly items: T[];
public [Symbol.iterator](): Iterator<T> {
return this.items.values();
}
public get length() {
return this.items.length;
}
public get values(): T[] {
return [...this.items];
}
private constructor(items: T[]) {
this.items = items;
}
public static empty<T>(): ImmutableArray<T> {
return ImmutableArray.EMPTY;
}
public static of<T>(items?: T[]): ImmutableArray<T> {
if (!items || items.length === 0) {
return ImmutableArray.EMPTY;
} else {
return new ImmutableArray<T>(freeze([...items]));
}
}
public map<R>(projection: (item: T) => R): ImmutableArray<R> {
return new ImmutableArray<R>(freeze(this.items.map(v => projection(v!))));
}
public filter(predicate: (item: T) => boolean): ImmutableArray<T> {
return new ImmutableArray<T>(this.items.filter(v => predicate(v!)));
}
public find(predicate: (item: T, index: number) => boolean): T {
return this.items.find(predicate);
}
public push(...items: T[]): ImmutableArray<T> {
if (!items || items.length === 0) {
return this;
}
return new ImmutableArray<T>([...this.items, ...freeze(items)]);
}
public remove(...items: T[]): ImmutableArray<T> {
if (!items || items.length === 0) {
return this;
}
const copy = this.items.slice();
for (let item of items) {
const index = copy.indexOf(item);
if (index >= 0) {
copy.splice(index, 1);
}
}
return new ImmutableArray<T>(copy);
}
public removeAll(predicate: (item: T, index: number) => boolean): ImmutableArray<T> {
const copy = this.items.slice();
let hasChange = false;
for (let i = 0; i < copy.length; ) {
if (predicate(copy[i], i)) {
copy.splice(i, 1);
hasChange = true;
} else {
++i;
}
}
return hasChange ? new ImmutableArray<T>(copy) : this;
}
public replace(oldItem: T, newItem: T): ImmutableArray<T> {
const index = this.items.indexOf(oldItem);
if (index >= 0) {
if (newItem) {
Object.freeze(newItem);
}
const copy = [...this.items.slice(0, index), newItem, ...this.items.slice(index + 1)];
return new ImmutableArray<T>(copy);
} else {
return this;
}
}
public replaceAll(predicate: (item: T, index: number) => boolean, replacer: (item: T) => T): ImmutableArray<T> {
const copy = this.items.slice();
let hasChange = false;
for (let i = 0; i < copy.length; i++) {
if (predicate(copy[i], i)) {
const newItem = replacer(copy[i]);
if (newItem) {
Object.freeze(newItem);
}
if (copy[i] !== newItem) {
copy[i] = newItem;
hasChange = true;
}
}
}
return hasChange ? new ImmutableArray<T>(copy) : this;
}
}

281
src/Squidex/app/framework/utils/immutable-id-map.spec.ts

@ -1,281 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { ImmutableIdMap } from './../';
class MockupData {
public readonly id: string;
constructor(public readonly value: string | null, id?: string) {
this.id = id || value!;
}
}
describe('ImmutableIdMap', () => {
const v1 = new MockupData('value1');
const v2 = new MockupData('value2');
const v3 = new MockupData('value3');
const v4 = new MockupData('value4');
const v5 = new MockupData('value5');
const v6 = new MockupData('value6');
it('should instantiate without arguments', () => {
const list = new ImmutableIdMap<MockupData>();
expect(list).toBeDefined();
});
it('should instantiate from array of items', () => {
const list_1 = new ImmutableIdMap<MockupData>([v1, v2, v3]);
expect(list_1.size).toBe(3);
expect(list_1.get('value1')).toBe(v1);
expect(list_1.get('value2')).toBe(v2);
expect(list_1.get('value3')).toBe(v3);
expect(list_1.first).toBe(v1);
expect(list_1.last).toBe(v3);
});
it('should add values to list', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.add(v2);
const list_4 = list_3.add(v3);
expect(list_4.size).toBe(3);
expect(list_4.get('value1')).toBe(v1);
expect(list_4.get('value2')).toBe(v2);
expect(list_4.get('value3')).toBe(v3);
});
it('should convert to array', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.add(v2);
const list_4 = list_3.add(v3);
const items = list_4.toArray();
expect(items.length).toBe(3);
expect(items[0]).toBe(v1);
expect(items[1]).toBe(v2);
expect(items[2]).toBe(v3);
});
it('should return original list when value to add has no id', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(new MockupData(null));
expect(list_2).toBe(list_1);
});
it('should return original list when value to add is null', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(null!);
expect(list_2).toBe(list_1);
});
it('should return original list when item to add has already been added', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.add(v1);
expect(list_3).toBe(list_2);
});
it('should update item', () => {
const newValue = new MockupData(v1.value, v1.id);
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.update(v1.id, t => newValue);
expect(list_3.size).toBe(1);
expect(list_3.get('value1')).toBe(newValue);
});
it('should return undefined for invalid id', () => {
const list_1 = new ImmutableIdMap<MockupData>();
expect(list_1.get(null!)).toBeUndefined();
});
it('should return original list when id to update is null', () => {
const newValue = new MockupData(v1.value, v1.id);
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.update(null!, t => newValue);
expect(list_3).toBe(list_2);
});
it('should return original list when id to update does not exists', () => {
const newValue = new MockupData(v1.value, v1.id);
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.update('unknown', t => newValue);
expect(list_3).toBe(list_2);
});
it('should return original list when updater is null', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.update(v1.id, null!);
expect(list_3).toBe(list_2);
});
it('should return original list when updater returns same item', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.update(v1.id, t => t);
expect(list_3).toBe(list_2);
});
it('should return original list when updater returns item with another id', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.update(v1.id, t => v2);
expect(list_3).toBe(list_2);
});
it('should remove values from list', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.add(v2);
const list_4 = list_3.remove('value1');
expect(list_4.size).toBe(1);
expect(list_4.get('value2')).toBe(v2);
expect(list_4.contains(v1.id)).toBeFalsy();
});
it('should return original list when id to remove is null', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.remove(v1.id, null!);
expect(list_3).toBe(list_2);
});
it('should return original list when id to remove does not exists', () => {
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(v1);
const list_3 = list_2.remove(v1.id, 'unknown');
expect(list_3).toBe(list_2);
});
it('should bring to front', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.bringToFront([v3.id, v5.id]);
expect(list_2.map(t => t.id)).toEqual([v1, v2, v4, v6, v3, v5].map(t => t.id));
});
it('should bring forwards', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.bringForwards([v3.id, v4.id]);
expect(list_2.map(t => t.id)).toEqual([v1, v2, v5, v3, v4, v6].map(t => t.id));
});
it('should send to back', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.sendToBack([v3.id, v5.id]);
expect(list_2.map(t => t.id)).toEqual([v3, v5, v1, v2, v4, v6].map(t => t.id));
});
it('should send backwards', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.sendBackwards([v3.id, v5.id]);
expect(list_2.map(t => t.id)).toEqual([v1, v3, v5, v2, v4, v6].map(t => t.id));
});
it('should move item', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.moveTo([v4.id], 1);
expect(list_2.map(t => t.id)).toEqual([v1, v4, v2, v3, v5, v6].map(t => t.id));
});
it('should ignore items that are not found', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.bringToFront([v3.id, 'not found']);
expect(list_2.map(t => t.id)).toEqual([v1, v2, v4, v5, v6, v3].map(t => t.id));
});
it('should return original list no id found', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.sendBackwards(['not found', 'other not found']);
expect(list_2).toBe(list_1);
});
it('should return original list when ids is null', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.sendBackwards(null!);
expect(list_2).toBe(list_1);
});
it('should return correct result for map', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
const result = list_1.map(t => t.id);
expect(result).toEqual(['value1', 'value2', 'value3', 'value4', 'value5', 'value6']);
});
it('should return correct result for forEach', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
const result: string[] = [];
list_1.forEach(t => result.push(t.id));
expect(result).toEqual(['value1', 'value2', 'value3', 'value4', 'value5', 'value6']);
});
it('should return correct result for filter', () => {
const list_1 = new ImmutableIdMap<MockupData>().add(v1, v2, v3, v4, v5, v6);
let i = 0;
const result = list_1.filter(t => { i++; return i % 2 === 1; });
expect(result).toEqual([v1, v3, v5]);
});
it('should add and remove large item set', () => {
const size = 1000;
const items: MockupData[] = [];
for (let i = 0; i < size; i++) {
items.push(new MockupData(`id${i}`));
}
const list_1 = new ImmutableIdMap<MockupData>();
const list_2 = list_1.add(...items);
expect(list_2.toArray()).toEqual(items);
const list_3 = list_2.remove(...items.map(t => t.id));
expect(list_3.size).toEqual(0);
});
});

218
src/Squidex/app/framework/utils/immutable-id-map.ts

@ -1,218 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import * as Immutable from 'immutable';
export interface WithId {
id: string;
}
export class ImmutableIdMap<T extends WithId> {
private readonly items: Immutable.OrderedMap<string, T>;
public get size(): number {
return this.items.size;
}
public get first(): T {
return this.items.first();
}
public get last(): T {
return this.items.last();
}
constructor(items?: T[] | Immutable.OrderedMap<string, T>) {
if (Array.isArray(items)) {
this.items = Immutable.OrderedMap<string, T>(items.map(x => [x.id, x]));
} else {
this.items = items || Immutable.OrderedMap<string, T>();
}
Object.freeze(this);
}
public get(key: string): T | undefined {
return this.items.get(key, undefined);
}
public contains(id: string): boolean {
return !!this.items.get(id);
}
public toArray(): T[] {
return this.items.toArray();
}
public map<R>(projection: (item: T, key?: string) => R): R[] {
return this.items.map((v, k) => projection(v!, k)).toArray();
}
public filter(projection: (item: T, key?: string) => boolean): T[] {
return this.items.filter((v, k) => projection(v!, k)).toArray();
}
public forEach(projection: (item: T, key?: string) => void): void {
this.items.forEach((v, k) => projection(v!, k));
}
public add(...items: T[]): ImmutableIdMap<T> {
for (let item of items) {
if (!item || !item.id || this.get(item.id)) {
return this;
}
}
let newItems = this.items;
if (items.length > 50) {
newItems = this.items.withMutations(mutable => {
for (let item of items) {
mutable.set(item.id, item);
}
});
} else {
for (let item of items) {
newItems = newItems.set(item.id, item);
}
}
return this.cloned(newItems);
}
public remove(...ids: string[]): ImmutableIdMap<T> {
for (let id of ids) {
if (!id || !this.get(id)) {
return this;
}
}
let newItems = this.items;
if (ids.length > 50) {
newItems = this.items.withMutations(mutable => {
for (let id of ids) {
mutable.remove(id);
}
});
} else {
for (let id of ids) {
newItems = newItems.remove(id);
}
}
return this.cloned(newItems);
}
public update(id: string, updater: (item: T) => T): ImmutableIdMap<T> {
const oldItem = this.items.get(id);
if (!oldItem || !updater) {
return this;
}
const newItem = updater(oldItem);
if (!newItem || newItem === oldItem || newItem.id !== oldItem.id) {
return this;
}
const newItems = this.items.set(id, newItem);
return this.cloned(newItems);
}
public bringToFront(ids: string[]): ImmutableIdMap<T> {
return this.moveTo(ids, Number.MAX_VALUE);
}
public bringForwards(ids: string[]): ImmutableIdMap<T> {
return this.moveTo(ids, 1, true);
}
public sendBackwards(ids: string[]): ImmutableIdMap<T> {
return this.moveTo(ids, -1, true);
}
public sendToBack(ids: string[]): ImmutableIdMap<T> {
return this.moveTo(ids, 0);
}
public moveTo(ids: string[], target: number, relative = false): ImmutableIdMap<T> {
const itemsToStay: ItemToSort<T>[] = [];
const itemsToMove: ItemToSort<T>[] = [];
this.items.toArray().forEach((item: T, index: number) => {
const itemToAdd: ItemToSort<T> = { isInIds: ids && ids.indexOf(item.id) >= 0, index: index, value: item };
if (itemToAdd.isInIds) {
itemsToMove.push(itemToAdd);
} else {
itemsToStay.push(itemToAdd);
}
});
if (itemsToMove.length === 0) {
return this;
}
let isBackwards = false, newIndex = 0;
if (relative) {
isBackwards = target <= 0;
let currentIndex =
target > 0 ?
Number.MIN_VALUE :
Number.MAX_VALUE;
for (let itemFromIds of itemsToMove) {
if (target > 0) {
currentIndex = Math.max(itemFromIds.index, currentIndex);
} else {
currentIndex = Math.min(itemFromIds.index, currentIndex);
}
}
newIndex = currentIndex + target;
} else {
newIndex = target;
if (itemsToMove[0].index > newIndex) {
isBackwards = true;
}
}
const result: any[][] = [];
for (let item of itemsToStay) {
if ((isBackwards && item.index >= newIndex) || item.index > newIndex) {
break;
}
result.push([item.value.id, item.value]);
}
for (let item of itemsToMove) {
result.push([item.value.id, item.value]);
}
for (let item of itemsToStay) {
if ((isBackwards && item.index >= newIndex) || item.index > newIndex) {
result.push([item.value.id, item.value]);
}
}
return this.cloned(Immutable.OrderedMap<string, T>(result));
}
private cloned(items: Immutable.OrderedMap<string, T>): ImmutableIdMap<T> {
return new ImmutableIdMap<T>(items);
}
}
interface ItemToSort<T> { isInIds: boolean; index: number; value: T; }

238
src/Squidex/app/framework/utils/immutable-list.spec.ts

@ -1,238 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { ImmutableList } from './../';
describe('ImmutableList', () => {
const v1 = 'value1';
const v2 = 'value2';
const v3 = 'value3';
const v4 = 'value4';
const v5 = 'value5';
const v6 = 'value6';
it('should instantiate without arguments', () => {
const list = new ImmutableList<string>();
expect(list).toBeDefined();
});
it('should instantiate from array of items', () => {
const list_1 = new ImmutableList<string>([v1, v2, v3]);
expect(list_1.size).toBe(3);
expect(list_1.get(0)).toBe(v1);
expect(list_1.get(1)).toBe(v2);
expect(list_1.get(2)).toBe(v3);
});
it('should add values to list', () => {
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(v1);
const list_3 = list_2.add(v2);
const list_4 = list_3.add(v3);
expect(list_4.size).toBe(3);
expect(list_4.get(0)).toBe(v1);
expect(list_4.get(1)).toBe(v2);
expect(list_4.get(2)).toBe(v3);
});
it('should convert to array', () => {
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(v1);
const list_3 = list_2.add(v2);
const list_4 = list_3.add(v3);
const items = list_4.toArray();
expect(items.length).toBe(3);
expect(items[0]).toBe(v1);
expect(items[1]).toBe(v2);
expect(items[2]).toBe(v3);
});
it('should return original list when value to add is null', () => {
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(null!);
expect(list_2).toBe(list_1);
});
it('should update item', () => {
const newValue = 'v1New';
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(v1);
const list_3 = list_2.update(v1, t => newValue);
expect(list_3.size).toBe(1);
expect(list_3.get(0)).toBe(newValue);
});
it('should return undefined for invalid index', () => {
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(v1);
expect(list_2.get(-10)).toBeUndefined();
expect(list_2.get(100)).toBeUndefined();
});
it('should return original list when item to update is null', () => {
const newValue = 'v1New';
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(v1);
const list_3 = list_2.update(null!, t => newValue);
expect(list_3).toBe(list_2);
});
it('should return original list when updater is null', () => {
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(v1);
const list_3 = list_2.update(v1, null!);
expect(list_3).toBe(list_2);
});
it('should return original list when updater returns same item', () => {
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(v1);
const list_3 = list_2.update(v1, t => t);
expect(list_3).toBe(list_2);
});
it('should remove values from list', () => {
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(v1);
const list_3 = list_2.add(v2);
const list_4 = list_3.remove(v1);
expect(list_4.size).toBe(1);
expect(list_4.get(0)).toBe(v2);
});
it('should return original list when item to remove is null', () => {
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(v1);
const list_3 = list_2.remove(null!);
expect(list_3).toBe(list_2);
});
it('should return original list when item to remove does not exists', () => {
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(v1);
const list_3 = list_2.remove(v4);
expect(list_3).toBe(list_2);
});
it('should bring to front', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.bringToFront([v3, v5]);
expect(list_2.toArray()).toEqual([v1, v2, v4, v6, v3, v5]);
});
it('should bring forwards', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.bringForwards([v3, v4]);
expect(list_2.toArray()).toEqual([v1, v2, v5, v3, v4, v6]);
});
it('should send to back', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.sendToBack([v3, v5]);
expect(list_2.toArray()).toEqual([v3, v5, v1, v2, v4, v6]);
});
it('should send backwards', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.sendBackwards([v3, v5]);
expect(list_2.toArray()).toEqual([v1, v3, v5, v2, v4, v6]);
});
it('should move item', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.moveTo([v4], 1);
expect(list_2.toArray()).toEqual([v1, v4, v2, v3, v5, v6]);
});
it('should ignore items that are not found', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.bringToFront([v3, 'not found']);
expect(list_2.toArray()).toEqual([v1, v2, v4, v5, v6, v3]);
});
it('should return original list no id found', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.sendBackwards(['not found']);
expect(list_2).toBe(list_1);
});
it('should return original list when ids is null', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
const list_2 = list_1.sendBackwards(null!);
expect(list_2).toBe(list_1);
});
it('should return correct result for map', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
const result = list_1.map(t => 'x_' + t);
expect(result).toEqual(['x_value1', 'x_value2', 'x_value3', 'x_value4', 'x_value5', 'x_value6']);
});
it('should return correct result for forEach', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
const result: string[] = [];
list_1.forEach(t => result.push('x_' + t));
expect(result).toEqual(['x_value1', 'x_value2', 'x_value3', 'x_value4', 'x_value5', 'x_value6']);
});
it('should return correct result for filter', () => {
const list_1 = new ImmutableList<string>().add(v1, v2, v3, v4, v5, v6);
let i = 0;
const result = list_1.filter(t => { i++; return i % 2 === 1; });
expect(result).toEqual([v1, v3, v5]);
});
it('should add and remove large item set', () => {
const size = 1000;
const items: string[] = [];
for (let i = 0; i < size; i++) {
items.push('id' + i);
}
const list_1 = new ImmutableList<string>();
const list_2 = list_1.add(...items);
expect(list_2.toArray()).toEqual(items);
const list_3 = list_2.remove(...items);
expect(list_3.size).toEqual(0);
});
});

210
src/Squidex/app/framework/utils/immutable-list.ts

@ -1,210 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import * as Immutable from 'immutable';
export class ImmutableList<T> implements Iterable<T> {
private readonly items: Immutable.List<T>;
public [Symbol.iterator](): Iterator<T> {
return this.items.values();
}
public get size(): number {
return this.items.size;
}
constructor(items?: T[] | Immutable.List<T>) {
if (Array.isArray(items)) {
this.items = Immutable.List<T>(items);
} else if (items) {
this.items = items || Immutable.List<T>();
}
Object.freeze(this);
}
public get(index: number): T | undefined {
return this.items.get(index, undefined);
}
public toArray(): T[] {
return this.items.toArray();
}
public map<R>(projection: (item: T) => R): ImmutableList<R> {
return new ImmutableList<R>(this.items.map(v => projection(v!)).toArray());
}
public filter(projection: (item: T) => boolean): T[] {
return this.items.filter(v => projection(v!)).toArray();
}
public forEach(projection: (item: T) => void): void {
this.items.forEach(v => projection(v!));
}
public add(...items: T[]): ImmutableList<T> {
for (let item of items) {
if (!item) {
return this;
}
}
let newItems = this.items;
if (items.length > 50) {
newItems = this.items.withMutations(mutable => {
for (let item of items) {
mutable.push(item);
}
});
} else {
for (let item of items) {
newItems = newItems.push(item);
}
}
return this.cloned(newItems);
}
public remove(...items: T[]): ImmutableList<T> {
for (let item of items) {
if (!item || this.items.indexOf(item) < 0) {
return this;
}
}
let newItems = this.items;
if (items.length > 50) {
newItems = this.items.withMutations(mutable => {
for (let item of items) {
mutable.remove(mutable.indexOf(item));
}
});
} else {
for (let item of items) {
newItems = newItems.remove(newItems.indexOf(item));
}
}
return this.cloned(newItems);
}
public update(item: T, updater: (item: T) => T): ImmutableList<T> {
const index = this.items.indexOf(item);
if (index < 0 || !updater) {
return this;
}
const newItem = updater(item);
if (!newItem || newItem === item) {
return this;
}
const newItems = this.items.set(index, newItem);
return this.cloned(newItems);
}
public bringToFront(items: T[]): ImmutableList<T> {
return this.moveTo(items, Number.MAX_VALUE);
}
public bringForwards(items: T[]): ImmutableList<T> {
return this.moveTo(items, 1, true);
}
public sendBackwards(items: T[]): ImmutableList<T> {
return this.moveTo(items, -1, true);
}
public sendToBack(items: T[]): ImmutableList<T> {
return this.moveTo(items, 0);
}
public moveTo(items: T[], target: number, relative = false): ImmutableList<T> {
const itemsToStay: ItemToSort<T>[] = [];
const itemsToMove: ItemToSort<T>[] = [];
const allItems = this.items.toArray();
for (let i = 0; i < allItems.length; i++) {
const item = allItems[i];
const itemToAdd: ItemToSort<T> = { isInItems: items && items.indexOf(item) >= 0, index: i, value: item };
if (itemToAdd.isInItems) {
itemsToMove.push(itemToAdd);
} else {
itemsToStay.push(itemToAdd);
}
}
if (itemsToMove.length === 0) {
return this;
}
let isBackwards = false, newIndex = 0;
if (relative) {
isBackwards = target <= 0;
let currentIndex =
target > 0 ?
Number.MIN_VALUE :
Number.MAX_VALUE;
for (let itemFromIds of itemsToMove) {
if (target > 0) {
currentIndex = Math.max(itemFromIds.index, currentIndex);
} else {
currentIndex = Math.min(itemFromIds.index, currentIndex);
}
}
newIndex = currentIndex + target;
} else {
newIndex = target;
if (itemsToMove[0].index > newIndex) {
isBackwards = true;
}
}
const result: T[] = [];
for (let item of itemsToStay) {
if ((isBackwards && item.index >= newIndex) || item.index > newIndex) {
break;
}
result.push(item.value);
}
for (let item of itemsToMove) {
result.push(item.value);
}
for (let item of itemsToStay) {
if ((isBackwards && item.index >= newIndex) || item.index > newIndex) {
result.push(item.value);
}
}
return new ImmutableList<T>(result);
}
private cloned(items: Immutable.List<T>): ImmutableList<T> {
return new ImmutableList<T>(items);
}
}
interface ItemToSort<T> { isInItems: boolean; index: number; value: T; }

158
src/Squidex/app/framework/utils/immutable-set.spec.ts

@ -1,158 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { ImmutableSet } from './../';
describe('ImmutableSet', () => {
it('should instantiate instance from array', () => {
const set_1 = new ImmutableSet<string>(['1', '1', '2', '3']);
expect(set_1.size).toBe(3);
expect(set_1.contains('1')).toBeTruthy();
expect(set_1.contains('2')).toBeTruthy();
expect(set_1.contains('3')).toBeTruthy();
});
it('should add items', () => {
const set_1 = new ImmutableSet<string>();
const set_2 = set_1.add('1');
const set_3 = set_2.add('1');
const set_4 = set_3.add('2');
const set_5 = set_4.add('3');
expect(set_5.size).toBe(3);
expect(set_5.contains('1')).toBeTruthy();
expect(set_5.contains('2')).toBeTruthy();
expect(set_5.contains('3')).toBeTruthy();
});
it('should convert to aray', () => {
const set_1 = new ImmutableSet<string>(['a', 'b']);
const array = set_1.toArray();
expect(array.length).toBe(2);
expect(array.indexOf('a') >= 0).toBeTruthy();
expect(array.indexOf('b') >= 0).toBeTruthy();
});
it('should return original set when item to add is null', () => {
const set_1 = new ImmutableSet<string>();
const set_2 = set_1.add(null!);
expect(set_2).toBe(set_1);
});
it('should return original set when item to add already exists', () => {
const set_1 = new ImmutableSet<string>();
const set_2 = set_1.add('1');
const set_3 = set_2.add('1');
expect(set_3).toBe(set_2);
});
it('should remove item', () => {
const set_1 = new ImmutableSet<string>();
const set_2 = set_1.add('1');
const set_3 = set_2.remove('1');
expect(set_3.size).toBe(0);
});
it('should return original set when item to remove is not found', () => {
const set_1 = new ImmutableSet<string>();
const set_2 = set_1.add('1');
const set_3 = set_2.remove('unknown');
expect(set_3).toBe(set_2);
});
it('should create new set', () => {
const set_1 = new ImmutableSet<string>();
const set_2 = set_1.add('1');
const set_3 = set_2.set(['a', 'b']);
expect(set_3.size).toBe(2);
expect(set_3.contains('a')).toBeTruthy();
expect(set_3.contains('b')).toBeTruthy();
});
it('should return original set when any item to set is null', () => {
const set_1 = new ImmutableSet<string>();
const set_2 = set_1.add('1');
const set_3 = set_2.set(['1', null!]);
expect(set_3).toBe(set_2);
});
it('should return original set when items to set is null', () => {
const set_1 = new ImmutableSet<string>();
const set_2 = set_1.add('1');
const set_3 = set_2.set(null!);
expect(set_3).toBe(set_2);
});
it('should return original set when items is same', () => {
const set_1 = new ImmutableSet<string>();
const set_2 = set_1.add('1');
const set_3 = set_2.set(['a', 'b']);
const set_4 = set_3.set(['a', 'b']);
expect(set_4).toBe(set_3);
});
it('should remvoe many', () => {
const set_1 = new ImmutableSet<string>(['1', '2', '3', '4']);
const set_2 = set_1.remove('2', '4');
expect(set_2.size).toBe(2);
expect(set_2.contains('1')).toBeTruthy();
expect(set_2.contains('3')).toBeTruthy();
});
it('should return original set when any item to remove is null', () => {
const set_1 = new ImmutableSet<string>(['1', '2', '3', '4']);
const set_2 = set_1.remove('3', null!);
expect(set_2).toBe(set_1);
});
it('should return original set when items to remove is null', () => {
const set_1 = new ImmutableSet<string>(['1', '2', '3', '4']);
const set_2 = set_1.remove(null!);
expect(set_2).toBe(set_1);
});
it('should return correct result for map', () => {
const set_1 = new ImmutableSet<string>(['1', '2', '3', '4']);
const result = set_1.map(t => t + t);
expect(result).toEqual(['11', '22', '33', '44']);
});
it('should return correct result for forEach', () => {
const set_1 = new ImmutableSet<string>(['1', '2', '3', '4']);
const result: string[] = [];
set_1.forEach(t => result.push(t + t));
expect(result).toEqual(['11', '22', '33', '44']);
});
it('should return correct result for filter', () => {
const set_1 = new ImmutableSet<string>(['1', '2', '3', '4']);
let i = 0;
const result = set_1.filter(t => { i++; return i % 2 === 1; });
expect(result).toEqual(['1', '3']);
});
});

96
src/Squidex/app/framework/utils/immutable-set.ts

@ -1,96 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import * as Immutable from 'immutable';
export class ImmutableSet<T> implements Iterable<T> {
private readonly items: Immutable.Set<T>;
public get size(): number {
return this.items.size;
}
public [Symbol.iterator](): Iterator<T> {
return this.items.values();
}
constructor(items?: T[] | Immutable.Set<T>) {
if (Array.isArray(items)) {
this.items = Immutable.Set<T>(items);
} else {
this.items = items || Immutable.Set<T>();
}
Object.freeze(this);
}
public contains(item: T): boolean {
return this.items.contains(item);
}
public toArray(): T[] {
return this.items.toArray();
}
public map<R>(projection: (item: T) => R): R[] {
return this.items.map(v => projection(v!)).toArray();
}
public filter(projection: (item: T) => boolean): T[] {
return this.items.filter(v => projection(v!)).toArray();
}
public forEach(projection: (item: T) => void): void {
this.items.forEach(v => projection(v!));
}
public add(item: T): ImmutableSet<T> {
if (!item) {
return this;
}
const newItems = this.items.add(item);
return this.cloned(newItems);
}
public remove(...items: T[]): ImmutableSet<T> {
for (let item of items) {
if (!item) {
return this;
}
}
const newItems = this.items.subtract(items);
return this.cloned(newItems);
}
public set(items: T[]): ImmutableSet<T> {
if (!items) {
return this;
}
for (let item of items) {
if (!item) {
return this;
}
}
const newItems = this.items.intersect(items).merge(items);
return this.cloned(newItems);
}
private cloned(items: Immutable.Set<T>): ImmutableSet<T> {
if (items !== this.items) {
return new ImmutableSet<T>(items!);
} else {
return this;
}
}
}

2
src/Squidex/app/shared/services/app-clients.service.spec.ts

@ -59,7 +59,7 @@ describe('AppClientsService', () => {
expect(clients).toEqual(
[
new AppClientDto('client1', 'secret1', 'Client 1', DateTime.parseISO_UTC('2016-12-12T10:10')),
new AppClientDto('client2', 'secret2', 'Client 2', DateTime.parseISO_UTC('2016-11-11T10:10')),
new AppClientDto('client2', 'secret2', 'Client 2', DateTime.parseISO_UTC('2016-11-11T10:10'))
]);
authService.verifyAll();

2
src/Squidex/app/shared/services/app-contributors.service.spec.ts

@ -52,7 +52,7 @@ describe('AppContributorsService', () => {
expect(contributors).toEqual(
[
new AppContributorDto('123', 'Owner'),
new AppContributorDto('456', 'Editor'),
new AppContributorDto('456', 'Editor')
]);
authService.verifyAll();

2
src/Squidex/app/shared/services/app-languages.service.spec.ts

@ -55,7 +55,7 @@ describe('AppLanguagesService', () => {
expect(languages).toEqual(
[
new AppLanguageDto('de', 'German', true),
new AppLanguageDto('en', 'English', false),
new AppLanguageDto('en', 'English', false)
]);
authService.verifyAll();

4
src/Squidex/app/shared/services/apps-store.service.spec.ts

@ -112,7 +112,7 @@ describe('AppsStoreService', () => {
result1 = x;
}).unsubscribe();
store.createApp(new CreateAppDto('new-name'), now).subscribe(x => { });
store.createApp(new CreateAppDto('new-name'), now).subscribe(x => { /* Do Nothing */ });
store.apps.subscribe(x => {
result2 = x;
@ -137,7 +137,7 @@ describe('AppsStoreService', () => {
let result: AppDto[] = null;
store.createApp(new CreateAppDto('new-name'), now).subscribe(x => { });
store.createApp(new CreateAppDto('new-name'), now).subscribe(x => { /* Do Nothing */ });
store.apps.subscribe(x => {
result = x;

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

@ -60,7 +60,7 @@ describe('AppsService', () => {
expect(apps).toEqual([
new AppDto('123', 'name1', DateTime.parseISO('2016-01-01'), DateTime.parseISO('2016-02-02'), 'Owner'),
new AppDto('456', 'name2', DateTime.parseISO('2017-01-01'), DateTime.parseISO('2017-02-02'), 'Editor'),
new AppDto('456', 'name2', DateTime.parseISO('2017-01-01'), DateTime.parseISO('2017-02-02'), 'Editor')
]);
authService.verifyAll();

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

@ -52,7 +52,7 @@ describe('LanguageService', () => {
expect(languages).toEqual(
[
new LanguageDto('de', 'German'),
new LanguageDto('en', 'English'),
new LanguageDto('en', 'English')
]);
authService.verifyAll();

10
src/Squidex/app/shared/services/users-provider.service.spec.ts

@ -14,7 +14,7 @@ import {
Profile,
UserDto,
UsersProviderService,
UsersService,
UsersService
} from './../';
describe('UsersProviderService', () => {
@ -29,7 +29,7 @@ describe('UsersProviderService', () => {
});
it('Should return users service when user not cached', () => {
const user = new UserDto('123', 'mail@domain.com', 'User1', 'path/to/image', );
const user = new UserDto('123', 'mail@domain.com', 'User1', 'path/to/image');
usersService.setup(x => x.getUser('123'))
.returns(() => Observable.of(user))
@ -47,7 +47,7 @@ describe('UsersProviderService', () => {
});
it('Should return provide user from cache', () => {
const user = new UserDto('123', 'mail@domain.com', 'User1', 'path/to/image', );
const user = new UserDto('123', 'mail@domain.com', 'User1', 'path/to/image');
usersService.setup(x => x.getUser('123'))
.returns(() => Observable.of(user))
@ -67,7 +67,7 @@ describe('UsersProviderService', () => {
});
it('Should return Me when user is current user', () => {
const user = new UserDto('123', 'mail@domain.com', 'User1', 'path/to/image', );
const user = new UserDto('123', 'mail@domain.com', 'User1', 'path/to/image');
authService.setup(x => x.user)
.returns(() => new Profile(<any>{ profile: { sub: '123'}}));
@ -82,7 +82,7 @@ describe('UsersProviderService', () => {
resultingUser = result;
}).unsubscribe();
expect(resultingUser).toEqual(new UserDto('123', 'mail@domain.com', 'Me', 'path/to/image', ));
expect(resultingUser).toEqual(new UserDto('123', 'mail@domain.com', 'Me', 'path/to/image'));
usersService.verifyAll();
});

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

@ -14,7 +14,7 @@ import {
ApiUrlConfig,
AuthService,
UserDto,
UsersService,
UsersService
} from './../';
describe('UsersService', () => {

7
src/Squidex/app/vendor.ts

@ -5,7 +5,7 @@
* Copyright (c) Sebastian Stehle. All rights reserved
*/
// tslint:disable ordered-imports
/* tslint:disable ordered-imports */
// Angular 2
import '@angular/platform-browser';
@ -18,11 +18,8 @@ import '@angular/router';
// Additional libs
import 'rxjs';
import 'oidc-client';
import 'moment';
import 'immutable';
import 'oidc-client';
// Bootstrap
import 'theme/vendor.scss';

1
src/Squidex/package.json

@ -25,7 +25,6 @@
"babel-polyfill": "^6.16.0",
"bootstrap": "^4.0.0-alpha.2",
"core-js": "^2.4.1",
"immutable": "^3.8.1",
"moment": "^2.17.0",
"mousetrap": "^1.6.0",
"oidc-client": "^1.2.2",

Loading…
Cancel
Save