sensor list complete
This commit is contained in:
4
@overflow/sensor/store/entity/sensor/index.ts
Normal file
4
@overflow/sensor/store/entity/sensor/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './sensor.action';
|
||||
export * from './sensor.effect';
|
||||
export * from './sensor.reducer';
|
||||
export * from './sensor.state';
|
||||
85
@overflow/sensor/store/entity/sensor/sensor.action.ts
Normal file
85
@overflow/sensor/store/entity/sensor/sensor.action.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { Action } from '@ngrx/store';
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { Sensor } from '@overflow/commons-typescript/model/sensor';
|
||||
import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams';
|
||||
import { Page } from '@overflow/commons-typescript/model/commons/Page';
|
||||
|
||||
export enum ActionType {
|
||||
ReadAllByDomainID = '[Sensor.list] ReadAllByDomainID',
|
||||
ReadAllByDomainIDSuccess = '[Sensor.list] ReadAllByDomainIDSuccess',
|
||||
ReadAllByDomainIDFailure = '[Sensor.list] ReadAllByDomainIDFailure',
|
||||
|
||||
Read = '[Sensor.detail] Read',
|
||||
ReadSuccess = '[Sensor.detail] ReadSuccess',
|
||||
ReadFailure = '[Sensor.detail] ReadFailure',
|
||||
|
||||
Modify = '[Sensor.detail] Modify',
|
||||
ModifySuccess = '[Sensor.detail] ModifySuccess',
|
||||
ModifyFailure = '[Sensor.detail] ModifyFailure',
|
||||
}
|
||||
|
||||
export class ReadAllByDomainID implements Action {
|
||||
readonly type = ActionType.ReadAllByDomainID;
|
||||
|
||||
constructor(public payload: {domainID: number, pageParams: PageParams}) {}
|
||||
}
|
||||
|
||||
export class ReadAllByDomainIDSuccess implements Action {
|
||||
readonly type = ActionType.ReadAllByDomainIDSuccess;
|
||||
|
||||
constructor(public payload: Page<Sensor>) {}
|
||||
}
|
||||
|
||||
export class ReadAllByDomainIDFailure implements Action {
|
||||
readonly type = ActionType.ReadAllByDomainIDFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) {}
|
||||
}
|
||||
|
||||
export class Read implements Action {
|
||||
readonly type = ActionType.Read;
|
||||
|
||||
constructor(public payload: number) {}
|
||||
}
|
||||
|
||||
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 class Modify implements Action {
|
||||
readonly type = ActionType.Modify;
|
||||
|
||||
constructor(public payload: Sensor) {}
|
||||
}
|
||||
|
||||
export class ModifySuccess implements Action {
|
||||
readonly type = ActionType.ModifySuccess;
|
||||
|
||||
constructor(public payload: Sensor) {}
|
||||
}
|
||||
|
||||
export class ModifyFailure implements Action {
|
||||
readonly type = ActionType.ModifyFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) {}
|
||||
}
|
||||
|
||||
export type Actions =
|
||||
| ReadAllByDomainID
|
||||
| ReadAllByDomainIDSuccess
|
||||
| ReadAllByDomainIDFailure
|
||||
| Read
|
||||
| ReadSuccess
|
||||
| ReadFailure
|
||||
| Modify
|
||||
| ModifySuccess
|
||||
| ModifyFailure
|
||||
;
|
||||
78
@overflow/sensor/store/entity/sensor/sensor.effect.ts
Normal file
78
@overflow/sensor/store/entity/sensor/sensor.effect.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
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 {
|
||||
ReadAllByDomainID,
|
||||
ReadAllByDomainIDFailure,
|
||||
ReadAllByDomainIDSuccess,
|
||||
Read,
|
||||
ReadSuccess,
|
||||
ReadFailure,
|
||||
Modify,
|
||||
ModifySuccess,
|
||||
ModifyFailure,
|
||||
ActionType
|
||||
} from './sensor.action';
|
||||
import { SensorService } from '../../../service/sensor.service';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private sensorService: SensorService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
ReadAllByDomainID$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.ReadAllByDomainID)
|
||||
.map((action: ReadAllByDomainID) => action.payload)
|
||||
.switchMap(payload => this.sensorService.readAllByDomainID(payload.domainID, payload.pageParams))
|
||||
.map(page => {
|
||||
return new ReadAllByDomainIDSuccess(page);
|
||||
})
|
||||
.catch((error: RPCClientError) => {
|
||||
return of(new ReadAllByDomainIDFailure(error));
|
||||
});
|
||||
|
||||
// @Effect()
|
||||
// Read$: Observable<Action> = this.actions$
|
||||
// .ofType(ActionType.Read)
|
||||
// .map((action: Read) => action.payload)
|
||||
// .switchMap(payload => this.sensorHostService.read(payload))
|
||||
// .map(sensorHost => {
|
||||
// return new ReadSuccess(sensorHost);
|
||||
// })
|
||||
// .catch((error: RPCClientError) => {
|
||||
// return of(new ReadFailure(error));
|
||||
// });
|
||||
|
||||
// @Effect()
|
||||
// Modify$: Observable<Action> = this.actions$
|
||||
// .ofType(ActionType.Modify)
|
||||
// .map((action: Modify) => action.payload)
|
||||
// .switchMap(payload => this.sensorService.modify(payload))
|
||||
// .map(sensor => {
|
||||
// return new ModifySuccess(sensor);
|
||||
// })
|
||||
// .catch((error: RPCClientError) => {
|
||||
// return of(new ModifyFailure(error));
|
||||
// });
|
||||
}
|
||||
63
@overflow/sensor/store/entity/sensor/sensor.reducer.ts
Normal file
63
@overflow/sensor/store/entity/sensor/sensor.reducer.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import {
|
||||
ActionType,
|
||||
Actions,
|
||||
} from './sensor.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
sensorAdapter,
|
||||
} from './sensor.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.ReadAllByDomainID: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainIDSuccess: {
|
||||
return sensorAdapter.setAll(action.payload.content, {...state, page: action.payload});
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainIDFailure: {
|
||||
return sensorAdapter.setError(action.payload, state);
|
||||
}
|
||||
|
||||
case ActionType.Read: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadSuccess: {
|
||||
return sensorAdapter.setOne(action.payload, {...state, page: null});
|
||||
}
|
||||
|
||||
case ActionType.ReadFailure: {
|
||||
return sensorAdapter.setError(action.payload, state);
|
||||
}
|
||||
|
||||
case ActionType.Modify: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifySuccess: {
|
||||
return sensorAdapter.upsertOne(action.payload, state);
|
||||
}
|
||||
|
||||
case ActionType.ModifyFailure: {
|
||||
return sensorAdapter.setError(action.payload, state);
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
@overflow/sensor/store/entity/sensor/sensor.state.ts
Normal file
24
@overflow/sensor/store/entity/sensor/sensor.state.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
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';
|
||||
import { Page } from '@overflow/commons-typescript/model/commons/Page';
|
||||
import { Sensor } from '@overflow/commons-typescript/model/sensor';
|
||||
|
||||
export const sensorAdapter = createEntityAdapter<Sensor, RPCClientError>();
|
||||
|
||||
export interface State extends EntityState<Sensor, RPCClientError> {
|
||||
page: Page<Sensor>;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
ids : [],
|
||||
entities : null,
|
||||
page: null,
|
||||
error: null,
|
||||
};
|
||||
|
||||
export function getSelectors<S>(selector: Selector<any, State>) {
|
||||
return sensorAdapter.getSelectors(selector);
|
||||
}
|
||||
|
||||
@@ -8,32 +8,30 @@ import { StateSelector } from '@overflow/core/ngrx/store';
|
||||
|
||||
import { MODULE } from '../sensor.constant';
|
||||
|
||||
import * as ListStore from './list';
|
||||
import * as DetailStore from './detail';
|
||||
import * as SensorEntityStore from './entity/sensor';
|
||||
|
||||
export interface State {
|
||||
list: ListStore.State;
|
||||
sensor: DetailStore.State;
|
||||
sensor: SensorEntityStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
list: ListStore.reducer,
|
||||
sensor: DetailStore.reducer,
|
||||
sensor: SensorEntityStore.reducer,
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
ListStore.Effects,
|
||||
DetailStore.Effects,
|
||||
SensorEntityStore.Effects,
|
||||
];
|
||||
|
||||
export const sensorState = createFeatureSelector<State>(MODULE.name);
|
||||
export const selectState = createFeatureSelector<State>(MODULE.name);
|
||||
|
||||
export const sensorListSelector = new StateSelector<ListStore.State>(createSelector(
|
||||
sensorState,
|
||||
(state: State) => state.list
|
||||
));
|
||||
export const sensorSelector = new StateSelector<DetailStore.State>(createSelector(
|
||||
sensorState,
|
||||
export const SensorEntitySelector = SensorEntityStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.sensor
|
||||
));
|
||||
|
||||
export const SensorPageSelector = createSelector(
|
||||
selectState,
|
||||
(state: State) => state.sensor.page
|
||||
);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user