This commit is contained in:
geek 2018-03-02 19:31:29 +09:00
commit 0c9ef4fb76
25 changed files with 274 additions and 98 deletions

View File

@ -0,0 +1,10 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
imports: [
CommonModule
],
declarations: []
})
export class CommonsModule { }

View File

@ -0,0 +1,121 @@
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
import { Subject } from 'rxjs/Subject';
import {
WebSocketSubject,
WebSocketSubjectConfig
} from 'rxjs/observable/dom/WebSocketSubject';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/share';
import 'rxjs/add/operator/takeWhile';
import 'rxjs/add/observable/interval';
export interface Codec {
decode(e: MessageEvent): any;
encode(data: any): string;
}
export const defaultCodec: Codec = {
encode: (e: MessageEvent) => {
return JSON.parse(e.data);
},
decode: (data: any): string => {
return JSON.stringify(data);
}
};
export class RxWebsocketSubject<T> extends Subject<T> {
private reconnectionObservable: Observable<number>;
private wsSubjectConfig: WebSocketSubjectConfig;
private socket: WebSocketSubject<any>;
private connectionObserver: Observer<boolean>;
private _connectionStatus: Observable<boolean>;
private _reconnectInterval = 5000;
private _reconnectAttempts = 10;
public constructor(private url: string, private codec?: Codec) {
super();
this._connectionStatus = new Observable<boolean>((observer) => {
this.connectionObserver = observer;
}).share().distinctUntilChanged();
if (undefined === codec) {
this.codec = defaultCodec;
}
this.wsSubjectConfig = {
url: url,
closeObserver: {
next: (e: CloseEvent) => {
this.socket = null;
this.connectionObserver.next(false);
}
},
openObserver: {
next: (e: Event) => {
this.connectionObserver.next(true);
}
},
resultSelector: this.codec.decode,
};
this._connectionStatus.subscribe((isConnected: boolean) => {
if (!this.reconnectionObservable && typeof(isConnected) === 'boolean' && !isConnected) {
this.reconnect();
}
});
}
public set reconnectInterval(reconnectInterval: number) {
this._reconnectInterval = reconnectInterval;
}
public set reconnectAttempts(reconnectAttempts: number) {
this._reconnectAttempts = reconnectAttempts;
}
public get connectionStatus(): Observable<boolean> {
return this._connectionStatus;
}
public connect(): void {
this.socket = new WebSocketSubject(this.wsSubjectConfig);
this.socket.subscribe(
(m) => {
this.next(m);
},
(error: Event) => {
if (!this.socket) {
this.reconnect();
}
}
);
}
private reconnect(): void {
this.reconnectionObservable = Observable.interval(this._reconnectInterval)
.takeWhile((v, index) => {
return index < this._reconnectAttempts && !this.socket;
});
this.reconnectionObservable.subscribe(
() => {
this.connect();
},
null,
() => {
this.reconnectionObservable = null;
if (!this.socket) {
this.complete();
this.connectionObserver.complete();
}
}
);
}
public send(data: any): void {
this.socket.next(this.codec.encode(data));
}
}

View File

@ -0,0 +1,5 @@
import { SettingComponent } from './setting/setting.component';
export const COMPONENTS = [
SettingComponent,
];

View File

@ -1,19 +1,19 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { SettingComponent } from './component/setting/setting.component'; import { COMPONENTS } from './component';
import { MaterialModule } from 'app/commons/ui/material/material.module'; import { MaterialModule } from 'app/commons/ui/material/material.module';
export const COMPONENTS = [
SettingComponent,
];
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, CommonModule,
MaterialModule MaterialModule
], ],
declarations: COMPONENTS, declarations: [
exports: COMPONENTS, COMPONENTS
],
exports: [
COMPONENTS,
],
}) })
export class DiscoveryModule { } export class DiscoveryModule { }

View File

@ -0,0 +1,5 @@
import { MapComponent } from './map/map.component';
export const COMPONENTS = [
MapComponent,
];

View File

@ -3,18 +3,18 @@ import { CommonModule } from '@angular/common';
import { MaterialModule } from 'app/commons/ui/material/material.module'; import { MaterialModule } from 'app/commons/ui/material/material.module';
import { MapComponent } from './component/map/map.component'; import { COMPONENTS } from './component';
export const COMPONENTS = [
MapComponent,
];
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, CommonModule,
MaterialModule MaterialModule
], ],
declarations: COMPONENTS, declarations: [
exports: COMPONENTS, COMPONENTS,
],
exports: [
COMPONENTS,
],
}) })
export class InfraModule { } export class InfraModule { }

View File

@ -0,0 +1,11 @@
import { ModifyComponent } from './modify/modify.component';
import { SigninComponent } from './signin/signin.component';
import { SignupComponent } from './signup/signup.component';
import { ResetPasswordComponent } from './reset-password/reset-password.component';
export const COMPONENTS = [
ModifyComponent,
SigninComponent,
SignupComponent,
ResetPasswordComponent,
];

View File

@ -8,15 +8,16 @@ import {
import { EffectsModule } from '@ngrx/effects'; import { EffectsModule } from '@ngrx/effects';
import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store'; import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store';
import { State as MemberState } from './store/state'; import {
import { reducers as memberReducers } from './store/reducer'; REDUCERS,
import { EFFECTS } from './store/effect'; EFFECTS,
} from './store';
import { MODULE } from './member.constant'; import { MODULE } from './member.constant';
@NgModule({ @NgModule({
imports: [ imports: [
StoreModule.forFeature(MODULE.name, memberReducers), StoreModule.forFeature(MODULE.name, REDUCERS),
EffectsModule.forFeature(EFFECTS), EffectsModule.forFeature(EFFECTS),
], ],
}) })

View File

@ -5,21 +5,12 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MaterialModule } from 'app/commons/ui/material/material.module'; import { MaterialModule } from 'app/commons/ui/material/material.module';
import { ModifyComponent } from './component/modify/modify.component';
import { SigninComponent } from './component/signin/signin.component';
import { SignupComponent } from './component/signup/signup.component';
import { ResetPasswordComponent } from './component/reset-password/reset-password.component';
import { MemberService } from './service/member.service';
import { AuthGuard } from './guard/auth.guard'; import { AuthGuard } from './guard/auth.guard';
import { MemberStoreModule } from './member-store.module'; import { MemberStoreModule } from './member-store.module';
export const COMPONENTS = [ import { COMPONENTS } from './component';
ModifyComponent, import { SERVICES } from './service';
SigninComponent,
SignupComponent,
ResetPasswordComponent,
];
@NgModule({ @NgModule({
imports: [ imports: [
@ -30,11 +21,14 @@ export const COMPONENTS = [
MaterialModule, MaterialModule,
MemberStoreModule, MemberStoreModule,
], ],
declarations: COMPONENTS, declarations: [
exports: COMPONENTS, COMPONENTS,
],
exports: [
COMPONENTS,
],
providers: [ providers: [
AuthGuard, SERVICES,
MemberService,
], ],
}) })
export class MemberModule { } export class MemberModule { }

View File

@ -0,0 +1,5 @@
import { MemberService } from './member.service';
export const SERVICES = [
MemberService,
];

View File

@ -1,7 +0,0 @@
import * as AuthStore from './auth';
import * as SignupStore from './signup';
export const EFFECTS = [
AuthStore.Effects,
SignupStore.Effects,
];

View File

@ -6,3 +6,12 @@ export interface State {
signup: SignupStore.Signup; signup: SignupStore.Signup;
} }
export const REDUCERS = {
auth: AuthStore.reducer,
signup: SignupStore.reducer,
};
export const EFFECTS = [
AuthStore.Effects,
SignupStore.Effects,
];

View File

@ -1,7 +0,0 @@
import * as AuthStore from './auth';
import * as SignupStore from './signup';
export const reducers = {
auth: AuthStore.reducer,
signup: SignupStore.reducer,
};

View File

@ -0,0 +1,5 @@
import { ListComponent } from './list/list.component';
export const COMPONENTS = [
ListComponent,
];

View File

@ -1,17 +1,17 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { ListComponent } from './component/list/list.component'; import { COMPONENTS } from './component';
export const COMPONENTS = [
ListComponent,
];
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule CommonModule
], ],
declarations: COMPONENTS, declarations: [
exports: COMPONENTS, COMPONENTS,
],
exports: [
COMPONENTS,
],
}) })
export class NoauthModule { } export class NoauthModule { }

View File

@ -0,0 +1,5 @@
import { NotificationComponent } from './notification/notification.component';
export const COMPONENTS = [
NotificationComponent,
];

View File

@ -6,12 +6,7 @@ import {
import { MaterialModule } from 'app/commons/ui/material/material.module'; import { MaterialModule } from 'app/commons/ui/material/material.module';
import { NotificationComponent } from './component/notification/notification.component'; import { COMPONENTS } from './component';
export const COMPONENTS = [
NotificationComponent,
];
@NgModule({ @NgModule({
imports: [ imports: [
@ -19,7 +14,11 @@ export const COMPONENTS = [
PerfectScrollbarModule, PerfectScrollbarModule,
MaterialModule, MaterialModule,
], ],
declarations: COMPONENTS, declarations: [
exports: COMPONENTS, COMPONENTS,
],
exports: [
COMPONENTS,
],
}) })
export class NotificationModule { } export class NotificationModule { }

View File

@ -0,0 +1,9 @@
import { DetailComponent } from './detail/detail.component';
import { ListComponent } from './list/list.component';
import { DownloadComponent } from './download/download.component';
export const COMPONENTS = [
ListComponent,
DetailComponent,
DownloadComponent,
];

View File

@ -3,15 +3,7 @@ import { CommonModule } from '@angular/common';
import { MaterialModule } from 'app/commons/ui/material/material.module'; import { MaterialModule } from 'app/commons/ui/material/material.module';
import { InfoTableModule } from 'app/commons/component/info-table/info-table.module'; import { InfoTableModule } from 'app/commons/component/info-table/info-table.module';
import { DetailComponent } from './component/detail/detail.component'; import { COMPONENTS } from './component';
import { ListComponent } from './component/list/list.component';
import { DownloadComponent } from './component/download/download.component';
export const COMPONENTS = [
ListComponent,
DetailComponent,
DownloadComponent,
];
@NgModule({ @NgModule({
imports: [ imports: [
@ -19,7 +11,11 @@ export const COMPONENTS = [
MaterialModule, MaterialModule,
InfoTableModule, InfoTableModule,
], ],
declarations: COMPONENTS, declarations: [
exports: COMPONENTS, COMPONENTS,
],
exports: [
COMPONENTS,
],
}) })
export class ProbeModule { } export class ProbeModule { }

View File

@ -0,0 +1,5 @@
import { ListComponent } from './list/list.component';
export const COMPONENTS = [
ListComponent,
];

View File

@ -1,11 +1,7 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { MaterialModule } from 'app/commons/ui/material/material.module'; import { MaterialModule } from 'app/commons/ui/material/material.module';
import { ListComponent } from './component/list/list.component'; import { COMPONENTS } from './component';
export const COMPONENTS = [
ListComponent,
];
@NgModule({ @NgModule({
@ -13,7 +9,11 @@ export const COMPONENTS = [
CommonModule, CommonModule,
MaterialModule, MaterialModule,
], ],
declarations: COMPONENTS, declarations: [
exports: COMPONENTS, COMPONENTS,
],
exports: [
COMPONENTS,
],
}) })
export class SensorItemModule { } export class SensorItemModule { }

View File

@ -0,0 +1,7 @@
import { DiscoverySettingComponent } from './setting/setting.component';
import { SettingResultComponent } from './setting-result/setting-result.component';
export const COMPONENTS = [
DiscoverySettingComponent,
SettingResultComponent,
];

View File

@ -4,13 +4,7 @@ import {FormsModule} from '@angular/forms';
import { MaterialModule } from 'app/commons/ui/material/material.module'; import { MaterialModule } from 'app/commons/ui/material/material.module';
import { DiscoverySettingComponent } from './component/setting/setting.component'; import { COMPONENTS } from './component';
import { SettingResultComponent } from './component/setting-result/setting-result.component';
export const COMPONENTS = [
DiscoverySettingComponent,
SettingResultComponent,
];
@NgModule({ @NgModule({
imports: [ imports: [
@ -18,7 +12,11 @@ export const COMPONENTS = [
MaterialModule, MaterialModule,
FormsModule FormsModule
], ],
declarations: COMPONENTS, declarations: [
exports: COMPONENTS, COMPONENTS,
],
exports: [
COMPONENTS,
],
}) })
export class SensorModule { } export class SensorModule { }

View File

@ -0,0 +1,7 @@
import { DetailComponent } from './detail/detail.component';
import { ListComponent } from './list/list.component';
export const COMPONENTS = [
ListComponent,
DetailComponent,
];

View File

@ -3,13 +3,7 @@ import { CommonModule } from '@angular/common';
import { MaterialModule } from 'app/commons/ui/material/material.module'; import { MaterialModule } from 'app/commons/ui/material/material.module';
import { InfoTableModule } from 'app/commons/component/info-table/info-table.module'; import { InfoTableModule } from 'app/commons/component/info-table/info-table.module';
import { DetailComponent } from './component/detail/detail.component'; import { COMPONENTS } from './component';
import { ListComponent } from './component/list/list.component';
export const COMPONENTS = [
ListComponent,
DetailComponent,
];
@NgModule({ @NgModule({
imports: [ imports: [
@ -17,7 +11,11 @@ export const COMPONENTS = [
MaterialModule, MaterialModule,
InfoTableModule InfoTableModule
], ],
declarations: COMPONENTS, declarations: [
exports: COMPONENTS, COMPONENTS,
],
exports: [
COMPONENTS,
],
}) })
export class TargetModule { } export class TargetModule { }