diff --git a/src/Squidex/app/features/administration/state/event-consumers.state.spec.ts b/src/Squidex/app/features/administration/state/event-consumers.state.spec.ts index b159f8a20..ccd674b28 100644 --- a/src/Squidex/app/features/administration/state/event-consumers.state.spec.ts +++ b/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({})); diff --git a/src/Squidex/app/features/administration/state/event-consumers.state.ts b/src/Squidex/app/features/administration/state/event-consumers.state.ts index 134fd0d8b..e8864aacf 100644 --- a/src/Squidex/app/features/administration/state/event-consumers.state.ts +++ b/src/Squidex/app/features/administration/state/event-consumers.state.ts @@ -41,10 +41,14 @@ export class EventConsumersState extends State { super({ eventConsumers: ImmutableArray.empty() }); } - public load(notifyLoad = false, notifyError = false): Observable { + public load(isReload = false, silent = false): Observable { + 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 { }); }) .catch(error => { - if (notifyError) { + if (silent) { this.dialogs.notifyError(error); } diff --git a/src/Squidex/app/features/administration/state/users.state.spec.ts b/src/Squidex/app/features/administration/state/users.state.spec.ts index 688a231a3..664feb8d7 100644 --- a/src/Squidex/app/features/administration/state/users.state.spec.ts +++ b/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()); diff --git a/src/Squidex/app/features/administration/state/users.state.ts b/src/Squidex/app/features/administration/state/users.state.ts index 9e190feda..cd871f0d7 100644 --- a/src/Squidex/app/features/administration/state/users.state.ts +++ b/src/Squidex/app/features/administration/state/users.state.ts @@ -133,13 +133,21 @@ export class UsersState extends State { }); } - public load(notifyLoad = false): Observable { + public load(isReload = false): Observable { + if (!isReload) { + this.resetState(); + } + + return this.loadInternal(isReload); + } + + private loadInternal(isReload = false): Observable { 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 { public search(query: string): Observable { this.next(s => ({ ...s, usersPager: new Pager(0), usersQuery: query })); - return this.load(); + return this.loadInternal(); } public goNext(): Observable { this.next(s => ({ ...s, usersPager: s.usersPager.goNext() })); - return this.load(); + return this.loadInternal(); } public goPrev(): Observable { this.next(s => ({ ...s, usersPager: s.usersPager.goPrev() })); - return this.load(); + return this.loadInternal(); } private replaceUser(user: UserDto) { diff --git a/src/Squidex/app/shared/state/assets.state.spec.ts b/src/Squidex/app/shared/state/assets.state.spec.ts index 258d3f4af..c6def135f 100644 --- a/src/Squidex/app/shared/state/assets.state.spec.ts +++ b/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()); diff --git a/src/Squidex/app/shared/state/assets.state.ts b/src/Squidex/app/shared/state/assets.state.ts index 333569bf9..45e936b3f 100644 --- a/src/Squidex/app/shared/state/assets.state.ts +++ b/src/Squidex/app/shared/state/assets.state.ts @@ -64,14 +64,18 @@ export class AssetsState extends State { super({ assets: ImmutableArray.empty(), assetsPager: new Pager(0, 0, 30) }); } - public load(notifyLoad = false, noReload = false): Observable { - if (this.snapshot.isLoaded && noReload) { - return Observable.of({}); + public load(isReload = false): Observable { + if (!isReload) { + this.resetState(); } + return this.loadInternal(isReload); + } + + private loadInternal(isReload = false): Observable { 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 { public search(query: string): Observable { this.next(s => ({ ...s, assetsPager: new Pager(0, 0, 30), assetsQuery: query })); - return this.load(); + return this.loadInternal(); } public goNext(): Observable { this.next(s => ({ ...s, assetsPager: s.assetsPager.goNext() })); - return this.load(); + return this.loadInternal(); } public goPrev(): Observable { this.next(s => ({ ...s, assetsPager: s.assetsPager.goPrev() })); - return this.load(); + return this.loadInternal(); } private get appName() { diff --git a/src/Squidex/app/shared/state/backups.state.spec.ts b/src/Squidex/app/shared/state/backups.state.spec.ts index bab4bab3d..b05e511e7 100644 --- a/src/Squidex/app/shared/state/backups.state.spec.ts +++ b/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({})); diff --git a/src/Squidex/app/shared/state/backups.state.ts b/src/Squidex/app/shared/state/backups.state.ts index cb23f4bee..992f26122 100644 --- a/src/Squidex/app/shared/state/backups.state.ts +++ b/src/Squidex/app/shared/state/backups.state.ts @@ -48,10 +48,14 @@ export class BackupsState extends State { super({ backups: ImmutableArray.empty() }); } - public load(notifyLoad = false, notifyError = false): Observable { + public load(isReload = false, silent = false): Observable { + 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 { }); }) .catch(error => { - if (notifyError) { + if (silent) { this.dialogs.notifyError(error); } diff --git a/src/Squidex/app/shared/state/clients.state.spec.ts b/src/Squidex/app/shared/state/clients.state.spec.ts index 5b5c9f494..e8fd8431a 100644 --- a/src/Squidex/app/shared/state/clients.state.spec.ts +++ b/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()); diff --git a/src/Squidex/app/shared/state/clients.state.ts b/src/Squidex/app/shared/state/clients.state.ts index e68007522..067f7e7ea 100644 --- a/src/Squidex/app/shared/state/clients.state.ts +++ b/src/Squidex/app/shared/state/clients.state.ts @@ -83,10 +83,14 @@ export class ClientsState extends State { super({ clients: ImmutableArray.empty(), version: new Version('') }); } - public load(notifyLoad = false): Observable { + public load(isReload = false): Observable { + if (!isReload) { + this.resetState(); + } + return this.appClientsService.getClients(this.appName) .do(dtos => { - if (notifyLoad) { + if (isReload) { this.dialogs.notifyInfo('Clients reloaded.'); } diff --git a/src/Squidex/app/shared/state/contents.state.ts b/src/Squidex/app/shared/state/contents.state.ts index 9304f132a..49cc5b43e 100644 --- a/src/Squidex/app/shared/state/contents.state.ts +++ b/src/Squidex/app/shared/state/contents.state.ts @@ -204,14 +204,22 @@ export abstract class ContentsStateBase extends State { }); } - public load(notifyLoad = false): Observable { + public load(isReload = false): Observable { + if (!isReload) { + this.resetState(); + } + + return this.loadInternal(isReload); + } + + private loadInternal(isReload = false): Observable { 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 { return Observable.of(error); }) - .switchMap(() => this.load()); + .switchMap(() => this.loadInternal()); } public delete(contents: ContentDto[]): Observable { @@ -276,7 +284,7 @@ export abstract class ContentsStateBase extends State { return Observable.of(error); }) - .switchMap(() => this.load()); + .switchMap(() => this.loadInternal()); } public update(content: ContentDto, request: any, now?: DateTime): Observable { @@ -311,31 +319,31 @@ export abstract class ContentsStateBase extends State { public goArchive(isArchive: boolean): Observable { this.next(s => ({ ...s, contentsPager: new Pager(0), contentsQuery: undefined, isArchive })); - return this.load(); + return this.loadInternal(); } public init(): Observable { this.next(s => ({ ...s, contentsPager: new Pager(0), contentsQuery: '', isArchive: false, isLoaded: false })); - return this.load(); + return this.loadInternal(); } public search(query: string): Observable { this.next(s => ({ ...s, contentsPager: new Pager(0), contentsQuery: query })); - return this.load(); + return this.loadInternal(); } public goNext(): Observable { this.next(s => ({ ...s, contentsPager: s.contentsPager.goNext() })); - return this.load(); + return this.loadInternal(); } public goPrev(): Observable { this.next(s => ({ ...s, contentsPager: s.contentsPager.goPrev() })); - return this.load(); + return this.loadInternal(); } public loadVersion(content: ContentDto, version: Version): Observable> { diff --git a/src/Squidex/app/shared/state/contributors.state.spec.ts b/src/Squidex/app/shared/state/contributors.state.spec.ts index ef61b3a2a..7408ea9f0 100644 --- a/src/Squidex/app/shared/state/contributors.state.spec.ts +++ b/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()); diff --git a/src/Squidex/app/shared/state/contributors.state.ts b/src/Squidex/app/shared/state/contributors.state.ts index 955b6edd6..71986f287 100644 --- a/src/Squidex/app/shared/state/contributors.state.ts +++ b/src/Squidex/app/shared/state/contributors.state.ts @@ -82,10 +82,14 @@ export class ContributorsState extends State { super({ contributors: ImmutableArray.empty(), version: new Version(''), maxContributors: -1 }); } - public load(notifyLoad = false): Observable { + public load(isReload = false): Observable { + if (!isReload) { + this.resetState(); + } + return this.appContributorsService.getContributors(this.appName) .do(dtos => { - if (notifyLoad) { + if (isReload) { this.dialogs.notifyInfo('Contributors reloaded.'); } diff --git a/src/Squidex/app/shared/state/languages.state.spec.ts b/src/Squidex/app/shared/state/languages.state.spec.ts index e8aa13dee..5a51cfe3f 100644 --- a/src/Squidex/app/shared/state/languages.state.spec.ts +++ b/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()); diff --git a/src/Squidex/app/shared/state/languages.state.ts b/src/Squidex/app/shared/state/languages.state.ts index 889804383..64c53da5d 100644 --- a/src/Squidex/app/shared/state/languages.state.ts +++ b/src/Squidex/app/shared/state/languages.state.ts @@ -108,14 +108,18 @@ export class LanguagesState extends State { }); } - public load(notifyLoad = false): Observable { + public load(isReload = false): Observable { + 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.'); } diff --git a/src/Squidex/app/shared/state/patterns.state.spec.ts b/src/Squidex/app/shared/state/patterns.state.spec.ts index 614510374..705f2814d 100644 --- a/src/Squidex/app/shared/state/patterns.state.spec.ts +++ b/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()); diff --git a/src/Squidex/app/shared/state/patterns.state.ts b/src/Squidex/app/shared/state/patterns.state.ts index 32dc5fbd2..1a1153764 100644 --- a/src/Squidex/app/shared/state/patterns.state.ts +++ b/src/Squidex/app/shared/state/patterns.state.ts @@ -78,10 +78,14 @@ export class PatternsState extends State { super({ patterns: ImmutableArray.empty(), version: new Version('') }); } - public load(notifyLoad = false): Observable { + public load(isReload = false): Observable { + if (!isReload) { + this.resetState(); + } + return this.appPatternsService.getPatterns(this.appName) .do(dtos => { - if (notifyLoad) { + if (isReload) { this.dialogs.notifyInfo('Patterns reloaded.'); } diff --git a/src/Squidex/app/shared/state/plans.state.spec.ts b/src/Squidex/app/shared/state/plans.state.spec.ts index 0f2bf8843..627259a61 100644 --- a/src/Squidex/app/shared/state/plans.state.spec.ts +++ b/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()); diff --git a/src/Squidex/app/shared/state/plans.state.ts b/src/Squidex/app/shared/state/plans.state.ts index 62e18b3ac..b4bebb278 100644 --- a/src/Squidex/app/shared/state/plans.state.ts +++ b/src/Squidex/app/shared/state/plans.state.ts @@ -77,10 +77,14 @@ export class PlansState extends State { super({ plans: ImmutableArray.empty(), version: new Version('') }); } - public load(notifyLoad = false, overridePlanId?: string): Observable { + public load(isReload = false, overridePlanId?: string): Observable { + if (!isReload) { + this.resetState(); + } + return this.plansService.getPlans(this.appName) .do(dto => { - if (notifyLoad) { + if (isReload) { this.dialogs.notifyInfo('Plans reloaded.'); } diff --git a/src/Squidex/app/shared/state/rule-events.state.spec.ts b/src/Squidex/app/shared/state/rule-events.state.spec.ts index e0cbbfc60..4430cc44e 100644 --- a/src/Squidex/app/shared/state/rule-events.state.spec.ts +++ b/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()); diff --git a/src/Squidex/app/shared/state/rule-events.state.ts b/src/Squidex/app/shared/state/rule-events.state.ts index 408eb9975..643a29eaa 100644 --- a/src/Squidex/app/shared/state/rule-events.state.ts +++ b/src/Squidex/app/shared/state/rule-events.state.ts @@ -50,12 +50,20 @@ export class RuleEventsState extends State { super({ ruleEvents: ImmutableArray.of(), ruleEventsPager: new Pager(0) }); } - public load(notifyLoad = false): Observable { + public load(isReload = false): Observable { + if (!isReload) { + this.resetState(); + } + + return this.loadInternal(isReload); + } + + private loadInternal(isReload = false): Observable { 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 { public goNext(): Observable { this.next(s => ({ ...s, ruleEventsPager: s.ruleEventsPager.goNext() })); - return this.load(); + return this.loadInternal(); } public goPrev(): Observable { this.next(s => ({ ...s, ruleEventsPager: s.ruleEventsPager.goPrev() })); - return this.load(); + return this.loadInternal(); } private get appName() { diff --git a/src/Squidex/app/shared/state/rules.state.spec.ts b/src/Squidex/app/shared/state/rules.state.spec.ts index f8e505dfa..74ea383d7 100644 --- a/src/Squidex/app/shared/state/rules.state.spec.ts +++ b/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()); diff --git a/src/Squidex/app/shared/state/rules.state.ts b/src/Squidex/app/shared/state/rules.state.ts index 4c1ef5de2..566dc229d 100644 --- a/src/Squidex/app/shared/state/rules.state.ts +++ b/src/Squidex/app/shared/state/rules.state.ts @@ -53,10 +53,14 @@ export class RulesState extends State { super({ rules: ImmutableArray.empty() }); } - public load(notifyLoad = false): Observable { + public load(isReload = false): Observable { + if (!isReload) { + this.resetState(); + } + return this.rulesService.getRules(this.appName) .do(dtos => { - if (notifyLoad) { + if (isReload) { this.dialogs.notifyInfo('Rules reloaded.'); } diff --git a/src/Squidex/app/shared/state/schemas.state.spec.ts b/src/Squidex/app/shared/state/schemas.state.spec.ts index 3a00d106e..8df92f2af 100644 --- a/src/Squidex/app/shared/state/schemas.state.spec.ts +++ b/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(); diff --git a/src/Squidex/app/shared/state/schemas.state.ts b/src/Squidex/app/shared/state/schemas.state.ts index c35c2478d..e397b0d15 100644 --- a/src/Squidex/app/shared/state/schemas.state.ts +++ b/src/Squidex/app/shared/state/schemas.state.ts @@ -198,13 +198,17 @@ export class SchemasState extends State { .catch(() => Observable.of(null)); } - public load(): Observable { - if (this.snapshot.schemasApp !== this.appName) { - this.next({ schemas: ImmutableArray.of() }); + public load(isReload = false): Observable { + 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);