ing
This commit is contained in:
@@ -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 { }
|
||||
Reference in New Issue
Block a user