Browse Source

Reset state correctly.

pull/282/head
Sebastian 8 years ago
parent
commit
b4ca9e719d
  1. 4
      src/Squidex/app/features/administration/state/event-consumers.state.spec.ts
  2. 10
      src/Squidex/app/features/administration/state/event-consumers.state.ts
  3. 2
      src/Squidex/app/features/administration/state/users.state.spec.ts
  4. 18
      src/Squidex/app/features/administration/state/users.state.ts
  5. 13
      src/Squidex/app/shared/state/assets.state.spec.ts
  6. 18
      src/Squidex/app/shared/state/assets.state.ts
  7. 4
      src/Squidex/app/shared/state/backups.state.spec.ts
  8. 10
      src/Squidex/app/shared/state/backups.state.ts
  9. 2
      src/Squidex/app/shared/state/clients.state.spec.ts
  10. 8
      src/Squidex/app/shared/state/clients.state.ts
  11. 26
      src/Squidex/app/shared/state/contents.state.ts
  12. 2
      src/Squidex/app/shared/state/contributors.state.spec.ts
  13. 8
      src/Squidex/app/shared/state/contributors.state.ts
  14. 2
      src/Squidex/app/shared/state/languages.state.spec.ts
  15. 8
      src/Squidex/app/shared/state/languages.state.ts
  16. 2
      src/Squidex/app/shared/state/patterns.state.spec.ts
  17. 8
      src/Squidex/app/shared/state/patterns.state.ts
  18. 2
      src/Squidex/app/shared/state/plans.state.spec.ts
  19. 8
      src/Squidex/app/shared/state/plans.state.ts
  20. 2
      src/Squidex/app/shared/state/rule-events.state.spec.ts
  21. 16
      src/Squidex/app/shared/state/rule-events.state.ts
  22. 2
      src/Squidex/app/shared/state/rules.state.spec.ts
  23. 8
      src/Squidex/app/shared/state/rules.state.ts
  24. 6
      src/Squidex/app/shared/state/schemas.state.spec.ts
  25. 10
      src/Squidex/app/shared/state/schemas.state.ts

4
src/Squidex/app/features/administration/state/event-consumers.state.spec.ts

@ -42,13 +42,13 @@ describe('EventConsumersState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
eventConsumersState.load(true, true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());
});
it('should show notification on load error when flag is true', () => {
it('should show notification on load error when silent is true', () => {
eventConsumersService.setup(x => x.getEventConsumers())
.returns(() => Observable.throw({}));

10
src/Squidex/app/features/administration/state/event-consumers.state.ts

@ -41,10 +41,14 @@ export class EventConsumersState extends State<Snapshot> {
super({ eventConsumers: ImmutableArray.empty() });
}
public load(notifyLoad = false, notifyError = false): Observable<any> {
public load(isReload = false, silent = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.eventConsumersService.getEventConsumers()
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Event Consumers reloaded.');
}
@ -55,7 +59,7 @@ export class EventConsumersState extends State<Snapshot> {
});
})
.catch(error => {
if (notifyError) {
if (silent) {
this.dialogs.notifyError(error);
}

2
src/Squidex/app/features/administration/state/users.state.spec.ts

@ -61,7 +61,7 @@ describe('UsersState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
usersState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());

18
src/Squidex/app/features/administration/state/users.state.ts

@ -133,13 +133,21 @@ export class UsersState extends State<Snapshot> {
});
}
public load(notifyLoad = false): Observable<any> {
public load(isReload = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.loadInternal(isReload);
}
private loadInternal(isReload = false): Observable<any> {
return this.usersService.getUsers(
this.snapshot.usersPager.pageSize,
this.snapshot.usersPager.skip,
this.snapshot.usersQuery)
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Users reloaded.');
}
@ -197,19 +205,19 @@ export class UsersState extends State<Snapshot> {
public search(query: string): Observable<any> {
this.next(s => ({ ...s, usersPager: new Pager(0), usersQuery: query }));
return this.load();
return this.loadInternal();
}
public goNext(): Observable<any> {
this.next(s => ({ ...s, usersPager: s.usersPager.goNext() }));
return this.load();
return this.loadInternal();
}
public goPrev(): Observable<any> {
this.next(s => ({ ...s, usersPager: s.usersPager.goPrev() }));
return this.load();
return this.loadInternal();
}
private replaceUser(user: UserDto) {

13
src/Squidex/app/shared/state/assets.state.spec.ts

@ -68,18 +68,7 @@ describe('AssetsState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should not reload when assets already loaded', () => {
assetsState.load(false, true).subscribe();
expect(assetsState.snapshot.assets.values).toEqual(oldAssets);
expect(assetsState.snapshot.assetsPager.numberOfItems).toEqual(200);
assetsService.verify(x => x.getAssets(app, 30, 0, undefined), Times.once());
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
assetsState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());

18
src/Squidex/app/shared/state/assets.state.ts

@ -64,14 +64,18 @@ export class AssetsState extends State<Snapshot> {
super({ assets: ImmutableArray.empty(), assetsPager: new Pager(0, 0, 30) });
}
public load(notifyLoad = false, noReload = false): Observable<any> {
if (this.snapshot.isLoaded && noReload) {
return Observable.of({});
public load(isReload = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.loadInternal(isReload);
}
private loadInternal(isReload = false): Observable<any> {
return this.assetsService.getAssets(this.appName, this.snapshot.assetsPager.pageSize, this.snapshot.assetsPager.skip, this.snapshot.assetsQuery)
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Assets reloaded.');
}
@ -118,19 +122,19 @@ export class AssetsState extends State<Snapshot> {
public search(query: string): Observable<any> {
this.next(s => ({ ...s, assetsPager: new Pager(0, 0, 30), assetsQuery: query }));
return this.load();
return this.loadInternal();
}
public goNext(): Observable<any> {
this.next(s => ({ ...s, assetsPager: s.assetsPager.goNext() }));
return this.load();
return this.loadInternal();
}
public goPrev(): Observable<any> {
this.next(s => ({ ...s, assetsPager: s.assetsPager.goPrev() }));
return this.load();
return this.loadInternal();
}
private get appName() {

4
src/Squidex/app/shared/state/backups.state.spec.ts

@ -54,13 +54,13 @@ describe('BackupsState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
backupsState.load(true, true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());
});
it('should show notification on load error when flag is true', () => {
it('should show notification on load error when silent is true', () => {
backupsService.setup(x => x.getBackups(app))
.returns(() => Observable.throw({}));

10
src/Squidex/app/shared/state/backups.state.ts

@ -48,10 +48,14 @@ export class BackupsState extends State<Snapshot> {
super({ backups: ImmutableArray.empty() });
}
public load(notifyLoad = false, notifyError = false): Observable<any> {
public load(isReload = false, silent = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.backupsService.getBackups(this.appName)
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Backups reloaded.');
}
@ -62,7 +66,7 @@ export class BackupsState extends State<Snapshot> {
});
})
.catch(error => {
if (notifyError) {
if (silent) {
this.dialogs.notifyError(error);
}

2
src/Squidex/app/shared/state/clients.state.spec.ts

@ -61,7 +61,7 @@ describe('ClientsState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
clientsState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());

8
src/Squidex/app/shared/state/clients.state.ts

@ -83,10 +83,14 @@ export class ClientsState extends State<Snapshot> {
super({ clients: ImmutableArray.empty(), version: new Version('') });
}
public load(notifyLoad = false): Observable<any> {
public load(isReload = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.appClientsService.getClients(this.appName)
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Clients reloaded.');
}

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

@ -204,14 +204,22 @@ export abstract class ContentsStateBase extends State<Snapshot> {
});
}
public load(notifyLoad = false): Observable<any> {
public load(isReload = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.loadInternal(isReload);
}
private loadInternal(isReload = false): Observable<any> {
return this.contentsService.getContents(this.appName, this.schemaName,
this.snapshot.contentsPager.pageSize,
this.snapshot.contentsPager.skip,
this.snapshot.contentsQuery, undefined,
this.snapshot.isArchive)
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Contents reloaded.');
}
@ -259,7 +267,7 @@ export abstract class ContentsStateBase extends State<Snapshot> {
return Observable.of(error);
})
.switchMap(() => this.load());
.switchMap(() => this.loadInternal());
}
public delete(contents: ContentDto[]): Observable<any> {
@ -276,7 +284,7 @@ export abstract class ContentsStateBase extends State<Snapshot> {
return Observable.of(error);
})
.switchMap(() => this.load());
.switchMap(() => this.loadInternal());
}
public update(content: ContentDto, request: any, now?: DateTime): Observable<any> {
@ -311,31 +319,31 @@ export abstract class ContentsStateBase extends State<Snapshot> {
public goArchive(isArchive: boolean): Observable<any> {
this.next(s => ({ ...s, contentsPager: new Pager(0), contentsQuery: undefined, isArchive }));
return this.load();
return this.loadInternal();
}
public init(): Observable<any> {
this.next(s => ({ ...s, contentsPager: new Pager(0), contentsQuery: '', isArchive: false, isLoaded: false }));
return this.load();
return this.loadInternal();
}
public search(query: string): Observable<any> {
this.next(s => ({ ...s, contentsPager: new Pager(0), contentsQuery: query }));
return this.load();
return this.loadInternal();
}
public goNext(): Observable<any> {
this.next(s => ({ ...s, contentsPager: s.contentsPager.goNext() }));
return this.load();
return this.loadInternal();
}
public goPrev(): Observable<any> {
this.next(s => ({ ...s, contentsPager: s.contentsPager.goPrev() }));
return this.load();
return this.loadInternal();
}
public loadVersion(content: ContentDto, version: Version): Observable<Versioned<any>> {

2
src/Squidex/app/shared/state/contributors.state.spec.ts

@ -71,7 +71,7 @@ describe('ContributorsState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
contributorsState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());

8
src/Squidex/app/shared/state/contributors.state.ts

@ -82,10 +82,14 @@ export class ContributorsState extends State<Snapshot> {
super({ contributors: ImmutableArray.empty(), version: new Version(''), maxContributors: -1 });
}
public load(notifyLoad = false): Observable<any> {
public load(isReload = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.appContributorsService.getContributors(this.appName)
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Contributors reloaded.');
}

2
src/Squidex/app/shared/state/languages.state.spec.ts

@ -85,7 +85,7 @@ describe('LanguagesState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
languagesState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());

8
src/Squidex/app/shared/state/languages.state.ts

@ -108,14 +108,18 @@ export class LanguagesState extends State<Snapshot> {
});
}
public load(notifyLoad = false): Observable<any> {
public load(isReload = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return Observable.forkJoin(
this.languagesService.getLanguages(),
this.appLanguagesService.getLanguages(this.appName),
(allLanguages, languages) => ({ allLanguages, languages })
)
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Languages reloaded.');
}

2
src/Squidex/app/shared/state/patterns.state.spec.ts

@ -59,7 +59,7 @@ describe('PatternsState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
patternsState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());

8
src/Squidex/app/shared/state/patterns.state.ts

@ -78,10 +78,14 @@ export class PatternsState extends State<Snapshot> {
super({ patterns: ImmutableArray.empty(), version: new Version('') });
}
public load(notifyLoad = false): Observable<any> {
public load(isReload = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.appPatternsService.getPatterns(this.appName)
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Patterns reloaded.');
}

2
src/Squidex/app/shared/state/plans.state.spec.ts

@ -90,7 +90,7 @@ describe('PlansState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
plansState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());

8
src/Squidex/app/shared/state/plans.state.ts

@ -77,10 +77,14 @@ export class PlansState extends State<Snapshot> {
super({ plans: ImmutableArray.empty(), version: new Version('') });
}
public load(notifyLoad = false, overridePlanId?: string): Observable<any> {
public load(isReload = false, overridePlanId?: string): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.plansService.getPlans(this.appName)
.do(dto => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Plans reloaded.');
}

2
src/Squidex/app/shared/state/rule-events.state.spec.ts

@ -60,7 +60,7 @@ describe('RuleEventsState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
ruleEventsState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());

16
src/Squidex/app/shared/state/rule-events.state.ts

@ -50,12 +50,20 @@ export class RuleEventsState extends State<Snapshot> {
super({ ruleEvents: ImmutableArray.of(), ruleEventsPager: new Pager(0) });
}
public load(notifyLoad = false): Observable<any> {
public load(isReload = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.loadInternal(isReload);
}
private loadInternal(isReload = false): Observable<any> {
return this.rulesService.getEvents(this.appName,
this.snapshot.ruleEventsPager.pageSize,
this.snapshot.ruleEventsPager.skip)
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('RuleEvents reloaded.');
}
@ -80,13 +88,13 @@ export class RuleEventsState extends State<Snapshot> {
public goNext(): Observable<any> {
this.next(s => ({ ...s, ruleEventsPager: s.ruleEventsPager.goNext() }));
return this.load();
return this.loadInternal();
}
public goPrev(): Observable<any> {
this.next(s => ({ ...s, ruleEventsPager: s.ruleEventsPager.goPrev() }));
return this.load();
return this.loadInternal();
}
private get appName() {

2
src/Squidex/app/shared/state/rules.state.spec.ts

@ -72,7 +72,7 @@ describe('RulesState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
});
it('should show notification on load when flag is true', () => {
it('should show notification on load when reload is true', () => {
rulesState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());

8
src/Squidex/app/shared/state/rules.state.ts

@ -53,10 +53,14 @@ export class RulesState extends State<Snapshot> {
super({ rules: ImmutableArray.empty() });
}
public load(notifyLoad = false): Observable<any> {
public load(isReload = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.rulesService.getRules(this.appName)
.do(dtos => {
if (notifyLoad) {
if (isReload) {
this.dialogs.notifyInfo('Rules reloaded.');
}

6
src/Squidex/app/shared/state/schemas.state.spec.ts

@ -94,6 +94,12 @@ describe('SchemasState', () => {
schemasService.verifyAll();
});
it('should show notification on load when reload is true', () => {
schemasState.load(true).subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once());
});
it('should return schema on select and reload when already loaded', () => {
schemasState.select('name2').subscribe();
schemasState.select('name2').subscribe();

10
src/Squidex/app/shared/state/schemas.state.ts

@ -198,13 +198,17 @@ export class SchemasState extends State<Snapshot> {
.catch(() => Observable.of(null));
}
public load(): Observable<any> {
if (this.snapshot.schemasApp !== this.appName) {
this.next({ schemas: ImmutableArray.of() });
public load(isReload = false): Observable<any> {
if (!isReload) {
this.resetState();
}
return this.schemasService.getSchemas(this.appName)
.do(dtos => {
if (isReload) {
this.dialogs.notifyInfo('Schemas reloaded.');
}
return this.next(s => {
const schemas = ImmutableArray.of(dtos).sortByStringAsc(x => x.displayName);

Loading…
Cancel
Save