This commit is contained in:
snoop 2018-03-13 15:54:07 +09:00
commit 3cdee810bb
13 changed files with 105 additions and 67 deletions

View File

@ -37,12 +37,18 @@ export class Effects {
@Effect({ dispatch: false }) @Effect({ dispatch: false })
signinSuccess$ = this.actions$ signinSuccess$ = this.actions$
.ofType(ActionType.SigninSuccess) .ofType(ActionType.SigninSuccess)
.map((action: SigninSuccess) => action.payload)
.do( .do(
() => { (result: Map<string, any>) => {
let queryString: string; const authToken = result['authToken'];
if (this.cookieService.check('AuthToken')) { // console.log(`authToken: ${authToken}`);
queryString = `AuthToken=${this.cookieService.get('AuthToken')}`;
} const expires = new Date();
expires.setDate(expires.getDate() + 1);
this.cookieService.set('authToken', authToken, expires, '/');
const queryString = `authToken=${authToken}`;
this.rpcClient.connect(queryString); this.rpcClient.connect(queryString);
} }
); );

View File

@ -12,14 +12,10 @@ import 'rxjs/add/observable/throw';
import { RESTError } from '../error'; import { RESTError } from '../error';
export class RESTClient { export class RESTClient {
private readonly httpHeaders: HttpHeaders;
constructor( constructor(
private _baseURL: string, private _baseURL: string,
private _httpClient: HttpClient, private _httpClient: HttpClient,
) { ) {
this.httpHeaders = new HttpHeaders()
.set('Content-Type', 'application/json');
} }
public get httpClient(): HttpClient { public get httpClient(): HttpClient {
@ -39,11 +35,15 @@ export class RESTClient {
reportProgress?: boolean; reportProgress?: boolean;
withCredentials?: boolean; withCredentials?: boolean;
}): Observable<T> { }): Observable<T> {
const headers: HttpHeaders = this.httpHeaders; // options.withCredentials = true;
return this._httpClient return this._httpClient
.request(method, Location.joinWithSlash(this._baseURL, entry), options) .request<T>(method, Location.joinWithSlash(this._baseURL, entry), options)
.map((response: string) => <T>JSON.parse(response)) .map(
(response: T) => {
return response;
}
)
.catch((error: HttpErrorResponse) => { .catch((error: HttpErrorResponse) => {
const aryMsg = error.error.message.split('|'); const aryMsg = error.error.message.split('|');
const resError: RESTError = { const resError: RESTError = {

View File

@ -17,13 +17,13 @@ export class MemberService {
} }
public signin(email: string, password: string): Observable<DomainMember> { public signin(email: string, password: string): Observable<any> {
const body = { const body = {
signinId: email, signinId: email,
signinPw: password, signinPw: password,
}; };
return this.restClient.request<DomainMember>('post', '/account/signin', { return this.restClient.request<any>('post', '/account/signin', {
body: body, body: body,
}); });
} }

View File

@ -24,7 +24,7 @@ export class Signin implements Action {
export class SigninSuccess implements Action { export class SigninSuccess implements Action {
readonly type = ActionType.SigninSuccess; readonly type = ActionType.SigninSuccess;
constructor(public payload: DomainMember) {} constructor(public payload: any) {}
} }
export class SigninFailure implements Action { export class SigninFailure implements Action {

View File

@ -47,8 +47,8 @@ export class Effects {
this._options = payload.options; this._options = payload.options;
return this.memberService.signin(payload.email, payload.password); return this.memberService.signin(payload.email, payload.password);
}) })
.map((domainMember: DomainMember) => { .map((result: any) => {
return new SigninSuccess(domainMember); return new SigninSuccess(result);
}) })
.catch((error: RESTError) => { .catch((error: RESTError) => {
return of(new SigninFailure(error)); return of(new SigninFailure(error));

View File

@ -10,6 +10,7 @@ import {
} from './auth.state'; } from './auth.state';
import { Member } from '../../model'; import { Member } from '../../model';
import { DomainMember } from '../../../domain/model';
export function reducer(state = initialState, action: Actions): State { export function reducer(state = initialState, action: Actions): State {
switch (action.type) { switch (action.type) {
@ -22,13 +23,14 @@ export function reducer(state = initialState, action: Actions): State {
} }
case ActionType.SigninSuccess: { case ActionType.SigninSuccess: {
const domainMember = action.payload['domainMember'];
return { return {
...state, ...state,
signined: true, signined: true,
error: null, error: null,
pending: false, pending: false,
member: action.payload.member, member: domainMember.member,
domain: action.payload.domain, domain: domainMember.domain,
}; };
} }

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
));