Browse Source

Better methods for event consumer state.

pull/282/head
Sebastian 8 years ago
parent
commit
8eff8a93ea
  1. 6
      src/Squidex/app/features/administration/pages/event-consumers/event-consumers-page.component.ts
  2. 10
      src/Squidex/app/features/administration/state/event-consumers.state.spec.ts
  3. 14
      src/Squidex/app/features/administration/state/event-consumers.state.ts
  4. 7
      src/Squidex/app/framework/state.ts
  5. 6
      src/Squidex/app/shared/components/assets-selector.component.html
  6. 6
      src/Squidex/app/shared/components/assets-selector.component.ts

6
src/Squidex/app/features/administration/pages/event-consumers/event-consumers-page.component.ts

@ -34,16 +34,16 @@ export class EventConsumersPageComponent implements OnDestroy, OnInit {
} }
public ngOnInit() { public ngOnInit() {
this.eventConsumersState.load(false, true).onErrorResumeNext().subscribe(); this.eventConsumersState.load().onErrorResumeNext().subscribe();
this.timerSubscription = this.timerSubscription =
Observable.timer(2000, 2000) Observable.timer(2000, 2000)
.switchMap(x => this.eventConsumersState.load().onErrorResumeNext()) .switchMap(x => this.eventConsumersState.reloadSilently().onErrorResumeNext())
.subscribe(); .subscribe();
} }
public reload() { public reload() {
this.eventConsumersState.load(true, true).onErrorResumeNext().subscribe(); this.eventConsumersState.reload().onErrorResumeNext().subscribe();
} }
public start(es: EventConsumerDto) { public start(es: EventConsumerDto) {

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

@ -42,17 +42,17 @@ describe('EventConsumersState', () => {
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never()); dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.never());
}); });
it('should show notification on load when flag is true', () => { it('should show notification on reload', () => {
eventConsumersState.load(true, true).subscribe(); eventConsumersState.reload().subscribe();
dialogs.verify(x => x.notifyInfo(It.isAnyString()), Times.once()); 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', () => {
eventConsumersService.setup(x => x.getEventConsumers()) eventConsumersService.setup(x => x.getEventConsumers())
.returns(() => Observable.throw({})); .returns(() => Observable.throw({}));
eventConsumersState.load(true, true).onErrorResumeNext().subscribe(); eventConsumersState.load().onErrorResumeNext().subscribe();
dialogs.verify(x => x.notifyError(It.isAny()), Times.once()); dialogs.verify(x => x.notifyError(It.isAny()), Times.once());
}); });
@ -61,7 +61,7 @@ describe('EventConsumersState', () => {
eventConsumersService.setup(x => x.getEventConsumers()) eventConsumersService.setup(x => x.getEventConsumers())
.returns(() => Observable.throw({})); .returns(() => Observable.throw({}));
eventConsumersState.load().onErrorResumeNext().subscribe(); eventConsumersState.reloadSilently().onErrorResumeNext().subscribe();
dialogs.verify(x => x.notifyError(It.isAny()), Times.never()); dialogs.verify(x => x.notifyError(It.isAny()), Times.never());
}); });

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

@ -41,7 +41,19 @@ export class EventConsumersState extends State<Snapshot> {
super({ eventConsumers: ImmutableArray.empty() }); super({ eventConsumers: ImmutableArray.empty() });
} }
public load(notifyLoad = false, notifyError = false): Observable<any> { public load() {
return this.loadInternal(true);
}
public reload() {
return this.loadInternal(true, true);
}
public reloadSilently() {
return this.loadInternal(false, false);
}
public loadInternal(notifyLoad = false, notifyError = false): Observable<any> {
return this.eventConsumersService.getEventConsumers() return this.eventConsumersService.getEventConsumers()
.do(dtos => { .do(dtos => {
if (notifyLoad) { if (notifyLoad) {

7
src/Squidex/app/framework/state.ts

@ -79,6 +79,7 @@ export class Form<T extends AbstractControl> {
export class State<T extends {}> { export class State<T extends {}> {
private readonly state: BehaviorSubject<T>; private readonly state: BehaviorSubject<T>;
private readonly initialState: T;
public get changes(): Observable<T> { public get changes(): Observable<T> {
return this.state; return this.state;
@ -89,9 +90,15 @@ export class State<T extends {}> {
} }
constructor(state: T) { constructor(state: T) {
this.initialState = state;
this.state = new BehaviorSubject(state); this.state = new BehaviorSubject(state);
} }
public resetState() {
this.next(this.initialState);
}
public next(update: ((v: T) => T) | object) { public next(update: ((v: T) => T) | object) {
if (update instanceof Function) { if (update instanceof Function) {
this.state.next(update(this.state.value)); this.state.next(update(this.state.value));

6
src/Squidex/app/shared/components/assets-selector.component.html

@ -4,7 +4,11 @@
</ng-container> </ng-container>
<ng-container tabs> <ng-container tabs>
<form class="form-inline" (ngSubmit)="search()"> <button class="float-right btn btn-link btn-secondary" (click)="reload()">
<i class="icon-reset"></i> Refresh
</button>
<form class="float-left form-inline" (ngSubmit)="search()">
<input class="form-control" [formControl]="assetsFilter" placeholder="Search for assets" /> <input class="form-control" [formControl]="assetsFilter" placeholder="Search for assets" />
</form> </form>
</ng-container> </ng-container>

6
src/Squidex/app/shared/components/assets-selector.component.ts

@ -39,11 +39,15 @@ export class AssetsSelectorComponent implements OnInit {
} }
public ngOnInit() { public ngOnInit() {
this.state.load(false, true).onErrorResumeNext().subscribe(); this.state.load().onErrorResumeNext().subscribe();
this.assetsFilter.setValue(this.state.snapshot.assetsQuery); this.assetsFilter.setValue(this.state.snapshot.assetsQuery);
} }
public reload() {
this.state.load(true).onErrorResumeNext().subscribe();
}
public search() { public search() {
this.state.search(this.assetsFilter.value).onErrorResumeNext().subscribe(); this.state.search(this.assetsFilter.value).onErrorResumeNext().subscribe();
} }

Loading…
Cancel
Save