Save config on shortcuts (#386)

Closes #383
This commit is contained in:
József Farkas
2017-08-12 02:23:53 +02:00
committed by László Monda
parent 49ec48c9e9
commit 4193cd0d1e

View File

@@ -2,9 +2,13 @@ import { Component, ViewEncapsulation, HostListener } from '@angular/core';
import { Router } from '@angular/router';
import { Store } from '@ngrx/store';
import { saveAs } from 'file-saver';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/first';
import 'rxjs/add/operator/ignoreElements';
import 'rxjs/add/operator/let';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/takeWhile';
import { AppState } from '../shared/store';
@@ -42,6 +46,35 @@ export class MainAppComponent {
this.sendUserConfiguration();
}
@HostListener('window:keydown.alt.j', ['$event'])
onAltJ(event: KeyboardEvent): void {
event.preventDefault();
event.stopPropagation();
this.store
.let(getUserConfiguration())
.first()
.subscribe(userConfiguration => {
const asString = JSON.stringify(userConfiguration.toJsonObject());
const asBlob = new Blob([asString], { type: 'text/plain' });
saveAs(asBlob, 'UserConfiguration.json');
});
}
@HostListener('window:keydown.alt.b', ['$event'])
onAltB(event: KeyboardEvent): void {
event.preventDefault();
event.stopPropagation();
this.store
.let(getUserConfiguration())
.first()
.map(userConfiguration => {
const uhkBuffer = new UhkBuffer();
userConfiguration.toBinary(uhkBuffer);
return new Blob([uhkBuffer.getBufferContent()]);
})
.subscribe(blob => saveAs(blob, 'UserConfiguration.bin'));
}
private sendUserConfiguration(): void {
this.store
.let(getUserConfiguration())