This commit is contained in:
crusader 2018-10-11 00:13:25 +09:00
parent a8422cad14
commit d98827fbba
6 changed files with 63 additions and 4 deletions

View File

@ -35,9 +35,9 @@
<p-dialog header="Export as CSV" [(visible)]="displayExportCSV" [modal]="true" [responsive]="true" [width]="350" <p-dialog header="Export as CSV" [(visible)]="displayExportCSV" [modal]="true" [responsive]="true" [width]="350"
[minWidth]="200" [minY]="70" [closable]="false"> [minWidth]="200" [minY]="70" [closable]="false">
<app-menu-export-csv></app-menu-export-csv> <app-menu-export-csv #exportCSV></app-menu-export-csv>
<p-footer> <p-footer>
<button type="button" pButton icon="pi pi-check" (click)="displayExportCSV=false" label="Yes"></button> <button type="button" pButton icon="pi pi-check" (click)="exportCSV.export(); displayExportCSV=false;" label="Yes"></button>
<button type="button" pButton icon="pi pi-close" (click)="displayExportCSV=false" label="No" class="ui-button-secondary"></button> <button type="button" pButton icon="pi pi-close" (click)="displayExportCSV=false" label="No" class="ui-button-secondary"></button>
</p-footer> </p-footer>
</p-dialog> </p-dialog>

View File

@ -1,15 +1,51 @@
import { Component, } from '@angular/core'; import { Component, OnInit, AfterContentInit, OnDestroy, } from '@angular/core';
import { Store, select } from '@ngrx/store';
import { take } from 'rxjs/operators';
import * as AppStore from '../../store';
import { TargetDisplayType } from '../../core/type';
const { saveSvgAsPng, svgAsDataUri } = require('save-svg-as-png');
@Component({ @Component({
selector: 'app-menu-export-csv', selector: 'app-menu-export-csv',
templateUrl: './export-csv.component.html', templateUrl: './export-csv.component.html',
styleUrls: ['./export-csv.component.scss'], styleUrls: ['./export-csv.component.scss'],
}) })
export class ExportCSVComponent { export class ExportCSVComponent implements OnInit, AfterContentInit, OnDestroy {
constructor( constructor(
private store: Store<any>,
) { ) {
} }
ngOnInit(): void {
}
ngAfterContentInit(): void {
}
ngOnDestroy(): void {
}
export() {
this.store.pipe(
take(1),
select((state) => {
const targetDisplayType = AppStore.TargetSelector.TargetSelector.selectTargetDisplayType(state);
const targetDisplayElementRef = AppStore.TargetSelector.TargetSelector.selectTargetDisplayElementRef(state);
if (TargetDisplayType.MAP !== targetDisplayType) {
return;
}
// svgAsDataUri(targetDisplayElementRef.nativeElement, {}, function (uri) {
// console.log(`uri: ${uri}`);
// });
saveSvgAsPng(targetDisplayElementRef.nativeElement, 'diagram.png', { backgroundColor: '#ffffff' });
}),
).subscribe();
}
} }

View File

@ -106,6 +106,7 @@ export class MapComponent implements OnInit, AfterContentInit, OnDestroy {
@ViewChild('displayTarget') set displayTarget(content: ElementRef) { @ViewChild('displayTarget') set displayTarget(content: ElementRef) {
this.displayTargetRef = content; this.displayTargetRef = content;
this.store.dispatch(new TargetStore.ChangeTargetDisplayElementRef({ targetDisplayElementRef: content }));
} }
private displayTargetRef: ElementRef; private displayTargetRef: ElementRef;
@ -260,6 +261,8 @@ export class MapComponent implements OnInit, AfterContentInit, OnDestroy {
} }
ngOnDestroy(): void { ngOnDestroy(): void {
this.store.dispatch(new TargetStore.ChangeTargetDisplayElementRef({ targetDisplayElementRef: null }));
if (null !== this.targetSubscription) { if (null !== this.targetSubscription) {
this.targetSubscription.unsubscribe(); this.targetSubscription.unsubscribe();
} }

View File

@ -1,3 +1,4 @@
import { ElementRef } from '@angular/core';
import { Action } from '@ngrx/store'; import { Action } from '@ngrx/store';
import { Host, Port, Service } from '@overflow/model/discovery'; import { Host, Port, Service } from '@overflow/model/discovery';
import { TargetDisplayType } from '../../../core/type'; import { TargetDisplayType } from '../../../core/type';
@ -10,6 +11,7 @@ export enum ActionType {
ChangeTargetDisplayType = '[app.target] ChangeTargetDisplayType', ChangeTargetDisplayType = '[app.target] ChangeTargetDisplayType',
RefreshTargetDisplay = '[app.target] RefreshTargetDisplay', RefreshTargetDisplay = '[app.target] RefreshTargetDisplay',
ChangeSelectedTarget = '[app.target] ChangeSelectedTarget', ChangeSelectedTarget = '[app.target] ChangeSelectedTarget',
ChangeTargetDisplayElementRef = '[app.target] ChangeTargetDisplayElementRef',
} }
export class SetHosts implements Action { export class SetHosts implements Action {
@ -48,6 +50,12 @@ export class ChangeSelectedTarget implements Action {
constructor(public payload: { group: string, target: Host | Port | Service }) { } constructor(public payload: { group: string, target: Host | Port | Service }) { }
} }
export class ChangeTargetDisplayElementRef implements Action {
readonly type = ActionType.ChangeTargetDisplayElementRef;
constructor(public payload: { targetDisplayElementRef: ElementRef }) { }
}
export type Actions = export type Actions =
| SetHosts | SetHosts
| SetPorts | SetPorts
@ -55,5 +63,6 @@ export type Actions =
| ChangeTargetDisplayType | ChangeTargetDisplayType
| RefreshTargetDisplay | RefreshTargetDisplay
| ChangeSelectedTarget | ChangeSelectedTarget
| ChangeTargetDisplayElementRef
; ;

View File

@ -52,6 +52,13 @@ export function reducer(state: State = initialState, action: Actions): State {
}; };
} }
case ActionType.ChangeTargetDisplayElementRef: {
return {
...state,
targetDisplayElementRef: action.payload.targetDisplayElementRef,
};
}
default: { default: {
return state; return state;
} }

View File

@ -1,3 +1,4 @@
import { ElementRef } from '@angular/core';
import { Selector, createSelector } from '@ngrx/store'; import { Selector, createSelector } from '@ngrx/store';
import { Host, Port, Service } from '@overflow/model/discovery'; import { Host, Port, Service } from '@overflow/model/discovery';
import { TargetDisplayType } from '../../../core/type'; import { TargetDisplayType } from '../../../core/type';
@ -13,6 +14,7 @@ export interface State {
group: string; group: string;
target: Host | Port | Service; target: Host | Port | Service;
} | null; } | null;
targetDisplayElementRef: ElementRef;
} }
export const initialState: State = { export const initialState: State = {
@ -23,6 +25,7 @@ export const initialState: State = {
targetDisplayType: TargetDisplayType.NONE, targetDisplayType: TargetDisplayType.NONE,
refreshTargetDisplay: false, refreshTargetDisplay: false,
selectedTarget: null, selectedTarget: null,
targetDisplayElementRef: null,
}; };
export function getSelectors<S>(selector: Selector<any, State>) { export function getSelectors<S>(selector: Selector<any, State>) {
@ -33,5 +36,6 @@ export function getSelectors<S>(selector: Selector<any, State>) {
selectTargetDisplayType: createSelector(selector, (state: State) => state.targetDisplayType), selectTargetDisplayType: createSelector(selector, (state: State) => state.targetDisplayType),
selectRefreshTargetDisplay: createSelector(selector, (state: State) => state.refreshTargetDisplay), selectRefreshTargetDisplay: createSelector(selector, (state: State) => state.refreshTargetDisplay),
selectSelectedTarget: createSelector(selector, (state: State) => state.selectedTarget), selectSelectedTarget: createSelector(selector, (state: State) => state.selectedTarget),
selectTargetDisplayElementRef: createSelector(selector, (state: State) => state.targetDisplayElementRef),
}; };
} }