test
This commit is contained in:
parent
fada7b057a
commit
638cfbf96c
|
@ -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) {
|
||||
|
|
|
@ -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 }));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
2
@overflow/probe/store/container/probe-selector/index.ts
Normal file
2
@overflow/probe/store/container/probe-selector/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * from './probe-selector.reducer';
|
||||
export * from './probe-selector.state';
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<ProbeHost, RPCClientError>();
|
||||
export interface State extends EntityState<ProbeHost, RPCClientError> {
|
||||
pending: boolean;
|
||||
}
|
||||
export const initialState: State = probeSelectorContainerAdapter.getInitialState({
|
||||
pending: false,
|
||||
});
|
||||
|
||||
export function getSelectors<S>(selector: Selector<any, State>) {
|
||||
return {
|
||||
...probeSelectorContainerAdapter.getSelectors(selector),
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
));
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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<Page<Sensor>>;
|
||||
@Output() select = new EventEmitter<Sensor>();
|
||||
@Output() addSensor = new EventEmitter();
|
||||
pageNo: number;
|
||||
|
||||
constructor(private store: Store<SensorEntityStore.State>) {
|
||||
this.page$ = store.pipe(select(SensorPageSelector));
|
||||
constructor(private store: Store<any>) {
|
||||
}
|
||||
|
||||
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 }));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ import { SensorEntitySelector } from '../store';
|
|||
})
|
||||
export class SensorSettingContainerComponent {
|
||||
|
||||
constructor(private store: Store<SensorEntityStore.State>) {
|
||||
constructor(private store: Store<any>) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
2
@overflow/sensor/store/container/sensor-list/index.ts
Normal file
2
@overflow/sensor/store/container/sensor-list/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export * from './sensor-list.reducer';
|
||||
export * from './sensor-list.state';
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Sensor, RPCClientError>();
|
||||
|
||||
export const sensorListContainerAdapter = createEntityAdapter<Sensor, RPCClientError>();
|
||||
export interface State extends EntityState<Sensor, RPCClientError> {
|
||||
page: Page<Sensor>;
|
||||
pending: boolean;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
ids : [],
|
||||
entities : null,
|
||||
export const initialState: State = sensorListContainerAdapter.getInitialState({
|
||||
page: null,
|
||||
error: null,
|
||||
};
|
||||
pending: false,
|
||||
});
|
||||
|
||||
export function getSelectors<S>(selector: Selector<any, State>) {
|
||||
return sensorAdapter.getSelectors(selector);
|
||||
export function getSelectors(selector: Selector<any, State>) {
|
||||
return {
|
||||
...sensorListContainerAdapter.getSelectors(selector),
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
};
|
||||
}
|
||||
|
|
@ -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
|
||||
;
|
|
@ -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();
|
||||
}));
|
||||
});
|
|
@ -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<Action> = 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));
|
||||
});
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
};
|
|
@ -1,4 +0,0 @@
|
|||
export * from './detail.action';
|
||||
export * from './detail.effect';
|
||||
export * from './detail.reducer';
|
||||
export * from './detail.state';
|
|
@ -1,4 +1,2 @@
|
|||
export * from './sensor.action';
|
||||
export * from './sensor.effect';
|
||||
export * from './sensor.reducer';
|
||||
export * from './sensor.state';
|
||||
|
|
|
@ -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<State>(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
|
||||
);
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
export * from './list.action';
|
||||
export * from './list.effect';
|
||||
export * from './list.reducer';
|
||||
export * from './list.state';
|
|
@ -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
|
||||
;
|
|
@ -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<Action> = 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<Action> = 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<Action> = 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));
|
||||
// });
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
};
|
|
@ -1,4 +0,0 @@
|
|||
export * from './regist.action';
|
||||
export * from './regist.effect';
|
||||
export * from './regist.reducer';
|
||||
export * from './regist.state';
|
|
@ -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
|
||||
;
|
|
@ -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<Action> = 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));
|
||||
});
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
};
|
|
@ -1,4 +0,0 @@
|
|||
export * from './regist.action';
|
||||
export * from './regist.effect';
|
||||
export * from './regist.reducer';
|
||||
export * from './regist.state';
|
Loading…
Reference in New Issue
Block a user