Merge remote-tracking branch 'origin/master'

This commit is contained in:
geek 2018-04-30 20:50:52 +09:00
commit 5bafb1243e
29 changed files with 418 additions and 195 deletions

View File

@ -15,7 +15,7 @@ const routes: Routes = [
{ path: 'sensor', loadChildren: './sensor/sensor-page.module#SensorPageModule' }, { path: 'sensor', loadChildren: './sensor/sensor-page.module#SensorPageModule' },
// { path: 'discovery', loadChildren: './discovery/discovery-page.module#DiscoveryPageModule' }, // { path: 'discovery', loadChildren: './discovery/discovery-page.module#DiscoveryPageModule' },
{ path: 'map', loadChildren: './infra/infra-page.module#InfraPageModule' }, { path: 'map', loadChildren: './infra/infra-page.module#InfraPageModule' },
// { path: 'target', loadChildren: './target/target-page.module#TargetPageModule' }, { path: 'target', loadChildren: './target/target-page.module#TargetPageModule' },
{ path: 'overview', loadChildren: './overview/overview-page.module#OverviewPageModule' }, { path: 'overview', loadChildren: './overview/overview-page.module#OverviewPageModule' },
{ path: 'dashboard', loadChildren: './dashboard/dashboard-page.module#DashboardPageModule' }, { path: 'dashboard', loadChildren: './dashboard/dashboard-page.module#DashboardPageModule' },
{ path: 'notification', loadChildren: './notification/notification-page.module#NotificationPageModule' }, { path: 'notification', loadChildren: './notification/notification-page.module#NotificationPageModule' },

View File

@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ListComponent as ProbeListComponent } from 'packages/probe/component/list/list.component';
import { TargetPageComponent } from 'app/pages/target/target-page.component';
import { DetailComponent as TargetDetailComponent } from 'packages/target/component/detail/detail.component';
const routes: Routes = [
{
path: '',
component: TargetPageComponent,
children: [
{ path: ':id/info', component: TargetDetailComponent }
]
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class TargetPageRoutingModule { }

View File

@ -0,0 +1,10 @@
<div class="ui-g">
<div class="ui-g-12">
<div class="card no-margin">
<of-tabbar [tabs]="tabs"></of-tabbar>
</div>
<div class="card no-margin">
<router-outlet></router-outlet>
</div>
</div>
</div>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TargetPageComponent } from './target-page.component';
describe('TargetsComponent', () => {
let component: TargetPageComponent;
let fixture: ComponentFixture<TargetPageComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ TargetPageComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TargetPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,25 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'of-pages-target',
templateUrl: './target-page.component.html',
})
export class TargetPageComponent implements OnInit {
tabs = undefined;
constructor(private router: Router) {
}
ngOnInit() {
const id = this.router.url.split('target/')[1].split('/')[0];
this.tabs = [
{ label: 'INFO', routerLink: ['/target/', id, 'info'] },
{ label: 'HISTORY', path: ['/target/', id, 'history'], disabled: true },
];
}
}

View File

@ -0,0 +1,22 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TargetModule } from 'packages/target/target.module';
import { TargetPageRoutingModule } from './target-page-routing.module';
import { TargetPageComponent } from './target-page.component';
import { PrimeNGModules } from 'packages/commons/prime-ng/prime-ng.module';
import { TabbarModule } from '../../commons/component/layout/tabbar/app.tabbar.module';
@NgModule({
imports: [
CommonModule,
TargetPageRoutingModule,
TargetModule,
PrimeNGModules,
TabbarModule
],
declarations: [
TargetPageComponent
]
})
export class TargetPageModule { }

View File

@ -4,12 +4,14 @@ import { CommonModule } from '@angular/common';
import { TargetModule } from 'packages/target/target.module'; import { TargetModule } from 'packages/target/target.module';
import { TargetsPageRoutingModule } from './targets-page-routing.module'; import { TargetsPageRoutingModule } from './targets-page-routing.module';
import { TargetsPageComponent } from './targets-page.component'; import { TargetsPageComponent } from './targets-page.component';
import { PrimeNGModules } from 'packages/commons/prime-ng/prime-ng.module';
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, CommonModule,
TargetsPageRoutingModule, TargetsPageRoutingModule,
TargetModule, TargetModule,
PrimeNGModules
], ],
declarations: [ declarations: [
TargetsPageComponent TargetsPageComponent

View File

@ -430,7 +430,7 @@ export class MapComponent implements OnInit, AfterContentInit {
if (nodeType === 'probe') { if (nodeType === 'probe') {
this.router.navigate(['probe', event.node.obj.id, 'info']); this.router.navigate(['probe', event.node.obj.id, 'info']);
} else if (nodeType === 'host' || nodeType === 'service') { } else if (nodeType === 'host' || nodeType === 'service') {
this.router.navigate(['sensors'], { queryParams: { target: event.node.obj.target.id } }); this.router.navigate(['target', event.node.obj.id, 'info']);
} else if (nodeType === 'sensor') { } else if (nodeType === 'sensor') {
this.router.navigate(['sensor', event.node.obj.id, 'info']); this.router.navigate(['sensor', event.node.obj.id, 'info']);
} }

View File

@ -36,7 +36,6 @@ export class NotificationComponent implements OnInit, AfterContentInit, OnDestro
this.notificationSubscription$ = this.notification$.subscribe( this.notificationSubscription$ = this.notification$.subscribe(
(page: Page) => { (page: Page) => {
if (page !== null) { if (page !== null) {
console.log(page);
this.notifications = page.content; this.notifications = page.content;
this.totalLength = page.totalElements; this.totalLength = page.totalElements;
} }

View File

@ -71,7 +71,8 @@ export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
} }
onTargetClick(target) { onTargetClick(target) {
this.router.navigate(['sensors'], { queryParams: { target: target.id } }); // this.router.navigate(['sensors'], { queryParams: { target: target.id } });
this.router.navigate(['target', target.id, 'info']);
} }
} }

View File

@ -1,14 +0,0 @@
.example-container {
display: flex;
flex-direction: column;
min-width: 300px;
}
.mat-table {
overflow: auto;
max-height: 500px;
}
.mat-header-cell.mat-sort-header-sorted {
color: black;
}

View File

@ -22,7 +22,6 @@ import { Subscription } from 'rxjs/Subscription';
@Component({ @Component({
selector: 'of-sensor-list', selector: 'of-sensor-list',
templateUrl: './list.component.html', templateUrl: './list.component.html',
styleUrls: ['./list.component.scss']
}) })
export class ListComponent implements OnInit, AfterContentInit, OnDestroy { export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
@ -32,9 +31,6 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
totalLength = 0; totalLength = 0;
sensorSettingDisplay = false; sensorSettingDisplay = false;
paramTarget?: Infra = null;
infra$ = this.infraDetailStore.pipe(select(InfraDetailSelector.select('infra')));
sensors: Sensor[]; sensors: Sensor[];
target: Target = null; target: Target = null;
targetSensor; targetSensor;
@ -49,19 +45,9 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
private router: Router, private router: Router,
private route: ActivatedRoute, private route: ActivatedRoute,
private store: Store<ListStore.State>, private store: Store<ListStore.State>,
private infraDetailStore: Store<InfraDetailStore.State>,
) { } ) { }
ngOnInit() { ngOnInit() {
let infraID = null;
this.route.queryParams.subscribe((queryParams: any) => {
infraID = queryParams.target;
if (infraID) {
this.getInfraInfo(infraID);
} else {
this.paramTarget = null;
}
});
this.sensorsSubscription$ = this.sensorList$.subscribe( this.sensorsSubscription$ = this.sensorList$.subscribe(
(page: Page) => { (page: Page) => {
@ -76,33 +62,16 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
); );
} }
ngAfterContentInit() {
this.getSensors(0);
}
ngOnDestroy() { ngOnDestroy() {
if (this.sensorsSubscription$) { if (this.sensorsSubscription$) {
this.sensorsSubscription$.unsubscribe(); this.sensorsSubscription$.unsubscribe();
} }
} }
getInfraInfo(infraID: string) {
this.infraDetailStore.dispatch(
new InfraDetailStore.Read(
{ id: infraID }
)
);
this.infra$.subscribe(
(infra: Infra) => {
console.log(infra);
this.paramTarget = infra;
},
(error: RPCClientError) => {
console.log(error.response.message);
}
);
}
ngAfterContentInit() {
this.getSensors(0);
}
getSensors(pageIndex: number) { getSensors(pageIndex: number) {
this.store.select(AuthSelector.select('domain')).subscribe( this.store.select(AuthSelector.select('domain')).subscribe(
@ -113,7 +82,6 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
sortCol: 'id', sortCol: 'id',
sortDirection: 'descending' sortDirection: 'descending'
}; };
this.store.dispatch(new ListStore.ReadAllByDomain({ domain, pageParams })); this.store.dispatch(new ListStore.ReadAllByDomain({ domain, pageParams }));
}, },
(error) => { (error) => {
@ -145,6 +113,7 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
this.generateTargetFilter(); this.generateTargetFilter();
} }
generateTargetFilter() { generateTargetFilter() {
if (this.targetOptions) { if (this.targetOptions) {
return; return;

View File

@ -11,4 +11,5 @@ export interface Sensor {
crawler?: MetaCrawler; crawler?: MetaCrawler;
crawlerInputItems?: string; crawlerInputItems?: string;
itemCount?: number; itemCount?: number;
displayName?: string;
} }

View File

@ -1 +1,75 @@
<div>target detail</div> <div *ngIf="infra">
<div *ngIf="infra.infraType.name == 'HOST'">
<button pButton type="button" label="Traceroute" (click)="onTraceroute()"></button>
</div>
<div class="ui-g">
<div class="ui-g-12">
<div class="ui-inputgroup">
<span class="md-inputfield">
<input #input type="text" pInputText value="{{infra.target.displayName}}" (keypress)="onDisplayNameChangeKeypress($event, input.value)">
<label></label>
</span>
<button pButton label="Save" type="button" (click)="onDisplayNameChange(input.value)"></button>
</div>
<p-panel [showHeader]="false">
<div class="ui-key-value">
<span>Status</span>
<span class="ng-star-inserted">
<i class="fa ui-icon-stop ui-status-icon ui-status-success"></i>Up</span>
</div>
<of-key-value [key]="'Description'" [value]="infra.target.description" class="ui-key-value"></of-key-value>
<of-key-value [key]="'Type'" [value]="infra.infraType.name" class="ui-key-value"></of-key-value>
<of-key-value [key]="'Created at'" [value]="infra.createDate | date: 'dd/MM/yyyy'" class="ui-key-value"></of-key-value>
<of-key-value [key]="'Sensors'" [value]="infra.target.sensorCount" class="ui-key-value"></of-key-value>
</p-panel>
</div>
</div>
<div class="ui-g">
<div class="ui-g-12">
<div class="ui-g">
<div class="ui-g-12 ui-md-5 ui-g-nopad">
<p-dialog [modal]="true" [width]="800" [(visible)]="sensorSettingDisplay" [showHeader]="false" [closeOnEscape]="false">
<of-sensor-setting [visible]="sensorSettingDisplay" [preTarget]="infra.target" (close)="onSensorSettingClose()"></of-sensor-setting>
</p-dialog>
<button type="button" label="Add Sensor" icon="ui-icon-add" pButton class="ui-button-large ui-button-width-fit" (click)="onAddSensor()"></button>
</div>
<div class="ui-g-12 ui-md-7 ui-g-nopad">
<div style="float: right; margin-top: 30px;">
<i class="fa ui-icon-stop ui-status-icon ui-status-success"></i>Up
<i class="fa ui-icon-stop ui-status-icon ui-status-fatal"></i>Down
<i class="fa ui-icon-stop ui-status-icon ui-status-warn"></i>Warn
<i class="fa ui-icon-stop ui-status-icon ui-status-error"></i>Error
</div>
</div>
</div>
<p-table [value]="sensors" selectionMode="single" (onRowSelect)="onRowSelect($event)" [resizableColumns]="true">
<ng-template pTemplate="header">
<tr>
<th>Alias</th>
<th>Status</th>
<th>Crawler</th>
<th>Items</th>
<th>Created at</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-sensor>
<tr [pSelectableRow]="sensor">
<td>{{sensor.displayName}}</td>
<td>{{sensor.status.name}}</td>
<td>{{sensor.crawler.name}}</td>
<td>{{sensor.itemCount}}</td>
<td>{{sensor.createDate | date: 'dd.MM.yyyy'}}</td>
</tr>
</ng-template>
</p-table>
<p-paginator [rows]="pageSize" [totalRecords]="sensorsCount" (onPageChange)="onPaging($event)"></p-paginator>
</div>
</div>
</div>

View File

@ -1,37 +0,0 @@
.table {
width: 100%;
max-width: 100%;
border-collapse: collapse;
}
.table tr:first-child td {
border-top: none;
}
.text-right {
text-align: right;
}
th, td {
padding: 8px;
text-align: left;
border-top: 1px solid #ddd;
}
.nav-item {
transition: all 0.6s cubic-bezier(0.165, 0.84, 0.44, 1);
cursor: default;
&:hover {
transform: translate(0, -8px);
box-shadow: 0 20px 20px rgba(0, 0, 0, .16)
}
}
.example-container {
display: flex;
flex-direction: column;
min-width: 300px;
}
.mat-table {
overflow: auto;
max-height: 500px;
}

View File

@ -1,28 +1,156 @@
import { Component, ViewChild, OnInit, Input, AfterContentInit } from '@angular/core'; import { Component, ViewChild, OnInit, Input, AfterContentInit, OnDestroy } from '@angular/core';
import { Router } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { Sensor } from 'packages/sensor/model'; import { Sensor } from 'packages/sensor/model';
import { Infra } from 'packages/infra/model';
import { Store, select } from '@ngrx/store';
import { DetailSelector as InfraDetailSelector } from 'packages/infra/store';
import * as InfraDetailStore from 'packages/infra/store/detail';
import { Subscription } from 'rxjs/Subscription';
import { RPCClientError } from '@loafer/ng-rpc/protocol';
import { sensorListSelector } from 'packages/sensor/store';
import * as SensorListStore from 'packages/sensor/store/list';
import { PageParams, Page } from 'app/commons/model';
// import { target } from 'packages/target/store';
// import * as SensorListStore from 'packages/sensor/store/list';
@Component({ @Component({
selector: 'of-target-detail', selector: 'of-target-detail',
templateUrl: './detail.component.html', templateUrl: './detail.component.html',
}) })
export class DetailComponent implements OnInit, AfterContentInit { export class DetailComponent implements OnInit, AfterContentInit, OnDestroy {
constructor(private router: Router) { } infraSubscription$: Subscription;
infra$ = this.infraDetailStore.pipe(select(InfraDetailSelector.select('infra')));
sensorsSubscription$: Subscription;
sensors$ = this.sensorListStore.pipe(select(sensorListSelector.select('page')));
targetSubscription$: Subscription;
infraId = null;
infra: Infra;
sensors: Sensor[];
sensorsCount = 0;
sensorSettingDisplay = false;
pageSize = '10';
totalLength = 0;
currPage = 0;
constructor(
private router: Router,
private route: ActivatedRoute,
private infraDetailStore: Store<InfraDetailStore.State>,
private sensorListStore: Store<SensorListStore.State>
) { }
ngOnInit() { ngOnInit() {
this.infraSubscription$ = this.infra$.subscribe(
(infra: Infra) => {
this.infra = infra;
},
(error: RPCClientError) => {
console.log(error.response.message);
}
);
this.sensorsSubscription$ = this.sensors$.subscribe(
(page: Page) => {
if (page) {
this.sensorsCount = page.totalElements;
this.sensors = page.content;
}
},
(error: RPCClientError) => {
console.log(error.response.message);
}
);
} }
ngAfterContentInit() { ngAfterContentInit() {
this.infraId = this.route.snapshot.paramMap.get('id');
this.getInfra();
this.getSensors(this.currPage);
} }
handleSensorClick(sensor: Sensor) { ngOnDestroy() {
if (this.infraSubscription$) {
this.infraSubscription$.unsubscribe();
}
} }
handleCheckAlive() { getInfra() {
this.infraDetailStore.dispatch(
new InfraDetailStore.Read(
{ id: this.infraId }
)
);
} }
handleTraceroute() { getSensors(pageIndex) {
const pageParams: PageParams = {
pageNo: pageIndex + '',
countPerPage: this.pageSize,
sortCol: 'id',
sortDirection: 'descending'
};
this.sensorListStore.dispatch(
new SensorListStore.ReadAllByInfra(
{ id: this.infraId, pageParams: pageParams }
)
);
}
onAddSensor() {
this.sensorSettingDisplay = true;
}
onSensorSettingClose() {
this.sensorSettingDisplay = false;
}
onPaging(e) {
this.getSensors(e.page);
}
onRowSelect(event) {
this.router.navigate(['sensor', event.data.id, 'info']);
}
onTraceroute() {
alert('지원 예정');
}
onDisplayNameChange(value: string) {
console.log(value);
// if (value === this.probe.displayName) {
// return;
// }
// this.probe.displayName = value;
// this.modifyStore.dispatch(
// new ModifyStore.Modify(this.probe)
// );
// const modifySuccessSubscription$: Subscription = this.modifySuccess$.subscribe(
// (probe: Probe) => {
// if (probe) {
// this.msgs = [];
// this.msgs.push({ severity: 'success', summary: 'Succeed', detail: 'Probe name has changed.' });
// }
// if (modifySuccessSubscription$) {
// modifySuccessSubscription$.unsubscribe();
// }
// },
// (error: RPCClientError) => {
// console.log(error.response.message);
// }
// );
}
onDisplayNameChangeKeypress(event, value) {
if (event.key === 'Enter') {
this.onDisplayNameChange(value);
} }
} }
}

View File

@ -14,18 +14,20 @@
</ng-template> </ng-template>
<ng-template pTemplate="body" let-infra let-rowIndex="rowIndex"> <ng-template pTemplate="body" let-infra let-rowIndex="rowIndex">
<tr [pSelectableRow]="infra"> <tr [pSelectableRow]="infra">
<td>{{rowIndex}}</td> <td>{{rowIndex + 1}}</td>
<td>??</td> <td>??</td>
<td>{{infra.infraType.name}}</td> <td>{{infra.infraType.name}}</td>
<td>{{infra.target.displayName}}</td> <td>{{infra.target.displayName}}</td>
<td>??</td> <td>{{infra.target.sensorCount}}</td>
<td>{{infra.createDate | date: 'dd.MM.yyyy'}}</td> <td>{{infra.createDate | date: 'dd.MM.yyyy'}}</td>
<td> <td>
<!-- <button type="button" label="Add Sensor" icon="ui-icon-add" pButton class="ui-s-button" (click)="onAddSensor(infra.target)"></button> --> <button type="button" label="Add Sensor" icon="ui-icon-add" pButton class="ui-s-button" (click)="onAddSensor(infra.target)"></button>
</td> </td>
</tr> </tr>
</ng-template> </ng-template>
</p-table> </p-table>
<p-paginator [rows]="pageSize" [totalRecords]="totalLength" (onPageChange)="onPaging($event)"></p-paginator>
<p-dialog [modal]="true" [width]="800" [(visible)]="sensorSettingDisplay" [showHeader]="false" [closeOnEscape]="false"> <p-dialog [modal]="true" [width]="800" [(visible)]="sensorSettingDisplay" [showHeader]="false" [closeOnEscape]="false">
<of-sensor-setting [visible]="sensorSettingDisplay" [preTarget]="target" (close)="onSensorSettingClose()"></of-sensor-setting> <of-sensor-setting [visible]="sensorSettingDisplay" [preTarget]="target" (close)="onSensorSettingClose()"></of-sensor-setting>

View File

@ -27,6 +27,10 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
target: Target = null; target: Target = null;
sensorSettingDisplay = false; sensorSettingDisplay = false;
pageSize = '10';
totalLength = 0;
currPage = 0;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router, private router: Router,
@ -40,6 +44,7 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
if (!page) { if (!page) {
return; return;
} }
this.totalLength = page.totalElements;
this.infras = page.content; this.infras = page.content;
}, },
(error: RPCClientError) => { (error: RPCClientError) => {
@ -50,10 +55,10 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
ngAfterContentInit() { ngAfterContentInit() {
this.route.params.subscribe((params: any) => { this.route.params.subscribe((params: any) => {
const probe = { this.probe = {
id: params['id'], id: params['id'],
}; };
this.getInfras(probe); this.getInfras(0);
}); });
} }
@ -63,22 +68,23 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
} }
} }
getInfras(probe) { getInfras(pageNo) {
const pageParams: PageParams = { const pageParams: PageParams = {
pageNo: '0', pageNo: pageNo + '',
countPerPage: '10', countPerPage: this.pageSize,
sortCol: 'id', sortCol: 'id',
sortDirection: 'descending' sortDirection: 'descending'
}; };
this.infraListStore.dispatch( this.infraListStore.dispatch(
new InfraListStore.ReadAllByProbe( new InfraListStore.ReadAllByProbe(
{ probe, pageParams } { probe: this.probe, pageParams: pageParams }
) )
); );
} }
onRowSelect(event) { onRowSelect(event) {
this.router.navigate(['sensors'], { queryParams: { target: event.data.id } }); // this.router.navigate(['target'], { queryParams: { target: event.data.id } });
this.router.navigate(['target', event.data.id, 'info']);
} }
onAddSensor(target: Target) { onAddSensor(target: Target) {
@ -90,4 +96,8 @@ export class ListComponent implements OnInit, AfterContentInit, OnDestroy {
this.sensorSettingDisplay = false; this.sensorSettingDisplay = false;
} }
onPaging(e) {
this.getInfras(e.page);
}
} }

View File

@ -7,5 +7,6 @@ export interface Target {
createDate?: Date; createDate?: Date;
displayName?: string; displayName?: string;
description?: string; description?: string;
sensorCount?: number;
sensors?: Sensor[]; sensors?: Sensor[];
} }

View File

@ -6,7 +6,6 @@ import 'rxjs/add/operator/map';
import { RPCService } from '@loafer/ng-rpc/service'; import { RPCService } from '@loafer/ng-rpc/service';
import { Target } from '../model'; import { Target } from '../model';
import { Domain } from '../../domain/model';
@Injectable() @Injectable()
@ -18,21 +17,8 @@ export class TargetService {
} }
public readAllByDomain(domain: Domain): Observable<Target[]> { public modify(target: Target): Observable<Target> {
const body = { return this.rpcService.call('TargetService.modify', target);
domain: domain,
};
return this.rpcService.call('TargetService.readAllByDomain', domain);
} }
// public readAllByProbe(domain: Domain): Observable<Target[]> {
// const body = {
// domain: domain,
// };
// return this.rpcService.call('TargetService.readAllByDomain', domain);
// }
} }

View File

@ -8,23 +8,23 @@ import {
import { MODULE } from '../target.constant'; import { MODULE } from '../target.constant';
import * as TargetStore from './target'; import * as TargetModifyStore from './modify';
export interface State { export interface State {
readallbydomain: TargetStore.State; modify: TargetModifyStore.State;
} }
export const REDUCERS = { export const REDUCERS = {
readallbydomain: TargetStore.reducer, modify: TargetModifyStore.reducer,
}; };
export const EFFECTS = [ export const EFFECTS = [
TargetStore.Effects, TargetModifyStore.Effects,
]; ];
export const selectTargetState = createFeatureSelector<State>(MODULE.name); export const selectTargetState = createFeatureSelector<State>(MODULE.name);
export const ReadAllByDomainSelector = new StateSelector<TargetStore.State>(createSelector( export const ReadAllByDomainSelector = new StateSelector<TargetModifyStore.State>(createSelector(
selectTargetState, selectTargetState,
(state: State) => state.readallbydomain (state: State) => state.modify
)); ));

View File

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

View File

@ -0,0 +1,35 @@
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc/protocol';
import { Target } from '../../model';
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
;

View File

@ -1,6 +1,6 @@
import { TestBed, inject } from '@angular/core/testing'; import { TestBed, inject } from '@angular/core/testing';
import { Effects } from './target.effect'; import { Effects } from './modify.effect';
describe('Target.Effects', () => { describe('Target.Effects', () => {
beforeEach(() => { beforeEach(() => {

View File

@ -17,11 +17,11 @@ import { Target } from '../../model';
import { TargetService } from '../../service/target.service'; import { TargetService } from '../../service/target.service';
import { import {
ReadAllByDomain, Modify,
ReadAllByDomainSuccess, ModifySuccess,
ReadAllByDomainFailure, ModifyFailure,
ActionType, ActionType,
} from './target.action'; } from './modify.action';
@Injectable() @Injectable()
export class Effects { export class Effects {
@ -33,14 +33,13 @@ export class Effects {
) { } ) { }
@Effect() @Effect()
readAllByMember$: Observable<Action> = this.actions$ modify$: Observable<Action> = this.actions$
.ofType(ActionType.ReadAllByDomain) .ofType(ActionType.Modify)
.map((action: ReadAllByDomain) => action.payload) .map((action: Modify) => action.payload)
.exhaustMap(domain => .exhaustMap(target =>
this.targetService this.targetService.modify(target)
.readAllByDomain(domain) .map(targets => new ModifySuccess(targets))
.map(targets => new ReadAllByDomainSuccess(targets)) .catch(error => of(new ModifyFailure(error)))
.catch(error => of(new ReadAllByDomainFailure(error)))
); );
} }

View File

@ -1,18 +1,18 @@
import { import {
Actions, Actions,
ActionType, ActionType,
} from './target.action'; } from './modify.action';
import { import {
State, State,
initialState, initialState,
} from './target.state'; } from './modify.state';
import { Target } from '../../model'; import { Target } from '../../model';
export function reducer(state = initialState, action: Actions): State { export function reducer(state = initialState, action: Actions): State {
switch (action.type) { switch (action.type) {
case ActionType.ReadAllByDomain: { case ActionType.Modify: {
return { return {
...state, ...state,
error: null, error: null,
@ -20,21 +20,21 @@ import {
}; };
} }
case ActionType.ReadAllByDomainSuccess: { case ActionType.ModifySuccess: {
return { return {
...state, ...state,
error: null, error: null,
pending: false, pending: false,
targets: action.payload target: action.payload
}; };
} }
case ActionType.ReadAllByDomainFailure: { case ActionType.ModifyFailure: {
return { return {
...state, ...state,
error: action.payload, error: action.payload,
pending: false, pending: false,
targets: null, target: null,
}; };
} }

View File

@ -1,15 +1,14 @@
import { RPCClientError } from '@loafer/ng-rpc/protocol'; import { RPCClientError } from '@loafer/ng-rpc/protocol';
import { Target } from '../../model'; import { Target } from '../../model';
export interface State { export interface State {
error: RPCClientError | null; error: RPCClientError | null;
pending: boolean; pending: boolean;
targets: Target[] | null; target: Target | null;
} }
export const initialState: State = { export const initialState: State = {
error: null, error: null,
pending: false, pending: false,
targets: null, target: null,
}; };

View File

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

View File

@ -1,36 +0,0 @@
import { Action } from '@ngrx/store';
import { RPCClientError } from '@loafer/ng-rpc/protocol';
import { Target } from '../../model';
import { Domain } from '../../../domain/model';
export enum ActionType {
ReadAllByDomain = '[Target.ReadAllByDomain] ReadAllByDomain',
ReadAllByDomainSuccess = '[Target.ReadAllByDomainSuccess] ReadAllByDomainSuccess',
ReadAllByDomainFailure = '[Target.ReadAllByDomainFailure] ReadAllByDomainFailure',
}
export class ReadAllByDomain implements Action {
readonly type = ActionType.ReadAllByDomain;
constructor(public payload: Domain) {}
}
export class ReadAllByDomainSuccess implements Action {
readonly type = ActionType.ReadAllByDomainSuccess;
constructor(public payload: Target[]) {}
}
export class ReadAllByDomainFailure implements Action {
readonly type = ActionType.ReadAllByDomainFailure;
constructor(public payload: RPCClientError) {}
}
export type Actions =
| ReadAllByDomain
| ReadAllByDomainSuccess
| ReadAllByDomainFailure
;