Files
agent/packages/uhk-web/src/app/components/macro/edit/macro-edit.component.ts
Róbert Kiss 1a413c824e Fix 560 delete bind play macro action when macro delete (#576)
* fix(config): delete KeyAction binding of deleted macro

* refactor: use sorter import

* fix(macro): read the macro id from route params

* fix(keyAction): use NoneAction in keyAction mapping
2018-02-11 20:12:12 +01:00

62 lines
1.9 KiB
TypeScript

import { Component, OnDestroy } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
import { Macro, MacroAction } from 'uhk-common';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/pluck';
import { MacroActions } from '../../../store/actions';
import { AppState } from '../../../store';
import { getMacro } from '../../../store/reducers/user-configuration';
@Component({
selector: 'macro-edit',
templateUrl: './macro-edit.component.html',
styleUrls: ['./macro-edit.component.scss'],
host: {
'class': 'container-fluid'
}
})
export class MacroEditComponent implements OnDestroy {
macro: Macro;
isNew: boolean;
macroId: number;
private subscription: Subscription;
constructor(private store: Store<AppState>, public route: ActivatedRoute) {
this.subscription = route
.params
.pluck<{}, string>('id')
.switchMap((id: string) => {
this.macroId = +id;
return store.let(getMacro(this.macroId));
})
.subscribe((macro: Macro) => {
this.macro = macro;
});
this.isNew = this.route.snapshot.params['empty'] === 'new';
}
ngOnDestroy() {
this.subscription.unsubscribe();
}
addAction(macroId: number, action: MacroAction) {
this.store.dispatch(MacroActions.addMacroAction(macroId, action));
}
editAction(macroId: number, index: number, action: MacroAction) {
this.store.dispatch(MacroActions.saveMacroAction(macroId, index, action));
}
deleteAction(macroId: number, index: number, action: MacroAction) {
this.store.dispatch(MacroActions.deleteMacroAction(macroId, index, action));
}
reorderAction(macroId: number, oldIndex: number, newIndex: number) {
this.store.dispatch(MacroActions.reorderMacroAction(macroId, oldIndex, newIndex));
}
}