ing
This commit is contained in:
parent
b74d45c303
commit
541ab7cac2
|
@ -8,34 +8,55 @@ import {
|
||||||
OnDestroy
|
OnDestroy
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { Store, select, StateObservable } from '@ngrx/store';
|
import { Store, select, StateObservable } from '@ngrx/store';
|
||||||
|
import { Observable, of } from 'rxjs';
|
||||||
|
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
||||||
|
|
||||||
import { RPCClientError } from '@loafer/ng-rpc';
|
import { RPCClientError } from '@loafer/ng-rpc';
|
||||||
import { MetaCrawler } from '@overflow/commons-typescript/model/meta';
|
import { MetaCrawler } from '@overflow/commons-typescript/model/meta';
|
||||||
import { Subscription } from 'rxjs/Subscription';
|
|
||||||
import { MetaCrawlerComponent } from '../../../../meta/component/abstract/meta-crawler.component';
|
|
||||||
import { MetaCrawlerService } from '../../../../meta/service/meta-crawler.service';
|
import { MetaCrawlerService } from '../../../../meta/service/meta-crawler.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'of-service-selector',
|
selector: 'of-service-selector',
|
||||||
templateUrl: './service-selector.component.html',
|
templateUrl: './service-selector.component.html',
|
||||||
})
|
})
|
||||||
export class ServiceSelectorComponent extends MetaCrawlerComponent implements OnInit, AfterContentInit, OnDestroy {
|
export class ServiceSelectorComponent implements OnInit, AfterContentInit, OnDestroy {
|
||||||
@Output() crawlerSelected = new EventEmitter<MetaCrawler>();
|
@Output() crawlerSelected = new EventEmitter<MetaCrawler>();
|
||||||
@Input() includeServices;
|
@Input() includeServices;
|
||||||
@Input() disabled: boolean;
|
@Input() disabled: boolean;
|
||||||
|
|
||||||
|
metaCrawlers$: Observable<MetaCrawler[]>;
|
||||||
|
pending$: Observable<boolean>;
|
||||||
|
error$: Observable<any>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
protected store: Store<any>,
|
protected store: Store<any>,
|
||||||
protected metaCrawlerService: MetaCrawlerService,
|
protected metaCrawlerService: MetaCrawlerService,
|
||||||
) {
|
) {
|
||||||
super(store, metaCrawlerService);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
super.ngOnInit();
|
this.metaCrawlers$ = this.metaCrawlerService.readAll()
|
||||||
|
.pipe(
|
||||||
|
tap(() => {
|
||||||
|
this.pending$ = of(true);
|
||||||
|
}),
|
||||||
|
map((metaCrawlers: MetaCrawler[]) => {
|
||||||
|
return metaCrawlers;
|
||||||
|
}),
|
||||||
|
catchError(error => {
|
||||||
|
this.error$ = of(error);
|
||||||
|
return of(null);
|
||||||
|
}),
|
||||||
|
tap(() => {
|
||||||
|
this.pending$ = of(false);
|
||||||
|
}),
|
||||||
|
).take(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
ngOnDestroy() {
|
||||||
super.ngOnDestroy();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterContentInit() {
|
ngAfterContentInit() {
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
||||||
import { Store, select } from '@ngrx/store';
|
|
||||||
import { Observable, of, Subscription } from 'rxjs';
|
|
||||||
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
|
||||||
|
|
||||||
import { RPCClientError } from '@loafer/ng-rpc';
|
|
||||||
|
|
||||||
import { MetaCrawler } from '@overflow/commons-typescript/model/meta';
|
|
||||||
|
|
||||||
import { MetaCrawlerEntitySelector } from '../../store';
|
|
||||||
import * as MetaCrawlerEntityStore from '../../store/entity/meta-crawler';
|
|
||||||
import { MetaCrawlerService } from '../../service/meta-crawler.service';
|
|
||||||
|
|
||||||
export abstract class MetaCrawlerComponent implements OnInit, OnDestroy {
|
|
||||||
metaCrawlers$: Observable<MetaCrawler[]>;
|
|
||||||
pending$: Observable<boolean>;
|
|
||||||
error$: Observable<any>;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
protected store: Store<any>,
|
|
||||||
protected metaCrawlerService: MetaCrawlerService,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnInit() {
|
|
||||||
this.metaCrawlers$ = this.store.pipe(select(MetaCrawlerEntitySelector.selectAll));
|
|
||||||
this.pending$ = this.store.pipe(select(MetaCrawlerEntitySelector.selectPending));
|
|
||||||
this.error$ = this.store.pipe(select(MetaCrawlerEntitySelector.selectError));
|
|
||||||
|
|
||||||
this.store.pipe(
|
|
||||||
select(MetaCrawlerEntitySelector.selectAll),
|
|
||||||
map((metaCrawlers: MetaCrawler[]) => {
|
|
||||||
if (0 < metaCrawlers.length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.store.dispatch(new MetaCrawlerEntityStore.ReadAll());
|
|
||||||
}),
|
|
||||||
).take(1).subscribe();
|
|
||||||
}
|
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,13 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs';
|
||||||
|
import { shareReplay, map } from 'rxjs/operators';
|
||||||
|
|
||||||
import { RPCService } from '@loafer/ng-rpc';
|
import { RPCService } from '@loafer/ng-rpc';
|
||||||
import { MetaCrawler } from '@overflow/commons-typescript/model/meta';
|
import { MetaCrawler } from '@overflow/commons-typescript/model/meta';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MetaCrawlerService {
|
export class MetaCrawlerService {
|
||||||
|
private metaCrawlerCache$: Observable<MetaCrawler[]>;
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private rpcService: RPCService,
|
private rpcService: RPCService,
|
||||||
|
@ -13,6 +16,12 @@ export class MetaCrawlerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public readAll(): Observable<MetaCrawler[]> {
|
public readAll(): Observable<MetaCrawler[]> {
|
||||||
return this.rpcService.call('MetaCrawlerService.readAll');
|
if (!this.metaCrawlerCache$) {
|
||||||
|
this.metaCrawlerCache$ = this.rpcService.call('MetaCrawlerService.readAll').pipe(
|
||||||
|
shareReplay<MetaCrawler[]>(1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.metaCrawlerCache$;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user