-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to restore backups without accessing filesystem (#513)
* feat: add ability to restore backups without accessing filesystem * fix
- Loading branch information
1 parent
d3e226e
commit 4a10590
Showing
7 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
• Added ability to restore backup without accessing files in the filesystem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<template> | ||
<ux-dialog class="small-dialog" data-cy="manage-cocktail-row-dialog"> | ||
<div click.delegate="cancel()"> | ||
<div click.delegate="$event.stopPropagation()" class="bg-base-100 modal-box relative m-auto p-4"> | ||
<label class="btn btn-sm btn-circle absolute right-2 top-2" click.trigger="cancel()">✕</label> | ||
<h3 class="text-lg font-bold" t="paste-backup-content-title"></h3> | ||
|
||
<div class="divider mt-2"></div> | ||
|
||
<p class="text-sm font-semibold mb-2" t="paste-backup-content"></p> | ||
|
||
<textarea class="textarea textarea-bordered w-full" value.bind="backupJson" rows="10"></textarea> | ||
|
||
<div class="text-sm text-error font-semibold">${errorMessage}</div> | ||
|
||
<div class="flex w-full justify-end mt-2"> | ||
<button | ||
click.delegate="restoreBackup()" | ||
disabled.bind="isValid === false" | ||
class="btn btn-warning" | ||
t="restore-backup"></button> | ||
</div> | ||
</div> | ||
</div> | ||
</ux-dialog> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { DialogController } from 'aurelia-dialog'; | ||
import { autoinject, observable } from 'aurelia-framework'; | ||
import { I18N } from 'aurelia-i18n'; | ||
import { ToastService } from 'components/toast/toast-service'; | ||
import { CocktailService } from 'services/cocktail-service'; | ||
import { IngredientService } from 'services/ingredient-service'; | ||
import { LocalStorageService } from 'services/local-storage-service'; | ||
|
||
@autoinject() | ||
export class LoadBackupDialog { | ||
public controller: DialogController; | ||
@observable public backupJson: string; | ||
public isValid = false; | ||
errorMessage: string; | ||
|
||
constructor( | ||
private _dialogContoller: DialogController, | ||
private _localStorageService: LocalStorageService, | ||
private _ingredientService: IngredientService, | ||
private _cocktailService: CocktailService, | ||
private _toastService: ToastService, | ||
private _i18n: I18N | ||
) {} | ||
|
||
backupJsonChanged(newValue: string) { | ||
this.isValid = this.IsValidJsonString(newValue.trim()); | ||
} | ||
|
||
private IsValidJsonString(str: string): boolean { | ||
try { | ||
const json = JSON.parse(str); | ||
console.log(json); | ||
return typeof json === 'object'; | ||
} catch (e) { | ||
console.log(e); | ||
return false; | ||
} | ||
} | ||
|
||
async restoreBackup() { | ||
try { | ||
this.errorMessage = ''; | ||
const backup = JSON.parse(this.backupJson); | ||
|
||
await this._localStorageService.restoreBackup(backup); | ||
this._ingredientService.reloadService(); | ||
this._cocktailService.reloadService(); | ||
|
||
this._toastService.addToastElement({ | ||
className: 'alert-success', | ||
text: this._i18n.tr('backup-restored-successfully') | ||
}); | ||
|
||
this._dialogContoller.ok(); | ||
} catch (error) { | ||
console.log(error); | ||
this.errorMessage = (error as Error).message; | ||
} | ||
} | ||
|
||
cancel() { | ||
this._dialogContoller.cancel(); | ||
} | ||
} |