Add the whole user configuration to the AppState

Closes #252
Fixes #219
This commit is contained in:
Farkas József
2017-02-07 23:43:34 +01:00
committed by József Farkas
parent e41a62be13
commit f1f8a8d64e
19 changed files with 374 additions and 525 deletions

View File

@@ -10,8 +10,9 @@ import 'rxjs/add/operator/switchMap';
import { Store } from '@ngrx/store';
import { Keymap } from './../../../config-serializer/config-items/Keymap';
import { AppState } from '../../../store/index';
import { getKeymapEntities } from '../../../store/reducers';
import { getKeymaps } from '../../../store/reducers/user-configuration';
@Injectable()
export class KeymapEditGuard implements CanActivate {
@@ -20,8 +21,8 @@ export class KeymapEditGuard implements CanActivate {
canActivate(): Observable<boolean> {
return this.store
.let(getKeymapEntities())
.do(keymaps => {
.let(getKeymaps())
.do((keymaps: Keymap[]) => {
const defaultKeymap = keymaps.find(keymap => keymap.isDefault);
this.router.navigate(['/keymap', defaultKeymap.abbreviation]);
})

View File

@@ -11,7 +11,7 @@ import { Observable } from 'rxjs/Observable';
import { Keymap } from '../../../config-serializer/config-items/Keymap';
import { AppState } from '../../../store';
import { getKeymap, getKeymapEntities } from '../../../store/reducers/keymap';
import { getKeymap, getKeymaps } from '../../../store/reducers/user-configuration';
@Component({
selector: 'keymap-edit',
@@ -37,7 +37,7 @@ export class KeymapEditComponent {
.publishReplay(1)
.refCount();
this.deletable$ = store.let(getKeymapEntities())
this.deletable$ = store.let(getKeymaps())
.map((keymaps: Keymap[]) => keymaps.length > 1);
}

View File

@@ -10,7 +10,7 @@ import { MacroAction } from '../../../config-serializer/config-items/macro-actio
import { MacroActions } from '../../../store/actions';
import { AppState } from '../../../store/index';
import { getMacro } from '../../../store/reducers/macro';
import { getMacro } from '../../../store/reducers/user-configuration';
@Component({
selector: 'macro-edit',

View File

@@ -9,7 +9,8 @@ import 'rxjs/add/operator/map';
import { Store } from '@ngrx/store';
import { AppState } from '../../../store/index';
import { getMacroEntities } from '../../../store/reducers';
import { getMacros } from '../../../store/reducers/user-configuration';
import { Macro } from './../../../config-serializer/config-items/Macro';
@Injectable()
export class MacroNotFoundGuard implements CanActivate {
@@ -18,8 +19,8 @@ export class MacroNotFoundGuard implements CanActivate {
canActivate(): Observable<boolean> {
return this.store
.let(getMacroEntities())
.map(macros => {
.let(getMacros())
.map((macros: Macro[]) => {
const hasMacros = macros.length > 0;
if (hasMacros) {
this.router.navigate(['/macro', macros[0].id]);

View File

@@ -19,7 +19,7 @@ import { Keymap } from '../../config-serializer/config-items/Keymap';
import { Tab } from './tab/tab';
import { AppState } from '../../store';
import { getKeymapEntities } from '../../store/reducers';
import { getKeymaps } from '../../store/reducers/user-configuration';
enum TabName {
Keypress,
@@ -90,7 +90,7 @@ export class PopoverComponent implements OnChanges {
constructor(private store: Store<AppState>) {
this.animationState = 'closed';
this.keymaps$ = store.let(getKeymapEntities())
this.keymaps$ = store.let(getKeymaps())
.map((keymaps: Keymap[]) =>
keymaps.filter((keymap: Keymap) => this.currentKeymap.abbreviation !== keymap.abbreviation)
);

View File

@@ -12,7 +12,7 @@ import { Macro } from '../../../../config-serializer/config-items/Macro';
import { Tab } from '../tab';
import { AppState } from '../../../../store/index';
import { getMacroEntities } from '../../../../store/reducers/macro';
import { getMacros } from '../../../../store/reducers/user-configuration';
@Component({
selector: 'macro-tab',
@@ -29,7 +29,7 @@ export class MacroTabComponent extends Tab implements OnInit, OnChanges, OnDestr
constructor(private store: Store<AppState>) {
super();
this.subscription = store.let(getMacroEntities())
this.subscription = store.let(getMacros())
.subscribe((macros: Macro[]) => this.macros = macros);
this.macroOptions = [];
this.selectedMacroIndex = 0;

View File

@@ -2,16 +2,17 @@ import { Component, Renderer, animate, state, style, transition, trigger } from
import { Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/let';
import { Keymap } from '../../config-serializer/config-items/Keymap';
import { Macro } from '../../config-serializer/config-items/Macro';
import { AppState } from '../../store';
import { MacroActions } from '../../store/actions';
import { getKeymapEntities, getMacroEntities } from '../../store/reducers';
import { getKeymaps, getMacros } from '../../store/reducers/user-configuration';
@Component({
animations: [
@@ -41,13 +42,13 @@ export class SideMenuComponent {
addon: 'active'
};
this.keymaps$ = store.let(getKeymapEntities())
this.keymaps$ = store.let(getKeymaps())
.map(keymaps => keymaps.slice()) // Creating a new array reference, because the sort is working in place
.do((keymaps: Keymap[]) => {
keymaps.sort((first: Keymap, second: Keymap) => first.name.localeCompare(second.name));
});
this.macros$ = store.let(getMacroEntities())
this.macros$ = store.let(getMacros())
.map(macros => macros.slice()) // Creating a new array reference, because the sort is working in place
.do((macros: Macro[]) => {
macros.sort((first: Macro, second: Macro) => first.name.localeCompare(second.name));

View File

@@ -23,7 +23,7 @@ import { CaptureService } from '../../../../services/capture.service';
import { MapperService } from '../../../../services/mapper.service';
import { AppState } from '../../../../store/index';
import { getMacroEntities } from '../../../../store/reducers/macro';
import { getMacros } from '../../../../store/reducers/user-configuration';
enum LabelTypes {
KeystrokeKey,
@@ -146,7 +146,7 @@ export class SvgKeyboardKeyComponent implements OnInit, OnChanges, OnDestroy {
private captureService: CaptureService,
private renderer: Renderer
) {
this.subscription = store.let(getMacroEntities())
this.subscription = store.let(getMacros())
.subscribe((macros: Macro[]) => this.macros = macros);
this.reset();

View File

@@ -283,8 +283,8 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
} else if (keyAction instanceof PlayMacroAction) {
const playMacroAction: PlayMacroAction = keyAction;
return this.store
.select(appState => appState.macros)
.map(macroState => macroState.entities.find(macro => {
.select(appState => appState.userConfiguration.macros)
.map(macroState => macroState.find(macro => {
return macro.id === playMacroAction.macroId;
}).name)
.map(macroName => {
@@ -303,7 +303,7 @@ export class SvgKeyboardWrapComponent implements OnInit, OnChanges {
} else if (keyAction instanceof SwitchKeymapAction) {
const switchKeymapAction: SwitchKeymapAction = keyAction;
return this.store
.select(appState => appState.keymaps.entities)
.select(appState => appState.userConfiguration.keymaps)
.map(keymaps => keymaps.find(keymap => keymap.abbreviation === switchKeymapAction.keymapAbbreviation).name)
.map(keymapName => {
const content: NameValuePair[] = [