Removed unnecessary services (#125)
They have been replaced with Store.
This commit is contained in:
committed by
József Farkas
parent
b16e83fc30
commit
a653333c9b
@@ -1,4 +1,8 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
||||
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
|
||||
import { Select2OptionData } from 'ng2-select2/ng2-select2';
|
||||
|
||||
@@ -7,29 +11,30 @@ import { Macro } from '../../../../config-serializer/config-items/Macro';
|
||||
|
||||
import { Tab } from '../tab';
|
||||
|
||||
import { UhkConfigurationService } from '../../../../services/uhk-configuration.service';
|
||||
import { AppState } from '../../../../store/index';
|
||||
import { getMacroEntities } from '../../../../store/reducers/macro';
|
||||
|
||||
@Component({
|
||||
selector: 'macro-tab',
|
||||
template: require('./macro-tab.component.html'),
|
||||
styles: [require('./macro-tab.component.scss')]
|
||||
})
|
||||
export class MacroTabComponent implements OnInit, Tab {
|
||||
export class MacroTabComponent implements OnInit, OnDestroy, Tab {
|
||||
@Input() defaultKeyAction: KeyAction;
|
||||
|
||||
private macros: Macro[];
|
||||
private macroOptions: Array<Select2OptionData>;
|
||||
private selectedMacroIndex: number;
|
||||
private subscription: Subscription;
|
||||
|
||||
constructor(private uhkConfigurationService: UhkConfigurationService) {
|
||||
this.macros = [];
|
||||
constructor(private store: Store<AppState>) {
|
||||
this.subscription = store.let(getMacroEntities())
|
||||
.subscribe((macros: Macro[]) => this.macros = macros);
|
||||
this.macroOptions = [];
|
||||
this.selectedMacroIndex = -1;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.macros = this.uhkConfigurationService.getUhkConfiguration().macros;
|
||||
|
||||
this.macroOptions.push({
|
||||
id: '-1',
|
||||
text: 'Select macro'
|
||||
@@ -72,4 +77,7 @@ export class MacroTabComponent implements OnInit, Tab {
|
||||
return keymapAction;
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
||||
import { Module } from '../../../config-serializer/config-items/Module';
|
||||
import { SvgModule } from '../module';
|
||||
|
||||
import { DataProviderService } from '../../../services/data-provider.service';
|
||||
|
||||
@Component({
|
||||
selector: 'svg-keyboard',
|
||||
template: require('./svg-keyboard.component.html'),
|
||||
@@ -18,13 +16,13 @@ export class SvgKeyboardComponent implements OnInit {
|
||||
private modules: SvgModule[];
|
||||
private svgAttributes: { viewBox: string, transform: string, fill: string };
|
||||
|
||||
constructor(private dps: DataProviderService) {
|
||||
constructor() {
|
||||
this.modules = [];
|
||||
this.svgAttributes = this.dps.getKeyboardSvgAttributes();
|
||||
this.svgAttributes = this.getKeyboardSvgAttributes();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.modules = this.dps.getSvgModules();
|
||||
this.modules = this.getSvgModules();
|
||||
}
|
||||
|
||||
onKeyClick(moduleId: number, keyId: number): void {
|
||||
@@ -43,4 +41,22 @@ export class SvgKeyboardComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
private getKeyboardSvgAttributes(): { viewBox: string, transform: string, fill: string } {
|
||||
let svg: any = this.getBaseLayer();
|
||||
return {
|
||||
viewBox: svg.$.viewBox,
|
||||
transform: svg.g[0].$.transform,
|
||||
fill: svg.g[0].$.fill
|
||||
};
|
||||
}
|
||||
|
||||
private getSvgModules(): SvgModule[] {
|
||||
let modules = this.getBaseLayer().g[0].g.map((obj: any) => new SvgModule(obj));
|
||||
return [modules[1], modules[0]]; // TODO: remove if the svg will be correct
|
||||
}
|
||||
|
||||
private getBaseLayer(): any {
|
||||
return require('xml!../../../../images/base-layer.svg').svg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { Component, Input, OnChanges, OnInit, SimpleChange } from '@angular/core';
|
||||
import {Component, Input, OnChanges, OnDestroy, OnInit, SimpleChange } from '@angular/core';
|
||||
|
||||
import { Store } from '@ngrx/store';
|
||||
|
||||
import { Subscription } from 'rxjs/Subscription';
|
||||
|
||||
import {
|
||||
KeyAction,
|
||||
@@ -10,10 +14,12 @@ import {
|
||||
SwitchLayerAction
|
||||
} from '../../../../config-serializer/config-items/key-action';
|
||||
import { KeyModifiers } from '../../../../config-serializer/config-items/KeyModifiers';
|
||||
import { UhkConfiguration } from '../../../../config-serializer/config-items/UhkConfiguration';
|
||||
import { Macro } from '../../../../config-serializer/config-items/Macro';
|
||||
|
||||
import { MapperService } from '../../../../services/mapper.service';
|
||||
import { UhkConfigurationService } from '../../../../services/uhk-configuration.service';
|
||||
|
||||
import { AppState } from '../../../../store/index';
|
||||
import { getMacroEntities } from '../../../../store/reducers/macro';
|
||||
|
||||
enum LabelTypes {
|
||||
KeystrokeKey,
|
||||
@@ -31,7 +37,7 @@ enum LabelTypes {
|
||||
template: require('./svg-keyboard-key.component.html'),
|
||||
styles: [require('./svg-keyboard-key.component.scss')]
|
||||
})
|
||||
export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
||||
export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
|
||||
@Input() id: string;
|
||||
@Input() rx: string;
|
||||
@Input() ry: string;
|
||||
@@ -46,8 +52,13 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
||||
|
||||
private labelSource: any;
|
||||
private labelType: LabelTypes;
|
||||
private macros: Macro[];
|
||||
private subscription: Subscription;
|
||||
|
||||
constructor(private mapperService: MapperService, private uhkConfigurationService: UhkConfigurationService) { }
|
||||
constructor(private mapperService: MapperService, private store: Store<AppState>) {
|
||||
this.subscription = store.let(getMacroEntities())
|
||||
.subscribe((macros: Macro[]) => this.macros = macros);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.setLabels();
|
||||
@@ -61,6 +72,10 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
||||
/* tslint:enable:no-string-literal */
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
|
||||
private setLabels(): void {
|
||||
if (!this.keyAction) {
|
||||
this.labelSource = undefined;
|
||||
@@ -150,11 +165,11 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
||||
this.labelSource = keyAction.keymapAbbreviation;
|
||||
} else if (this.keyAction instanceof PlayMacroAction) {
|
||||
let keyAction: PlayMacroAction = this.keyAction as PlayMacroAction;
|
||||
let macro: Macro = this.macros.find((macro: Macro) => macro.id === keyAction.macroId);
|
||||
this.labelType = LabelTypes.IconText;
|
||||
let uhkConfiguration: UhkConfiguration = this.uhkConfigurationService.getUhkConfiguration();
|
||||
this.labelSource = {
|
||||
icon: this.mapperService.getIcon('macro'),
|
||||
text: uhkConfiguration.getMacro(keyAction.macroId).name
|
||||
text: macro.name
|
||||
};
|
||||
} else if (this.keyAction instanceof MouseAction) {
|
||||
this.labelType = LabelTypes.MouseKey;
|
||||
@@ -162,7 +177,5 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
||||
} else {
|
||||
this.labelSource = undefined;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user