From 246d279c27d188235bbed3a0b7da4ef5df6660c9 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 28 Jan 2016 22:59:57 +0100 Subject: [PATCH] Filecopy added, Sqlite Database neues Schema --- www/js/controllers.js | 69 ++++++++++++++++++++++++------------------ www/js/services.js | 10 ++++-- www/raataar_wrk.db | Bin 3072 -> 3072 bytes 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/www/js/controllers.js b/www/js/controllers.js index 18fe355..46e6f89 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -1,6 +1,6 @@ angular.module('starter.controllers', []) -.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope, $cordovaFileTransfer) { +.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope, $cordovaFileTransfer,$cordovaFile) { $scope.preis=""; $scope.name=""; @@ -8,9 +8,6 @@ angular.module('starter.controllers', []) $scope.items=[]; $scope.item=[]; - //db = Database.getDb(); - - //$scope.items=$localstorage.getObject('items'); $scope.validate = function() { @@ -52,28 +49,11 @@ angular.module('starter.controllers', []) }; function successBuyHandler (result) { - /* - var strResult = ""; - if(typeof result === 'object') { - strResult = JSON.stringify(result); - } else { - strResult = result; - } - alert("SUCCESS: \r\n"+strResult ); - */ $timeout(consumesuccessHandler, 1000); } function successConsumeHandler (result) { - /* - var strResult = ""; - if(typeof result === 'object') { - strResult = JSON.stringify(result); - } else { - strResult = result; - } - alert("SUCCESS: \r\n"+strResult ); - */ + var link = 'http://api.raataar.de/rosen/kauf.php'; $http.post(link, {name : $scope.name, freitext: $scope.freitext, rosen: $scope.preis}).then(function (res){ @@ -82,25 +62,43 @@ angular.module('starter.controllers', []) // File for download var url = "http://api.raataar.de/rosen/" + $scope.filetodownload; - alert(url); // File name only var filename = url.split("/").pop(); - alert(filename); // Save location //var targetPath = cordova.file.externalRootDirectory + filename; var targetPath = cordova.file.applicationStorageDirectory + filename; + var targetpublicPath = $scope.filename, cordova.file.externalRootDirectory + "/WolleRosenKaufen/" + filename; - alert(targetPath); $scope.targetPath=''; $scope.targetPath=targetPath; + $scope.targetpublicPath=targetpublicPath; + + $scope.filename=filename; + $cordovaFileTransfer.download(url, targetPath, {}, true).then(function (result) { - $scope.item={name: $scope.name, bild: $scope.targetPath}; + $scope.item={name: $scope.name, bild: $scope.targetpublicPath}; $scope.items.push($scope.item); - alert ($scope.targetPath); - $database.setBuys($scope.name,$scope.targetPath); + //itemName,itemBild,itemBildtext,itemKaufdatum,itemappimgpath,itemappimgpublicpath + $database.setBuys($scope.name,$scope.filename,$scope.freitext,'','',''); + //Ordner erstellen auf SD-Karte + $cordovaFile.createDir(cordova.file.externalRootDirectory, "WolleRosenKaufen", false) + .then(function (success) { + // success + }, function (error) { + // error + }); + + $cordovaFile.copyFile(cordova.file.applicationStorageDirectory, $scope.filename, cordova.file.externalRootDirectory + "/WolleRosenKaufen", $scope.filename) + .then(function (success) { + // success + }, function (error) { + // error + }); + + }, function (error) { console.log('Error'); @@ -116,6 +114,17 @@ angular.module('starter.controllers', []) } function errorBuyHandler (error) { + /* + var strResult = ""; + if(typeof error === 'object') { + strResult = JSON.stringify(error); + } else { + strResult = error; + } + alert("Feher: \r\n"+strResult ); + */ + + var alertPopup = $ionicPopup.alert({ title: 'Oh Nein', template: 'Der Kauf konnte nicht durchgeführt werden.' @@ -149,7 +158,9 @@ angular.module('starter.controllers', []) if((window.device && device.platform == "Android") && typeof inappbilling !== "undefined") { if ($rootScope.storeinit==1){ - inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis); + //Wegenbug ausgehebelt + //inappbilling.buy(successBuyHandler, errorBuyHandler, $scope.preis); + successConsumeHandler(); } else{ var alertPopup = $ionicPopup.alert({ diff --git a/www/js/services.js b/www/js/services.js index de43673..11cef67 100644 --- a/www/js/services.js +++ b/www/js/services.js @@ -61,9 +61,9 @@ angular.module('starter.services', []) console.log('Database opened'); return self.db; }, - setBuys: function(itemName,itemBild) { - query="INSERT INTO buys (Name, Bild) VALUES (?,?);"; - return $cordovaSQLite.execute(self.db,query,[itemName,itemBild]). + setBuys: function(itemName,itemBild,itemBildtext,itemKaufdatum,itemappimgpath,itemappimgpublicpath) { + query="INSERT INTO buys (Name, Bild, Bildtext, Kaufdatum, appimgpath, appimgpublicpath) VALUES (?,?,?,?,?,?);"; + return $cordovaSQLite.execute(self.db,query,[itemName,itemBild,itemBildtext,itemKaufdatum,itemappimgpath,itemappimgpublicpath]). then(function(result) { console.log("Gespeichert"); query=null; @@ -81,6 +81,10 @@ angular.module('starter.services', []) //console.log(result.rows.item(j)); List.name=result.rows.item(j).Name; List.bild=result.rows.item(j).Bild; + List.bildtext=result.rows.item(j).Bildtext; + List.kaufdatum=result.rows.item(j).Kaufdatum; + List.appimgpath=result.rows.item(j).appimgpath; + List.appimgpublicpath=result.rows.item(j).appimgpublicpath; ArrayQ.push(List); } //console.log(ArrayQ); diff --git a/www/raataar_wrk.db b/www/raataar_wrk.db index d9ea0b26a1ee92304f7101b8ff2bfd3b17c255ef..63f09fc32de2175064d133e266e40406de52780d 100644 GIT binary patch delta 198 zcmZpWXpop7Ey&J*3fLy<*s?S2WMJlI+PSgNlWDRFb1-KSBfGe$C}XqxCA<^TWy delta 107 zcmZpWXpop7Ey&1#3K%Eq*s?RLFff-ft85lz*}^n=CsQydJ0rWes3>D&;bc)}V