target detail-sensorlist

This commit is contained in:
insanity 2018-04-30 17:53:15 +09:00
parent cae76a196d
commit fd51af6d67
3 changed files with 54 additions and 13 deletions

View File

@ -11,4 +11,5 @@ export interface Sensor {
crawler?: MetaCrawler; crawler?: MetaCrawler;
crawlerInputItems?: string; crawlerInputItems?: string;
itemCount?: number; itemCount?: number;
displayName?: string;
} }

View File

@ -1,4 +1,3 @@
<h1>Sensors</h1>
<div *ngIf="infra"> <div *ngIf="infra">
<div class="ui-g"> <div class="ui-g">
<div class="ui-g-12"> <div class="ui-g-12">
@ -41,25 +40,24 @@
<p-table [value]="sensors" selectionMode="single" (onRowSelect)="onRowSelect($event)" [resizableColumns]="true"> <p-table [value]="sensors" selectionMode="single" (onRowSelect)="onRowSelect($event)" [resizableColumns]="true">
<ng-template pTemplate="header"> <ng-template pTemplate="header">
<tr> <tr>
<th>No.</th> <th>Alias</th>
<th>Description</th>
<th>Status</th> <th>Status</th>
<th>Crawler</th> <th>Crawler</th>
<th>Items</th> <th>Items</th>
<th>Created at</th> <th>Created at</th>
</tr> </tr>
</ng-template> </ng-template>
<ng-template pTemplate="body" let-sensor let-rowIndex="rowIndex"> <ng-template pTemplate="body" let-sensor>
<tr [pSelectableRow]="sensor"> <tr [pSelectableRow]="sensor">
<td>{{rowIndex + 1}}</td> <td>{{sensor.displayName}}</td>
<td>{{sensor.Description}}</td>
<td>{{sensor.status.name}}</td> <td>{{sensor.status.name}}</td>
<td>{{sensor.crawler.name}}</td> <td>{{sensor.crawler.name}}</td>
<td>???</td> <td>{{sensor.itemCount}}</td>
<td>{{sensor.createDate | date: 'dd.MM.yyyy'}}</td> <td>{{sensor.createDate | date: 'dd.MM.yyyy'}}</td>
</tr> </tr>
</ng-template> </ng-template>
</p-table> </p-table>
<p-paginator [rows]="pageSize" [totalRecords]="sensorsCount" (onPageChange)="onPaging($event)"></p-paginator>
</div> </div>
</div> </div>
</div> </div>

View File

@ -10,6 +10,7 @@ import { RPCClientError } from '@loafer/ng-rpc/protocol';
import { sensorListSelector } from 'packages/sensor/store'; import { sensorListSelector } from 'packages/sensor/store';
import * as SensorListStore from 'packages/sensor/store/list'; import * as SensorListStore from 'packages/sensor/store/list';
import { PageParams, Page } from 'app/commons/model';
@Component({ @Component({
@ -23,9 +24,16 @@ export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
sensorsSubscription$: Subscription; sensorsSubscription$: Subscription;
sensors$ = this.sensorListStore.pipe(select(sensorListSelector.select('page'))); sensors$ = this.sensorListStore.pipe(select(sensorListSelector.select('page')));
infraId = null;
infra: Infra; infra: Infra;
sensors: Sensor[];
sensorsCount = 0;
sensorSettingDisplay = false; sensorSettingDisplay = false;
pageSize = '10';
totalLength = 0;
currPage = 0;
constructor( constructor(
private router: Router, private router: Router,
private route: ActivatedRoute, private route: ActivatedRoute,
@ -42,15 +50,23 @@ export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
console.log(error.response.message); console.log(error.response.message);
} }
); );
this.sensorsSubscription$ = this.sensors$.subscribe(
(page: Page) => {
if (page) {
this.sensorsCount = page.totalElements;
this.sensors = page.content;
}
},
(error: RPCClientError) => {
console.log(error.response.message);
}
);
} }
ngAfterContentInit() { ngAfterContentInit() {
const infraId = this.route.snapshot.paramMap.get('id'); this.infraId = this.route.snapshot.paramMap.get('id');
this.infraDetailStore.dispatch( this.getInfra();
new InfraDetailStore.Read( this.getSensors(this.currPage);
{ id: infraId }
)
);
} }
ngOnDestroy() { ngOnDestroy() {
@ -59,6 +75,28 @@ export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
} }
} }
getInfra() {
this.infraDetailStore.dispatch(
new InfraDetailStore.Read(
{ id: this.infraId }
)
);
}
getSensors(pageIndex) {
const pageParams: PageParams = {
pageNo: pageIndex + '',
countPerPage: this.pageSize,
sortCol: 'id',
sortDirection: 'descending'
};
this.sensorListStore.dispatch(
new SensorListStore.ReadAllByInfra(
{ id: this.infraId, pageParams: pageParams }
)
);
}
onAddSensor() { onAddSensor() {
this.sensorSettingDisplay = true; this.sensorSettingDisplay = true;
} }
@ -67,4 +105,8 @@ export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
this.sensorSettingDisplay = false; this.sensorSettingDisplay = false;
} }
onPaging(e) {
this.getSensors(e.page);
}
} }