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 })
signinSuccess$ = this.actions$
.ofType(ActionType.SigninSuccess)
.map((action: SigninSuccess) => action.payload)
.do(
() => {
let queryString: string;
if (this.cookieService.check('AuthToken')) {
queryString = `AuthToken=${this.cookieService.get('AuthToken')}`;
}
(result: Map<string, any>) => {
const authToken = result['authToken'];
// console.log(`authToken: ${authToken}`);
const expires = new Date();
expires.setDate(expires.getDate() + 1);
this.cookieService.set('authToken', authToken, expires, '/');
const queryString = `authToken=${authToken}`;
this.rpcClient.connect(queryString);
}
);

View File

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

View File

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

View File

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

View File

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

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.dataSource = new MatTableDataSource(data);
this.probes$.subscribe(
(probes: Probe[]) => {
console.log(probes);
this.dataSource = new MatTableDataSource(probes);
this.dataSource.sort = this.sort;
},
(error: RPCError) => {
console.log(error.message);
}
);
// // 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
));