Skip to content

Commit

Permalink
Settings reinitializing & Fixing temperatur show
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Aug 6, 2018
1 parent 0b1dfba commit 818fed3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@
"android"
]
}
}
}
2 changes: 1 addition & 1 deletion src/classes/storageClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export abstract class StorageClass {
this.isInitialized = -1;
this.__initializeStorage();
}
private __initializeStorage() {
protected __initializeStorage() {
this.uiStorage.get(this.DB_PATH).then((_data) => {
if (_data === null || _data === undefined) {
//No beans have been added yet
Expand Down
4 changes: 2 additions & 2 deletions src/pages/brews/add/brews-add.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
<ion-label floating>Gewicht</ion-label>
<ion-input [prevent-characters] [(ngModel)]="data.grind_weight" type="text"></ion-input>
</ion-item>
<ion-row>
<ion-row ngIf="settings.brew_temperature === true">

<ion-col no-padding col-4>
<ion-item *ngIf="settings.brew_temperature === true">
<ion-item>
<ion-label floating>Temperatur</ion-label>
<ion-input [prevent-characters] [(ngModel)]="data.brew_temperature" type="text"></ion-input>
</ion-item>
Expand Down
38 changes: 5 additions & 33 deletions src/pages/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export class SettingsPage {
private uiPreparationStorage: UIPreparationStorage,
private uiBeanStorage: UIBeanStorage,
private uiBrewStorage: UIBrewStorage) {
this.__initializeSettings();
}

private __initializeSettings(){
this.settings = this.uiSettingsStorage.getSettings();
}

Expand Down Expand Up @@ -75,39 +79,6 @@ export class SettingsPage {

}

private test() {
this.uiStorage.export().then((_back) => {
let parsedContent = _back;
if (parsedContent[this.uiPreparationStorage.getDBPath()] &&
parsedContent[this.uiBeanStorage.getDBPath()] &&
parsedContent[this.uiBrewStorage.getDBPath()] &&
parsedContent[this.uiSettingsStorage.getDBPath()]) {

this.__cleanupImportBeanData(parsedContent[this.uiBeanStorage.getDBPath()]);
this.__cleanupImportBrewData(parsedContent[this.uiBrewStorage.getDBPath()]);

this.uiStorage.import(parsedContent).then((_data) => {
if (_data.BACKUP === false) {
this.__reinitializeStorages().then(() => {
this.uiAlert.showMessage("Import erfolgreich");
})

}
else {
this.uiAlert.showMessage("Import unerfolgreich, Daten wurden nicht verändert");
}

}, () => {
this.uiAlert.showMessage("Import unerfolgreich, Daten wurden nicht verändert");
})

}
else {
this.uiAlert.showMessage("Invalider Dateiinhalt");
}
})
}

private __readJSONFile(path, file) {
var promise = new Promise((resolve, reject) => {
this.file.readAsText(path, file)
Expand All @@ -124,6 +95,7 @@ export class SettingsPage {
this.uiStorage.import(parsedContent).then((_data) => {
if (_data.BACKUP === false) {
this.__reinitializeStorages().then(() => {
this.__initializeSettings();
this.uiAlert.showMessage("Import erfolgreich");
})

Expand Down
17 changes: 17 additions & 0 deletions src/services/uiSettingsStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,23 @@ export class UISettingsStorage extends StorageClass {
})
}

public reinitializeStorage(){
super.reinitializeStorage();

super.storageReady().then(() => {
let entries: Array<any> = this.getAllEntries();
if (entries.length > 0) {
//We already had some settings here.
this.settings.initializeByObject(entries[0]);
}
else {
//Take the new settings obj.
super.add(this.settings);
}
}, () => {
//Outsch, cant do much.
})
}
public getSettings(): Settings {
return this.settings;
}
Expand Down

0 comments on commit 818fed3

Please sign in to comment.