fix(user-config): Fix user configuration savings (#433)
* test(user-config): Fix saveAs functionality * feat(user-config): Add 2 space indent when save user-config to json file * refactor(user-config): Move user config savings into user config effect * build: Remove unused package
This commit is contained in:
committed by
László Monda
parent
35c0d98cd2
commit
23af522a48
@@ -9,7 +9,9 @@ export const ActionTypes = {
|
||||
LOAD_CONFIG_FROM_DEVICE: type(PREFIX + 'Load User Config from Device'),
|
||||
LOAD_CONFIG_FROM_DEVICE_REPLY: type(PREFIX + 'Load User Config from Device reply'),
|
||||
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_BIN_FILE: type(PREFIX + 'Save User Config in binary file')
|
||||
};
|
||||
|
||||
export class LoadUserConfigAction implements Action {
|
||||
@@ -38,10 +40,20 @@ export class SaveUserConfigSuccessAction implements Action {
|
||||
constructor(public payload: UserConfiguration) { }
|
||||
}
|
||||
|
||||
export class SaveUserConfigInJsonFileAction implements Action {
|
||||
type = ActionTypes.SAVE_USER_CONFIG_IN_JSON_FILE;
|
||||
}
|
||||
|
||||
export class SaveUserConfigInBinaryFileAction implements Action {
|
||||
type = ActionTypes.SAVE_USER_CONFIG_IN_BIN_FILE;
|
||||
}
|
||||
|
||||
export type Actions
|
||||
= LoadUserConfigAction
|
||||
| LoadUserConfigSuccessAction
|
||||
| SaveUserConfigSuccessAction
|
||||
| LoadConfigFromDeviceAction
|
||||
| LoadConfigFromDeviceReplyAction
|
||||
| SaveUserConfigInJsonFileAction
|
||||
| SaveUserConfigInBinaryFileAction
|
||||
;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { go } from '@ngrx/router-store';
|
||||
import { Actions, Effect, toPayload } from '@ngrx/effects';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Action, Store } from '@ngrx/store';
|
||||
import { saveAs } from 'file-saver';
|
||||
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/switchMap';
|
||||
@@ -148,6 +149,25 @@ export class UserConfigEffects {
|
||||
}
|
||||
});
|
||||
|
||||
@Effect({dispatch: false}) saveUserConfigInJsonFile$ = this.actions$
|
||||
.ofType(ActionTypes.SAVE_USER_CONFIG_IN_JSON_FILE)
|
||||
.withLatestFrom(this.store.select(getUserConfiguration))
|
||||
.do(([action, userConfiguration]) => {
|
||||
const asString = JSON.stringify(userConfiguration.toJsonObject(), null, 2);
|
||||
const asBlob = new Blob([asString], {type: 'text/plain'});
|
||||
saveAs(asBlob, 'UserConfiguration.json');
|
||||
});
|
||||
|
||||
@Effect({dispatch: false}) saveUserConfigInBinFile$ = this.actions$
|
||||
.ofType(ActionTypes.SAVE_USER_CONFIG_IN_BIN_FILE)
|
||||
.withLatestFrom(this.store.select(getUserConfiguration))
|
||||
.do(([action, userConfiguration]) => {
|
||||
const uhkBuffer = new UhkBuffer();
|
||||
userConfiguration.toBinary(uhkBuffer);
|
||||
const blob = new Blob([uhkBuffer.getBufferContent()]);
|
||||
saveAs(blob, 'UserConfiguration.bin');
|
||||
});
|
||||
|
||||
constructor(private actions$: Actions,
|
||||
private dataStorageRepository: DataStorageRepositoryService,
|
||||
private store: Store<AppState>,
|
||||
|
||||
Reference in New Issue
Block a user