This commit is contained in:
insanity 2018-03-12 20:05:05 +09:00
parent 419a8fab9f
commit 43582c7199
7 changed files with 78 additions and 48 deletions

View File

@ -35,6 +35,7 @@ export class ListComponent implements OnInit, AfterContentInit {
ngAfterContentInit() { ngAfterContentInit() {
this.store.select(AuthSelector.select('domain')).subscribe( this.store.select(AuthSelector.select('domain')).subscribe(
(domain: Domain) => { (domain: Domain) => {
console.log(domain);
this.store.dispatch(new ListStore.ReadAllByDomain(domain)); this.store.dispatch(new ListStore.ReadAllByDomain(domain));
} }
); );

View File

@ -8,12 +8,12 @@
<ng-container matColumnDef="ip"> <ng-container matColumnDef="ip">
<mat-header-cell *matHeaderCellDef mat-sort-header> IP </mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header> IP </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.host.ip}} </mat-cell> <mat-cell *matCellDef="let element"> </mat-cell>
</ng-container> </ng-container>
<ng-container matColumnDef="os"> <ng-container matColumnDef="os">
<mat-header-cell *matHeaderCellDef mat-sort-header> OS </mat-header-cell> <mat-header-cell *matHeaderCellDef mat-sort-header> OS </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.host.os.meta}} </mat-cell> <mat-cell *matCellDef="let element"> </mat-cell>
</ng-container> </ng-container>
<ng-container matColumnDef="cidr"> <ng-container matColumnDef="cidr">

View File

@ -19,8 +19,8 @@ import { ListSelector } from '../../store';
}) })
export class ListComponent implements OnInit, AfterContentInit { export class ListComponent implements OnInit, AfterContentInit {
probes$ = this.store.pipe(select(ListSelector.select('probes'))); probes$ = this.store.pipe(select(ListSelector.select('probes')));
pageSize = '25'; // pageSize = '25';
length = '100'; // length = '100';
displayedColumns = ['name', 'ip', 'os', 'cidr', 'targetCnt', 'date', 'authBy']; displayedColumns = ['name', 'ip', 'os', 'cidr', 'targetCnt', 'date', 'authBy'];
dataSource: MatTableDataSource<Probe>; dataSource: MatTableDataSource<Probe>;
@ -33,15 +33,6 @@ export class ListComponent implements OnInit, AfterContentInit {
} }
ngAfterContentInit() { ngAfterContentInit() {
this.probes$.subscribe(
(probes: Probe[]) => {
this.dataSource = new MatTableDataSource(probes);
this.dataSource.sort = this.sort;
},
(error: RPCError) => {
console.log(error);
}
);
this.store.select(AuthSelector.select('domain')).subscribe( this.store.select(AuthSelector.select('domain')).subscribe(
(domain: Domain) => { (domain: Domain) => {
@ -52,34 +43,45 @@ export class ListComponent implements OnInit, AfterContentInit {
} }
); );
// temporary data this.probes$.subscribe(
const data: Probe[] = new Array(); (probes: Probe[]) => {
for (let i = 0; i < 100; i++) { console.log(probes);
const p: Probe = { this.dataSource = new MatTableDataSource(probes);
id: i, this.dataSource.sort = this.sort;
displayName: String('displayName' + i), },
host: { (error: RPCError) => {
ip: i, console.log(error.message);
os: { }
meta: 'blahblahblah' );
},
},
cidr: String('cidr' + i),
targets: [
{
id: i,
},
],
authorizeDate: new Date(),
authorizeMember: {
'name': String('insanity')
},
};
data.push(p);
}
this.dataSource = new MatTableDataSource(data); // // temporary data
this.dataSource.sort = this.sort; // const data: Probe[] = new Array();
// for (let i = 0; i < 100; i++) {
// const p: Probe = {
// id: i,
// displayName: String('displayName' + i),
// host: {
// ip: i,
// os: {
// meta: 'blahblahblah'
// },
// },
// cidr: String('cidr' + i),
// targets: [
// {
// id: i,
// },
// ],
// authorizeDate: new Date(),
// authorizeMember: {
// 'name': String('insanity')
// },
// };
// data.push(p);
// }
// this.dataSource = new MatTableDataSource(data);
// this.dataSource.sort = this.sort;
} }
ngOnInit() { ngOnInit() {

View File

@ -16,6 +16,6 @@ export interface Probe {
cidr?: string; cidr?: string;
authorizeDate?: Date; authorizeDate?: Date;
authorizeMember?: Member; authorizeMember?: Member;
host?: InfraHost; // host?: InfraHost;
targets?: Target[]; targets?: Target[];
} }

View File

@ -9,10 +9,12 @@ import {
import { import {
State, State,
initialState, initialState,
adapter,
} from './detail.state'; } from './detail.state';
import { Probe } from '../../model'; import { Probe } from '../../model';
export function reducer(state = initialState, action: Actions): State { export function reducer(state = initialState, action: Actions): State {
switch (action.type) { switch (action.type) {
case ActionType.Read: { case ActionType.Read: {

View File

@ -2,18 +2,39 @@ import { RPCError } from 'packages/core/rpc/error';
import { Probe } from '../../model'; import { Probe } from '../../model';
export interface State { // export interface State {
// error: RPCError | null;
// isPending: boolean;
// probe: Probe | null;
// }
// export const initialState: State = {
// error: null,
// isPending: false,
// probe: null,
// };
// export const getProbe = (state: State) => state.probe;
// export const getError = (state: State) => state.error;
// export const isPending = (state: State) => state.isPending;
import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity';
export interface State extends EntityState<Probe> {
error: RPCError | null; error: RPCError | null;
isPending: boolean; isPending: boolean;
probe: Probe | null; probe: Probe | null;
} }
export const adapter: EntityAdapter<Probe> = createEntityAdapter<Probe>();
export const initialState: State = { export const initialState: State = adapter.getInitialState({
error: null, error: null,
isPending: false, isPending: false,
probe: null, probe: null,
}; });
export const getProbe = (state: State) => state.probe; // export const {
export const getError = (state: State) => state.error; // selectIds,
export const isPending = (state: State) => state.isPending; // selectEntities,
// selectAll,
// selectTotal,
// } = adapter.getSelectors();

View File

@ -32,3 +32,7 @@ export const ListSelector = new StateSelector<ProbeListStore.State>(createSelect
selectProbeState, selectProbeState,
(state: State) => state.list (state: State) => state.list
)); ));
export const DetailSelector = new StateSelector<ProbeDetailStore.State>(createSelector(
selectProbeState,
(state: State) => state.detail
));