member_webapp/@overflow/target/component/target-list.component.ts

114 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-06-07 09:21:56 +00:00
import {
Component,
Input,
EventEmitter,
Output,
ViewChild,
OnChanges,
SimpleChanges
} from '@angular/core';
2018-06-01 10:27:27 +00:00
2018-06-07 09:21:56 +00:00
import {
Observable,
of
} from 'rxjs';
import { Store } from '@ngrx/store';
import {
catchError,
map,
tap,
take
} from 'rxjs/operators';
2018-06-07 06:24:55 +00:00
2018-06-07 09:21:56 +00:00
import { Target } from '@overflow/commons-typescript/model/target';
2018-06-21 11:10:18 +00:00
import { TargetService } from '../service/target.service';
2018-06-07 09:24:23 +00:00
2018-06-07 09:21:56 +00:00
import { Paginator } from 'primeng/primeng';
2018-06-11 11:28:05 +00:00
import {PlatformLocation} from '@angular/common';
2018-04-16 10:45:10 +00:00
2018-04-16 08:28:39 +00:00
@Component({
2018-06-07 06:24:55 +00:00
selector: 'of-target-list',
2018-06-21 11:10:18 +00:00
templateUrl: './target-list.component.html',
2018-04-16 08:28:39 +00:00
})
2018-06-21 11:10:18 +00:00
export class TargetListComponent implements OnChanges {
2018-06-07 09:21:56 +00:00
@Input() probeID;
@Input() pageIdx;
@Output() pageChange = new EventEmitter<number>();
2018-06-11 07:33:34 +00:00
@Output() targetSelect = new EventEmitter<Target>();
2018-06-07 09:21:56 +00:00
@ViewChild('paginator') paginator: Paginator;
2018-04-16 08:28:39 +00:00
2018-06-21 11:10:18 +00:00
targetList: Target[];
2018-06-07 06:24:55 +00:00
pending$: Observable<boolean>;
error$: Observable<any>;
2018-06-21 11:10:18 +00:00
// countPerPage: number;
2018-06-11 13:31:42 +00:00
2018-06-07 06:24:55 +00:00
constructor(
private store: Store<any>,
private targetService: TargetService,
2018-06-11 11:28:05 +00:00
private location: PlatformLocation
2018-06-07 06:24:55 +00:00
) {
2018-06-21 11:10:18 +00:00
// this.countPerPage = 2;
2018-06-07 06:24:55 +00:00
}
2018-06-07 09:21:56 +00:00
ngOnChanges(changes: SimpleChanges): void {
2018-06-11 07:33:34 +00:00
// console.log(changes);
2018-06-11 13:02:27 +00:00
if (changes['pageIdx']) {
2018-06-11 07:33:34 +00:00
// console.log(this.pageIdx);
2018-06-11 03:27:25 +00:00
this.getTargetList();
2018-06-11 13:02:27 +00:00
// const p: number = this.pageIdx - 1;
// this.paginator.changePage(this.pageIdx);
2018-06-07 09:21:56 +00:00
}
}
2018-06-11 03:27:25 +00:00
private getTargetList() {
2018-06-21 11:10:18 +00:00
// if (this.pageIdx <= 0 || this.pageIdx === undefined || this.pageIdx === null || isNaN(this.pageIdx)) {
// this.pageIdx = 1;
// }
2018-06-11 13:02:27 +00:00
const p: number = this.pageIdx - 1;
2018-06-21 11:10:18 +00:00
// const pageParams: PageParams = {
// pageNo: p,
// countPerPage: this.countPerPage,
// sortCol: 'id',
// sortDirection: 'descending',
// };
2018-06-07 09:21:56 +00:00
2018-06-21 11:10:18 +00:00
// this.targetService.readAllByProbeID(this.probeID, pageParams)
this.targetService.readAllByProbeID(this.probeID)
2018-06-07 06:24:55 +00:00
.pipe(
tap(() => {
this.pending$ = of(true);
}),
2018-06-21 11:10:18 +00:00
map((targetList: Target[]) => {
this.targetList = targetList;
2018-06-07 06:24:55 +00:00
}),
catchError(err => {
console.log(err);
return err;
}),
tap(() => {
this.pending$ = of(false);
}),
take(1),
).subscribe();
}
onRowSelect(event) {
2018-06-11 07:33:34 +00:00
this.targetSelect.emit(event.data);
2018-06-07 06:24:55 +00:00
}
onAddSensor(target: Target) {
// this.target = target;
// this.sensorSettingDisplay = true;
}
2018-06-07 09:21:56 +00:00
onPaginate(e) {
2018-06-11 11:28:05 +00:00
// e.changePage();
2018-06-11 13:02:27 +00:00
this.pageChange.emit(Number(e.page));
2018-06-07 06:24:55 +00:00
}
2018-04-16 08:28:39 +00:00
}