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>
|
<i class="fa fa-cog"></i>
|
||||||
<span>Device settings...</span>
|
<span>Device settings...</span>
|
||||||
</h1>
|
</h1>
|
||||||
|
<a (click)="resetUserConfiguration()">Reset user configuration</a>
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
|
||||||
|
import { AppState } from '../../../store';
|
||||||
|
import { ResetUserConfigurationAction } from '../../../store/actions/device';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'device-settings',
|
selector: 'device-settings',
|
||||||
@@ -10,6 +14,10 @@ import { Component } from '@angular/core';
|
|||||||
})
|
})
|
||||||
export class DeviceSettingsComponent {
|
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'),
|
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_SUCCESS: type(PREFIX + 'save to keyboard success'),
|
||||||
SAVE_TO_KEYBOARD_FAILED: type(PREFIX + 'save to keyboard failed'),
|
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 {
|
export class SetPrivilegeOnLinuxAction implements Action {
|
||||||
@@ -68,6 +69,10 @@ export class HideSaveToKeyboardButton implements Action {
|
|||||||
type = ActionTypes.HIDE_SAVE_TO_KEYBOARD_BUTTON;
|
type = ActionTypes.HIDE_SAVE_TO_KEYBOARD_BUTTON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class ResetUserConfigurationAction implements Action {
|
||||||
|
type = ActionTypes.RESET_USER_CONFIGURATION;
|
||||||
|
}
|
||||||
|
|
||||||
export type Actions
|
export type Actions
|
||||||
= SetPrivilegeOnLinuxAction
|
= SetPrivilegeOnLinuxAction
|
||||||
| SetPrivilegeOnLinuxReplyAction
|
| SetPrivilegeOnLinuxReplyAction
|
||||||
@@ -78,4 +83,6 @@ export type Actions
|
|||||||
| SaveConfigurationReplyAction
|
| SaveConfigurationReplyAction
|
||||||
| SaveToKeyboardSuccessAction
|
| SaveToKeyboardSuccessAction
|
||||||
| SaveToKeyboardSuccessFailed
|
| SaveToKeyboardSuccessFailed
|
||||||
| HideSaveToKeyboardButton;
|
| HideSaveToKeyboardButton
|
||||||
|
| ResetUserConfigurationAction
|
||||||
|
;
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ export const ActionTypes = {
|
|||||||
LOAD_USER_CONFIG_SUCCESS: type(PREFIX + 'Load User Config Success'),
|
LOAD_USER_CONFIG_SUCCESS: type(PREFIX + 'Load User Config Success'),
|
||||||
SAVE_USER_CONFIG_SUCCESS: type(PREFIX + 'Save 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_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 {
|
export class LoadUserConfigAction implements Action {
|
||||||
@@ -48,6 +49,12 @@ export class SaveUserConfigInBinaryFileAction implements Action {
|
|||||||
type = ActionTypes.SAVE_USER_CONFIG_IN_BIN_FILE;
|
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
|
export type Actions
|
||||||
= LoadUserConfigAction
|
= LoadUserConfigAction
|
||||||
| LoadUserConfigSuccessAction
|
| LoadUserConfigSuccessAction
|
||||||
@@ -56,4 +63,5 @@ export type Actions
|
|||||||
| LoadConfigFromDeviceReplyAction
|
| LoadConfigFromDeviceReplyAction
|
||||||
| SaveUserConfigInJsonFileAction
|
| SaveUserConfigInJsonFileAction
|
||||||
| SaveUserConfigInBinaryFileAction
|
| SaveUserConfigInBinaryFileAction
|
||||||
|
| LoadResetUserConfigurationAction
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import 'rxjs/add/operator/do';
|
|||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
import 'rxjs/add/operator/mergeMap';
|
import 'rxjs/add/operator/mergeMap';
|
||||||
import 'rxjs/add/operator/withLatestFrom';
|
import 'rxjs/add/operator/withLatestFrom';
|
||||||
|
import 'rxjs/add/operator/switchMap';
|
||||||
|
|
||||||
import { NotificationType, IpcResponse, UhkBuffer, UserConfiguration } from 'uhk-common';
|
import { NotificationType, IpcResponse, UhkBuffer, UserConfiguration } from 'uhk-common';
|
||||||
import {
|
import {
|
||||||
@@ -18,13 +19,19 @@ import {
|
|||||||
ConnectionStateChangedAction,
|
ConnectionStateChangedAction,
|
||||||
HideSaveToKeyboardButton,
|
HideSaveToKeyboardButton,
|
||||||
PermissionStateChangedAction,
|
PermissionStateChangedAction,
|
||||||
|
SaveConfigurationAction,
|
||||||
SaveToKeyboardSuccessAction,
|
SaveToKeyboardSuccessAction,
|
||||||
SaveToKeyboardSuccessFailed
|
SaveToKeyboardSuccessFailed
|
||||||
} from '../actions/device';
|
} from '../actions/device';
|
||||||
import { DeviceRendererService } from '../../services/device-renderer.service';
|
import { DeviceRendererService } from '../../services/device-renderer.service';
|
||||||
import { ShowNotificationAction } from '../actions/app';
|
import { ShowNotificationAction } from '../actions/app';
|
||||||
import { AppState } from '../index';
|
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()
|
@Injectable()
|
||||||
export class DeviceEffects {
|
export class DeviceEffects {
|
||||||
@@ -124,10 +131,22 @@ export class DeviceEffects {
|
|||||||
.switchMap(() => Observable.of(new HideSaveToKeyboardButton()))
|
.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,
|
constructor(private actions$: Actions,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private deviceRendererService: DeviceRendererService,
|
private deviceRendererService: DeviceRendererService,
|
||||||
private store: Store<AppState>) {
|
private store: Store<AppState>,
|
||||||
|
private defaultUserConfigurationService: DefaultUserConfigurationService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private sendUserConfigToKeyboard(userConfiguration: UserConfiguration): void {
|
private sendUserConfigToKeyboard(userConfiguration: UserConfiguration): void {
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ export class UserConfigEffects {
|
|||||||
this.logService.error('Eeprom parse error:', err);
|
this.logService.error('Eeprom parse error:', err);
|
||||||
return [new ShowNotificationAction({
|
return [new ShowNotificationAction({
|
||||||
type: NotificationType.Error,
|
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);
|
const changedUserConfiguration: UserConfiguration = Object.assign(new UserConfiguration(), state);
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
case ActionTypes.LOAD_RESET_USER_CONFIGURATION:
|
||||||
case ActionTypes.LOAD_USER_CONFIG_SUCCESS: {
|
case ActionTypes.LOAD_USER_CONFIG_SUCCESS: {
|
||||||
return Object.assign(changedUserConfiguration, action.payload);
|
return Object.assign(changedUserConfiguration, action.payload);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user