Browse Source

Temp

pull/1/head
Sebastian 10 years ago
parent
commit
e83de94177
  1. 12
      src/Squidex/app/components/internal/app/settings/clients-page.component.ts
  2. 12
      src/Squidex/app/components/internal/app/settings/contributors-page.component.ts
  3. 10
      src/Squidex/app/components/internal/app/settings/languages-page.component.ts
  4. 1
      src/Squidex/app/framework/declarations.ts
  5. 12
      src/Squidex/app/framework/utils/immutable-list.ts
  6. 38
      src/Squidex/app/framework/utils/immutable-object.spec.ts
  7. 24
      src/Squidex/app/framework/utils/immutable-object.ts
  8. 6
      src/Squidex/app/framework/utils/immutable-set.ts

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

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

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

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

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

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

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

@ -44,7 +44,6 @@ export * from './utils/date-time';
export * from './utils/duration'; export * from './utils/duration';
export * from './utils/immutable-id-map'; export * from './utils/immutable-id-map';
export * from './utils/immutable-list'; export * from './utils/immutable-list';
export * from './utils/immutable-object';
export * from './utils/immutable-set'; export * from './utils/immutable-set';
export * from './utils/math-helper'; export * from './utils/math-helper';
export * from './utils/modal-view'; export * from './utils/modal-view';

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

@ -7,9 +7,13 @@
import * as Immutable from 'immutable'; import * as Immutable from 'immutable';
export class ImmutableList<T> { export class ImmutableList<T> implements Iterable<T> {
private readonly items: Immutable.List<T>; private readonly items: Immutable.List<T>;
public [Symbol.iterator](): Iterator<T> {
return this.items.values();
}
public get size(): number { public get size(): number {
return this.items.size; return this.items.size;
} }
@ -17,7 +21,7 @@ export class ImmutableList<T> {
constructor(items?: T[] | Immutable.List<T>) { constructor(items?: T[] | Immutable.List<T>) {
if (Array.isArray(items)) { if (Array.isArray(items)) {
this.items = Immutable.List<T>(items); this.items = Immutable.List<T>(items);
} else { } else if (items) {
this.items = items || Immutable.List<T>(); this.items = items || Immutable.List<T>();
} }
@ -32,8 +36,8 @@ export class ImmutableList<T> {
return this.items.toArray(); return this.items.toArray();
} }
public map<R>(projection: (item: T) => R): R[] { public map<R>(projection: (item: T) => R): ImmutableList<R> {
return this.items.map(v => projection(v!)).toArray(); return new ImmutableList<R>(this.items.map(v => projection(v!)).toArray());
} }
public filter(projection: (item: T) => boolean): T[] { public filter(projection: (item: T) => boolean): T[] {

38
src/Squidex/app/framework/utils/immutable-object.spec.ts

@ -1,38 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { ImmutableObject } from './../';
class MockupObject extends ImmutableObject {
constructor(
public property1: string,
public property2: string
) {
super();
}
public changeProperty1(newValue: string): MockupObject {
return super.cloned<MockupObject>((x: MockupObject) => x.property1 = newValue);
}
public clone(): ImmutableObject {
return new MockupObject(this.property1, this.property2);
}
}
describe('ImmutableObject', () => {
it('should create new instance on update', () => {
const oldObj = new MockupObject('old1', 'old2');
const newObj = oldObj.changeProperty1('new1');
expect(oldObj.property1).toBe('old1');
expect(oldObj.property2).toBe('old2');
expect(newObj.property1).toBe('new1');
expect(newObj.property2).toBe('old2');
});
});

24
src/Squidex/app/framework/utils/immutable-object.ts

@ -1,24 +0,0 @@
/*
* Squidex Headless CMS
*
* @license
* Copyright (c) Sebastian Stehle. All rights reserved
*/
/* tslint:disable:no-empty */
export abstract class ImmutableObject {
public abstract clone(): ImmutableObject;
protected afterClone() { }
protected cloned<T extends ImmutableObject>(updater: (instance: ImmutableObject) => void) {
const cloned = <T>this.clone();
updater(cloned);
cloned.afterClone();
return cloned;
}
}

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

@ -7,13 +7,17 @@
import * as Immutable from 'immutable'; import * as Immutable from 'immutable';
export class ImmutableSet<T> { export class ImmutableSet<T> implements Iterable<T> {
private readonly items: Immutable.Set<T>; private readonly items: Immutable.Set<T>;
public get size(): number { public get size(): number {
return this.items.size; return this.items.size;
} }
public [Symbol.iterator](): Iterator<T> {
return this.items.values();
}
constructor(items?: T[] | Immutable.Set<T>) { constructor(items?: T[] | Immutable.Set<T>) {
if (Array.isArray(items)) { if (Array.isArray(items)) {
this.items = Immutable.Set<T>(items); this.items = Immutable.Set<T>(items);

Loading…
Cancel
Save