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
-5
@@ -58,16 +58,14 @@ import { SvgModuleComponent } from './components/svg/module';
|
|||||||
import { SvgKeyboardWrapComponent } from './components/svg/wrap';
|
import { SvgKeyboardWrapComponent } from './components/svg/wrap';
|
||||||
import { MainAppComponent, appRoutingProviders, routing } from './main-app';
|
import { MainAppComponent, appRoutingProviders, routing } from './main-app';
|
||||||
|
|
||||||
import { DataProviderService } from './services/data-provider.service';
|
|
||||||
import { MapperService } from './services/mapper.service';
|
import { MapperService } from './services/mapper.service';
|
||||||
import { UhkConfigurationService } from './services/uhk-configuration.service';
|
|
||||||
|
|
||||||
import { KeymapEffects, MacroEffects } from './store/effects';
|
import { KeymapEffects, MacroEffects } from './store/effects';
|
||||||
import { keymapReducer, macroReducer, presetReducer } from './store/reducers';
|
import { keymapReducer, macroReducer, presetReducer } from './store/reducers';
|
||||||
import { DataStorage } from './store/storage';
|
import { DataStorage } from './store/storage';
|
||||||
|
|
||||||
// Create DataStorage dependency injection
|
// Create DataStorage dependency injection
|
||||||
const storageProvider = ReflectiveInjector.resolve([DataStorage, DataProviderService]);
|
const storageProvider = ReflectiveInjector.resolve([DataStorage]);
|
||||||
const storageInjector = ReflectiveInjector.fromResolvedProviders(storageProvider);
|
const storageInjector = ReflectiveInjector.fromResolvedProviders(storageProvider);
|
||||||
const storageService: DataStorage = storageInjector.get(DataStorage);
|
const storageService: DataStorage = storageInjector.get(DataStorage);
|
||||||
|
|
||||||
@@ -143,8 +141,6 @@ const storeConfig = {
|
|||||||
EffectsModule.runAfterBootstrap(MacroEffects)
|
EffectsModule.runAfterBootstrap(MacroEffects)
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
DataProviderService,
|
|
||||||
UhkConfigurationService,
|
|
||||||
MapperService,
|
MapperService,
|
||||||
appRoutingProviders
|
appRoutingProviders
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -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';
|
import { Select2OptionData } from 'ng2-select2/ng2-select2';
|
||||||
|
|
||||||
@@ -7,29 +11,30 @@ import { Macro } from '../../../../config-serializer/config-items/Macro';
|
|||||||
|
|
||||||
import { Tab } from '../tab';
|
import { Tab } from '../tab';
|
||||||
|
|
||||||
import { UhkConfigurationService } from '../../../../services/uhk-configuration.service';
|
import { AppState } from '../../../../store/index';
|
||||||
|
import { getMacroEntities } from '../../../../store/reducers/macro';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'macro-tab',
|
selector: 'macro-tab',
|
||||||
template: require('./macro-tab.component.html'),
|
template: require('./macro-tab.component.html'),
|
||||||
styles: [require('./macro-tab.component.scss')]
|
styles: [require('./macro-tab.component.scss')]
|
||||||
})
|
})
|
||||||
export class MacroTabComponent implements OnInit, Tab {
|
export class MacroTabComponent implements OnInit, OnDestroy, Tab {
|
||||||
@Input() defaultKeyAction: KeyAction;
|
@Input() defaultKeyAction: KeyAction;
|
||||||
|
|
||||||
private macros: Macro[];
|
private macros: Macro[];
|
||||||
private macroOptions: Array<Select2OptionData>;
|
private macroOptions: Array<Select2OptionData>;
|
||||||
private selectedMacroIndex: number;
|
private selectedMacroIndex: number;
|
||||||
|
private subscription: Subscription;
|
||||||
|
|
||||||
constructor(private uhkConfigurationService: UhkConfigurationService) {
|
constructor(private store: Store<AppState>) {
|
||||||
this.macros = [];
|
this.subscription = store.let(getMacroEntities())
|
||||||
|
.subscribe((macros: Macro[]) => this.macros = macros);
|
||||||
this.macroOptions = [];
|
this.macroOptions = [];
|
||||||
this.selectedMacroIndex = -1;
|
this.selectedMacroIndex = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.macros = this.uhkConfigurationService.getUhkConfiguration().macros;
|
|
||||||
|
|
||||||
this.macroOptions.push({
|
this.macroOptions.push({
|
||||||
id: '-1',
|
id: '-1',
|
||||||
text: 'Select macro'
|
text: 'Select macro'
|
||||||
@@ -72,4 +77,7 @@ export class MacroTabComponent implements OnInit, Tab {
|
|||||||
return keymapAction;
|
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 { Module } from '../../../config-serializer/config-items/Module';
|
||||||
import { SvgModule } from '../module';
|
import { SvgModule } from '../module';
|
||||||
|
|
||||||
import { DataProviderService } from '../../../services/data-provider.service';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'svg-keyboard',
|
selector: 'svg-keyboard',
|
||||||
template: require('./svg-keyboard.component.html'),
|
template: require('./svg-keyboard.component.html'),
|
||||||
@@ -18,13 +16,13 @@ export class SvgKeyboardComponent implements OnInit {
|
|||||||
private modules: SvgModule[];
|
private modules: SvgModule[];
|
||||||
private svgAttributes: { viewBox: string, transform: string, fill: string };
|
private svgAttributes: { viewBox: string, transform: string, fill: string };
|
||||||
|
|
||||||
constructor(private dps: DataProviderService) {
|
constructor() {
|
||||||
this.modules = [];
|
this.modules = [];
|
||||||
this.svgAttributes = this.dps.getKeyboardSvgAttributes();
|
this.svgAttributes = this.getKeyboardSvgAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.modules = this.dps.getSvgModules();
|
this.modules = this.getSvgModules();
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyClick(moduleId: number, keyId: number): void {
|
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 {
|
import {
|
||||||
KeyAction,
|
KeyAction,
|
||||||
@@ -10,10 +14,12 @@ import {
|
|||||||
SwitchLayerAction
|
SwitchLayerAction
|
||||||
} from '../../../../config-serializer/config-items/key-action';
|
} from '../../../../config-serializer/config-items/key-action';
|
||||||
import { KeyModifiers } from '../../../../config-serializer/config-items/KeyModifiers';
|
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 { 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 {
|
enum LabelTypes {
|
||||||
KeystrokeKey,
|
KeystrokeKey,
|
||||||
@@ -31,7 +37,7 @@ enum LabelTypes {
|
|||||||
template: require('./svg-keyboard-key.component.html'),
|
template: require('./svg-keyboard-key.component.html'),
|
||||||
styles: [require('./svg-keyboard-key.component.scss')]
|
styles: [require('./svg-keyboard-key.component.scss')]
|
||||||
})
|
})
|
||||||
export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
|
||||||
@Input() id: string;
|
@Input() id: string;
|
||||||
@Input() rx: string;
|
@Input() rx: string;
|
||||||
@Input() ry: string;
|
@Input() ry: string;
|
||||||
@@ -46,8 +52,13 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
private labelSource: any;
|
private labelSource: any;
|
||||||
private labelType: LabelTypes;
|
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() {
|
ngOnInit() {
|
||||||
this.setLabels();
|
this.setLabels();
|
||||||
@@ -61,6 +72,10 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
|||||||
/* tslint:enable:no-string-literal */
|
/* tslint:enable:no-string-literal */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy() {
|
||||||
|
this.subscription.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
private setLabels(): void {
|
private setLabels(): void {
|
||||||
if (!this.keyAction) {
|
if (!this.keyAction) {
|
||||||
this.labelSource = undefined;
|
this.labelSource = undefined;
|
||||||
@@ -150,11 +165,11 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
|||||||
this.labelSource = keyAction.keymapAbbreviation;
|
this.labelSource = keyAction.keymapAbbreviation;
|
||||||
} else if (this.keyAction instanceof PlayMacroAction) {
|
} else if (this.keyAction instanceof PlayMacroAction) {
|
||||||
let keyAction: PlayMacroAction = this.keyAction as PlayMacroAction;
|
let keyAction: PlayMacroAction = this.keyAction as PlayMacroAction;
|
||||||
|
let macro: Macro = this.macros.find((macro: Macro) => macro.id === keyAction.macroId);
|
||||||
this.labelType = LabelTypes.IconText;
|
this.labelType = LabelTypes.IconText;
|
||||||
let uhkConfiguration: UhkConfiguration = this.uhkConfigurationService.getUhkConfiguration();
|
|
||||||
this.labelSource = {
|
this.labelSource = {
|
||||||
icon: this.mapperService.getIcon('macro'),
|
icon: this.mapperService.getIcon('macro'),
|
||||||
text: uhkConfiguration.getMacro(keyAction.macroId).name
|
text: macro.name
|
||||||
};
|
};
|
||||||
} else if (this.keyAction instanceof MouseAction) {
|
} else if (this.keyAction instanceof MouseAction) {
|
||||||
this.labelType = LabelTypes.MouseKey;
|
this.labelType = LabelTypes.MouseKey;
|
||||||
@@ -162,7 +177,5 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges {
|
|||||||
} else {
|
} else {
|
||||||
this.labelSource = undefined;
|
this.labelSource = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
|
|
||||||
import { Keymap } from '../config-serializer/config-items/Keymap';
|
|
||||||
import { UhkConfiguration } from '../config-serializer/config-items/UhkConfiguration';
|
|
||||||
|
|
||||||
import { SvgModule } from '../components/svg/module/svg-module.model';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class DataProviderService {
|
|
||||||
|
|
||||||
private uhkConfiguration: UhkConfiguration;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.uhkConfiguration = new UhkConfiguration().fromJsObject(require('json!../config-serializer/uhk-config.json'));
|
|
||||||
}
|
|
||||||
|
|
||||||
getUHKConfig(): UhkConfiguration {
|
|
||||||
return this.uhkConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
getDefaultKeymaps(): Keymap[] {
|
|
||||||
return (<any[]>require('json!../config-serializer/preset-keymaps.json')).map(keymap => new Keymap().fromJsObject(keymap));
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
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,20 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core';
|
|
||||||
|
|
||||||
import { UhkConfiguration } from '../config-serializer/config-items/UhkConfiguration';
|
|
||||||
|
|
||||||
import { DataProviderService } from './data-provider.service';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class UhkConfigurationService {
|
|
||||||
|
|
||||||
private configuration: UhkConfiguration;
|
|
||||||
|
|
||||||
constructor(private dataProviderService: DataProviderService) {
|
|
||||||
this.configuration = new UhkConfiguration().fromJsObject(this.dataProviderService.getUHKConfig());
|
|
||||||
}
|
|
||||||
|
|
||||||
getUhkConfiguration(): UhkConfiguration {
|
|
||||||
return this.configuration;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,25 +4,27 @@ import { Action } from '@ngrx/store';
|
|||||||
|
|
||||||
import { Keymap } from '../../config-serializer/config-items/Keymap';
|
import { Keymap } from '../../config-serializer/config-items/Keymap';
|
||||||
import { Macro } from '../../config-serializer/config-items/Macro';
|
import { Macro } from '../../config-serializer/config-items/Macro';
|
||||||
|
import { UhkConfiguration } from '../../config-serializer/config-items/UhkConfiguration';
|
||||||
|
|
||||||
import { KeymapActions, MacroActions } from '../actions';
|
import { KeymapActions, MacroActions } from '../actions';
|
||||||
import { AppState } from '../index';
|
import { AppState } from '../index';
|
||||||
import { Electron } from './electron';
|
import { Electron } from './electron';
|
||||||
import { Local } from './local';
|
import { Local } from './local';
|
||||||
|
|
||||||
import { UhkConfiguration } from '../../config-serializer/config-items/UhkConfiguration';
|
|
||||||
import { DataProviderService } from '../../services/data-provider.service';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DataStorage {
|
export class DataStorage {
|
||||||
|
|
||||||
private _environment: Local | Electron;
|
private _environment: Local | Electron;
|
||||||
|
private uhkConfiguration: UhkConfiguration;
|
||||||
|
private uhkPresets: Keymap[];
|
||||||
|
|
||||||
constructor(private dataProvider: DataProviderService) {
|
constructor() {
|
||||||
|
this.initUHKJson();
|
||||||
this.detectEnvironment();
|
this.detectEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
initialState(): AppState {
|
initialState(): AppState {
|
||||||
let config: UhkConfiguration = this._environment.getConfig() || this.dataProvider.getUHKConfig();
|
let config: UhkConfiguration = this._environment.getConfig() || this.uhkConfiguration;
|
||||||
return {
|
return {
|
||||||
keymaps: {
|
keymaps: {
|
||||||
entities: config.keymaps
|
entities: config.keymaps
|
||||||
@@ -30,7 +32,7 @@ export class DataStorage {
|
|||||||
macros: {
|
macros: {
|
||||||
entities: config.macros
|
entities: config.macros
|
||||||
},
|
},
|
||||||
presetKeymaps: this.dataProvider.getDefaultKeymaps()
|
presetKeymaps: this.uhkPresets
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ export class DataStorage {
|
|||||||
}
|
}
|
||||||
// Local storage
|
// Local storage
|
||||||
else {
|
else {
|
||||||
this._environment = new Local(this.dataProvider);
|
this._environment = new Local();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +62,7 @@ export class DataStorage {
|
|||||||
(state.entities && state.entities.length && state.entities[0] instanceof Keymap)
|
(state.entities && state.entities.length && state.entities[0] instanceof Keymap)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
config = this._environment.getConfig();
|
config = this._environment.getConfig() || this.uhkConfiguration;
|
||||||
config.keymaps = Object.values(nextState.entities);
|
config.keymaps = Object.values(nextState.entities);
|
||||||
this._environment.saveConfig(config);
|
this._environment.saveConfig(config);
|
||||||
} else if (
|
} else if (
|
||||||
@@ -70,11 +72,17 @@ export class DataStorage {
|
|||||||
(state.entities && state.entities.length && state.entities[0] instanceof Macro)
|
(state.entities && state.entities.length && state.entities[0] instanceof Macro)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
config = this._environment.getConfig();
|
config = this._environment.getConfig() || this.uhkConfiguration;
|
||||||
config.macros = Object.values(nextState.entities);
|
config.macros = Object.values(nextState.entities);
|
||||||
this._environment.saveConfig(config);
|
this._environment.saveConfig(config);
|
||||||
}
|
}
|
||||||
return nextState;
|
return nextState;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initUHKJson() {
|
||||||
|
this.uhkConfiguration = new UhkConfiguration().fromJsObject(require('json!../../config-serializer/uhk-config.json'));
|
||||||
|
this.uhkPresets = (<any[]>require('json!../../config-serializer/preset-keymaps.json'))
|
||||||
|
.map(keymap => new Keymap().fromJsObject(keymap));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import { UhkConfiguration } from '../../config-serializer/config-items/UhkConfiguration';
|
import { UhkConfiguration } from '../../config-serializer/config-items/UhkConfiguration';
|
||||||
import { DataProviderService } from '../../services/data-provider.service';
|
|
||||||
|
|
||||||
export class Local {
|
export class Local {
|
||||||
|
|
||||||
constructor(private dataProvider: DataProviderService) { }
|
constructor() { }
|
||||||
|
|
||||||
getConfig(): UhkConfiguration {
|
getConfig(): UhkConfiguration {
|
||||||
let configJson = localStorage.getItem('config');
|
let configJson = localStorage.getItem('config');
|
||||||
let config: UhkConfiguration;
|
let config: UhkConfiguration;
|
||||||
|
|
||||||
if (configJson) {
|
if (configJson) {
|
||||||
config = new UhkConfiguration().fromJsObject(JSON.parse(configJson));
|
config = new UhkConfiguration().fromJsObject(JSON.parse(configJson));
|
||||||
} else {
|
|
||||||
config = this.dataProvider.getUHKConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
|
|||||||
Reference in New Issue
Block a user