sensor regist store

This commit is contained in:
insanity 2018-03-27 16:43:42 +09:00
parent 3c636a238a
commit 4196a124c2
13 changed files with 207 additions and 40 deletions

View File

@ -5,7 +5,7 @@
</tr> </tr>
</table> --> </table> -->
<form *ngFor="let elem of data"> <form *ngFor="let elem of data">
<mat-form-field class="example-full-width" > <mat-form-field class="full-width" >
<input matInput placeholder={{elem.key}} value={{elem.value}} readonly="readonly"> <input matInput placeholder={{elem.key}} value={{elem.value}} [readonly]="true">
</mat-form-field> </mat-form-field>
</form> </form>

View File

@ -1,10 +1,4 @@
.example-container { .full-width {
display: flex; width: 100%;
flex-direction: column;
min-width: 300px;
} }
.mat-table {
overflow: auto;
max-height: 500px;
}

View File

@ -22,12 +22,16 @@
Status: 기본 센서 데이터에서 저장한 metric으로.. Status: 기본 센서 데이터에서 저장한 metric으로..
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile [colspan]="2" [rowspan]="1" class="text-inside-grid"> <mat-grid-tile [colspan]="2" [rowspan]="1" class="text-inside-grid">
<div class="text-inside-grid">????</div> <div class="text-inside-grid">
service list
</div>
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile [colspan]="1" [rowspan]="1"> <mat-grid-tile [colspan]="1" [rowspan]="1">
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile [colspan]="2" [rowspan]="1" class="text-inside-grid"> <mat-grid-tile [colspan]="2" [rowspan]="1" class="text-inside-grid">
<div class="text-inside-grid">?????</div> <div class="text-inside-grid">
sensor list
</div>
</mat-grid-tile> </mat-grid-tile>
<mat-grid-tile [colspan]="1" [rowspan]="1"> <mat-grid-tile [colspan]="1" [rowspan]="1">
<div class="add-sensor-button"> <div class="add-sensor-button">

View File

@ -18,9 +18,10 @@
<input *ngIf="inputItem.inputType.id == 1" matInput type="text" placeholder={{inputItem.name}} required={{inputItem.required}}> <input *ngIf="inputItem.inputType.id == 1" matInput type="text" placeholder={{inputItem.name}} required={{inputItem.required}}>
<input *ngIf="inputItem.inputType.id == 2" matInput type="password" placeholder={{inputItem.name}} required={{inputItem.required}}> <input *ngIf="inputItem.inputType.id == 2" matInput type="password" placeholder={{inputItem.name}} required={{inputItem.required}}>
<input *ngIf="inputItem.inputType.id == 3" matInput type="number" placeholder={{inputItem.name}} required={{inputItem.required}}> <input *ngIf="inputItem.inputType.id == 3" matInput type="number" placeholder={{inputItem.name}} required={{inputItem.required}}>
<mat-select *ngIf="inputItem.inputType.id == 4" placeholder={{inputItem.name}}>
<input *ngIf="inputItem.inputType.id == 4" matInput type="text" placeholder={{inputItem.name}} required={{inputItem.required}}> <mat-option value="true">Yes</mat-option>
<mat-option value="true">No</mat-option>
</mat-select>
<mat-select *ngIf="inputItem.inputType.id == 5" placeholder={{inputItem.name}}> <mat-select *ngIf="inputItem.inputType.id == 5" placeholder={{inputItem.name}}>
<mat-option *ngFor="let option of inputItem.keyValue.split('|')" value="option">{{option}}</mat-option> <mat-option *ngFor="let option of inputItem.keyValue.split('|')" value="option">{{option}}</mat-option>
</mat-select> </mat-select>

View File

@ -44,7 +44,6 @@ export class CrawlerAuthComponent implements OnInit, OnChanges {
} }
ngOnChanges() { ngOnChanges() {
if (this.selectedCrawler === null) { return; }
this.getCrawlerAuthInputItems(); this.getCrawlerAuthInputItems();
} }

View File

@ -5,8 +5,10 @@ import 'rxjs/add/operator/map';
import { RPCService } from '@loafer/ng-rpc/service'; import { RPCService } from '@loafer/ng-rpc/service';
import { Domain } from '../../domain/model';
import { PageParams, Page } from 'app/commons/model'; import { PageParams, Page } from 'app/commons/model';
import { SensorItem } from 'packages/sensor-item/model/SensorItem';
import { Sensor } from '../model';
import { Domain } from 'packages/domain/model';
@Injectable() @Injectable()
@ -22,5 +24,7 @@ export class SensorService {
return this.rpcService.call('SensorService.readAllByDomain', domain, pageParams); return this.rpcService.call('SensorService.readAllByDomain', domain, pageParams);
} }
public regist(sensor: Sensor, sensorItems: SensorItem[]): Observable<Sensor> {
return null;
}
} }

View File

@ -2,29 +2,38 @@ import {
createSelector, createSelector,
createFeatureSelector, createFeatureSelector,
ActionReducerMap, ActionReducerMap,
} from '@ngrx/store'; } from '@ngrx/store';
import { StateSelector } from 'packages/core/ngrx/store'; import { StateSelector } from 'packages/core/ngrx/store';
import { MODULE } from '../sensor.constant'; import { MODULE } from '../sensor.constant';
import * as ReadAllByDomainStore from './list'; import * as ReadAllByDomainStore from './list';
import * as RegistStore from './regist';
export interface State { export interface State {
list: ReadAllByDomainStore.State; list: ReadAllByDomainStore.State;
} sensor: RegistStore.State;
}
export const REDUCERS = { export const REDUCERS = {
list: ReadAllByDomainStore.reducer, list: ReadAllByDomainStore.reducer,
}; sensor: RegistStore.reducer,
};
export const EFFECTS = [ export const EFFECTS = [
ReadAllByDomainStore.Effects, ReadAllByDomainStore.Effects,
]; RegistStore.Effects,
];
export const selectState = createFeatureSelector<State>(MODULE.name); export const sensorState = createFeatureSelector<State>(MODULE.name);
export const sensorListSelector = new StateSelector<ReadAllByDomainStore.State>(createSelector( export const sensorListSelector = new StateSelector<ReadAllByDomainStore.State>(createSelector(
selectState, sensorState,
(state: State) => state.list (state: State) => state.list
)); ));
export const sensorSelector = new StateSelector<RegistStore.State>(createSelector(
sensorState,
(state: State) => state.sensor
));

View File

@ -0,0 +1,4 @@
export * from './regist.action';
export * from './regist.effect';
export * from './regist.reducer';
export * from './regist.state';

View File

@ -0,0 +1,38 @@
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc/protocol';
import { Domain } from 'packages/domain/model';
import { PageParams, Page } from 'app/commons/model';
import { Sensor } from '../../model';
import { SensorItem } from 'packages/sensor-item/model/SensorItem';
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
;

View File

@ -0,0 +1,49 @@
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/protocol';
import { Sensor } from '../../model';
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.regist(payload.sensor, payload.sensorItems))
.map(list => {
return new RegistSuccess(list);
})
.catch((error: RPCClientError) => {
return of(new RegistFailure(error));
});
}

View File

@ -0,0 +1,45 @@
import {
Actions,
ActionType,
} from './regist.action';
import {
State,
initialState,
} from './regist.state';
import { Sensor } from '../../model';
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;
}
}
}

View File

@ -0,0 +1,16 @@
import { RPCClientError } from '@loafer/ng-rpc/protocol';
import { Page } from 'app/commons/model';
import { Sensor } from '../../model';
export interface State {
error: RPCClientError | null;
pending: boolean;
sensor: Sensor | null;
}
export const initialState: State = {
error: null,
pending: false,
sensor: null,
};

View File

@ -0,0 +1,4 @@
export * from './regist.action';
export * from './regist.effect';
export * from './regist.reducer';
export * from './regist.state';