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

117 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-06-07 09:21:56 +00:00
import {
Component,
OnInit,
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-06 10:36:51 +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-07 09:24:23 +00:00
import { Page, PageParams} from '@overflow/commons-typescript';
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',
templateUrl: './list.component.html',
2018-04-16 08:28:39 +00:00
})
2018-06-07 09:21:56 +00:00
export class ListComponent implements OnInit, OnChanges {
@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-07 09:21:56 +00:00
targetPage: Page<Target>;
2018-06-07 06:24:55 +00:00
pending$: Observable<boolean>;
error$: Observable<any>;
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-11 11:28:05 +00:00
2018-06-07 06:24:55 +00:00
}
ngOnInit() {
2018-06-11 03:27:25 +00:00
this.getTargetList();
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() {
if (this.pageIdx <= 0 || this.pageIdx === undefined || this.pageIdx === null || isNaN(this.pageIdx)) {
2018-06-11 13:02:27 +00:00
this.pageIdx = 1;
2018-06-11 03:27:25 +00:00
}
2018-06-11 13:02:27 +00:00
const p: number = this.pageIdx - 1;
2018-06-11 03:27:25 +00:00
const pageParams: PageParams = {
2018-06-11 13:02:27 +00:00
pageNo: p,
2018-06-11 03:27:25 +00:00
countPerPage: 2,
sortCol: 'id',
sortDirection: 'descending',
};
2018-06-07 09:21:56 +00:00
this.targetService.readAllByProbeID(this.probeID, pageParams)
2018-06-07 06:24:55 +00:00
.pipe(
tap(() => {
this.pending$ = of(true);
}),
map((page: Page<Target>) => {
2018-06-07 09:21:56 +00:00
this.targetPage = page;
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
}