Skip to content

Commit ba1fff7

Browse files
ert78gbmondalaci
authored andcommitted
feat(device): Reset user configuration on device (#435)
1 parent 23af522 commit ba1fff7

File tree

7 files changed

+51
-7
lines changed

7 files changed

+51
-7
lines changed

packages/uhk-web/src/app/components/device/settings/device-settings.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ <h1>
22
<i class="fa fa-cog"></i>
33
<span>Device settings...</span>
44
</h1>
5+
<a (click)="resetUserConfiguration()">Reset user configuration</a>

packages/uhk-web/src/app/components/device/settings/device-settings.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { Component } from '@angular/core';
2+
import { Store } from '@ngrx/store';
3+
4+
import { AppState } from '../../../store';
5+
import { ResetUserConfigurationAction } from '../../../store/actions/device';
26

37
@Component({
48
selector: 'device-settings',
@@ -10,6 +14,10 @@ import { Component } from '@angular/core';
1014
})
1115
export class DeviceSettingsComponent {
1216

13-
constructor() {}
17+
constructor(private store: Store<AppState>) {
18+
}
1419

20+
resetUserConfiguration() {
21+
this.store.dispatch(new ResetUserConfigurationAction());
22+
}
1523
}

packages/uhk-web/src/app/store/actions/device.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export const ActionTypes = {
1515
SHOW_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'show save to keyboard button'),
1616
SAVE_TO_KEYBOARD_SUCCESS: type(PREFIX + 'save to keyboard success'),
1717
SAVE_TO_KEYBOARD_FAILED: type(PREFIX + 'save to keyboard failed'),
18-
HIDE_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'hide save to keyboard button')
18+
HIDE_SAVE_TO_KEYBOARD_BUTTON: type(PREFIX + 'hide save to keyboard button'),
19+
RESET_USER_CONFIGURATION: type(PREFIX + 'reset user configuration')
1920
};
2021

2122
export class SetPrivilegeOnLinuxAction implements Action {
@@ -68,6 +69,10 @@ export class HideSaveToKeyboardButton implements Action {
6869
type = ActionTypes.HIDE_SAVE_TO_KEYBOARD_BUTTON;
6970
}
7071

72+
export class ResetUserConfigurationAction implements Action {
73+
type = ActionTypes.RESET_USER_CONFIGURATION;
74+
}
75+
7176
export type Actions
7277
= SetPrivilegeOnLinuxAction
7378
| SetPrivilegeOnLinuxReplyAction
@@ -78,4 +83,6 @@ export type Actions
7883
| SaveConfigurationReplyAction
7984
| SaveToKeyboardSuccessAction
8085
| SaveToKeyboardSuccessFailed
81-
| HideSaveToKeyboardButton;
86+
| HideSaveToKeyboardButton
87+
| ResetUserConfigurationAction
88+
;

packages/uhk-web/src/app/store/actions/user-config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const ActionTypes = {
1111
LOAD_USER_CONFIG_SUCCESS: type(PREFIX + 'Load User Config Success'),
1212
SAVE_USER_CONFIG_SUCCESS: type(PREFIX + 'Save User Config Success'),
1313
SAVE_USER_CONFIG_IN_JSON_FILE: type(PREFIX + 'Save User Config in JSON file'),
14-
SAVE_USER_CONFIG_IN_BIN_FILE: type(PREFIX + 'Save User Config in binary file')
14+
SAVE_USER_CONFIG_IN_BIN_FILE: type(PREFIX + 'Save User Config in binary file'),
15+
LOAD_RESET_USER_CONFIGURATION: type(PREFIX + 'Load reset user configuration')
1516
};
1617

1718
export class LoadUserConfigAction implements Action {
@@ -48,6 +49,12 @@ export class SaveUserConfigInBinaryFileAction implements Action {
4849
type = ActionTypes.SAVE_USER_CONFIG_IN_BIN_FILE;
4950
}
5051

52+
export class LoadResetUserConfigurationAction implements Action {
53+
type = ActionTypes.LOAD_RESET_USER_CONFIGURATION;
54+
55+
constructor(public payload: UserConfiguration) { }
56+
}
57+
5158
export type Actions
5259
= LoadUserConfigAction
5360
| LoadUserConfigSuccessAction
@@ -56,4 +63,5 @@ export type Actions
5663
| LoadConfigFromDeviceReplyAction
5764
| SaveUserConfigInJsonFileAction
5865
| SaveUserConfigInBinaryFileAction
66+
| LoadResetUserConfigurationAction
5967
;

packages/uhk-web/src/app/store/effects/device.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,27 @@ import 'rxjs/add/operator/do';
1111
import 'rxjs/add/operator/map';
1212
import 'rxjs/add/operator/mergeMap';
1313
import 'rxjs/add/operator/withLatestFrom';
14+
import 'rxjs/add/operator/switchMap';
1415

1516
import { NotificationType, IpcResponse, UhkBuffer, UserConfiguration } from 'uhk-common';
1617
import {
1718
ActionTypes,
1819
ConnectionStateChangedAction,
1920
HideSaveToKeyboardButton,
2021
PermissionStateChangedAction,
22+
SaveConfigurationAction,
2123
SaveToKeyboardSuccessAction,
2224
SaveToKeyboardSuccessFailed
2325
} from '../actions/device';
2426
import { DeviceRendererService } from '../../services/device-renderer.service';
2527
import { ShowNotificationAction } from '../actions/app';
2628
import { AppState } from '../index';
27-
import { LoadConfigFromDeviceAction } from '../actions/user-config';
29+
import {
30+
LoadConfigFromDeviceAction,
31+
LoadResetUserConfigurationAction,
32+
ActionTypes as UserConfigActions
33+
} from '../actions/user-config';
34+
import { DefaultUserConfigurationService } from '../../services/default-user-configuration.service';
2835

2936
@Injectable()
3037
export class DeviceEffects {
@@ -124,10 +131,22 @@ export class DeviceEffects {
124131
.switchMap(() => Observable.of(new HideSaveToKeyboardButton()))
125132
);
126133

134+
@Effect() resetUserConfiguration$: Observable<Action> = this.actions$
135+
.ofType(ActionTypes.RESET_USER_CONFIGURATION)
136+
.switchMap(() => {
137+
const config = this.defaultUserConfigurationService.getDefault();
138+
return Observable.of(new LoadResetUserConfigurationAction(config));
139+
});
140+
141+
@Effect() saveResetUserConfigurationToDevice$ = this.actions$
142+
.ofType(UserConfigActions.LOAD_RESET_USER_CONFIGURATION)
143+
.switchMap(() => Observable.of(new SaveConfigurationAction()));
144+
127145
constructor(private actions$: Actions,
128146
private router: Router,
129147
private deviceRendererService: DeviceRendererService,
130-
private store: Store<AppState>) {
148+
private store: Store<AppState>,
149+
private defaultUserConfigurationService: DefaultUserConfigurationService) {
131150
}
132151

133152
private sendUserConfigToKeyboard(userConfiguration: UserConfiguration): void {

packages/uhk-web/src/app/store/effects/user-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export class UserConfigEffects {
144144
this.logService.error('Eeprom parse error:', err);
145145
return [new ShowNotificationAction({
146146
type: NotificationType.Error,
147-
message: err.message
147+
message: err
148148
})];
149149
}
150150
});

packages/uhk-web/src/app/store/reducers/user-configuration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default function (state = initialState, action: Action): UserConfiguratio
1616
const changedUserConfiguration: UserConfiguration = Object.assign(new UserConfiguration(), state);
1717

1818
switch (action.type) {
19+
case ActionTypes.LOAD_RESET_USER_CONFIGURATION:
1920
case ActionTypes.LOAD_USER_CONFIG_SUCCESS: {
2021
return Object.assign(changedUserConfiguration, action.payload);
2122
}

0 commit comments

Comments
 (0)