Skip to content

Commit

Permalink
Finished import/export
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Aug 6, 2018
1 parent 6877ff8 commit 2998222
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 48 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.beanconqueror.app" version="1.2.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="com.beanconqueror.app" version="1.3.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Beanconqueror</name>
<description />
<author email="[email protected]" href="https://github.com/graphefruit/beanconqueror">Lars Saalbach</author>
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down 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 @@ -49,7 +49,7 @@ export abstract class StorageClass {
return promise;
}

public __reinitlizeStorage(){
public reinitializeStorage(){
this.isInitialized = -1;
this.__initializeStorage();
}
Expand Down
5 changes: 4 additions & 1 deletion src/pages/brews/table/brews-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
</ion-buttons>
<ion-buttons end>
<button ion-button icon-only (click)="scaleFontSmaller()">
<ion-icon name="remove"></ion-icon>
<ion-icon class="fa fa-search-minus"></ion-icon>
</button>
<button ion-button icon-only (click)="scaleFontBigger()">
<ion-icon class="fa fa-search-plus"></ion-icon>
</button>
<button [disabled]="!hasBeans || !hasPreparationMethods" ion-button icon-only (click)="addBrew()">
<ion-icon name="add"></ion-icon>
</button>
</ion-buttons>
Expand Down
45 changes: 30 additions & 15 deletions src/pages/brews/table/brews-table.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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({
Expand All @@ -27,44 +28,58 @@ import {UIBrewStorage} from "../../../services/uiBrewStorage";
})
export class BrewsTableModal {

@ViewChild("tableEl", ) tableEl: ElementRef;
public brews: Array<Brew>=[];
@ViewChild("tableEl",) tableEl: ElementRef;
public brews: Array<Brew> = [];



private startingFontSize:number=14;
private startingFontSize: number = 14;

method_of_preparations: Array<IPreparation> = [];
beans: Array<IBean> = [];

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() {
Expand Down
86 changes: 61 additions & 25 deletions src/pages/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class SettingsPage {
}

public import() {

if (this.platform.is("android")) {
this.fileChooser.open()
.then((uri) => {
Expand All @@ -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");
}
})
}

Expand All @@ -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");
})

}
Expand All @@ -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<IBean>) {
if (_data != null && _data != undefined && _data.length > 0) {
for (let i = 0; i < _data.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/services/uiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/theme/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,6 @@ $colors: (

@import "roboto";
@import "noto-sans";


$toolbar-background: rgb(225,217,207);

0 comments on commit 2998222

Please sign in to comment.