Skip to content

Commit

Permalink
Finalizing export
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Jan 16, 2018
1 parent 30730d2 commit 17eaa82
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 28 deletions.
3 changes: 2 additions & 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.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<widget id="com.beanconqueror.app" version="1.0.1" 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 Expand Up @@ -93,4 +93,5 @@
<plugin name="cordova-sqlite-storage" spec="^2.0.4" />
<plugin name="ionic-plugin-keyboard" spec="^2.2.1" />
<engine name="android" spec="^6.2.3" />
<plugin name="cordova-plugin-app-version" spec="^0.1.9" />
</widget>
12 changes: 11 additions & 1 deletion package-lock.json

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

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "beanconqueror",
"version": "1.0.0",
"version": "1.0.1",
"author": "Lars Saalbach, Richard Polzin",
"homepage": "https://github.com/graphefruit/beanconqueror",
"private": true,
Expand All @@ -26,6 +26,7 @@
"@angular/platform-browser-dynamic": "5.0.0",
"@ionic-native/android-permissions": "^4.4.2",
"@ionic-native/app-minimize": "^4.3.1",
"@ionic-native/app-version": "^4.5.2",
"@ionic-native/core": "4.3.0",
"@ionic-native/image-picker": "^4.4.2",
"@ionic-native/media-capture": "^4.3.1",
Expand All @@ -36,6 +37,7 @@
"cordova-android": "^6.2.3",
"cordova-plugin-allow-backup": "0.0.2",
"cordova-plugin-android-permissions": "^1.0.0",
"cordova-plugin-app-version": "^0.1.9",
"cordova-plugin-appminimize": "^1.0.0",
"cordova-plugin-compat": "^1.0.0",
"cordova-plugin-device": "^1.1.4",
Expand Down Expand Up @@ -77,10 +79,11 @@
"com.synconset.imagepicker": {
"PHOTO_LIBRARY_USAGE_DESCRIPTION": "Bitte um Freigabe"
},
"cordova-plugin-android-permissions": {}
"cordova-plugin-android-permissions": {},
"cordova-plugin-app-version": {}
},
"platforms": [
"android"
]
}
}
}
1 change: 1 addition & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import {Component, ViewChild} from '@angular/core';
/**Ionic**/
import {Nav, Platform, IonicApp, MenuController} from 'ionic-angular';
import { AppVersion } from '@ionic-native/app-version';
/**Ionic native**/
import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {AppMinimize} from '@ionic-native/app-minimize';
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';
/**Pages**/
import {MyApp} from './app.component';
import {HomePage} from '../pages/home/home';
Expand Down Expand Up @@ -99,6 +100,7 @@ import {TimerComponent} from '../components/timer/timer';
],
providers: [
StatusBar,
AppVersion,
SplashScreen,
UIStorage,
UISettingsStorage,
Expand Down
22 changes: 19 additions & 3 deletions src/pages/beans/beans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Component, ChangeDetectorRef} from '@angular/core';
import {ModalController} from 'ionic-angular';
/**Services**/
import {UIBeanStorage} from '../../services/uiBeanStorage';
import {UIBrewStorage} from '../../services/uiBrewStorage';
import {UIAlert} from '../../services/uiAlert';
/**Modals**/
import {BeansAddModal} from '../beans/add/beans-add';
Expand All @@ -14,6 +15,7 @@ import {IBean} from '../../interfaces/bean/iBean';
* Classes
*/
import {Bean} from '../../classes/bean/bean';
import {Brew} from '../../classes/brew/brew';
@Component({
templateUrl: 'beans.html',
selector: 'beans-list',
Expand All @@ -22,7 +24,7 @@ export class BeansPage {

beans: Array<Bean> = null;

constructor(public modalCtrl: ModalController, private changeDetectorRef: ChangeDetectorRef, private uiBeanStorage: UIBeanStorage, private uiAlert: UIAlert) {
constructor(public modalCtrl: ModalController, private changeDetectorRef: ChangeDetectorRef, private uiBeanStorage: UIBeanStorage, private uiAlert: UIAlert, private uiBrewStorage:UIBrewStorage) {

}

Expand Down Expand Up @@ -56,9 +58,10 @@ export class BeansPage {
}

public deleteBean(_bean: IBean) {
this.uiAlert.showConfirm("Bohne löschen?", "Sicher?").then(() => {
this.uiAlert.showConfirm("Bohne löschen? Alle zugehörigen Brühungen werden mit entfernt.", "Sicher?").then(() => {
//Yes
this.__deleteBean(_bean)
this.__deleteBean(_bean);

},
() => {
//No
Expand All @@ -67,6 +70,19 @@ export class BeansPage {
}

private __deleteBean(_bean: IBean) {
let brews:Array<Brew> = this.uiBrewStorage.getAllEntries();

let deletingBrewIndex:Array<number> = [];
for (let i=0;i<brews.length;i++){
if (brews[i].bean === _bean.config.uuid){
deletingBrewIndex.push(i);
}
}
for(let i = deletingBrewIndex.length; i--;)
{
this.uiBrewStorage.removeByUUID(brews[deletingBrewIndex[i]].config.uuid);
}

this.uiBeanStorage.removeByObject(_bean);
this.loadBeans();

Expand Down
27 changes: 16 additions & 11 deletions src/pages/brews/brews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import {Component, ChangeDetectorRef} from '@angular/core';
import {PopoverController, NavParams} from 'ionic-angular';
/**Ionic**/
import {ModalController} from 'ionic-angular';
import {ModalController, AlertController} from 'ionic-angular';


/**Services**/
import {UIBrewStorage} from '../../services/uiBrewStorage';
Expand Down Expand Up @@ -45,7 +46,7 @@ export class BrewsPage {
constructor(private modalCtrl: ModalController, private uiBrewStorage: UIBrewStorage,
private changeDetectorRef: ChangeDetectorRef, private uiAlert: UIAlert,
private uiBeanStorage: UIBeanStorage, private uiPreparationStorage: UIPreparationStorage,
private uiHelper: UIHelper, private uiSettingsStorage: UISettingsStorage, private popoverCtrl: PopoverController) {
private uiHelper: UIHelper, private uiSettingsStorage: UISettingsStorage, private popoverCtrl: PopoverController, public alertCtrl: AlertController) {
this.settings = this.uiSettingsStorage.getSettings();


Expand Down Expand Up @@ -102,22 +103,21 @@ export class BrewsPage {
}

private downloadCSV() {
var me = this;

function exportToCsv(filename, rows) {
var processRow = function (row) {
var exportToCsv = (filename, rows) => {
var processRow = (row) => {
var finalVal = '';
for (var j = 0; j < row.length; j++) {
var innerValue = row[j] === null ? '' : row[j].toString();
if (row[j] instanceof Date) {
innerValue = row[j].toLocaleString();
}
;

var result = innerValue.replace(/"/g, '""');
if (result.search(/("|,|\n)/g) >= 0)
result = '"' + result + '"';
if (j > 0)
finalVal += ';';
finalVal += ',';
finalVal += result;
}
return finalVal + '\n';
Expand All @@ -128,11 +128,16 @@ export class BrewsPage {
csvFile += processRow(rows[i]);
}

me.uiHelper.exportCSV(filename, csvFile).then(() => {
alert('Datei wurde erfolgreich heruntergeladen');
this.uiHelper.exportCSV(filename, csvFile).then((_downloadedFileName) => {
let alert = this.alertCtrl.create({
title: 'Heruntergeladen!',
subTitle: `CSV-Datei '${_downloadedFileName}' wurde erfolgreich in den Download-Ordner heruntergeladen!`,
buttons: ['OK']
});
alert.present();
});

}
};


let entries: Array<Array<{ VALUE: any, LABEL: string }>> = [];
Expand All @@ -153,7 +158,7 @@ export class BrewsPage {
{"VALUE": brew.coffee_concentration, "LABEL": "Kaffee-Konzentration"},
{"VALUE": brew.coffee_first_drip_time, "LABEL": "Erster Kaffeetropfen"},
{"VALUE": brew.coffee_blooming_time, "LABEL": "Blooming-Zeit / Preinfusion"},
{"VALUE":brew.getCalculatedBeanAge(),"LABEL":"Bohnenalter"},
{"VALUE": brew.getCalculatedBeanAge(), "LABEL": "Bohnenalter"},
];
entries.push(entry);
}
Expand Down
32 changes: 24 additions & 8 deletions src/pages/preparations/preparations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@ import {Component, ChangeDetectorRef} from '@angular/core';
import {ModalController} from 'ionic-angular';
/**Services**/
import {UIPreparationStorage} from '../../services/uiPreparationStorage';
import {UIBrewStorage} from '../../services/uiBrewStorage';
import {UIAlert} from '../../services/uiAlert';
/**Modals**/
import {PreparationsAddModal} from '../preparations/add/preparations-add';
import {PreparationsEditModal} from '../preparations/edit/preparations-edit';

/**Interfaces**/
import {IPreparation} from '../../interfaces/preparation/iPreparation';

/**
* Classes
*/
import {Brew} from '../../classes/brew/brew';
import {Preparation} from '../../classes/preparation/preparation';
@Component({
templateUrl: 'preparations.html'
})
export class PreparationsPage {

preparations: Array<IPreparation> = [];
preparations: Array<Preparation> = [];

constructor(public modalCtrl: ModalController, private changeDetectorRef: ChangeDetectorRef, private uiPreparationStorage:UIPreparationStorage, private uiAlert:UIAlert) {
constructor(public modalCtrl: ModalController, private changeDetectorRef: ChangeDetectorRef, private uiPreparationStorage:UIPreparationStorage, private uiAlert:UIAlert, private uiBrewStorage:UIBrewStorage) {

}

Expand Down Expand Up @@ -52,8 +55,8 @@ export class PreparationsPage {
}


public deletePreparation(_preparation: IPreparation) {
this.uiAlert.showConfirm("Zubereitungsmethode löschen?", "Sicher?").then(() => {
public deletePreparation(_preparation: Preparation) {
this.uiAlert.showConfirm("Zubereitungsmethode löschen? Alle zugehörigen Brühungen werden mit entfernt.", "Sicher?").then(() => {
//Yes
this.__deletePreparation(_preparation)
},
Expand All @@ -63,7 +66,20 @@ export class PreparationsPage {

}

private __deletePreparation(_preparation: IPreparation) {
private __deletePreparation(_preparation: Preparation) {
let brews:Array<Brew> = this.uiBrewStorage.getAllEntries();
let deletingBrewIndex:Array<number> = [];
for (let i=0;i<brews.length;i++){
if (brews[i].method_of_preparation === _preparation.config.uuid){
deletingBrewIndex.push(i);
}
}
for(let i = deletingBrewIndex.length; i--;)
{
this.uiBrewStorage.removeByUUID(brews[deletingBrewIndex[i]].config.uuid);
}


this.uiPreparationStorage.removeByObject(_preparation);
this.loadPreparations();

Expand Down
3 changes: 2 additions & 1 deletion src/services/uiHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class UIHelper {

fileEntry.createWriter(function (writer) {
writer.onwriteend = function () {
resolve();
resolve(fileName);

};

Expand All @@ -157,6 +157,7 @@ export class UIHelper {
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
resolve('test.csv');

}
}
Expand Down

0 comments on commit 17eaa82

Please sign in to comment.