From 316136e35df7023d93fd6973a564f21b7dc6cb16 Mon Sep 17 00:00:00 2001 From: Lars Saalbach Date: Sat, 4 Aug 2018 10:56:49 +0200 Subject: [PATCH 1/3] First draft for import / export --- config.xml | 3 + install.txt | 12 +++ package-lock.json | 31 ++++++- package.json | 12 ++- src/app/app.module.ts | 6 ++ src/classes/storageClass.ts | 4 + src/pages/settings/settings.ts | 156 ++++++++++++++++++++++++++++++++- src/services/uiHelper.ts | 79 +++++++++++++++++ src/services/uiStorage.ts | 72 ++++++++++++++- 9 files changed, 366 insertions(+), 9 deletions(-) diff --git a/config.xml b/config.xml index c043cbeea..8abc0ba92 100644 --- a/config.xml +++ b/config.xml @@ -90,5 +90,8 @@ + + + diff --git a/install.txt b/install.txt index 7deea0d01..02be10548 100644 --- a/install.txt +++ b/install.txt @@ -26,3 +26,15 @@ ionic cordova plugin add cordova-plugin-allow-backup --variable BACKUP=true http://ionicframework.com/docs/native/android-permissions/ ionic cordova plugin add cordova-plugin-android-permissions npm install --save @ionic-native/android-permissions + +https://ionicframework.com/docs/native/file-chooser/ +ionic cordova plugin add cordova-plugin-filechooser +npm install --save @ionic-native/file-chooser + +https://ionicframework.com/docs/native/file-path/ +ionic cordova plugin add cordova-plugin-filepath +npm install --save @ionic-native/file-path + +https://ionicframework.com/docs/native/file/ +ionic cordova plugin add cordova-plugin-file +npm install --save @ionic-native/file diff --git a/package-lock.json b/package-lock.json index 95d0a02c0..c9b9a4a9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -111,6 +111,21 @@ "resolved": "https://registry.npmjs.org/@ionic-native/core/-/core-4.9.0.tgz", "integrity": "sha512-lqM2DRiice2oyrkJR5O1cPP9qVCCPi2w1fDHcy2IhJeAuAqtx8LBrWFaXLUuy/355OhX+/dSaGErf43RLZjCeA==" }, + "@ionic-native/file": { + "version": "4.11.0", + "resolved": "https://registry.npmjs.org/@ionic-native/file/-/file-4.11.0.tgz", + "integrity": "sha512-kZm31SBN91VPXaiJLraSu/GomaMA5NwIdKDulUonvmUSkC31OzEbttpW+3vnib4gPJuYcECbatiTFP9HJ4Yfqg==" + }, + "@ionic-native/file-chooser": { + "version": "4.11.0", + "resolved": "https://registry.npmjs.org/@ionic-native/file-chooser/-/file-chooser-4.11.0.tgz", + "integrity": "sha512-VdYWhMG1m4iXpiAsgTK3liZxkDeSSWv2adheeQo9kYhE4Y/1tdjRjNrv2lTcwyg2X8bTBBtFcr/VunDYkszZ2w==" + }, + "@ionic-native/file-path": { + "version": "4.11.0", + "resolved": "https://registry.npmjs.org/@ionic-native/file-path/-/file-path-4.11.0.tgz", + "integrity": "sha512-oGdq6WPfMoKNx9TI2X9Eu/zGnXYtTeRRyKrGQg1MeBJNBrcz812/+qbQZE7px5Sttbk0RPff6F4yvzIAC9pcZA==" + }, "@ionic-native/image-picker": { "version": "4.9.0", "resolved": "https://registry.npmjs.org/@ionic-native/image-picker/-/image-picker-4.9.0.tgz", @@ -1944,6 +1959,16 @@ "resolved": "https://registry.npmjs.org/cordova-plugin-file/-/cordova-plugin-file-4.3.3.tgz", "integrity": "sha1-AS6Xqhr7kfhJFuY0G1SDZtI96bk=" }, + "cordova-plugin-filechooser": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/cordova-plugin-filechooser/-/cordova-plugin-filechooser-1.0.1.tgz", + "integrity": "sha1-+lnpe4zdkSYL4L7EYNuOxd6TSI8=" + }, + "cordova-plugin-filepath": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/cordova-plugin-filepath/-/cordova-plugin-filepath-1.4.2.tgz", + "integrity": "sha512-6AKL6dIUkY+iOYesP+3/9LC1cxIilDIo0Hdu4tdDNM/ELIxrmxKywTqGy4x76Fv/LIl6l7g8R2tgCbBXTaBvMw==" + }, "cordova-plugin-ionic-webview": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/cordova-plugin-ionic-webview/-/cordova-plugin-ionic-webview-1.2.1.tgz", @@ -1975,9 +2000,9 @@ "integrity": "sha1-tehezbv+Wu3tQKG/TuI3LmfZb7Q=" }, "cordova-sqlite-storage": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/cordova-sqlite-storage/-/cordova-sqlite-storage-2.3.2.tgz", - "integrity": "sha512-rgWusdiGvRvSN9jshab6a+ZXGtzbVXq28+dHwiWJc8nCZpaOTmS9L5RB0757ckWUAkcGK/5B6Suqb4/SELdSgw==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/cordova-sqlite-storage/-/cordova-sqlite-storage-2.3.3.tgz", + "integrity": "sha512-YZRIFZihX4KPPeeP5pUdSJYv6lf4Pq3P7dHyfDOwr2C/0LSoF8ustqqT6l25WCLccFTk1ZEFJQkXfkPi74lg7g==", "requires": { "cordova-sqlite-storage-dependencies": "1.2.0" } diff --git a/package.json b/package.json index ac4650ca9..4a0c8c990 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,9 @@ "@ionic-native/app-minimize": "4.9.0", "@ionic-native/app-version": "4.9.0", "@ionic-native/core": "4.9.0", + "@ionic-native/file": "^4.11.0", + "@ionic-native/file-chooser": "^4.11.0", + "@ionic-native/file-path": "^4.11.0", "@ionic-native/image-picker": "4.9.0", "@ionic-native/media-capture": "4.9.0", "@ionic-native/splash-screen": "4.9.0", @@ -42,13 +45,15 @@ "cordova-plugin-compat": "^1.2.0", "cordova-plugin-device": "^1.1.7", "cordova-plugin-file": "^4.3.3", + "cordova-plugin-filechooser": "^1.0.1", + "cordova-plugin-filepath": "^1.4.2", "cordova-plugin-ionic-webview": "^1.2.1", "cordova-plugin-media-capture": "^1.4.3", "cordova-plugin-splashscreen": "^4.1.0", "cordova-plugin-statusbar": "^2.4.2", "cordova-plugin-telerik-imagepicker": "^2.1.8", "cordova-plugin-whitelist": "^1.3.3", - "cordova-sqlite-storage": "^2.3.2", + "cordova-sqlite-storage": "^2.3.3", "ionic-angular": "3.9.2", "ionic-plugin-keyboard": "^2.2.1", "ionicons": "3.0.0", @@ -77,7 +82,10 @@ "cordova-plugin-app-version": {}, "com.synconset.imagepicker": { "PHOTO_LIBRARY_USAGE_DESCRIPTION": "Bitte um Freigabe" - } + }, + "cordova-plugin-filechooser": {}, + "cordova-plugin-filepath": {}, + "cordova-plugin-file": {} }, "platforms": [ "android" diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 90af3272c..611cede12 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -13,6 +13,9 @@ import {MediaCapture} from '@ionic-native/media-capture'; import {ImagePicker} from '@ionic-native/image-picker'; import { AndroidPermissions } from '@ionic-native/android-permissions'; import { AppVersion } from '@ionic-native/app-version'; +import { FileChooser } from '@ionic-native/file-chooser'; +import {FilePath} from "@ionic-native/file-path"; +import {File} from "@ionic-native/file"; /**Pages**/ import {MyApp} from './app.component'; import {HomePage} from '../pages/home/home'; @@ -108,6 +111,9 @@ import {TimerComponent} from '../components/timer/timer'; providers: [ StatusBar, AppVersion, + FileChooser, + FilePath, + File, SplashScreen, UIStorage, UISettingsStorage, diff --git a/src/classes/storageClass.ts b/src/classes/storageClass.ts index d8be06ffc..408772652 100644 --- a/src/classes/storageClass.ts +++ b/src/classes/storageClass.ts @@ -49,6 +49,10 @@ export abstract class StorageClass { return promise; } + public __reinitlizeStorage(){ + this.isInitialized = -1; + this.__initializeStorage(); + } private __initializeStorage() { this.uiStorage.get(this.DB_PATH).then((_data) => { if (_data === null || _data === undefined) { diff --git a/src/pages/settings/settings.ts b/src/pages/settings/settings.ts index 90e35b609..a45e85129 100644 --- a/src/pages/settings/settings.ts +++ b/src/pages/settings/settings.ts @@ -8,20 +8,170 @@ import {BREW_VIEW_ENUM} from '../../enums/settings/brewView'; /**Services**/ import {UISettingsStorage} from '../../services/uiSettingsStorage'; +import {UIStorage} from "../../services/uiStorage"; +import {UIHelper} from "../../services/uiHelper"; + +/**Native imports**/ +import {File} from "@ionic-native/file"; +import {FileChooser} from '@ionic-native/file-chooser'; +import {AlertController, Platform} from "ionic-angular"; +import {FilePath} from "@ionic-native/file-path"; +import {UIAlert} from "../../services/uiAlert"; +import {UIPreparationStorage} from "../../services/uiPreparationStorage"; +import {UIBeanStorage} from "../../services/uiBeanStorage"; +import {UIBrewStorage} from "../../services/uiBrewStorage"; + + +import {IBean} from "../../interfaces/bean/iBean"; +import {IBrew} from "../../interfaces/brew/iBrew"; @Component({ templateUrl: 'settings.html' }) export class SettingsPage { - settings:ISettings; + settings: ISettings; public BREW_VIEWS = BREW_VIEW_ENUM; - constructor(public uiSettingsStorage:UISettingsStorage) { + + constructor(public platform: Platform, public uiSettingsStorage: UISettingsStorage, public uiStorage: UIStorage, public uiHelper: UIHelper, + private fileChooser: FileChooser, + private filePath: FilePath, + private file: File, private alertCtrl: AlertController, + private uiAlert: UIAlert, + private uiPreparationStorage: UIPreparationStorage, + private uiBeanStorage: UIBeanStorage, + private uiBrewStorage: UIBrewStorage) { this.settings = this.uiSettingsStorage.getSettings(); } - public saveSettings(_event:any){ + public saveSettings(_event: any) { this.uiSettingsStorage.saveSettings(this.settings); } + public import() { + if (this.platform.is("android")) { + this.fileChooser.open() + .then((uri) => { + if (uri && uri.endsWith(".json")) { + this.filePath.resolveNativePath(uri).then(resolvedFilePath => { + let path = resolvedFilePath.substring(0, resolvedFilePath.lastIndexOf('/')); + let file = resolvedFilePath.substring(resolvedFilePath.lastIndexOf('/') + 1, resolvedFilePath.length); + this.__readJSONFile(path, file).then(() => { + }, (_err) => { + this.uiAlert.showMessage("Fehler beim Dateiauslesen (" + JSON.stringify(_err) + ")"); + }) + + }).catch(_err => { + this.uiAlert.showMessage("Datei konnte nicht gefunden werden (" + JSON.stringify(_err) + ")"); + }); + } else { + this.uiAlert.showMessage("Invalides Dateiformat"); + } + }); + + + } + + } + + 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.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"); + }) + + } + }) + } + + private __readJSONFile(path, file) { + var promise = new Promise((resolve, reject) => { + this.file.readAsText(path, file) + .then(content => { + let parsedContent = JSON.parse(content); + 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.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"); + } + }) + .catch(err => { + reject(err); + + }); + }); + + return promise; + + } + + private __cleanupImportBeanData(_data: Array) { + if (_data != null && _data != undefined && _data.length > 0) { + for (let i = 0; i < _data.length; i++) { + _data[i].filePath = ""; + } + } + } + + private __cleanupImportBrewData(_data: Array) { + if (_data != null && _data != undefined && _data.length > 0) { + for (let i = 0; i < _data.length; i++) { + _data[i].attachments = []; + } + } + } + + public export() { + + this.uiStorage.export().then((_data) => { + + this.uiHelper.exportJSON("Beanconqueror.json", JSON.stringify(_data)).then((_downloadedFilename) => { + + let alert = this.alertCtrl.create({ + title: 'Heruntergeladen!', + subTitle: `JSON-Datei '${_downloadedFilename}' wurde erfolgreich in den Download-Ordner heruntergeladen!`, + buttons: ['OK'] + }); + alert.present(); + + }) + }) + + } } diff --git a/src/services/uiHelper.ts b/src/services/uiHelper.ts index a0d8548c8..823f03d24 100644 --- a/src/services/uiHelper.ts +++ b/src/services/uiHelper.ts @@ -102,6 +102,85 @@ export class UIHelper { } + public exportJSON(fileName:string, jsonContent:string){ + let promise = new Promise((resolve, reject) => { + let errorCallback = (e) => { + console.log("Error: " + e); + reject(); + }; + + //Fixed umlaut issue + //Thanks to: https://stackoverflow.com/questions/31959487/utf-8-encoidng-issue-when-exporting-csv-file-javascript + var blob = new Blob([jsonContent], {type: 'application/json;charset=UTF-8;'}); + if (this.platform.is("android") || this.platform.is("ios")) { + let storageLocation: string = ""; + + switch (device.platform) { + + case "Android": + storageLocation = 'file:///storage/emulated/0/'; + break; + case "iOS": + storageLocation = cordova.file.documentsDirectory; + break; + + } + + window.resolveLocalFileSystemURL(storageLocation, + function (fileSystem) { + + fileSystem.getDirectory('Download', { + create: true, + exclusive: false + }, + function (directory) { + + //You need to put the name you would like to use for the file here. + directory.getFile(fileName, { + create: true, + exclusive: false + }, + function (fileEntry) { + + + fileEntry.createWriter(function (writer) { + writer.onwriteend = function () { + resolve(fileName); + }; + + writer.seek(0); + writer.write(blob); //You need to put the file, blob or base64 representation here. + + }, errorCallback); + }, errorCallback); + }, errorCallback); + }, errorCallback); + } + else { + setTimeout(() => { + if (navigator.msSaveBlob) { // IE 10+ + navigator.msSaveBlob(blob, fileName); + } else { + var link = document.createElement("a"); + if (link.download !== undefined) { // feature detection + // Browsers that support HTML5 download attribute + var url = URL.createObjectURL(blob); + link.setAttribute("href", url); + link.setAttribute("download", fileName); + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + resolve(fileName); + + } + } + }, 250); + } + + }); + return promise; + } + public exportCSV(fileName: string, csvContent: string) { let promise = new Promise((resolve, reject) => { diff --git a/src/services/uiStorage.ts b/src/services/uiStorage.ts index 4155f9c5b..f52d09d1b 100644 --- a/src/services/uiStorage.ts +++ b/src/services/uiStorage.ts @@ -1,7 +1,7 @@ /**Core**/ import {Injectable} from '@angular/core'; /**Ionic native**/ -import { Storage } from '@ionic/storage'; +import {Storage} from '@ionic/storage'; @Injectable() export class UIStorage { @@ -18,4 +18,74 @@ export class UIStorage { return this.storage.get(_key); } + public export(): Promise { + + var promise = new Promise((resolve, reject) => { + let exportObj = {}; + this.storage.forEach((_value, _key, _index) => { + exportObj[_key] = _value; + + }).then(() => { + resolve(exportObj); + }); + }); + + return promise; + } + + private __safteyBackup() { + var promise = new Promise((resolve, reject) => { + this.export().then((_data) => { + resolve(_data); + }) + }); + return promise; + + } + + private __importBackup(_data) { + var promise = new Promise((resolve, reject) => { + + let keysCount: number = Object.keys(_data).length; + let finishedImport: number = 0; + for (let key in _data) { + this.storage.set(key, _data[key]).then(() => { + finishedImport++; + if (keysCount == finishedImport) { + resolve(); + } + }, () => { + reject(); + }); + } + }); + return promise; + } + + public import(_data: any): Promise { + + //Before we import, we do a saftey backup + var promise = new Promise((resolve, reject) => { + + this.__safteyBackup().then((_backup) => { + + this.__importBackup(_data).then( ()=>{ + //Successfully imported backup + resolve({"BACKUP":false}); + }, ()=>{ + this.__importBackup(_backup).then( ()=>{ + resolve({"BACKUP":true}); + }, ()=>{ + reject({"BACKUP":true}) + }) + }) + }); + + }); + + return promise; + + } + + } From 6877ff80fe3de65b13a3337454fc010c7f1eab07 Mon Sep 17 00:00:00 2001 From: Lars Saalbach Date: Sat, 4 Aug 2018 10:56:59 +0200 Subject: [PATCH 2/3] missing file --- src/pages/settings/settings.html | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/settings.html b/src/pages/settings/settings.html index a2873b855..a9be8bb5e 100644 --- a/src/pages/settings/settings.html +++ b/src/pages/settings/settings.html @@ -16,6 +16,15 @@

Hier findest du alle spezifischen Einstellungen der App

+ + Datenübertragen + + + Allgemeine Einstellungen @@ -87,8 +96,6 @@ - - From 29982226e3aadc5a73520ab72da65129ec9d7285 Mon Sep 17 00:00:00 2001 From: Lars Saalbach Date: Mon, 6 Aug 2018 20:50:49 +0200 Subject: [PATCH 3/3] Finished import/export --- config.xml | 2 +- package-lock.json | 2 +- package.json | 4 +- src/classes/storageClass.ts | 2 +- src/pages/brews/table/brews-table.html | 5 +- src/pages/brews/table/brews-table.ts | 45 +++++++++----- src/pages/settings/settings.ts | 86 ++++++++++++++++++-------- src/services/uiHelper.ts | 4 +- src/theme/variables.scss | 3 + 9 files changed, 105 insertions(+), 48 deletions(-) diff --git a/config.xml b/config.xml index 8abc0ba92..16f0a035b 100644 --- a/config.xml +++ b/config.xml @@ -1,5 +1,5 @@ - + Beanconqueror Lars Saalbach diff --git a/package-lock.json b/package-lock.json index c9b9a4a9d..789be1b02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "beanconqueror", - "version": "1.2.0", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4a0c8c990..49f9866de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "beanconqueror", - "version": "1.2.0", + "version": "1.3.0", "author": "Lars Saalbach, Richard Polzin", "homepage": "https://github.com/graphefruit/beanconqueror", "private": true, @@ -91,4 +91,4 @@ "android" ] } -} \ No newline at end of file +} diff --git a/src/classes/storageClass.ts b/src/classes/storageClass.ts index 408772652..cf33e36d3 100644 --- a/src/classes/storageClass.ts +++ b/src/classes/storageClass.ts @@ -49,7 +49,7 @@ export abstract class StorageClass { return promise; } - public __reinitlizeStorage(){ + public reinitializeStorage(){ this.isInitialized = -1; this.__initializeStorage(); } diff --git a/src/pages/brews/table/brews-table.html b/src/pages/brews/table/brews-table.html index 8a70d8fc6..9c55c6d39 100644 --- a/src/pages/brews/table/brews-table.html +++ b/src/pages/brews/table/brews-table.html @@ -8,9 +8,12 @@ + diff --git a/src/pages/brews/table/brews-table.ts b/src/pages/brews/table/brews-table.ts index f4f8eeee6..8f1b6369a 100644 --- a/src/pages/brews/table/brews-table.ts +++ b/src/pages/brews/table/brews-table.ts @@ -1,7 +1,7 @@ /**Core**/ -import {Component, ViewChild, ElementRef,Renderer2} from '@angular/core'; +import {Component, ViewChild, ElementRef, Renderer2} from '@angular/core'; /**Ionic**/ -import {ViewController, NavParams, Slides} from 'ionic-angular'; +import {ViewController, NavParams, Slides, ModalController} from 'ionic-angular'; /**Services**/ import {UIBeanStorage} from '../../../services/uiBeanStorage'; import {UISettingsStorage} from '../../../services/uiSettingsStorage'; @@ -19,6 +19,7 @@ import {IBean} from '../../../interfaces/bean/iBean'; import {IBrew} from '../../../interfaces/brew/iBrew'; import {BrewView} from "../../../classes/brew/brewView"; import {UIBrewStorage} from "../../../services/uiBrewStorage"; +import {BrewsAddModal} from "../add/brews-add"; @Component({ @@ -27,44 +28,58 @@ import {UIBrewStorage} from "../../../services/uiBrewStorage"; }) export class BrewsTableModal { - @ViewChild("tableEl", ) tableEl: ElementRef; - public brews: Array=[]; + @ViewChild("tableEl",) tableEl: ElementRef; + public brews: Array = []; - - private startingFontSize:number=14; + private startingFontSize: number = 14; method_of_preparations: Array = []; beans: Array = []; - public settings:Settings; + public settings: Settings; + public hasBeans: boolean = false; + public hasPreparationMethods: boolean = false; constructor(private viewCtrl: ViewController, private navParams: NavParams, private uiBeanStorage: UIBeanStorage, private uiPreparationStorage: UIPreparationStorage, - public uiHelper: UIHelper, private uiImage: UIImage, private uiSettingsStorage:UISettingsStorage, private uiBrewStorage:UIBrewStorage, private renderer:Renderer2) { + public uiHelper: UIHelper, private uiImage: UIImage, + private uiSettingsStorage: UISettingsStorage, private uiBrewStorage: UIBrewStorage, + private renderer: Renderer2, private modalCtrl:ModalController) { this.settings = this.uiSettingsStorage.getSettings(); //Moved from ionViewDidEnter, because of Ionic issues with ion-range this.method_of_preparations = this.uiPreparationStorage.getAllEntries(); this.beans = this.uiBeanStorage.getAllEntries(); + this.hasBeans = (this.uiBeanStorage.getAllEntries().length > 0); + this.hasPreparationMethods = (this.uiPreparationStorage.getAllEntries().length > 0); this.__initializeBrews(); } - scaleFontBigger(){ - this.startingFontSize ++; - this.renderer.setStyle(this.tableEl.nativeElement,"fontSize",this.startingFontSize + "px"); + + public addBrew() { + let addBrewsModal = this.modalCtrl.create(BrewsAddModal, {}); + addBrewsModal.onDidDismiss(() => { + this.__initializeBrews(); + }); + addBrewsModal.present({animate: false}); + } + + scaleFontBigger() { + this.startingFontSize++; + this.renderer.setStyle(this.tableEl.nativeElement, "fontSize", this.startingFontSize + "px"); } - scaleFontSmaller(){ + + scaleFontSmaller() { this.startingFontSize--; - if (this.startingFontSize <6) - { + if (this.startingFontSize < 6) { this.startingFontSize = 6; } - this.renderer.setStyle(this.tableEl.nativeElement,"fontSize",this.startingFontSize + "px"); + this.renderer.setStyle(this.tableEl.nativeElement, "fontSize", this.startingFontSize + "px"); } dismiss() { diff --git a/src/pages/settings/settings.ts b/src/pages/settings/settings.ts index a45e85129..a1a592af1 100644 --- a/src/pages/settings/settings.ts +++ b/src/pages/settings/settings.ts @@ -49,6 +49,7 @@ export class SettingsPage { } public import() { + if (this.platform.is("android")) { this.fileChooser.open() .then((uri) => { @@ -74,30 +75,36 @@ export class SettingsPage { } - private test(){ - this.uiStorage.export().then((_back)=>{ + 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.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"); + 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"); + } }) } @@ -114,16 +121,19 @@ export class SettingsPage { this.__cleanupImportBeanData(parsedContent[this.uiBeanStorage.getDBPath()]); this.__cleanupImportBrewData(parsedContent[this.uiBrewStorage.getDBPath()]); - this.uiStorage.import(parsedContent).then((_data)=>{ - if (_data.BACKUP === false){ - this.uiAlert.showMessage("Import erfolgreich"); + 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"); + }, () => { + this.uiAlert.showMessage("Import unerfolgreich, Daten wurden nicht verändert"); }) } @@ -141,6 +151,32 @@ export class SettingsPage { } + private __reinitializeStorages() { + var promise = new Promise((resolve, reject) => { + + this.uiBeanStorage.reinitializeStorage(); + this.uiBrewStorage.reinitializeStorage(); + this.uiPreparationStorage.reinitializeStorage(); + this.uiSettingsStorage.reinitializeStorage(); + + let beanStorageReadyCallback = this.uiBeanStorage.storageReady(); + let preparationStorageReadyCallback = this.uiPreparationStorage.storageReady(); + let uiSettingsStorageReadyCallback = this.uiSettingsStorage.storageReady(); + let brewStorageReadyCallback = this.uiBrewStorage.storageReady(); + Promise.all([ + beanStorageReadyCallback, + preparationStorageReadyCallback, + brewStorageReadyCallback, + uiSettingsStorageReadyCallback, + ]).then(() => { + resolve(); + }, () => { + resolve(); + }) + }); + return promise; + } + private __cleanupImportBeanData(_data: Array) { if (_data != null && _data != undefined && _data.length > 0) { for (let i = 0; i < _data.length; i++) { diff --git a/src/services/uiHelper.ts b/src/services/uiHelper.ts index 823f03d24..363eea43f 100644 --- a/src/services/uiHelper.ts +++ b/src/services/uiHelper.ts @@ -118,7 +118,7 @@ export class UIHelper { switch (device.platform) { case "Android": - storageLocation = 'file:///storage/emulated/0/'; + storageLocation = cordova.file.externalRootDirectory; break; case "iOS": storageLocation = cordova.file.documentsDirectory; @@ -198,7 +198,7 @@ export class UIHelper { switch (device.platform) { case "Android": - storageLocation = 'file:///storage/emulated/0/'; + storageLocation = cordova.file.externalRootDirectory; break; case "iOS": storageLocation = cordova.file.documentsDirectory; diff --git a/src/theme/variables.scss b/src/theme/variables.scss index 18276a461..9cb924157 100644 --- a/src/theme/variables.scss +++ b/src/theme/variables.scss @@ -86,3 +86,6 @@ $colors: ( @import "roboto"; @import "noto-sans"; + + +$toolbar-background: rgb(225,217,207);