ing
This commit is contained in:
parent
f290f5bdb1
commit
fd369d3519
|
@ -1,19 +0,0 @@
|
|||
// import { NgModule } from '@angular/core';
|
||||
// import { StoreModule } from '@ngrx/store';
|
||||
|
||||
// import { EffectsModule } from '@ngrx/effects';
|
||||
|
||||
// import {
|
||||
// REDUCERS,
|
||||
// EFFECTS,
|
||||
// } from './store';
|
||||
|
||||
// import { MODULE } from './alert.constant';
|
||||
|
||||
// @NgModule({
|
||||
// imports: [
|
||||
// StoreModule.forFeature(MODULE.name, REDUCERS),
|
||||
// EffectsModule.forFeature(EFFECTS),
|
||||
// ],
|
||||
// })
|
||||
// export class DiscoveryStoreModule { }
|
|
@ -2,11 +2,6 @@ import { NgModule } from '@angular/core';
|
|||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
||||
|
||||
// import { InputChipModule } from '@overflow/commons/component/input-chip/input-chip.module';
|
||||
|
||||
// import { DiscoveryStoreModule } from './discovery-store.module';
|
||||
// import { DiscoveryRPCModule } from './discovery-rpc.module';
|
||||
import { AlertLoggerModule } from './alert-logger.module';
|
||||
|
||||
import { COMPONENTS } from './component';
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
export * from './selectors';
|
|
@ -1,16 +0,0 @@
|
|||
import {
|
||||
createSelector,
|
||||
MemoizedSelector,
|
||||
} from '@ngrx/store';
|
||||
|
||||
export class StateSelector<State> {
|
||||
public constructor(private _selector: MemoizedSelector<object, State>) {
|
||||
}
|
||||
|
||||
public select = (propertyPath: string) => createSelector(this._selector, (state: State) => {
|
||||
return propertyPath.split('.').reduce(
|
||||
(prev, curr) => {
|
||||
return prev ? prev[curr] : undefined;
|
||||
}, state);
|
||||
})
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
import { MapComponent } from './map/map.component';
|
||||
// import { ProbeSummaryComponent } from './probe-summary/probe-summary.component';
|
||||
import { HostSummaryComponent } from './host-summary/host-summary.component';
|
||||
import { ServiceSummaryComponent } from './service-summary/service-summary.component';
|
||||
import { InfraMapComponent } from './infra-map.component';
|
||||
// import { InfraProbeSummaryComponent } from './infra-probe-summary.component';
|
||||
import { InfraHostSummaryComponent } from './infra-host-summary.component';
|
||||
import { InfraServiceSummaryComponent } from './infra-service-summary.component';
|
||||
|
||||
export const COMPONENTS = [
|
||||
MapComponent,
|
||||
// ProbeSummaryComponent,
|
||||
HostSummaryComponent,
|
||||
ServiceSummaryComponent
|
||||
InfraMapComponent,
|
||||
// InfraProbeSummaryComponent,
|
||||
InfraHostSummaryComponent,
|
||||
InfraServiceSummaryComponent
|
||||
];
|
||||
|
|
|
@ -3,10 +3,10 @@ import { InfraHost } from '@overflow/commons-typescript/model/infra';
|
|||
|
||||
|
||||
@Component({
|
||||
selector: 'of-host-summary',
|
||||
templateUrl: './host-summary.component.html',
|
||||
selector: 'of-infra-host-summary',
|
||||
templateUrl: './infra-host-summary.component.html',
|
||||
})
|
||||
export class HostSummaryComponent implements OnInit, AfterContentInit, OnChanges {
|
||||
export class InfraHostSummaryComponent implements OnInit, AfterContentInit, OnChanges {
|
||||
|
||||
@Input() host: InfraHost;
|
||||
@Input() visible: boolean;
|
|
@ -1,20 +1,20 @@
|
|||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { MapComponent } from './map.component';
|
||||
import { InfraMapComponent } from './infra-map.component';
|
||||
|
||||
describe('MapComponent', () => {
|
||||
let component: MapComponent;
|
||||
let fixture: ComponentFixture<MapComponent>;
|
||||
describe('InfraMapComponent', () => {
|
||||
let component: InfraMapComponent;
|
||||
let fixture: ComponentFixture<InfraMapComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [MapComponent]
|
||||
declarations: [InfraMapComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(MapComponent);
|
||||
fixture = TestBed.createComponent(InfraMapComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
|
@ -4,18 +4,17 @@ import {
|
|||
AfterContentInit,
|
||||
ViewChild
|
||||
} from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
|
||||
import { Observable, of, Subscription } from 'rxjs';
|
||||
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
||||
|
||||
import { TreeNode, MenuItem, ContextMenu } from 'primeng/primeng';
|
||||
import { Store, select } from '@ngrx/store';
|
||||
import * as ListStore from '../../store/list';
|
||||
import { ListSelector } from '../../store';
|
||||
import { Target } from '@overflow/commons-typescript/model/target';
|
||||
import { Infra, InfraHost, InfraService } from '@overflow/commons-typescript/model/infra';
|
||||
import { Domain, DomainMember } from '@overflow/commons-typescript/model/domain';
|
||||
import { AuthSelector } from '@overflow/shared/auth/store';
|
||||
|
||||
// import { sensorListSelector } from '@overflow/sensor/store';
|
||||
|
||||
import { Sensor } from '@overflow/commons-typescript/model/sensor';
|
||||
|
||||
|
||||
|
@ -28,12 +27,15 @@ interface HostData {
|
|||
|
||||
@Component({
|
||||
selector: 'of-infra-map',
|
||||
templateUrl: './map.component.html'
|
||||
templateUrl: './infra-map.component.html'
|
||||
})
|
||||
export class MapComponent implements OnInit, AfterContentInit {
|
||||
export class InfraMapComponent implements OnInit, AfterContentInit {
|
||||
infras$: Observable<Infra>;
|
||||
pending$: Observable<boolean>;
|
||||
error$: Observable<any>;
|
||||
|
||||
infraTree: TreeNode[] = [];
|
||||
|
||||
infras$ = this.listStore.pipe(select(ListSelector.select('page')));
|
||||
// sensors$ = this.sensorListStore.pipe(select(sensorListSelector.select('page')));
|
||||
display = false;
|
||||
loading = false;
|
||||
|
@ -60,55 +62,21 @@ export class MapComponent implements OnInit, AfterContentInit {
|
|||
sensorSettingDisplay = false;
|
||||
target: Target = null;
|
||||
|
||||
constructor(private router: Router,
|
||||
private listStore: Store<any>,
|
||||
) { }
|
||||
constructor(
|
||||
private store: Store<any>,
|
||||
private infraService: InfraService,
|
||||
) {
|
||||
|
||||
}
|
||||
ngOnInit() {
|
||||
|
||||
this.initContextMenu();
|
||||
}
|
||||
|
||||
ngAfterContentInit() {
|
||||
|
||||
this.listStore.select(AuthSelector.selectDomainMember).subscribe(
|
||||
(domainMember: DomainMember) => {
|
||||
|
||||
// const pageParams: PageParams = {
|
||||
// pageNo: '0',
|
||||
// countPerPage: '99999',
|
||||
// sortCol: 'id',
|
||||
// sortDirection: 'descending'
|
||||
// };
|
||||
|
||||
// this.listStore.dispatch(new ListStore.ReadAllByDomain({ domain: domain, pageParams: pageParams }));
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
// this.infras$.subscribe(
|
||||
// (page: Page) => {
|
||||
// if (page !== null) {
|
||||
// this.totalList = page.content;
|
||||
// this.infraTree = this.generateInfraHostData();
|
||||
// }
|
||||
// },
|
||||
// (error: RPCClientError) => {
|
||||
// console.log(error.response.message);
|
||||
// });
|
||||
|
||||
// this.sensors$.subscribe(
|
||||
// (page: Page) => {
|
||||
// if (page !== null) {
|
||||
// const sensorList = page.content;
|
||||
// this.addTreeForSensor(sensorList);
|
||||
// }
|
||||
// },
|
||||
// (error: RPCClientError) => {
|
||||
// console.log(error.response.message);
|
||||
// }
|
||||
// );
|
||||
this.initContextMenu();
|
||||
}
|
||||
|
||||
initContextMenu() {
|
||||
this.contextMenuProbe = [
|
||||
|
@ -385,7 +353,7 @@ export class MapComponent implements OnInit, AfterContentInit {
|
|||
|
||||
showDialog() {
|
||||
// this.display = true;
|
||||
this.router.navigateByUrl('/discovery');
|
||||
// this.router.navigateByUrl('/discovery');
|
||||
}
|
||||
|
||||
// closeDialog() {
|
||||
|
@ -414,15 +382,15 @@ export class MapComponent implements OnInit, AfterContentInit {
|
|||
}
|
||||
|
||||
onNodeSelect(event) {
|
||||
const nodeType = event.node.type;
|
||||
this.selectedNode = event.node;
|
||||
if (nodeType === 'probe') {
|
||||
this.router.navigate(['probe', event.node.obj.id, 'info']);
|
||||
} else if (nodeType === 'host' || nodeType === 'service') {
|
||||
this.router.navigate(['target', event.node.obj.id, 'info']);
|
||||
} else if (nodeType === 'sensor') {
|
||||
this.router.navigate(['sensor', event.node.obj.id, 'info']);
|
||||
}
|
||||
// const nodeType = event.node.type;
|
||||
// this.selectedNode = event.node;
|
||||
// if (nodeType === 'probe') {
|
||||
// this.router.navigate(['probe', event.node.obj.id, 'info']);
|
||||
// } else if (nodeType === 'host' || nodeType === 'service') {
|
||||
// this.router.navigate(['target', event.node.obj.id, 'info']);
|
||||
// } else if (nodeType === 'sensor') {
|
||||
// this.router.navigate(['sensor', event.node.obj.id, 'info']);
|
||||
// }
|
||||
}
|
||||
|
||||
viewInfo() {
|
|
@ -8,10 +8,10 @@
|
|||
|
||||
|
||||
// @Component({
|
||||
// selector: 'of-probe-summary',
|
||||
// templateUrl: './probe-summary.component.html',
|
||||
// selector: 'of-infra-probe-summary',
|
||||
// templateUrl: './infra-probe-summary.component.html',
|
||||
// })
|
||||
// export class ProbeSummaryComponent implements OnInit, AfterContentInit, OnChanges {
|
||||
// export class InfraProbeSummaryComponent implements OnInit, AfterContentInit, OnChanges {
|
||||
|
||||
// @Input() probe: Object;
|
||||
// @Input() visible: boolean;
|
|
@ -1,13 +1,13 @@
|
|||
import { Component, OnInit, AfterContentInit, Input, OnChanges } from '@angular/core';
|
||||
import { InfraHost } from '@overflow/commons-typescript/model/infra';
|
||||
import { InfraService } from '../../service/infra.service';
|
||||
import { InfraService } from '../service/infra.service';
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'of-service-summary',
|
||||
templateUrl: './service-summary.component.html',
|
||||
selector: 'of-infra-service-summary',
|
||||
templateUrl: './infra-service-summary.component.html',
|
||||
})
|
||||
export class ServiceSummaryComponent implements OnInit, AfterContentInit, OnChanges {
|
||||
export class InfraServiceSummaryComponent implements OnInit, AfterContentInit, OnChanges {
|
||||
|
||||
@Input() service: InfraService;
|
||||
@Input() visible: boolean;
|
|
@ -1,19 +0,0 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
|
||||
import {
|
||||
REDUCERS,
|
||||
EFFECTS,
|
||||
} from './store';
|
||||
|
||||
import { MODULE } from './infra.constant';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
StoreModule.forFeature(MODULE.name, REDUCERS),
|
||||
EffectsModule.forFeature(EFFECTS),
|
||||
],
|
||||
})
|
||||
export class InfraStoreModule { }
|
|
@ -1,6 +1,5 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { InfraStoreModule } from './infra-store.module';
|
||||
import { COMPONENTS } from './component';
|
||||
import { SERVICES } from './service';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
|
@ -13,7 +12,6 @@ import { UIModule } from '@overflow/shared/ui/ui.module';
|
|||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
InfraStoreModule,
|
||||
FormsModule,
|
||||
UIModule,
|
||||
DiscoveryModule,
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
import { Action } from '@ngrx/store';
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { Infra } from '@overflow/commons-typescript/model/infra';
|
||||
|
||||
export enum ActionType {
|
||||
Read = '[Infra.list] Read',
|
||||
ReadSuccess = '[Infra.list] ReadSuccess',
|
||||
ReadFailure = '[Infra.list] 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: Infra) { }
|
||||
}
|
||||
|
||||
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 './list.effect';
|
||||
|
||||
describe('list.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/map';
|
||||
import 'rxjs/add/operator/take';
|
||||
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
|
||||
import { Infra } from '@overflow/commons-typescript/model/infra';
|
||||
|
||||
import {
|
||||
Read,
|
||||
ReadSuccess,
|
||||
ReadFailure,
|
||||
ActionType,
|
||||
} from './detail.action';
|
||||
import { InfraService } from '../../service/infra.service';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private infraService: InfraService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
read$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Read)
|
||||
.map((action: Read) => action.payload)
|
||||
.switchMap(payload => this.infraService.read(payload.id))
|
||||
.map(infra => {
|
||||
return new ReadSuccess(infra);
|
||||
})
|
||||
.catch((error: RPCClientError) => {
|
||||
return of(new ReadFailure(error));
|
||||
});
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
import { Actions, ActionType } from './detail.action';
|
||||
import { State, initialState } from './detail.state';
|
||||
|
||||
import { Infra } from '@overflow/commons-typescript/model/infra';
|
||||
|
||||
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,
|
||||
infra: action.payload
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
isPending: false,
|
||||
infra: null
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
|
||||
import { Infra } from '@overflow/commons-typescript/model/infra';
|
||||
|
||||
export interface State {
|
||||
error: RPCClientError | null;
|
||||
isPending: boolean;
|
||||
infra: Infra | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
isPending: false,
|
||||
infra: null,
|
||||
};
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
export * from './detail.action';
|
||||
export * from './detail.effect';
|
||||
export * from './detail.reducer';
|
||||
export * from './detail.state';
|
|
@ -1,38 +0,0 @@
|
|||
import {
|
||||
createSelector,
|
||||
createFeatureSelector,
|
||||
ActionReducerMap,
|
||||
} from '@ngrx/store';
|
||||
|
||||
import { MODULE } from '../infra.constant';
|
||||
|
||||
import * as ListStore from './list';
|
||||
import * as DetailStore from './detail';
|
||||
import { StateSelector } from '@overflow/core/ngrx/store';
|
||||
|
||||
export interface State {
|
||||
list: ListStore.State;
|
||||
sensor: DetailStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
list: ListStore.reducer,
|
||||
sensor: DetailStore.reducer
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
ListStore.Effects,
|
||||
DetailStore.Effects
|
||||
];
|
||||
|
||||
export const selectInfraState = createFeatureSelector<State>(MODULE.name);
|
||||
|
||||
export const ListSelector = new StateSelector<ListStore.State>(createSelector(
|
||||
selectInfraState,
|
||||
(state: State) => state.list
|
||||
));
|
||||
|
||||
export const DetailSelector = new StateSelector<DetailStore.State>(createSelector(
|
||||
selectInfraState,
|
||||
(state: State) => state.sensor
|
||||
));
|
|
@ -1,4 +0,0 @@
|
|||
export * from './list.action';
|
||||
export * from './list.effect';
|
||||
export * from './list.reducer';
|
||||
export * from './list.state';
|
|
@ -1,63 +0,0 @@
|
|||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
|
||||
// import { PageParams, Page } from 'app/commons/model';
|
||||
import { Domain } from '@overflow/commons-typescript/model/domain';
|
||||
import { Probe } from '@overflow/commons-typescript/model/probe';
|
||||
|
||||
export enum ActionType {
|
||||
ReadAllByDomain = '[Infra.list] ReadAllByDomain',
|
||||
ReadAllByDomainSuccess = '[Infra.list] ReadAllByDomainSuccess',
|
||||
ReadAllByDomainFailure = '[Infra.list] ReadAllByDomainFailure',
|
||||
|
||||
ReadAllByProbe = '[Infra.list] ReadAllByProbe',
|
||||
ReadAllByProbeSuccess = '[Infra.list] ReadAllByProbeSuccess',
|
||||
ReadAllByProbeFailure = '[Infra.list] ReadAllByProbeFailure',
|
||||
}
|
||||
|
||||
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 ReadAllByProbe implements Action {
|
||||
readonly type = ActionType.ReadAllByProbe;
|
||||
|
||||
// constructor(public payload: { probe: Probe, pageParams: PageParams }) { }
|
||||
}
|
||||
|
||||
export class ReadAllByProbeSuccess implements Action {
|
||||
readonly type = ActionType.ReadAllByProbeSuccess;
|
||||
|
||||
// constructor(public payload: Page) { }
|
||||
}
|
||||
|
||||
export class ReadAllByProbeFailure implements Action {
|
||||
readonly type = ActionType.ReadAllByProbeFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) { }
|
||||
}
|
||||
|
||||
|
||||
export type Actions =
|
||||
| ReadAllByDomain
|
||||
| ReadAllByDomainSuccess
|
||||
| ReadAllByDomainFailure
|
||||
| ReadAllByProbe
|
||||
| ReadAllByProbeSuccess
|
||||
| ReadAllByProbeFailure
|
||||
;
|
|
@ -1,15 +0,0 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './list.effect';
|
||||
|
||||
describe('list.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -1,64 +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 { Infra } from '@overflow/commons-typescript/model/infra';
|
||||
import { InfraService } from '../../service/infra.service';
|
||||
|
||||
import {
|
||||
ReadAllByDomain,
|
||||
ReadAllByDomainSuccess,
|
||||
ReadAllByDomainFailure,
|
||||
ReadAllByProbe,
|
||||
ReadAllByProbeSuccess,
|
||||
ReadAllByProbeFailure,
|
||||
ActionType,
|
||||
} from './list.action';
|
||||
import { Domain } from '@overflow/commons-typescript/model/domain';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private infraService: InfraService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
// @Effect()
|
||||
// readAllByDomain$: Observable<Action> = this.actions$
|
||||
// .ofType(ActionType.ReadAllByDomain)
|
||||
// .map((action: ReadAllByDomain) => action.payload)
|
||||
// .switchMap(payload => this.infraService.readAllByDomain(payload.domain, payload.pageParams))
|
||||
// .map(page => {
|
||||
// return new ReadAllByDomainSuccess(page);
|
||||
// })
|
||||
// .catch((error: RPCClientError) => {
|
||||
// return of(new ReadAllByDomainFailure(error));
|
||||
// });
|
||||
|
||||
// @Effect()
|
||||
// readAllByProbe$: Observable<Action> = this.actions$
|
||||
// .ofType(ActionType.ReadAllByProbe)
|
||||
// .map((action: ReadAllByProbe) => action.payload)
|
||||
// .switchMap(payload => this.infraService.readAllByProbe(payload.probe, payload.pageParams))
|
||||
// .map(page => {
|
||||
// return new ReadAllByProbeSuccess(page);
|
||||
// })
|
||||
// .catch((error: RPCClientError) => {
|
||||
// return of(new ReadAllByProbeFailure(error));
|
||||
// });
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
import { Actions, ActionType } from './list.action';
|
||||
|
||||
import { State, initialState } from './list.state';
|
||||
|
||||
import { Infra } from '@overflow/commons-typescript/model/infra';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.ReadAllByDomain: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
isPending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
isPending: false,
|
||||
// page: action.payload
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
isPending: false,
|
||||
// page: null
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByProbe: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
isPending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByProbeSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
isPending: false,
|
||||
// page: action.payload
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByProbeFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
isPending: false,
|
||||
// page: null
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
|
||||
import { Infra } from '@overflow/commons-typescript/model/infra';
|
||||
// import { Page } from 'app/commons/model';
|
||||
|
||||
export interface State {
|
||||
error: RPCClientError | null;
|
||||
isPending: boolean;
|
||||
// page: Page | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
isPending: false,
|
||||
// page: null,
|
||||
};
|
||||
|
|
@ -3,8 +3,6 @@ import {
|
|||
createFeatureSelector,
|
||||
} from '@ngrx/store';
|
||||
|
||||
import { StateSelector } from '@overflow/core/ngrx/store';
|
||||
|
||||
import { MODULE } from '../notification.constant';
|
||||
|
||||
import * as NotificationEntityStore from './entity/notification';
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
|
||||
import {
|
||||
StoreRouterConnectingModule,
|
||||
RouterStateSerializer,
|
||||
} from '@ngrx/router-store';
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
import { combineReducers, ActionReducer, ActionReducerMap, MetaReducer } from '@ngrx/store';
|
||||
|
||||
import {
|
||||
REDUCERS,
|
||||
EFFECTS,
|
||||
} from './store';
|
||||
|
||||
import { MODULE } from './probe.constant';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
StoreModule.forFeature(MODULE.name, REDUCERS),
|
||||
EffectsModule.forFeature(EFFECTS),
|
||||
],
|
||||
})
|
||||
export class ProbeStoreModule { }
|
|
@ -1,2 +0,0 @@
|
|||
export * from './probe-detail.reducer';
|
||||
export * from './probe-detail.state';
|
|
@ -1,31 +0,0 @@
|
|||
import { ActionType, Actions } from '../../entity/probe';
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
probeListContainerAdapter
|
||||
} from './probe-detail.state';
|
||||
|
||||
import { Probe } from '@overflow/commons-typescript/model/probe';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Read: {
|
||||
return {
|
||||
...state,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadSuccess: {
|
||||
return probeListContainerAdapter.setOne(action.payload, {...state, pending: false});
|
||||
}
|
||||
|
||||
case ActionType.ReadFailure: {
|
||||
return probeListContainerAdapter.setError(action.payload, {...state, pending: false});
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
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 probeListContainerAdapter = createEntityAdapter<ProbeHost, RPCClientError>();
|
||||
export interface State extends EntityState<ProbeHost, RPCClientError> {
|
||||
pending: boolean;
|
||||
}
|
||||
export const initialState: State = probeListContainerAdapter.getInitialState({
|
||||
pending: false,
|
||||
});
|
||||
|
||||
export function getSelectors<S>(selector: Selector<any, State>) {
|
||||
return {
|
||||
...probeListContainerAdapter.getSelectors(selector),
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
};
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
export * from './probe-list.reducer';
|
||||
export * from './probe-list.state';
|
|
@ -1,31 +0,0 @@
|
|||
import { ActionType, Actions } from '../../entity/probe';
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
probeListContainerAdapter
|
||||
} from './probe-list.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 probeListContainerAdapter.setAll(action.payload, {...state, pending: false});
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainIDFailure: {
|
||||
return probeListContainerAdapter.setError(action.payload, {...state, pending: false});
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
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 probeListContainerAdapter = createEntityAdapter<ProbeHost, RPCClientError>();
|
||||
export interface State extends EntityState<ProbeHost, RPCClientError> {
|
||||
pending: boolean;
|
||||
}
|
||||
export const initialState: State = probeListContainerAdapter.getInitialState({
|
||||
pending: false,
|
||||
});
|
||||
|
||||
export function getSelectors<S>(selector: Selector<any, State>) {
|
||||
return {
|
||||
...probeListContainerAdapter.getSelectors(selector),
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
export * from './probe-selector.reducer';
|
||||
export * from './probe-selector.state';
|
|
@ -1,31 +0,0 @@
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
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),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
export * from './probe.action';
|
||||
export * from './probe.effect';
|
|
@ -1,83 +0,0 @@
|
|||
import { Action } from '@ngrx/store';
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { ProbeHost, Probe } from '@overflow/commons-typescript/model/probe';
|
||||
|
||||
export enum ActionType {
|
||||
ReadAllByDomainID = '[probe.list] ReadAllByDomainID',
|
||||
ReadAllByDomainIDSuccess = '[probe.list] ReadAllByDomainIDSuccess',
|
||||
ReadAllByDomainIDFailure = '[probe.list] ReadAllByDomainIDFailure',
|
||||
|
||||
Read = '[probe.detail] Read',
|
||||
ReadSuccess = '[probe.detail] ReadSuccess',
|
||||
ReadFailure = '[probe.detail] ReadFailure',
|
||||
|
||||
Modify = '[probe.detail] Modify',
|
||||
ModifySuccess = '[probe.detail] ModifySuccess',
|
||||
ModifyFailure = '[probe.detail] ModifyFailure',
|
||||
}
|
||||
|
||||
export class ReadAllByDomainID implements Action {
|
||||
readonly type = ActionType.ReadAllByDomainID;
|
||||
|
||||
constructor(public payload: number) {}
|
||||
}
|
||||
|
||||
export class ReadAllByDomainIDSuccess implements Action {
|
||||
readonly type = ActionType.ReadAllByDomainIDSuccess;
|
||||
|
||||
constructor(public payload: ProbeHost[]) {}
|
||||
}
|
||||
|
||||
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: ProbeHost) {}
|
||||
}
|
||||
|
||||
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: Probe) {}
|
||||
}
|
||||
|
||||
export class ModifySuccess implements Action {
|
||||
readonly type = ActionType.ModifySuccess;
|
||||
|
||||
constructor(public payload: ProbeHost) {}
|
||||
}
|
||||
|
||||
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
|
||||
;
|
|
@ -1,81 +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 { Domain } from '@overflow/commons-typescript/model/domain';
|
||||
import { Probe } from '@overflow/commons-typescript/model/probe';
|
||||
|
||||
import {
|
||||
ReadAllByDomainID,
|
||||
ReadAllByDomainIDFailure,
|
||||
ReadAllByDomainIDSuccess,
|
||||
Read,
|
||||
ReadSuccess,
|
||||
ReadFailure,
|
||||
Modify,
|
||||
ModifySuccess,
|
||||
ModifyFailure,
|
||||
ActionType
|
||||
} from './probe.action';
|
||||
import { ProbeHostService } from '../../../service/probe-host.service';
|
||||
import { ProbeService } from '../../../service/probe.service';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private probeHostService: ProbeHostService,
|
||||
private probeService: ProbeService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
ReadAllByDomainID$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.ReadAllByDomainID)
|
||||
.map((action: ReadAllByDomainID) => action.payload)
|
||||
.switchMap(payload => this.probeHostService.readAllByDomainID(payload))
|
||||
.map(probeHosts => {
|
||||
return new ReadAllByDomainIDSuccess(probeHosts);
|
||||
})
|
||||
.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.probeHostService.read(payload))
|
||||
.map(probeHost => {
|
||||
return new ReadSuccess(probeHost);
|
||||
})
|
||||
.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.probeService.modify(payload))
|
||||
.map(probe => {
|
||||
return new ModifySuccess(probe);
|
||||
})
|
||||
.catch((error: RPCClientError) => {
|
||||
return of(new ModifyFailure(error));
|
||||
});
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
import {
|
||||
createSelector,
|
||||
createFeatureSelector,
|
||||
ActionReducerMap,
|
||||
} from '@ngrx/store';
|
||||
|
||||
import { StateSelector } from '@overflow/core/ngrx/store';
|
||||
|
||||
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_selector_container: ProbeSelectorContainerStore.reducer
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
ProbeEntityStore.Effects,
|
||||
];
|
||||
|
||||
export const selectState = createFeatureSelector<State>(MODULE.name);
|
||||
|
||||
export const ProbeListContainerSelector = ProbeListContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.probe_list_container
|
||||
));
|
||||
|
||||
export const ProbeDetailContainerSelector = ProbeDetailContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.probe_detail_container
|
||||
));
|
||||
|
||||
export const ProbeSelectorContainerSelector = ProbeSelectorContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.probe_selector_container
|
||||
));
|
|
@ -1,19 +0,0 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
|
||||
import {
|
||||
REDUCERS,
|
||||
EFFECTS,
|
||||
} from './store';
|
||||
|
||||
import { MODULE } from './sensor-item.constant';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
StoreModule.forFeature(MODULE.name, REDUCERS),
|
||||
EffectsModule.forFeature(EFFECTS),
|
||||
],
|
||||
})
|
||||
export class SensorItemStoreModule { }
|
|
@ -4,14 +4,12 @@ import { CommonModule } from '@angular/common';
|
|||
import { UIModule } from '@overflow/shared/ui/ui.module';
|
||||
|
||||
import { COMPONENTS } from './component';
|
||||
import { SensorItemStoreModule } from './sensor-item-store.module';
|
||||
import { SERVICES } from './service';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
UIModule,
|
||||
SensorItemStoreModule,
|
||||
],
|
||||
declarations: [
|
||||
COMPONENTS,
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
import {
|
||||
createSelector,
|
||||
createFeatureSelector,
|
||||
} from '@ngrx/store';
|
||||
|
||||
import { StateSelector } from '@overflow/core/ngrx/store';
|
||||
|
||||
|
||||
import * as ListStore from './key-list';
|
||||
import { MODULE } from '../sensor-item.constant';
|
||||
|
||||
export interface State {
|
||||
list: ListStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
list: ListStore.reducer,
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
ListStore.Effects,
|
||||
];
|
||||
|
||||
export const selectState = createFeatureSelector<State>(MODULE.name);
|
||||
|
||||
export const ReadSensorItemKeySelector = new StateSelector<ListStore.State>(createSelector(
|
||||
selectState,
|
||||
(state: State) => state.list
|
||||
));
|
|
@ -1,4 +0,0 @@
|
|||
export * from './list.action';
|
||||
export * from './list.effect';
|
||||
export * from './list.reducer';
|
||||
export * from './list.state';
|
|
@ -1,37 +0,0 @@
|
|||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { MetaSensorItemKey } from '@overflow/commons-typescript/model/meta';
|
||||
import { MetaSensorDisplayItem } from '@overflow/commons-typescript/model/meta';
|
||||
|
||||
|
||||
export enum ActionType {
|
||||
ReadAllByDisplayItem = '[meta.sensor-display-key-list] ReadAllByDisplayItem',
|
||||
ReadAllByDisplayItemSuccess = '[meta.sensor-display-key-list] ReadAllByDisplayItemSuccess',
|
||||
ReadAllByDisplayItemFailure = '[meta.sensor-display-key-list] ReadAllByDisplayItemFailure',
|
||||
}
|
||||
|
||||
export class ReadAllByDisplayItem implements Action {
|
||||
readonly type = ActionType.ReadAllByDisplayItem;
|
||||
|
||||
constructor(public payload: MetaSensorDisplayItem) {}
|
||||
}
|
||||
|
||||
export class ReadAllByDisplayItemSuccess implements Action {
|
||||
readonly type = ActionType.ReadAllByDisplayItemSuccess;
|
||||
|
||||
constructor(public payload: MetaSensorItemKey[]) {}
|
||||
}
|
||||
|
||||
export class ReadAllByDisplayItemFailure implements Action {
|
||||
readonly type = ActionType.ReadAllByDisplayItemFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) {}
|
||||
}
|
||||
|
||||
export type Actions =
|
||||
| ReadAllByDisplayItem
|
||||
| ReadAllByDisplayItemSuccess
|
||||
| ReadAllByDisplayItemFailure
|
||||
|
||||
;
|
|
@ -1,15 +0,0 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './list.effect';
|
||||
|
||||
describe('List.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -1,48 +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 {
|
||||
ReadAllByDisplayItem,
|
||||
ReadAllByDisplayItemSuccess,
|
||||
ReadAllByDisplayItemFailure,
|
||||
ActionType,
|
||||
} from './list.action';
|
||||
import { SensorItemDependencyService } from '../../service/sensor-item-dependency.service';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private service: SensorItemDependencyService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
readAllByDisplayItem$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.ReadAllByDisplayItem)
|
||||
.map((action: ReadAllByDisplayItem) => action.payload)
|
||||
.switchMap(payload => this.service.readAllByDisplayItem(payload))
|
||||
.map(list => {
|
||||
return new ReadAllByDisplayItemSuccess(list);
|
||||
})
|
||||
.catch((error: RPCClientError) => {
|
||||
return of(new ReadAllByDisplayItemFailure(error));
|
||||
});
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from './list.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './list.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.ReadAllByDisplayItem: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDisplayItemSuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: false,
|
||||
list: action.payload
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDisplayItemFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
list: null,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { MetaSensorItemKey } from '@overflow/commons-typescript/model/meta';
|
||||
|
||||
|
||||
export interface State {
|
||||
error: RPCClientError | null;
|
||||
pending: boolean;
|
||||
list: MetaSensorItemKey[] | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
pending: false,
|
||||
list: null,
|
||||
};
|
|
@ -2,8 +2,6 @@ import { Component, EventEmitter, Output, OnInit } from '@angular/core';
|
|||
import { Observable } from 'rxjs';
|
||||
import { Store, select } from '@ngrx/store';
|
||||
import { Sensor } from '@overflow/commons-typescript/model/sensor';
|
||||
import * as SensorEntityStore from '../store/entity/sensor';
|
||||
import { SensorListContainerSelector } from '../store';
|
||||
import { AuthSelector } from '@overflow/shared/auth/store';
|
||||
import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams';
|
||||
import { Page } from '@overflow/commons-typescript/model/commons/Page';
|
||||
|
@ -27,7 +25,7 @@ export class SensorListContainerComponent implements OnInit {
|
|||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.page$ = this.store.pipe(select(SensorListContainerSelector.selectPage));
|
||||
// this.page$ = this.store.pipe(select(SensorListContainerSelector.selectPage));
|
||||
// this.page$ = this.store.pipe(select(SensorListContainerSelector.selectPage));
|
||||
|
||||
this.getSensors();
|
||||
|
@ -42,7 +40,7 @@ export class SensorListContainerComponent implements OnInit {
|
|||
sortCol: 'id',
|
||||
sortDirection: 'descending',
|
||||
};
|
||||
this.store.dispatch(new SensorEntityStore.ReadAllByDomainID({ domainID: domainMember.domain.id, pageParams }));
|
||||
// this.store.dispatch(new SensorEntityStore.ReadAllByDomainID({ domainID: domainMember.domain.id, pageParams }));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ import { Component, EventEmitter, Output, OnInit } from '@angular/core';
|
|||
import { Observable } from 'rxjs';
|
||||
import { Store, select } from '@ngrx/store';
|
||||
import { Sensor } from '@overflow/commons-typescript/model/sensor';
|
||||
import * as SensorEntityStore from '../store/entity/sensor';
|
||||
|
||||
@Component({
|
||||
selector: 'of-sensor-setting-container',
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
|
||||
import {
|
||||
StoreRouterConnectingModule,
|
||||
RouterStateSerializer,
|
||||
} from '@ngrx/router-store';
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
|
||||
import {
|
||||
REDUCERS,
|
||||
EFFECTS,
|
||||
} from './store';
|
||||
|
||||
import { MODULE } from './sensor.constant';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
StoreModule.forFeature(MODULE.name, REDUCERS),
|
||||
EffectsModule.forFeature(EFFECTS),
|
||||
],
|
||||
})
|
||||
export class SensorStoreModule { }
|
|
@ -6,7 +6,6 @@ import { UIModule } from '@overflow/shared/ui/ui.module';
|
|||
|
||||
import { COMPONENTS } from './component';
|
||||
import { SERVICES } from './service';
|
||||
import { SensorStoreModule } from './sensor-store.module';
|
||||
import { SensorItemModule } from '../sensor-item/sensor-item.module';
|
||||
import { CONTAINER_COMPONENTS } from './container';
|
||||
// import { MetaCrawlerModule } from '../meta/crawler/crawler.module';
|
||||
|
@ -18,7 +17,6 @@ import { CONTAINER_COMPONENTS } from './container';
|
|||
CommonModule,
|
||||
FormsModule,
|
||||
UIModule,
|
||||
SensorStoreModule,
|
||||
SensorItemModule,
|
||||
],
|
||||
declarations: [
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
export * from './sensor-list.reducer';
|
||||
export * from './sensor-list.state';
|
|
@ -1,58 +0,0 @@
|
|||
import { ActionType, Actions } from '../../entity/sensor';
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
sensorListContainerAdapter,
|
||||
} from './sensor-list.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.ReadAllByDomainID: {
|
||||
return {
|
||||
...state,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainIDSuccess: {
|
||||
return sensorListContainerAdapter.setAll(action.payload.content, { ...state, page: action.payload, pending: false });
|
||||
}
|
||||
|
||||
case ActionType.ReadAllByDomainIDFailure: {
|
||||
return sensorListContainerAdapter.setError(action.payload, { ...state, page: null, pending: false });
|
||||
}
|
||||
|
||||
case ActionType.Read: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ReadSuccess: {
|
||||
return sensorListContainerAdapter.setOne(action.payload, { ...state, page: null, pending: false });
|
||||
}
|
||||
|
||||
case ActionType.ReadFailure: {
|
||||
return sensorListContainerAdapter.setError(action.payload, { ...state, pending: false });
|
||||
}
|
||||
|
||||
case ActionType.Modify: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifySuccess: {
|
||||
return sensorListContainerAdapter.upsertOne(action.payload, state);
|
||||
}
|
||||
|
||||
case ActionType.ModifyFailure: {
|
||||
return sensorListContainerAdapter.setError(action.payload, state);
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
|
||||
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';
|
||||
|
||||
export const sensorListContainerAdapter = createEntityAdapter<Sensor, RPCClientError>();
|
||||
export interface State extends EntityState<Sensor, RPCClientError> {
|
||||
page: Page<Sensor>;
|
||||
pending: boolean;
|
||||
}
|
||||
export const initialState: State = sensorListContainerAdapter.getInitialState({
|
||||
page: null,
|
||||
pending: false,
|
||||
});
|
||||
|
||||
export function getSelectors(selector: Selector<any, State>) {
|
||||
return {
|
||||
...sensorListContainerAdapter.getSelectors(selector),
|
||||
selectPending: createSelector(selector, (state: State) => state.pending),
|
||||
selectPage: createSelector(selector, (state: State) => {
|
||||
return state.page;
|
||||
})
|
||||
};
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
export * from './sensor.action';
|
||||
export * from './sensor.effect';
|
|
@ -1,85 +0,0 @@
|
|||
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
|
||||
;
|
|
@ -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/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));
|
||||
// });
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
import {
|
||||
createSelector,
|
||||
createFeatureSelector,
|
||||
} from '@ngrx/store';
|
||||
|
||||
import { MODULE } from '../sensor.constant';
|
||||
|
||||
import * as SensorEntityStore from './entity/sensor';
|
||||
import * as SensorListContainerStore from './container/sensor-list';
|
||||
|
||||
export interface State {
|
||||
sensor_list: SensorListContainerStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
sensor_list: SensorListContainerStore.reducer,
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
SensorEntityStore.Effects,
|
||||
];
|
||||
|
||||
export const selectState = createFeatureSelector<State>(MODULE.name);
|
||||
|
||||
export const SensorListContainerSelector = SensorListContainerStore.getSelectors(createSelector(
|
||||
selectState,
|
||||
(state: State) => {
|
||||
return state.sensor_list;
|
||||
}
|
||||
));
|
|
@ -1,16 +1,15 @@
|
|||
import { Component, ViewChild, OnInit, Input, AfterContentInit, OnDestroy } from '@angular/core';
|
||||
import { Observable, of, Subscription } from 'rxjs';
|
||||
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
||||
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { Sensor } from '@overflow/commons-typescript/model/sensor';
|
||||
import { Infra } from '@overflow/commons-typescript/model/infra';
|
||||
import { Store, select } from '@ngrx/store';
|
||||
import { DetailSelector as InfraDetailSelector } from '@overflow/infra/store';
|
||||
import * as InfraDetailStore from '@overflow/infra/store/detail';
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
// import * as SensorListStore from '@overflow/sensor/store/list';
|
||||
// import { PageParams, Page } from 'app/commons/model';
|
||||
import { ModifySelector } from '@overflow/target/store';
|
||||
import * as TargetModifyStore from '@overflow/target/store/modify';
|
||||
import { Target } from '@overflow/commons-typescript/model/target';
|
||||
|
||||
|
||||
|
@ -20,11 +19,11 @@ import { Target } from '@overflow/commons-typescript/model/target';
|
|||
})
|
||||
export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
|
||||
|
||||
infra$: Observable<Infra>;
|
||||
infraSubscription$: Subscription;
|
||||
infra$ = this.infraDetailStore.pipe(select(InfraDetailSelector.select('infra')));
|
||||
sensorsSubscription$: Subscription;
|
||||
// sensors$ = this.sensorListStore.pipe(select(sensorListSelector.select('page')));
|
||||
target$ = this.targetModifyStore.pipe(select(ModifySelector.select('target')));
|
||||
target$: Observable<Target>;
|
||||
|
||||
infraId = null;
|
||||
infra: Infra;
|
||||
|
@ -39,9 +38,7 @@ export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
|
|||
constructor(
|
||||
private router: Router,
|
||||
private route: ActivatedRoute,
|
||||
private infraDetailStore: Store<InfraDetailStore.State>,
|
||||
// private sensorListStore: Store<SensorListStore.State>,
|
||||
private targetModifyStore: Store<TargetModifyStore.State>
|
||||
private store: Store<any>,
|
||||
) { }
|
||||
|
||||
ngOnInit() {
|
||||
|
@ -79,11 +76,11 @@ export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
|
|||
}
|
||||
|
||||
getInfra() {
|
||||
this.infraDetailStore.dispatch(
|
||||
new InfraDetailStore.Read(
|
||||
{ id: this.infraId }
|
||||
)
|
||||
);
|
||||
// this.infraDetailStore.dispatch(
|
||||
// new InfraDetailStore.Read(
|
||||
// { id: this.infraId }
|
||||
// )
|
||||
// );
|
||||
}
|
||||
|
||||
getSensors(pageIndex) {
|
||||
|
@ -127,9 +124,9 @@ export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
|
|||
}
|
||||
const target = this.infra.target;
|
||||
target.displayName = value;
|
||||
this.targetModifyStore.dispatch(
|
||||
new TargetModifyStore.Modify(target)
|
||||
);
|
||||
// this.targetModifyStore.dispatch(
|
||||
// new TargetModifyStore.Modify(target)
|
||||
// );
|
||||
|
||||
const modifySuccessSubscription$: Subscription = this.target$.subscribe(
|
||||
(t: Target) => {
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
import { Component, OnInit, AfterContentInit, OnDestroy } from '@angular/core';
|
||||
import { Observable, of, Subscription } from 'rxjs';
|
||||
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
|
||||
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { Infra } from '@overflow/commons-typescript/model/infra';
|
||||
import { Store, select } from '@ngrx/store';
|
||||
import { ListSelector } from '@overflow/infra/store';
|
||||
import * as InfraListStore from '@overflow/infra/store/list';
|
||||
// import { Page, PageParams } from 'app/commons/model';
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { Probe } from '@overflow/commons-typescript/model/probe';
|
||||
|
||||
import { Target } from '@overflow/commons-typescript/model/target';
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -19,7 +20,7 @@ import { Subscription } from 'rxjs/Subscription';
|
|||
export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
|
||||
|
||||
infrasSubscription$: Subscription;
|
||||
infras$ = this.infraListStore.pipe(select(ListSelector.select('page')));
|
||||
infras$: Observable<Infra[]>;
|
||||
infras: Infra[];
|
||||
probe: Probe;
|
||||
target: Target = null;
|
||||
|
@ -32,7 +33,7 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
|
|||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private infraListStore: Store<InfraListStore.State>,
|
||||
private store: Store<any>,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
import {
|
||||
createSelector,
|
||||
createFeatureSelector,
|
||||
ActionReducerMap,
|
||||
} from '@ngrx/store';
|
||||
|
||||
import { StateSelector } from '@overflow/core/ngrx/store';
|
||||
|
||||
import { MODULE } from '../target.constant';
|
||||
|
||||
import * as TargetModifyStore from './modify';
|
||||
|
||||
export interface State {
|
||||
modify: TargetModifyStore.State;
|
||||
}
|
||||
|
||||
export const REDUCERS = {
|
||||
modify: TargetModifyStore.reducer,
|
||||
};
|
||||
|
||||
export const EFFECTS = [
|
||||
TargetModifyStore.Effects,
|
||||
];
|
||||
|
||||
export const selectTargetState = createFeatureSelector<State>(MODULE.name);
|
||||
|
||||
export const ModifySelector = new StateSelector<TargetModifyStore.State>(createSelector(
|
||||
selectTargetState,
|
||||
(state: State) => state.modify
|
||||
));
|
|
@ -1,4 +0,0 @@
|
|||
export * from './modify.action';
|
||||
export * from './modify.effect';
|
||||
export * from './modify.reducer';
|
||||
export * from './modify.state';
|
|
@ -1,34 +0,0 @@
|
|||
import { Action } from '@ngrx/store';
|
||||
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { Target } from '@overflow/commons-typescript/model/target';
|
||||
|
||||
export enum ActionType {
|
||||
Modify = '[Target.modify] Modify',
|
||||
ModifySuccess = '[Target.modify] ModifySuccess',
|
||||
ModifyFailure = '[Target.modify] ModifyFailure',
|
||||
}
|
||||
|
||||
export class Modify implements Action {
|
||||
readonly type = ActionType.Modify;
|
||||
|
||||
constructor(public payload: Target) {}
|
||||
}
|
||||
|
||||
export class ModifySuccess implements Action {
|
||||
readonly type = ActionType.ModifySuccess;
|
||||
|
||||
constructor(public payload: Target) {}
|
||||
}
|
||||
|
||||
export class ModifyFailure implements Action {
|
||||
readonly type = ActionType.ModifyFailure;
|
||||
|
||||
constructor(public payload: RPCClientError) {}
|
||||
}
|
||||
|
||||
export type Actions =
|
||||
| Modify
|
||||
| ModifySuccess
|
||||
| ModifyFailure
|
||||
;
|
|
@ -1,15 +0,0 @@
|
|||
import { TestBed, inject } from '@angular/core/testing';
|
||||
|
||||
import { Effects } from './modify.effect';
|
||||
|
||||
describe('Target.Effects', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [Effects]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([Effects], (effects: Effects) => {
|
||||
expect(effects).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -1,44 +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 { TargetService } from '../../service/target.service';
|
||||
|
||||
import {
|
||||
Modify,
|
||||
ModifySuccess,
|
||||
ModifyFailure,
|
||||
ActionType,
|
||||
} from './modify.action';
|
||||
|
||||
@Injectable()
|
||||
export class Effects {
|
||||
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private targetService: TargetService,
|
||||
private router: Router
|
||||
) { }
|
||||
|
||||
@Effect()
|
||||
modify$: Observable<Action> = this.actions$
|
||||
.ofType(ActionType.Modify)
|
||||
.map((action: Modify) => action.payload)
|
||||
.exhaustMap(target =>
|
||||
this.targetService.modify(target)
|
||||
.map(targets => new ModifySuccess(targets))
|
||||
.catch(error => of(new ModifyFailure(error)))
|
||||
);
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
import {
|
||||
Actions,
|
||||
ActionType,
|
||||
} from './modify.action';
|
||||
|
||||
import {
|
||||
State,
|
||||
initialState,
|
||||
} from './modify.state';
|
||||
|
||||
export function reducer(state = initialState, action: Actions): State {
|
||||
switch (action.type) {
|
||||
case ActionType.Modify: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: true,
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifySuccess: {
|
||||
return {
|
||||
...state,
|
||||
error: null,
|
||||
pending: false,
|
||||
target: action.payload
|
||||
};
|
||||
}
|
||||
|
||||
case ActionType.ModifyFailure: {
|
||||
return {
|
||||
...state,
|
||||
error: action.payload,
|
||||
pending: false,
|
||||
target: null,
|
||||
};
|
||||
}
|
||||
|
||||
default: {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { Target } from '@overflow/commons-typescript/model/target';
|
||||
|
||||
export interface State {
|
||||
error: RPCClientError | null;
|
||||
pending: boolean;
|
||||
target: Target | null;
|
||||
}
|
||||
|
||||
export const initialState: State = {
|
||||
error: null,
|
||||
pending: false,
|
||||
target: null,
|
||||
};
|
|
@ -1,18 +0,0 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { StoreModule } from '@ngrx/store';
|
||||
import { EffectsModule } from '@ngrx/effects';
|
||||
|
||||
import {
|
||||
REDUCERS,
|
||||
EFFECTS,
|
||||
} from './store';
|
||||
|
||||
import { MODULE } from './target.constant';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
StoreModule.forFeature(MODULE.name, REDUCERS),
|
||||
EffectsModule.forFeature(EFFECTS),
|
||||
],
|
||||
})
|
||||
export class TargetStoreModule { }
|
Loading…
Reference in New Issue
Block a user