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() {
this.store.select(AuthSelector.select('domain')).subscribe(
(domain: Domain) => {
console.log(domain);
this.store.dispatch(new ListStore.ReadAllByDomain(domain));
}
);

View File

@ -8,12 +8,12 @@
<ng-container matColumnDef="ip">
<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 matColumnDef="os">
<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 matColumnDef="cidr">

View File

@ -19,8 +19,8 @@ import { ListSelector } from '../../store';
})
export class ListComponent implements OnInit, AfterContentInit {
probes$ = this.store.pipe(select(ListSelector.select('probes')));
pageSize = '25';
length = '100';
// pageSize = '25';
// length = '100';
displayedColumns = ['name', 'ip', 'os', 'cidr', 'targetCnt', 'date', 'authBy'];
dataSource: MatTableDataSource<Probe>;
@ -33,15 +33,6 @@ export class ListComponent implements OnInit, AfterContentInit {
}
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(
(domain: Domain) => {
@ -52,34 +43,45 @@ export class ListComponent implements OnInit, AfterContentInit {
}
);
// temporary data
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.probes$.subscribe(
(probes: Probe[]) => {
console.log(probes);
this.dataSource = new MatTableDataSource(probes);
this.dataSource.sort = this.sort;
},
(error: RPCError) => {
console.log(error.message);
}
);
this.dataSource = new MatTableDataSource(data);
this.dataSource.sort = this.sort;
// // temporary data
// 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() {

View File

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

View File

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

View File

@ -2,18 +2,39 @@ import { RPCError } from 'packages/core/rpc/error';
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;
isPending: boolean;
probe: Probe | null;
}
export const initialState: State = {
export const adapter: EntityAdapter<Probe> = createEntityAdapter<Probe>();
export const initialState: State = adapter.getInitialState({
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;
// export const {
// selectIds,
// selectEntities,
// selectAll,
// selectTotal,
// } = adapter.getSelectors();

View File

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