This commit is contained in:
geek 2018-06-07 18:21:56 +09:00
parent 10d529e0f7
commit f8f1052e82
6 changed files with 79 additions and 39 deletions

View File

@ -1,6 +1,10 @@
<h1>Targets</h1> <h1>Targets</h1>
<div *ngIf="!targetPage; else content">
No data
</div>
<p-table [value]="page.content" selectionMode="single" (onRowSelect)="onRowSelect($event)" [resizableColumns]="true" > <ng-template #content>
<p-table [value]="targetPage.content" selectionMode="single" (onRowSelect)="onRowSelect($event)" [resizableColumns]="true" >
<ng-template pTemplate="header"> <ng-template pTemplate="header">
<tr> <tr>
<th style="width: 4em">No.</th> <th style="width: 4em">No.</th>
@ -26,5 +30,7 @@
</tr> </tr>
</ng-template> </ng-template>
</p-table> </p-table>
<p-paginator #paginator [rows]="page.size" [totalRecords]="page.totalElements" <p-paginator #paginator [rows]="targetPage.size" [totalRecords]="targetPage.totalElements"
(onPageChange)="onPaginate($event)" ></p-paginator> (onPageChange)="onPaginate($event)" ></p-paginator>
</ng-template>

View File

@ -1,25 +1,45 @@
import { Component, OnInit, AfterContentInit, OnDestroy } from '@angular/core'; import {
import { Router, ActivatedRoute } from '@angular/router'; Component,
import { Infra } from '@overflow/commons-typescript/model/infra'; OnInit,
import { Probe } from '@overflow/commons-typescript/model/probe'; Input,
EventEmitter,
Output,
ViewChild,
OnChanges,
SimpleChanges
} from '@angular/core';
import {
Observable,
of
} from 'rxjs';
import { Store } from '@ngrx/store';
import {
catchError,
map,
tap,
take
} from 'rxjs/operators';
import { Target } from '@overflow/commons-typescript/model/target'; import { Target } from '@overflow/commons-typescript/model/target';
import { Observable, of, Subscription } from 'rxjs';
import { Store, select } from '@ngrx/store';
import { catchError, map, tap, take } from 'rxjs/operators';
import { TargetService } from '../../service/target.service'; import { TargetService } from '../../service/target.service';
import { InfraService } from '@overflow/infra/service/infra.service';
import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams'; import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams';
import { Page } from '@overflow/commons-typescript/model/commons/Page'; import { Page } from '@overflow/commons-typescript/model/commons/Page';
import { Paginator } from 'primeng/primeng';
@Component({ @Component({
selector: 'of-target-list', selector: 'of-target-list',
templateUrl: './list.component.html', templateUrl: './list.component.html',
}) })
export class ListComponent implements OnInit { export class ListComponent implements OnInit, OnChanges {
page: Page<Target>; @Input() probeID;
@Input() pageIdx;
@Output() pageChange = new EventEmitter<number>();
@ViewChild('paginator') paginator: Paginator;
targetPage: Page<Target>;
pending$: Observable<boolean>; pending$: Observable<boolean>;
error$: Observable<any>; error$: Observable<any>;
@ -32,18 +52,39 @@ export class ListComponent implements OnInit {
ngOnInit() { ngOnInit() {
const pageParams: PageParams = { const pageParams: PageParams = {
pageNo: 0, pageNo: 0,
countPerPage: 5, countPerPage: 2,
sortCol: 'id', sortCol: 'id',
sortDirection: 'descending', sortDirection: 'descending',
}; };
this.targetService.readAllByProbeID(1, pageParams) this.getTargetList(pageParams);
}
ngOnChanges(changes: SimpleChanges): void {
console.log(changes);
if (changes['pageIdx'] && this.paginator) {
const pageParams: PageParams = {
pageNo: this.pageIdx - 1,
countPerPage: 2,
sortCol: 'id',
sortDirection: 'descending',
};
console.log(this.pageIdx);
this.paginator.changePage(this.pageIdx);
this.getTargetList(pageParams);
}
}
private getTargetList(pageParams: PageParams) {
this.targetService.readAllByProbeID(this.probeID, pageParams)
.pipe( .pipe(
tap(() => { tap(() => {
this.pending$ = of(true); this.pending$ = of(true);
}), }),
map((page: Page<Target>) => { map((page: Page<Target>) => {
this.page = page; this.targetPage = page;
}), }),
catchError(err => { catchError(err => {
console.log(err); console.log(err);
@ -56,20 +97,6 @@ export class ListComponent implements OnInit {
).subscribe(); ).subscribe();
} }
getInfras(pageNo) {
// const pageParams: PageParams = {
// pageNo: pageNo + '',
// countPerPage: this.pageSize,
// sortCol: 'id',
// sortDirection: 'descending'
// };
// this.infraListStore.dispatch(
// new InfraListStore.ReadAllByProbe(
// { probe: this.probe, pageParams: pageParams }
// )
// );
}
onRowSelect(event) { onRowSelect(event) {
// this.router.navigate(['target'], { queryParams: { target: event.data.id } }); // this.router.navigate(['target'], { queryParams: { target: event.data.id } });
// this.router.navigate(['target', event.data.id, 'info']); // this.router.navigate(['target', event.data.id, 'info']);
@ -80,7 +107,7 @@ export class ListComponent implements OnInit {
// this.sensorSettingDisplay = true; // this.sensorSettingDisplay = true;
} }
onPaginate(event) { onPaginate(e) {
this.pageChange.emit(e.page);
} }
} }

View File

@ -2,7 +2,7 @@
<div class="ui-g"> <div class="ui-g">
<div class="ui-g-12"> <div class="ui-g-12">
<div class="card no-margin"> <div class="card no-margin">
<of-target-list></of-target-list> <of-target-list [probeID]="probeID" [pageIdx]="pageIdx" (pageChange)="onPageChange($event)"></of-target-list>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,5 +1,5 @@
import {Component, Input, OnInit} from '@angular/core'; import {Component, Input, OnInit} from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
@Component({ @Component({
selector: 'of-pages-target-list', selector: 'of-pages-target-list',
@ -7,13 +7,20 @@ import { ActivatedRoute } from '@angular/router';
}) })
export class TargetListPageComponent implements OnInit { export class TargetListPageComponent implements OnInit {
// @Input() probeHostID: string; @Input() probeID: number;
pageIdx: number;
constructor( constructor(
private router: Router,
private route: ActivatedRoute private route: ActivatedRoute
) { } ) { }
ngOnInit() { ngOnInit() {
} }
onPageChange(pageNo: number) {
this.pageIdx = pageNo + 1;
this.router.navigate(['/probe', this.probeID, 'target'], { queryParams: { page: pageNo + 1 } });
}
} }

View File

@ -3,7 +3,7 @@
<div class="card no-margin"> <div class="card no-margin">
<!--<router-outlet *ngIf="probeID !== undefined" else complete></router-outlet>--> <!--<router-outlet *ngIf="probeID !== undefined" else complete></router-outlet>-->
<!--<ng-template #complete>--> <!--<ng-template #complete>-->
<of-pages-target-list></of-pages-target-list> <of-pages-target-list [probeID]="probeID" ></of-pages-target-list>
<!--</ng-template>--> <!--</ng-template>-->
</div> </div>
</div> </div>

View File

@ -7,13 +7,13 @@ import {BreadcrumbService} from '../../commons/service/breadcrumb.service';
templateUrl: './target-page.component.html', templateUrl: './target-page.component.html',
}) })
export class TargetPageComponent implements OnInit { export class TargetPageComponent implements OnInit {
// probeHostID: string; probeID: number;
constructor( constructor(
private router: Router, private router: Router,
private activatedRoute: ActivatedRoute, private activatedRoute: ActivatedRoute,
) { ) {
// this.probeHostID = this.activatedRoute.snapshot.params['id']; this.probeID = this.activatedRoute.snapshot.params['id'];
} }
ngOnInit() { ngOnInit() {