diff --git a/@overflow/notification/container/badge/badge-container.component.ts b/@overflow/notification/container/badge/badge-container.component.ts index 7dfc8c9..60408e4 100644 --- a/@overflow/notification/container/badge/badge-container.component.ts +++ b/@overflow/notification/container/badge/badge-container.component.ts @@ -2,11 +2,10 @@ import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core'; import { AfterContentInit, OnDestroy, OnChanges, SimpleChanges } from '@angular/core/src/metadata/lifecycle_hooks'; import { Store, select } from '@ngrx/store'; import { Observable } from 'rxjs/Observable'; -import { Domain } from '@overflow/commons-typescript/model/domain'; +import { Domain, DomainMember } from '@overflow/commons-typescript/model/domain'; import * as NotificationEntityStore from '../../store/entity/notification'; import { NotificationEntitySelector } from '../../store/'; -import { AuthSelector } from '../../../member/store'; -import { Member } from '@overflow/commons-typescript/model/member'; +import { AuthContainerSelector } from '@overflow/shared/auth/store'; import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams'; import { Page } from '@overflow/commons-typescript/model/commons/Page'; import { Notification } from '@overflow/commons-typescript/model/notification'; @@ -38,37 +37,34 @@ export class NotificationBadgeContainerComponent implements OnInit, OnChanges { } getNotifications() { - this.store.select(AuthSelector.select('member')).subscribe( - (member: Member) => { + this.store.select(AuthContainerSelector.selectDomainMember).subscribe( + (domainMember: DomainMember) => { const pageParams: PageParams = { pageNo: 0, countPerPage: 10, sortCol: 'id', sortDirection: 'descending', }; - this.store.dispatch(new NotificationEntityStore.ReadAllByMember({ member, pageParams })); - }, - (error) => { - console.log(error); + this.store.dispatch(new NotificationEntityStore.ReadAllByMember({ member: domainMember.member, pageParams })); } - ); + ); } markAllasRead() { - this.store.select(AuthSelector.select('member')).subscribe( - (member: Member) => { - const pageParams: PageParams = { - pageNo: 0, - countPerPage: 10, - sortCol: 'id', - sortDirection: 'descending' - }; - this.store.dispatch(new NotificationEntityStore.MarkAllAsRead({ member, pageParams })); - }, - (error) => { - console.log(error); - } - ); + // this.store.select(AuthSelector.select('member')).subscribe( + // (member: Member) => { + // const pageParams: PageParams = { + // pageNo: 0, + // countPerPage: 10, + // sortCol: 'id', + // sortDirection: 'descending' + // }; + // this.store.dispatch(new NotificationEntityStore.MarkAllAsRead({ member, pageParams })); + // }, + // (error) => { + // console.log(error); + // } + // ); } onSelect(notification: Notification) { diff --git a/@overflow/notification/container/list/list-container.component.ts b/@overflow/notification/container/list/list-container.component.ts index f03eb01..75f8407 100644 --- a/@overflow/notification/container/list/list-container.component.ts +++ b/@overflow/notification/container/list/list-container.component.ts @@ -2,15 +2,15 @@ import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core'; import { AfterContentInit, OnDestroy } from '@angular/core/src/metadata/lifecycle_hooks'; import { Store, select } from '@ngrx/store'; import { Observable } from 'rxjs/Observable'; -import { Domain } from '@overflow/commons-typescript/model/domain'; import * as NotificationEntityStore from '../../store/entity/notification'; import { NotificationEntitySelector } from '../../store/'; -import { AuthSelector } from '../../../member/store'; +import { AuthContainerSelector } from '@overflow/shared/auth/store'; import { Member } from '@overflow/commons-typescript/model/member'; import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams'; import { Page } from '@overflow/commons-typescript/model/commons/Page'; import { Notification } from '@overflow/commons-typescript/model/notification'; import { ActivatedRoute } from '@angular/router'; +import { DomainMember } from '@overflow/commons-typescript/model/domain'; @Component({ selector: 'of-notification-container', @@ -40,35 +40,29 @@ export class NotificationListContainerComponent implements OnInit { } getNotifications() { - this.store.select(AuthSelector.select('member')).subscribe( - (member: Member) => { + this.store.select(AuthContainerSelector.selectDomainMember).subscribe( + (domainMember: DomainMember) => { const pageParams: PageParams = { pageNo: this.pageNo, countPerPage: 10, sortCol: 'id', sortDirection: 'descending', }; - this.store.dispatch(new NotificationEntityStore.ReadAllByMember({ member, pageParams })); - }, - (error) => { - console.log(error); + this.store.dispatch(new NotificationEntityStore.ReadAllByMember({ member: domainMember.member, pageParams })); } ); } markAllasRead() { - this.store.select(AuthSelector.select('member')).subscribe( - (member: Member) => { + this.store.select(AuthContainerSelector.selectDomainMember).subscribe( + (domainMember: DomainMember) => { const pageParams: PageParams = { pageNo: this.pageNo, countPerPage: 10, sortCol: 'id', - sortDirection: 'descending' + sortDirection: 'descending', }; - this.store.dispatch(new NotificationEntityStore.MarkAllAsRead({ member, pageParams })); - }, - (error) => { - console.log(error); + this.store.dispatch(new NotificationEntityStore.MarkAllAsRead({ member: domainMember.member, pageParams })); } ); } diff --git a/@overflow/probe/store/container/probe-selector/index.ts b/@overflow/probe/store/container/probe-selector/index.ts new file mode 100644 index 0000000..a6667d6 --- /dev/null +++ b/@overflow/probe/store/container/probe-selector/index.ts @@ -0,0 +1,2 @@ +export * from './probe-selector.reducer'; +export * from './probe-selector.state'; diff --git a/@overflow/probe/store/container/probe-selector/probe-selector.reducer.ts b/@overflow/probe/store/container/probe-selector/probe-selector.reducer.ts new file mode 100644 index 0000000..462438b --- /dev/null +++ b/@overflow/probe/store/container/probe-selector/probe-selector.reducer.ts @@ -0,0 +1,31 @@ +import { ActionType, Actions } from '../../entity/probe'; +import { + State, + initialState, + probeSelectorContainerAdapter +} from './probe-selector.state'; + +import { Probe } from '@overflow/commons-typescript/model/probe'; + +export function reducer(state = initialState, action: Actions): State { + switch (action.type) { + case ActionType.ReadAllByDomainID: { + return { + ...state, + pending: true, + }; + } + + case ActionType.ReadAllByDomainIDSuccess: { + return probeSelectorContainerAdapter.setAll(action.payload, {...state, pending: false}); + } + + case ActionType.ReadAllByDomainIDFailure: { + return probeSelectorContainerAdapter.setError(action.payload, {...state, pending: false}); + } + + default: { + return state; + } + } +} diff --git a/@overflow/probe/store/container/probe-selector/probe-selector.state.ts b/@overflow/probe/store/container/probe-selector/probe-selector.state.ts new file mode 100644 index 0000000..27efd23 --- /dev/null +++ b/@overflow/probe/store/container/probe-selector/probe-selector.state.ts @@ -0,0 +1,21 @@ +import { RPCClientError } from '@loafer/ng-rpc'; +import { ProbeHost } from '@overflow/commons-typescript/model/probe'; +import { Selector, createSelector } from '@ngrx/store'; +import { createEntityAdapter, EntityState } from '@loafer/ng-entity'; + +export const probeSelectorContainerAdapter = createEntityAdapter(); +export interface State extends EntityState { + pending: boolean; +} +export const initialState: State = probeSelectorContainerAdapter.getInitialState({ + pending: false, +}); + +export function getSelectors(selector: Selector) { + return { + ...probeSelectorContainerAdapter.getSelectors(selector), + selectPending: createSelector(selector, (state: State) => state.pending), + }; +} + + diff --git a/@overflow/probe/store/index.ts b/@overflow/probe/store/index.ts index 6a8f41d..ba13e76 100644 --- a/@overflow/probe/store/index.ts +++ b/@overflow/probe/store/index.ts @@ -11,15 +11,18 @@ import { MODULE } from '../probe.constant'; import * as ProbeEntityStore from './entity/probe'; import * as ProbeListContainerStore from './container/probe-list'; import * as ProbeDetailContainerStore from './container/probe-detail'; +import * as ProbeSelectorContainerStore from './container/probe-selector'; export interface State { probe_list_container: ProbeListContainerStore.State; probe_detail_container: ProbeDetailContainerStore.State; + probe_selector_container: ProbeSelectorContainerStore.State; } export const REDUCERS = { probe_list_container: ProbeListContainerStore.reducer, - probe_detail_container: ProbeDetailContainerStore.reducer + probe_detail_container: ProbeDetailContainerStore.reducer, + probe_selector_container: ProbeSelectorContainerStore.reducer }; export const EFFECTS = [ @@ -37,3 +40,8 @@ export const ProbeDetailContainerSelector = ProbeDetailContainerStore.getSelecto selectState, (state: State) => state.probe_detail_container )); + +export const ProbeSelectorContainerSelector = ProbeSelectorContainerStore.getSelectors(createSelector( + selectState, + (state: State) => state.probe_selector_container +)); diff --git a/@overflow/sensor/component/detail/detail.component.ts b/@overflow/sensor/component/detail/detail.component.ts index 10ddde9..3c105c2 100644 --- a/@overflow/sensor/component/detail/detail.component.ts +++ b/@overflow/sensor/component/detail/detail.component.ts @@ -3,7 +3,6 @@ import { ActivatedRoute, Router } from '@angular/router'; import { ConfirmationService } from 'primeng/primeng'; import { Store, select } from '@ngrx/store'; import { RPCClientError } from '@loafer/ng-rpc'; -import * as DetailStore from '../../store/detail'; // import { sensorSelector } from '../../store'; import { Sensor } from '@overflow/commons-typescript/model/sensor'; import { Subscription } from 'rxjs/Subscription'; diff --git a/@overflow/sensor/container/sensor-list-container.component.ts b/@overflow/sensor/container/sensor-list-container.component.ts index 8e70f35..6afa8e4 100644 --- a/@overflow/sensor/container/sensor-list-container.component.ts +++ b/@overflow/sensor/container/sensor-list-container.component.ts @@ -4,11 +4,11 @@ import { Store, select } from '@ngrx/store'; import { Sensor } from '@overflow/commons-typescript/model/sensor'; import * as SensorEntityStore from '../store/entity/sensor'; import { SensorEntitySelector, SensorPageSelector } from '../store'; -import { AuthSelector } from '../../member/store'; -import { Domain } from '@overflow/commons-typescript/model/domain'; +import { AuthContainerSelector } from '@overflow/shared/auth/store'; import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams'; import { Page } from '@overflow/commons-typescript/model/commons/Page'; import { Target } from '@overflow/commons-typescript/model/target'; +import { DomainMember } from '@overflow/commons-typescript/model/domain'; @Component({ selector: 'of-sensor-list-container', @@ -19,26 +19,27 @@ export class SensorListContainerComponent implements OnInit { page$: Observable>; @Output() select = new EventEmitter(); @Output() addSensor = new EventEmitter(); + pageNo: number; - constructor(private store: Store) { - this.page$ = store.pipe(select(SensorPageSelector)); + constructor(private store: Store) { } ngOnInit() { - this.store.select(AuthSelector.select('domain')).subscribe( - (domain: Domain) => { + this.page$ = this.store.pipe(select(SensorPageSelector)); + this.getSensors(); + } + + getSensors() { + this.store.select(AuthContainerSelector.selectDomainMember).subscribe( + (domainMember: DomainMember) => { const pageParams: PageParams = { - pageNo: 0, + pageNo: this.pageNo, countPerPage: 10, sortCol: 'id', sortDirection: 'descending', }; - this.store.dispatch(new SensorEntityStore.ReadAllByDomainID({domainID : domain.id, pageParams})); - }, - (error) => { - console.log(error); + this.store.dispatch(new SensorEntityStore.ReadAllByDomainID({ domainID: domainMember.domain.id, pageParams })); } ); } - } diff --git a/@overflow/sensor/container/sensor-setting-container.component.ts b/@overflow/sensor/container/sensor-setting-container.component.ts index ddae4ca..0d90ffa 100644 --- a/@overflow/sensor/container/sensor-setting-container.component.ts +++ b/@overflow/sensor/container/sensor-setting-container.component.ts @@ -11,7 +11,7 @@ import { SensorEntitySelector } from '../store'; }) export class SensorSettingContainerComponent { - constructor(private store: Store) { + constructor(private store: Store) { } } diff --git a/@overflow/sensor/store/container/sensor-list/index.ts b/@overflow/sensor/store/container/sensor-list/index.ts new file mode 100644 index 0000000..835388c --- /dev/null +++ b/@overflow/sensor/store/container/sensor-list/index.ts @@ -0,0 +1,2 @@ +export * from './sensor-list.reducer'; +export * from './sensor-list.state'; diff --git a/@overflow/sensor/store/entity/sensor/sensor.reducer.ts b/@overflow/sensor/store/container/sensor-list/sensor-list.reducer.ts similarity index 53% rename from @overflow/sensor/store/entity/sensor/sensor.reducer.ts rename to @overflow/sensor/store/container/sensor-list/sensor-list.reducer.ts index c17cbee..f0053b7 100644 --- a/@overflow/sensor/store/entity/sensor/sensor.reducer.ts +++ b/@overflow/sensor/store/container/sensor-list/sensor-list.reducer.ts @@ -1,13 +1,11 @@ -import { - ActionType, - Actions, -} from './sensor.action'; - +import { ActionType, Actions } from '../../entity/sensor'; import { State, initialState, - sensorAdapter, -} from './sensor.state'; + sensorListContainerAdapter, +} from './sensor-list.state'; + +import { Probe } from '@overflow/commons-typescript/model/probe'; export function reducer(state = initialState, action: Actions): State { switch (action.type) { @@ -19,11 +17,11 @@ export function reducer(state = initialState, action: Actions): State { } case ActionType.ReadAllByDomainIDSuccess: { - return sensorAdapter.setAll(action.payload.content, {...state, page: action.payload}); + return sensorListContainerAdapter.setAll(action.payload.content, {...state, page: action.payload}); } case ActionType.ReadAllByDomainIDFailure: { - return sensorAdapter.setError(action.payload, state); + return sensorListContainerAdapter.setError(action.payload, state); } case ActionType.Read: { @@ -34,11 +32,11 @@ export function reducer(state = initialState, action: Actions): State { } case ActionType.ReadSuccess: { - return sensorAdapter.setOne(action.payload, {...state, page: null}); + return sensorListContainerAdapter.setOne(action.payload, {...state, page: null}); } case ActionType.ReadFailure: { - return sensorAdapter.setError(action.payload, state); + return sensorListContainerAdapter.setError(action.payload, state); } case ActionType.Modify: { @@ -49,15 +47,11 @@ export function reducer(state = initialState, action: Actions): State { } case ActionType.ModifySuccess: { - return sensorAdapter.upsertOne(action.payload, state); + return sensorListContainerAdapter.upsertOne(action.payload, state); } case ActionType.ModifyFailure: { - return sensorAdapter.setError(action.payload, state); - } - - default: { - return state; + return sensorListContainerAdapter.setError(action.payload, state); } } } diff --git a/@overflow/sensor/store/entity/sensor/sensor.state.ts b/@overflow/sensor/store/container/sensor-list/sensor-list.state.ts similarity index 50% rename from @overflow/sensor/store/entity/sensor/sensor.state.ts rename to @overflow/sensor/store/container/sensor-list/sensor-list.state.ts index 55d3de5..5fe9892 100644 --- a/@overflow/sensor/store/entity/sensor/sensor.state.ts +++ b/@overflow/sensor/store/container/sensor-list/sensor-list.state.ts @@ -1,24 +1,23 @@ import { RPCClientError } from '@loafer/ng-rpc'; -import { ProbeHost } from '@overflow/commons-typescript/model/probe'; + +import { Sensor } from '@overflow/commons-typescript/model/sensor'; import { Selector, createSelector } from '@ngrx/store'; import { createEntityAdapter, EntityState } from '@loafer/ng-entity'; import { Page } from '@overflow/commons-typescript/model/commons/Page'; -import { Sensor } from '@overflow/commons-typescript/model/sensor'; - -export const sensorAdapter = createEntityAdapter(); +export const sensorListContainerAdapter = createEntityAdapter(); export interface State extends EntityState { page: Page; + pending: boolean; } - -export const initialState: State = { - ids : [], - entities : null, +export const initialState: State = sensorListContainerAdapter.getInitialState({ page: null, - error: null, -}; + pending: false, +}); -export function getSelectors(selector: Selector) { - return sensorAdapter.getSelectors(selector); +export function getSelectors(selector: Selector) { + return { + ...sensorListContainerAdapter.getSelectors(selector), + selectPending: createSelector(selector, (state: State) => state.pending), + }; } - diff --git a/@overflow/sensor/store/detail/detail.action.ts b/@overflow/sensor/store/detail/detail.action.ts deleted file mode 100644 index 67899d0..0000000 --- a/@overflow/sensor/store/detail/detail.action.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { Action } from '@ngrx/store'; - -import { RPCClientError } from '@loafer/ng-rpc'; - -import { Sensor } from '@overflow/commons-typescript/model/sensor'; - - -export enum ActionType { - Read = '[sensor.detail] Read', - ReadSuccess = '[sensor.detail] ReadSuccess', - ReadFailure = '[sensor.detail] ReadFailure', -} - -export class Read implements Action { - readonly type = ActionType.Read; - - constructor(public payload: {id: string}) {} -} - -export class ReadSuccess implements Action { - readonly type = ActionType.ReadSuccess; - - constructor(public payload: Sensor) {} -} - -export class ReadFailure implements Action { - readonly type = ActionType.ReadFailure; - - constructor(public payload: RPCClientError) {} -} - - -export type Actions = - | Read - | ReadSuccess - | ReadFailure -; diff --git a/@overflow/sensor/store/detail/detail.effect.spec.ts b/@overflow/sensor/store/detail/detail.effect.spec.ts deleted file mode 100644 index b1c2217..0000000 --- a/@overflow/sensor/store/detail/detail.effect.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { TestBed, inject } from '@angular/core/testing'; - -import { Effects } from './detail.effect'; - -describe('ProbeDetail.Effects', () => { - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [Effects] - }); - }); - - it('should be created', inject([Effects], (effects: Effects) => { - expect(effects).toBeTruthy(); - })); -}); diff --git a/@overflow/sensor/store/detail/detail.effect.ts b/@overflow/sensor/store/detail/detail.effect.ts deleted file mode 100644 index fbdf6ba..0000000 --- a/@overflow/sensor/store/detail/detail.effect.ts +++ /dev/null @@ -1,49 +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 { RPCClientError } from '@loafer/ng-rpc'; - -import { Sensor } from '@overflow/commons-typescript/model/sensor'; -import { SensorService } from '../../service/sensor.service'; - -import { - Read, - ReadFailure, - ReadSuccess, - ActionType -} from './detail.action'; - -@Injectable() -export class Effects { - - constructor( - private actions$: Actions, - private sensorService: SensorService, - private router: Router - ) { } - - @Effect() - read$: Observable = this.actions$ - .ofType(ActionType.Read) - .map((action: Read) => action.payload) - .switchMap(payload => this.sensorService.read(payload.id)) - .map(sensor => { - return new ReadSuccess(sensor); - }) - .catch((error: RPCClientError) => { - return of(new ReadFailure(error)); - }); -} diff --git a/@overflow/sensor/store/detail/detail.reducer.ts b/@overflow/sensor/store/detail/detail.reducer.ts deleted file mode 100644 index 90b2ac2..0000000 --- a/@overflow/sensor/store/detail/detail.reducer.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { - Read, - ReadFailure, - ReadSuccess, - ActionType, - Actions, -} from './detail.action'; - -import { - State, - initialState, -} from './detail.state'; - -import { Sensor } from '@overflow/commons-typescript/model/sensor'; - - -export function reducer(state = initialState, action: Actions): State { - switch (action.type) { - case ActionType.Read: { - return { - ...state, - error: null, - isPending: true, - }; - } - - case ActionType.ReadSuccess: { - return { - ...state, - error: null, - isPending: false, - sensor: action.payload, - }; - } - - case ActionType.ReadFailure: { - return { - ...state, - error: action.payload, - isPending: false, - sensor: null, - }; - } - - default: { - return state; - } - } -} diff --git a/@overflow/sensor/store/detail/detail.state.ts b/@overflow/sensor/store/detail/detail.state.ts deleted file mode 100644 index 6bd4ad2..0000000 --- a/@overflow/sensor/store/detail/detail.state.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { RPCClientError } from '@loafer/ng-rpc'; -import { Sensor } from '@overflow/commons-typescript/model/sensor'; - -export interface State { - error: RPCClientError | null; - isPending: boolean; - sensor: Sensor | null; -} - -export const initialState: State = { - error: null, - isPending: false, - sensor: null, -}; diff --git a/@overflow/sensor/store/detail/index.ts b/@overflow/sensor/store/detail/index.ts deleted file mode 100644 index 23ae8ab..0000000 --- a/@overflow/sensor/store/detail/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './detail.action'; -export * from './detail.effect'; -export * from './detail.reducer'; -export * from './detail.state'; diff --git a/@overflow/sensor/store/entity/sensor/index.ts b/@overflow/sensor/store/entity/sensor/index.ts index 7f1866f..7dd9e29 100644 --- a/@overflow/sensor/store/entity/sensor/index.ts +++ b/@overflow/sensor/store/entity/sensor/index.ts @@ -1,4 +1,2 @@ export * from './sensor.action'; export * from './sensor.effect'; -export * from './sensor.reducer'; -export * from './sensor.state'; diff --git a/@overflow/sensor/store/index.ts b/@overflow/sensor/store/index.ts index ab23145..550a3dd 100644 --- a/@overflow/sensor/store/index.ts +++ b/@overflow/sensor/store/index.ts @@ -1,21 +1,19 @@ import { createSelector, createFeatureSelector, - ActionReducerMap, } from '@ngrx/store'; -import { StateSelector } from '@overflow/core/ngrx/store'; - import { MODULE } from '../sensor.constant'; import * as SensorEntityStore from './entity/sensor'; +import * as SensorListContainerStore from './container/sensor-list'; export interface State { - sensor: SensorEntityStore.State; + sensor_list: SensorListContainerStore.State; } export const REDUCERS = { - sensor: SensorEntityStore.reducer, + sensor: SensorListContainerStore.reducer, }; export const EFFECTS = [ @@ -24,14 +22,12 @@ export const EFFECTS = [ export const selectState = createFeatureSelector(MODULE.name); -export const SensorEntitySelector = SensorEntityStore.getSelectors(createSelector( +export const SensorEntitySelector = SensorListContainerStore.getSelectors(createSelector( selectState, - (state: State) => state.sensor + (state: State) => state.sensor_list )); export const SensorPageSelector = createSelector( selectState, - (state: State) => state.sensor.page + (state: State) => state.sensor_list.page ); - - diff --git a/@overflow/sensor/store/list/index.ts b/@overflow/sensor/store/list/index.ts deleted file mode 100644 index 7fd86e0..0000000 --- a/@overflow/sensor/store/list/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './list.action'; -export * from './list.effect'; -export * from './list.reducer'; -export * from './list.state'; diff --git a/@overflow/sensor/store/list/list.action.ts b/@overflow/sensor/store/list/list.action.ts deleted file mode 100644 index b8178db..0000000 --- a/@overflow/sensor/store/list/list.action.ts +++ /dev/null @@ -1,86 +0,0 @@ -import { Action } from '@ngrx/store'; - -import { RPCClientError } from '@loafer/ng-rpc'; - -import { Domain } from '@overflow/commons-typescript/model/domain'; -// import { PageParams, Page } from 'app/commons/model'; -import { Target } from '@overflow/commons-typescript/model/target'; - -export enum ActionType { - ReadAllByDomain = '[Sensor.ReadAllByDomain] ReadAllByDomain', - ReadAllByDomainSuccess = '[Sensor.ReadAllByDomainSuccess] ReadAllByDomainSuccess', - ReadAllByDomainFailure = '[Sensor.ReadAllByDomainFailure] ReadAllByDomainFailure', - - ReadAllByInfra = '[Sensor.ReadAllByInfra] ReadAllByInfra', - ReadAllByInfraSuccess = '[Sensor.ReadAllByInfraSuccess] ReadAllByInfraSuccess', - ReadAllByInfraFailure = '[Sensor.ReadAllByInfraFailure] ReadAllByInfraFailure', - - ReadAllByTarget = '[Sensor.ReadAllByTarget] ReadAllByTarget', - ReadAllByTargetSuccess = '[Sensor.ReadAllByTargetSuccess] ReadAllByTargetSuccess', - ReadAllByTargetFailure = '[Sensor.ReadAllByTargetFailure] ReadAllByTargetFailure', -} - -export class ReadAllByDomain implements Action { - readonly type = ActionType.ReadAllByDomain; - - // constructor(public payload: { domain: Domain, pageParams: PageParams}) {} -} - -export class ReadAllByDomainSuccess implements Action { - readonly type = ActionType.ReadAllByDomainSuccess; - - // constructor(public payload: Page) {} -} - -export class ReadAllByDomainFailure implements Action { - readonly type = ActionType.ReadAllByDomainFailure; - - constructor(public payload: RPCClientError) {} -} - -export class ReadAllByInfra implements Action { - readonly type = ActionType.ReadAllByInfra; - - // constructor(public payload: { id: string, pageParams: PageParams}) {} -} - -export class ReadAllByInfraSuccess implements Action { - readonly type = ActionType.ReadAllByInfraSuccess; - - // constructor(public payload: Page) {} -} - -export class ReadAllByInfraFailure implements Action { - readonly type = ActionType.ReadAllByInfraFailure; - - constructor(public payload: RPCClientError) {} -} -// -export class ReadAllByTarget implements Action { - readonly type = ActionType.ReadAllByTarget; - - // constructor(public payload: { target: Target, pageParams: PageParams}) {} -} - -export class ReadAllByTargetSuccess implements Action { - readonly type = ActionType.ReadAllByTargetSuccess; - - // constructor(public payload: Page) {} -} - -export class ReadAllByTargetFailure implements Action { - readonly type = ActionType.ReadAllByTargetFailure; - - constructor(public payload: RPCClientError) {} -} -export type Actions = - | ReadAllByDomain - | ReadAllByDomainSuccess - | ReadAllByDomainFailure - | ReadAllByInfra - | ReadAllByInfraSuccess - | ReadAllByInfraFailure - | ReadAllByTarget - | ReadAllByTargetSuccess - | ReadAllByTargetFailure -; diff --git a/@overflow/sensor/store/list/list.effect.spec.ts b/@overflow/sensor/store/list/list.effect.spec.ts deleted file mode 100644 index e69de29..0000000 diff --git a/@overflow/sensor/store/list/list.effect.ts b/@overflow/sensor/store/list/list.effect.ts deleted file mode 100644 index 509ee9c..0000000 --- a/@overflow/sensor/store/list/list.effect.ts +++ /dev/null @@ -1,78 +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/map'; -import 'rxjs/add/operator/take'; - -import { RPCClientError } from '@loafer/ng-rpc'; - -import { Sensor } from '@overflow/commons-typescript/model/sensor'; -import { SensorService } from '../../service/sensor.service'; - -import { - ReadAllByDomain, - ReadAllByDomainSuccess, - ReadAllByDomainFailure, - ReadAllByInfra, - ReadAllByInfraSuccess, - ReadAllByInfraFailure, - ReadAllByTarget, - ReadAllByTargetSuccess, - ReadAllByTargetFailure, - ActionType, -} from './list.action'; - -@Injectable() -export class Effects { - - constructor( - private actions$: Actions, - private service: SensorService, - private router: Router - ) { } - - // @Effect() - // readAllByDomain$: Observable = this.actions$ - // .ofType(ActionType.ReadAllByDomain) - // .map((action: ReadAllByDomain) => action.payload) - // .switchMap(payload => this.service.readAllByDomain(payload.domain, payload.pageParams)) - // .map(list => { - // return new ReadAllByDomainSuccess(list); - // }) - // .catch((error: RPCClientError) => { - // return of(new ReadAllByDomainFailure(error)); - // }); - - // @Effect() - // readAllByInfra$: Observable = this.actions$ - // .ofType(ActionType.ReadAllByInfra) - // .map((action: ReadAllByInfra) => action.payload) - // .switchMap(payload => this.service.readAllByInfra(payload.id, payload.pageParams)) - // .map(list => { - // return new ReadAllByInfraSuccess(list); - // }) - // .catch((error: RPCClientError) => { - // return of(new ReadAllByInfraFailure(error)); - // }); - - // @Effect() - // readAllByTarget$: Observable = this.actions$ - // .ofType(ActionType.ReadAllByTarget) - // .map((action: ReadAllByTarget) => action.payload) - // .switchMap(payload => this.service.readAllByTarget(payload.target, payload.pageParams)) - // .map(list => { - // return new ReadAllByTargetSuccess(list); - // }) - // .catch((error: RPCClientError) => { - // return of(new ReadAllByTargetFailure(error)); - // }); -} diff --git a/@overflow/sensor/store/list/list.reducer.ts b/@overflow/sensor/store/list/list.reducer.ts deleted file mode 100644 index a03065c..0000000 --- a/@overflow/sensor/store/list/list.reducer.ts +++ /dev/null @@ -1,96 +0,0 @@ -import { - Actions, - ActionType, - } from './list.action'; - - import { - State, - initialState, - } from './list.state'; - - import { Sensor } from '@overflow/commons-typescript/model/sensor'; - - export function reducer(state = initialState, action: Actions): State { - switch (action.type) { - case ActionType.ReadAllByDomain: { - return { - ...state, - error: null, - pending: true, - }; - } - - case ActionType.ReadAllByDomainSuccess: { - return { - ...state, - error: null, - pending: false, - // page: action.payload - }; - } - - case ActionType.ReadAllByDomainFailure: { - return { - ...state, - error: action.payload, - pending: false, - // page: null, - }; - } - - case ActionType.ReadAllByInfra: { - return { - ...state, - error: null, - pending: true, - }; - } - - case ActionType.ReadAllByInfraSuccess: { - return { - ...state, - error: null, - pending: false, - // page: action.payload - }; - } - - case ActionType.ReadAllByInfraFailure: { - return { - ...state, - error: action.payload, - pending: false, - // page: null, - }; - } - - case ActionType.ReadAllByTarget: { - return { - ...state, - error: null, - pending: true, - }; - } - - case ActionType.ReadAllByTargetSuccess: { - return { - ...state, - error: null, - pending: false, - // page: action.payload - }; - } - - case ActionType.ReadAllByTargetFailure: { - return { - ...state, - error: action.payload, - pending: false, - // page: null, - }; - } - default: { - return state; - } - } - } diff --git a/@overflow/sensor/store/list/list.state.ts b/@overflow/sensor/store/list/list.state.ts deleted file mode 100644 index d1afd16..0000000 --- a/@overflow/sensor/store/list/list.state.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { RPCClientError } from '@loafer/ng-rpc'; - -// import { Page } from 'app/commons/model'; - -export interface State { - error: RPCClientError | null; - pending: boolean; - // page: Page | null; -} - -export const initialState: State = { - error: null, - pending: false, - // page: null, -}; diff --git a/@overflow/sensor/store/regist/index.ts b/@overflow/sensor/store/regist/index.ts deleted file mode 100644 index f6da3fb..0000000 --- a/@overflow/sensor/store/regist/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './regist.action'; -export * from './regist.effect'; -export * from './regist.reducer'; -export * from './regist.state'; diff --git a/@overflow/sensor/store/regist/regist.action.ts b/@overflow/sensor/store/regist/regist.action.ts deleted file mode 100644 index 6636de8..0000000 --- a/@overflow/sensor/store/regist/regist.action.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Action } from '@ngrx/store'; - -import { RPCClientError } from '@loafer/ng-rpc'; - -import { Domain } from '@overflow/commons-typescript/model/domain'; -// import { PageParams, Page } from 'app/commons/model'; -import { Sensor } from '@overflow/commons-typescript/model/sensor'; -import { SensorItem } from '@overflow/commons-typescript/model/sensor-item'; - -export enum ActionType { - Regist = '[Sensor.Regist] Regist', - RegistSuccess = '[Sensor.RegistSuccess] RegistSuccess', - RegistFailure = '[Sensor.RegistFailure] RegistFailure', -} - -export class Regist implements Action { - readonly type = ActionType.Regist; - - constructor(public payload: { sensor: Sensor, sensorItems: SensorItem[]}) {} -} - -export class RegistSuccess implements Action { - readonly type = ActionType.RegistSuccess; - - constructor(public payload: Sensor) {} -} - -export class RegistFailure implements Action { - readonly type = ActionType.RegistFailure; - - constructor(public payload: RPCClientError) {} -} - -export type Actions = - | Regist - | RegistSuccess - | RegistFailure -; diff --git a/@overflow/sensor/store/regist/regist.effect.ts b/@overflow/sensor/store/regist/regist.effect.ts deleted file mode 100644 index da62c8c..0000000 --- a/@overflow/sensor/store/regist/regist.effect.ts +++ /dev/null @@ -1,49 +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/map'; -import 'rxjs/add/operator/take'; - -import { RPCClientError } from '@loafer/ng-rpc'; - -import { Sensor } from '@overflow/commons-typescript/model/sensor'; -import { SensorService } from '../../service/sensor.service'; - -import { - Regist, - RegistSuccess, - RegistFailure, - ActionType, -} from './regist.action'; - -@Injectable() -export class Effects { - - constructor( - private actions$: Actions, - private service: SensorService, - private router: Router - ) { } - - @Effect() - regist$: Observable = this.actions$ - .ofType(ActionType.Regist) - .map((action: Regist) => action.payload) - .switchMap(payload => this.service.registSensorConfig(payload.sensor, payload.sensorItems)) - .map(list => { - return new RegistSuccess(list); - }) - .catch((error: RPCClientError) => { - return of(new RegistFailure(error)); - }); - -} diff --git a/@overflow/sensor/store/regist/regist.reducer.ts b/@overflow/sensor/store/regist/regist.reducer.ts deleted file mode 100644 index 95e1d10..0000000 --- a/@overflow/sensor/store/regist/regist.reducer.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { - Actions, - ActionType, - } from './regist.action'; - - import { - State, - initialState, - } from './regist.state'; - - import { Sensor } from '@overflow/commons-typescript/model/sensor'; - - export function reducer(state = initialState, action: Actions): State { - switch (action.type) { - case ActionType.Regist: { - return { - ...state, - error: null, - pending: true, - }; - } - - case ActionType.RegistSuccess: { - return { - ...state, - error: null, - pending: false, - sensor: action.payload - }; - } - - case ActionType.RegistFailure: { - return { - ...state, - error: action.payload, - pending: false, - sensor: null, - }; - } - - default: { - return state; - } - } - } diff --git a/@overflow/sensor/store/regist/regist.state.ts b/@overflow/sensor/store/regist/regist.state.ts deleted file mode 100644 index 970674b..0000000 --- a/@overflow/sensor/store/regist/regist.state.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { RPCClientError } from '@loafer/ng-rpc'; - -// import { Page } from 'app/commons/model'; -import { Sensor } from '@overflow/commons-typescript/model/sensor'; - -export interface State { - error: RPCClientError | null; - pending: boolean; - sensor: Sensor | null; -} - -export const initialState: State = { - error: null, - pending: false, - sensor: null, -}; diff --git a/@overflow/sensor/store/regist/regist.ts b/@overflow/sensor/store/regist/regist.ts deleted file mode 100644 index f6da3fb..0000000 --- a/@overflow/sensor/store/regist/regist.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './regist.action'; -export * from './regist.effect'; -export * from './regist.reducer'; -export * from './regist.state';