Merge remote-tracking branch 'origin/master'
# Conflicts: # @overflow/member/container/index.ts
This commit is contained in:
@@ -6,55 +6,60 @@ import {
|
||||
RouterStateSnapshot,
|
||||
Router,
|
||||
} from '@angular/router';
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/take';
|
||||
import 'rxjs/add/operator/map';
|
||||
|
||||
import { Store, select } from '@ngrx/store';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, take } from 'rxjs/operators';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
|
||||
import * as AuthStore from '@overflow/member/store/auth';
|
||||
import { AuthSelector } from '@overflow/member/store';
|
||||
import { AuthContainerSelector } from '@overflow/shared/auth/store';
|
||||
import * as MemberEntityStore from '@overflow/member/store/entity/member';
|
||||
import * as SigninContaifnerStore from '../store/container/signin';
|
||||
|
||||
@Injectable()
|
||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
||||
constructor(
|
||||
private store: Store<AuthStore.State>,
|
||||
private store: Store<any>,
|
||||
private router: Router,
|
||||
private cookieService: CookieService,
|
||||
) { }
|
||||
|
||||
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
|
||||
return this.store
|
||||
.select(AuthSelector.select('signined'))
|
||||
.map(signined => {
|
||||
return this.store.pipe(
|
||||
select(AuthContainerSelector.selectSignined),
|
||||
map(signined => {
|
||||
if (!signined) {
|
||||
if (this.cookieService.check('authToken')) {
|
||||
this.store.dispatch(new AuthStore.SigninCookie({authToken: this.cookieService.get('authToken'), returnURL: state.url}));
|
||||
this.store.dispatch(new MemberEntityStore.SigninCookie({authToken: this.cookieService.get('authToken'), returnURL: state.url}));
|
||||
} else {
|
||||
// this.store.dispatch(new AuthStore.SigninRedirect(state.url));
|
||||
this.router.navigateByUrl(state.url);
|
||||
this.store.dispatch(new SigninContaifnerStore.SigninRedirect({returnURL: state.url}));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.take(1);
|
||||
}),
|
||||
take(1)
|
||||
);
|
||||
}
|
||||
|
||||
canActivateChild(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
|
||||
return this.store
|
||||
.select(AuthSelector.select('signined'))
|
||||
.map(signined => {
|
||||
return this.store.pipe(
|
||||
select(AuthContainerSelector.selectSignined),
|
||||
map(signined => {
|
||||
if (!signined) {
|
||||
this.store.dispatch(new AuthStore.SigninRedirect(state.url));
|
||||
if (this.cookieService.check('authToken')) {
|
||||
this.store.dispatch(new MemberEntityStore.SigninCookie({authToken: this.cookieService.get('authToken'), returnURL: state.url}));
|
||||
} else {
|
||||
this.store.dispatch(new SigninContaifnerStore.SigninRedirect({returnURL: state.url}));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.take(1);
|
||||
}),
|
||||
take(1)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
15
src/app/commons/store/container/signin/app-signin.action.ts
Normal file
15
src/app/commons/store/container/signin/app-signin.action.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Action } from '@ngrx/store';
|
||||
|
||||
export enum ActionType {
|
||||
SigninRedirect = '[app.signin] SigninRedirect',
|
||||
}
|
||||
|
||||
export class SigninRedirect implements Action {
|
||||
readonly type = ActionType.SigninRedirect;
|
||||
|
||||
constructor(public payload: {returnURL: string}) {}
|
||||
}
|
||||
|
||||
export type Actions =
|
||||
| SigninRedirect
|
||||
;
|
||||
@@ -1,8 +1,8 @@
|
||||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './signin-init.effect';
|
||||
import { Effects } from './app-signin.effect';
|
||||
|
||||
describe('SigninInit.Effects', () => {
|
||||
describe('app-signin-container.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
72
src/app/commons/store/container/signin/app-signin.effect.ts
Normal file
72
src/app/commons/store/container/signin/app-signin.effect.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { Effect, Actions, ofType } from '@ngrx/effects';
|
||||
|
||||
import { map, tap } from 'rxjs/operators';
|
||||
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import { RPCService } from '@loafer/ng-rpc';
|
||||
|
||||
import {
|
||||
SigninSuccess,
|
||||
SigninCookieSuccess,
|
||||
ActionType as AuthActionType,
|
||||
} from '@overflow/shared/auth/store/container/auth';
|
||||
|
||||
import {
|
||||
SigninRedirect,
|
||||
ActionType,
|
||||
} from './app-signin.action';
|
||||
|
||||
import { DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private rpcService: RPCService,
|
||||
private cookieService: CookieService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinSuccess$ = this.actions$.pipe(
|
||||
ofType(AuthActionType.SigninSuccess),
|
||||
map((action: SigninSuccess) => action.payload),
|
||||
tap((info: {authToken: string, domainMember: DomainMember, returnURL: string}) => {
|
||||
const expires = new Date();
|
||||
expires.setDate(expires.getDate() + 1);
|
||||
this.cookieService.set('authToken', info.authToken, expires, '/');
|
||||
const queryString = `authToken=${info.authToken}`;
|
||||
this.rpcService.connect(queryString);
|
||||
|
||||
this.router.navigateByUrl(info.returnURL);
|
||||
})
|
||||
);
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinCookieSuccess$ = this.actions$.pipe(
|
||||
ofType(AuthActionType.SigninCookieSuccess),
|
||||
map((action: SigninCookieSuccess) => action.payload),
|
||||
tap((info: {domainMember: DomainMember, returnURL: string}) => {
|
||||
const authToken = this.cookieService.get('authToken');
|
||||
const queryString = `authToken=${authToken}`;
|
||||
this.rpcService.connect(queryString);
|
||||
|
||||
this.router.navigateByUrl(info.returnURL);
|
||||
})
|
||||
);
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinRedirect$ = this.actions$.pipe(
|
||||
ofType(ActionType.SigninRedirect),
|
||||
map((action: SigninRedirect) => action.payload),
|
||||
tap((info: {returnURL: string}) => {
|
||||
this.router.navigate(['/auth/signin'], {queryParams: {returnURL: info.returnURL}});
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
2
src/app/commons/store/container/signin/index.ts
Normal file
2
src/app/commons/store/container/signin/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './app-signin.action';
|
||||
export * from './app-signin.effect';
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ActionReducerMap } from '@ngrx/store';
|
||||
|
||||
import * as SigninInitStore from './signin-init';
|
||||
import * as SigninContainerStore from './container/signin';
|
||||
|
||||
export interface State {
|
||||
}
|
||||
@@ -9,5 +9,5 @@ export const REDUCERS: ActionReducerMap<State> = {
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
SigninInitStore.Effects,
|
||||
SigninContainerStore.Effects,
|
||||
];
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export * from './signin-init.effect';
|
||||
@@ -1,68 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { Effect, Actions, ofType } from '@ngrx/effects';
|
||||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { of } from 'rxjs/observable/of';
|
||||
|
||||
import 'rxjs/add/operator/catch';
|
||||
import 'rxjs/add/operator/do';
|
||||
import 'rxjs/add/operator/exhaustMap';
|
||||
import 'rxjs/add/operator/switchMap';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/take';
|
||||
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
|
||||
import { RPCService } from '@loafer/ng-rpc';
|
||||
|
||||
import {
|
||||
SigninSuccess,
|
||||
SigninCookieSuccess,
|
||||
ActionType,
|
||||
} from '@overflow/member/store/auth';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private rpcService: RPCService,
|
||||
private cookieService: CookieService,
|
||||
) { }
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinSuccess$ = this.actions$
|
||||
.ofType(ActionType.SigninSuccess)
|
||||
.map((action: SigninSuccess) => action.payload)
|
||||
.do(
|
||||
(result) => {
|
||||
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.rpcService.connect(queryString);
|
||||
}
|
||||
);
|
||||
|
||||
@Effect({ dispatch: false })
|
||||
signinCookieSuccess$ = this.actions$
|
||||
.ofType(ActionType.SigninCookieSuccess)
|
||||
.map((action: SigninCookieSuccess) => action.payload)
|
||||
.do(
|
||||
(result) => {
|
||||
const authToken = this.cookieService.get('authToken');
|
||||
// console.log(`authToken: ${authToken}`);
|
||||
const queryString = `authToken=${authToken}`;
|
||||
|
||||
this.rpcService.connect(queryString);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
<div class="ui-g-12">
|
||||
<div class="card no-margin">
|
||||
<!--<of-discovery></of-discovery>-->
|
||||
<of-discovery-container (hostID)="hostId"></of-discovery-container>
|
||||
<of-discovery-container [probeHostID]="probeHostID"></of-discovery-container>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@ import { ActivatedRoute } from '@angular/router';
|
||||
})
|
||||
export class DiscoveryPageComponent implements OnInit {
|
||||
|
||||
hostId: number;
|
||||
probeHostID: number;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute
|
||||
@@ -15,8 +15,7 @@ export class DiscoveryPageComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.route.params.subscribe((params: any) => {
|
||||
this.hostId = params['probeHostID'];
|
||||
// console.log('probeHostID : ' + probeHostID);
|
||||
this.probeHostID = params['probeHostID'];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
import { NoAuthProbePageComponent } from './noauth-probe-page.component';
|
||||
import { ProbeListComponent } from '@overflow/probe/component/list/list.component';
|
||||
import { NoAuthProbeListComponent } from '@overflow/noauth-probe/component/list/list.component';
|
||||
import { ProbeDownloadComponent } from '@overflow/probe/component/download/download.component';
|
||||
|
||||
const routes: Routes = [
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
<div *ngIf="!isDetail; else detailView">
|
||||
<of-sensor-list-container *ngIf="router.url === '/sensor/list'" (select)="onSensorSelect($event)" (addSensor)="onAddSensor($event)"> </of-sensor-list-container>
|
||||
<of-sensor-setting-container *ngIf="router.url === '/sensor/setting'"></of-sensor-setting-container>
|
||||
</div>
|
||||
|
||||
<ng-template #detailView>
|
||||
<of-sensor-detail-container></of-sensor-detail-container>
|
||||
</ng-template>
|
||||
<of-sensor-list-container *ngIf="containerType === 1" (select)="onSensorSelect($event)" (addSensor)="onAddSensor($event)">
|
||||
</of-sensor-list-container>
|
||||
<of-sensor-detail-container *ngIf="containerType === 2"></of-sensor-detail-container>
|
||||
<of-sensor-setting-container *ngIf="containerType === 3"></of-sensor-setting-container>
|
||||
@@ -4,13 +4,19 @@ import { Sensor } from '@overflow/commons-typescript/model/sensor';
|
||||
import { BreadcrumbService } from '@app/commons/service/breadcrumb.service';
|
||||
import { Target } from '@overflow/commons-typescript/model/target';
|
||||
|
||||
enum CONTAINER_TYPES {
|
||||
List = 1,
|
||||
Detail,
|
||||
Setting,
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'of-pages-sensor',
|
||||
templateUrl: './sensor-page.component.html',
|
||||
})
|
||||
export class SensorPageComponent {
|
||||
|
||||
isDetail: boolean;
|
||||
containerType: CONTAINER_TYPES;
|
||||
sensorID: string;
|
||||
|
||||
constructor(
|
||||
@@ -31,7 +37,11 @@ export class SensorPageComponent {
|
||||
this.breadcrumbService.setItems([
|
||||
{ label: 'Sensor', routerLink: ['/sensor/list'], }
|
||||
]);
|
||||
this.isDetail = false;
|
||||
if (this.router.url === '/sensor/list') {
|
||||
this.containerType = CONTAINER_TYPES.List;
|
||||
} else {
|
||||
this.containerType = CONTAINER_TYPES.Setting;
|
||||
}
|
||||
}
|
||||
|
||||
onDetailContainer(sensorID: string) {
|
||||
@@ -40,7 +50,7 @@ export class SensorPageComponent {
|
||||
{ label: 'Sensor', routerLink: ['/sensor/list'] },
|
||||
{ label: this.sensorID }
|
||||
]);
|
||||
this.isDetail = true;
|
||||
this.containerType = CONTAINER_TYPES.Detail;
|
||||
}
|
||||
|
||||
onSensorSelect(sensor: Sensor) {
|
||||
|
||||
Reference in New Issue
Block a user