member_webapp/@overflow/discovery/component/service-selector.component.ts

91 lines
2.1 KiB
TypeScript
Raw Normal View History

2018-05-25 10:56:28 +00:00
import {
Component,
OnInit,
Input,
AfterContentInit,
Output,
EventEmitter,
OnDestroy
} from '@angular/core';
2018-05-03 11:45:49 +00:00
import { Store, select, StateObservable } from '@ngrx/store';
2018-05-31 10:06:49 +00:00
import { Observable, of } from 'rxjs';
2018-06-04 08:55:47 +00:00
import { catchError, exhaustMap, map, tap, take } from 'rxjs/operators';
2018-05-31 10:06:49 +00:00
2018-05-24 06:44:13 +00:00
import { RPCClientError } from '@loafer/ng-rpc';
2018-05-03 11:45:49 +00:00
import { MetaCrawler } from '@overflow/commons-typescript/model/meta';
2018-05-31 10:06:49 +00:00
2018-05-31 13:26:14 +00:00
import { MetaCrawlerService } from '@overflow/meta/service/meta-crawler.service';
2018-05-03 11:45:49 +00:00
@Component({
selector: 'of-service-selector',
templateUrl: './service-selector.component.html',
})
2018-05-31 10:06:49 +00:00
export class ServiceSelectorComponent implements OnInit, AfterContentInit, OnDestroy {
2018-05-31 13:26:14 +00:00
includeServices: MetaCrawler[];
@Output() change = new EventEmitter<MetaCrawler[]>();
2018-05-29 12:18:43 +00:00
@Input() disabled: boolean;
2018-05-03 11:45:49 +00:00
2018-05-31 13:26:14 +00:00
metaCrawlers: MetaCrawler[];
2018-05-31 10:06:49 +00:00
pending$: Observable<boolean>;
error$: Observable<any>;
2018-05-03 11:45:49 +00:00
constructor(
2018-05-31 09:30:58 +00:00
protected store: Store<any>,
protected metaCrawlerService: MetaCrawlerService,
2018-05-03 11:45:49 +00:00
) {
2018-05-31 13:26:14 +00:00
this.includeServices = [];
2018-05-03 11:45:49 +00:00
}
ngOnInit() {
2018-05-31 13:26:14 +00:00
this.metaCrawlerService.readAll()
2018-05-31 10:06:49 +00:00
.pipe(
tap(() => {
this.pending$ = of(true);
}),
map((metaCrawlers: MetaCrawler[]) => {
2018-05-31 13:26:14 +00:00
this.metaCrawlers = metaCrawlers;
2018-05-31 10:06:49 +00:00
}),
catchError(error => {
this.error$ = of(error);
return of(null);
}),
tap(() => {
this.pending$ = of(false);
2018-05-31 13:26:14 +00:00
this.includeServices = this.metaCrawlers.slice();
this.change.emit(this.includeServices);
2018-05-31 10:06:49 +00:00
}),
2018-06-04 08:55:47 +00:00
take(1),
).subscribe();
2018-05-31 09:30:58 +00:00
}
ngOnDestroy() {
2018-05-31 10:06:49 +00:00
2018-05-03 11:45:49 +00:00
}
ngAfterContentInit() {
2018-05-28 05:48:17 +00:00
// this.listStore.dispatch(new ListStore.ReadAll());
2018-05-03 11:45:49 +00:00
}
2018-05-31 13:26:14 +00:00
onSelectAll() {
this.includeServices = [];
this.metaCrawlers.forEach((value) => {
this.includeServices.push(value);
});
this.change.emit(this.includeServices);
}
onUnselectAll() {
this.includeServices = [];
this.change.emit(this.includeServices);
}
onSelect(crawler: MetaCrawler) {
this.change.emit(this.includeServices);
}
onUnselect(crawler: MetaCrawler) {
this.change.emit(this.includeServices);
2018-05-31 11:53:11 +00:00
}
2018-05-03 11:45:49 +00:00
}