From ba1fff788d39d87c2e21a92feca2c8c3eed279c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Kiss?= Date: Sun, 8 Oct 2017 00:23:46 +0200 Subject: [PATCH] feat(device): Reset user configuration on device (#435) --- .../settings/device-settings.component.html | 1 + .../settings/device-settings.component.ts | 10 +++++++- .../uhk-web/src/app/store/actions/device.ts | 11 +++++++-- .../src/app/store/actions/user-config.ts | 10 +++++++- .../uhk-web/src/app/store/effects/device.ts | 23 +++++++++++++++++-- .../src/app/store/effects/user-config.ts | 2 +- .../app/store/reducers/user-configuration.ts | 1 + 7 files changed, 51 insertions(+), 7 deletions(-) diff --git a/packages/uhk-web/src/app/components/device/settings/device-settings.component.html b/packages/uhk-web/src/app/components/device/settings/device-settings.component.html index 33a20c48..2e5a5497 100644 --- a/packages/uhk-web/src/app/components/device/settings/device-settings.component.html +++ b/packages/uhk-web/src/app/components/device/settings/device-settings.component.html @@ -2,3 +2,4 @@ Device settings... +Reset user configuration diff --git a/packages/uhk-web/src/app/components/device/settings/device-settings.component.ts b/packages/uhk-web/src/app/components/device/settings/device-settings.component.ts index fb409ae7..a7b4d039 100644 --- a/packages/uhk-web/src/app/components/device/settings/device-settings.component.ts +++ b/packages/uhk-web/src/app/components/device/settings/device-settings.component.ts @@ -1,4 +1,8 @@ import { Component } from '@angular/core'; +import { Store } from '@ngrx/store'; + +import { AppState } from '../../../store'; +import { ResetUserConfigurationAction } from '../../../store/actions/device'; @Component({ selector: 'device-settings', @@ -10,6 +14,10 @@ import { Component } from '@angular/core'; }) export class DeviceSettingsComponent { - constructor() {} + constructor(private store: Store) { + } + resetUserConfiguration() { + this.store.dispatch(new ResetUserConfigurationAction()); + } } diff --git a/packages/uhk-web/src/app/store/actions/device.ts b/packages/uhk-web/src/app/store/actions/device.ts index 2beed482..675cbe09 100644 --- a/packages/uhk-web/src/app/store/actions/device.ts +++ b/packages/uhk-web/src/app/store/actions/device.ts @@ -15,7 +15,8 @@ export const ActionTypes = { SHOW_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'show save to keyboard button'), SAVE_TO_KEYBOARD_SUCCESS: type(PREFIX + 'save to keyboard success'), SAVE_TO_KEYBOARD_FAILED: type(PREFIX + 'save to keyboard failed'), - HIDE_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'hide save to keyboard button') + HIDE_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'hide save to keyboard button'), + RESET_USER_CONFIGURATION: type(PREFIX + 'reset user configuration') }; export class SetPrivilegeOnLinuxAction implements Action { @@ -68,6 +69,10 @@ export class HideSaveToKeyboardButton implements Action { type = ActionTypes.HIDE_SAVE_TO_KEYBOARD_BUTTON; } +export class ResetUserConfigurationAction implements Action { + type = ActionTypes.RESET_USER_CONFIGURATION; +} + export type Actions = SetPrivilegeOnLinuxAction | SetPrivilegeOnLinuxReplyAction @@ -78,4 +83,6 @@ export type Actions | SaveConfigurationReplyAction | SaveToKeyboardSuccessAction | SaveToKeyboardSuccessFailed - | HideSaveToKeyboardButton; + | HideSaveToKeyboardButton + | ResetUserConfigurationAction + ; diff --git a/packages/uhk-web/src/app/store/actions/user-config.ts b/packages/uhk-web/src/app/store/actions/user-config.ts index 003c2ad3..0718bd48 100644 --- a/packages/uhk-web/src/app/store/actions/user-config.ts +++ b/packages/uhk-web/src/app/store/actions/user-config.ts @@ -11,7 +11,8 @@ export const ActionTypes = { LOAD_USER_CONFIG_SUCCESS: type(PREFIX + 'Load User Config Success'), SAVE_USER_CONFIG_SUCCESS: type(PREFIX + 'Save User Config Success'), SAVE_USER_CONFIG_IN_JSON_FILE: type(PREFIX + 'Save User Config in JSON file'), - SAVE_USER_CONFIG_IN_BIN_FILE: type(PREFIX + 'Save User Config in binary file') + SAVE_USER_CONFIG_IN_BIN_FILE: type(PREFIX + 'Save User Config in binary file'), + LOAD_RESET_USER_CONFIGURATION: type(PREFIX + 'Load reset user configuration') }; export class LoadUserConfigAction implements Action { @@ -48,6 +49,12 @@ export class SaveUserConfigInBinaryFileAction implements Action { type = ActionTypes.SAVE_USER_CONFIG_IN_BIN_FILE; } +export class LoadResetUserConfigurationAction implements Action { + type = ActionTypes.LOAD_RESET_USER_CONFIGURATION; + + constructor(public payload: UserConfiguration) { } +} + export type Actions = LoadUserConfigAction | LoadUserConfigSuccessAction @@ -56,4 +63,5 @@ export type Actions | LoadConfigFromDeviceReplyAction | SaveUserConfigInJsonFileAction | SaveUserConfigInBinaryFileAction + | LoadResetUserConfigurationAction ; diff --git a/packages/uhk-web/src/app/store/effects/device.ts b/packages/uhk-web/src/app/store/effects/device.ts index fb1e0e96..2f1e6a1f 100644 --- a/packages/uhk-web/src/app/store/effects/device.ts +++ b/packages/uhk-web/src/app/store/effects/device.ts @@ -11,6 +11,7 @@ import 'rxjs/add/operator/do'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/mergeMap'; import 'rxjs/add/operator/withLatestFrom'; +import 'rxjs/add/operator/switchMap'; import { NotificationType, IpcResponse, UhkBuffer, UserConfiguration } from 'uhk-common'; import { @@ -18,13 +19,19 @@ import { ConnectionStateChangedAction, HideSaveToKeyboardButton, PermissionStateChangedAction, + SaveConfigurationAction, SaveToKeyboardSuccessAction, SaveToKeyboardSuccessFailed } from '../actions/device'; import { DeviceRendererService } from '../../services/device-renderer.service'; import { ShowNotificationAction } from '../actions/app'; import { AppState } from '../index'; -import { LoadConfigFromDeviceAction } from '../actions/user-config'; +import { + LoadConfigFromDeviceAction, + LoadResetUserConfigurationAction, + ActionTypes as UserConfigActions +} from '../actions/user-config'; +import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service'; @Injectable() export class DeviceEffects { @@ -124,10 +131,22 @@ export class DeviceEffects { .switchMap(() => Observable.of(new HideSaveToKeyboardButton())) ); + @Effect() resetUserConfiguration$: Observable = this.actions$ + .ofType(ActionTypes.RESET_USER_CONFIGURATION) + .switchMap(() => { + const config = this.defaultUserConfigurationService.getDefault(); + return Observable.of(new LoadResetUserConfigurationAction(config)); + }); + + @Effect() saveResetUserConfigurationToDevice$ = this.actions$ + .ofType(UserConfigActions.LOAD_RESET_USER_CONFIGURATION) + .switchMap(() => Observable.of(new SaveConfigurationAction())); + constructor(private actions$: Actions, private router: Router, private deviceRendererService: DeviceRendererService, - private store: Store) { + private store: Store, + private defaultUserConfigurationService: DefaultUserConfigurationService) { } private sendUserConfigToKeyboard(userConfiguration: UserConfiguration): void { diff --git a/packages/uhk-web/src/app/store/effects/user-config.ts b/packages/uhk-web/src/app/store/effects/user-config.ts index 320697a1..fc28d020 100644 --- a/packages/uhk-web/src/app/store/effects/user-config.ts +++ b/packages/uhk-web/src/app/store/effects/user-config.ts @@ -144,7 +144,7 @@ export class UserConfigEffects { this.logService.error('Eeprom parse error:', err); return [new ShowNotificationAction({ type: NotificationType.Error, - message: err.message + message: err })]; } }); diff --git a/packages/uhk-web/src/app/store/reducers/user-configuration.ts b/packages/uhk-web/src/app/store/reducers/user-configuration.ts index 2249f773..d0468f1b 100644 --- a/packages/uhk-web/src/app/store/reducers/user-configuration.ts +++ b/packages/uhk-web/src/app/store/reducers/user-configuration.ts @@ -16,6 +16,7 @@ export default function (state = initialState, action: Action): UserConfiguratio const changedUserConfiguration: UserConfiguration = Object.assign(new UserConfiguration(), state); switch (action.type) { + case ActionTypes.LOAD_RESET_USER_CONFIGURATION: case ActionTypes.LOAD_USER_CONFIG_SUCCESS: { return Object.assign(changedUserConfiguration, action.payload); }