feat(device): Reset user configuration on device (#435)
This commit is contained in:
committed by
László Monda
parent
23af522a48
commit
ba1fff788d
@@ -2,3 +2,4 @@
|
||||
<i class="fa fa-cog"></i>
|
||||
<span>Device settings...</span>
|
||||
</h1>
|
||||
<a (click)="resetUserConfiguration()">Reset user configuration</a>
|
||||
|
||||
@@ -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<AppState>) {
|
||||
}
|
||||
|
||||
resetUserConfiguration() {
|
||||
this.store.dispatch(new ResetUserConfigurationAction());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
;
|
||||
|
||||
@@ -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
|
||||
;
|
||||
|
||||
@@ -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<Action> = 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<AppState>) {
|
||||
private store: Store<AppState>,
|
||||
private defaultUserConfigurationService: DefaultUserConfigurationService) {
|
||||
}
|
||||
|
||||
private sendUserConfigToKeyboard(userConfiguration: UserConfiguration): void {
|
||||
|
||||
@@ -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
|
||||
})];
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user