Erste lauffähige Version
This commit is contained in:
@@ -7,9 +7,10 @@
|
||||
// 'starter.controllers' is found in controllers.js
|
||||
var db;
|
||||
|
||||
angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter.services'])
|
||||
angular.module('starter', ['ionic', 'ngCordova', 'jett.ionic.filter.bar','starter.controllers', 'starter.services'])
|
||||
|
||||
.run(function($ionicPlatform, $window, $ionicHistory, $database, $ionicPopup, $state, $window, $rootScope) {
|
||||
|
||||
.run(function($ionicPlatform) {
|
||||
$ionicPlatform.ready(function() {
|
||||
|
||||
|
||||
@@ -20,7 +21,7 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
|
||||
$ionicPlatform.registerBackButtonAction(function(event) {
|
||||
|
||||
// Handle Android back button to avoid the application exits accidentaly
|
||||
if ($state.current.name=="tab.dash") {
|
||||
if ($state.current.name=="tab.dash") {
|
||||
$ionicPopup.confirm({
|
||||
title: 'System-Hinweis',
|
||||
template: 'Möchten Sie die App beenden?'
|
||||
@@ -49,7 +50,7 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
|
||||
|
||||
// Mandatory for InAppBrowser plugin
|
||||
if(window.cordova){
|
||||
window.open = cordova.InAppBrowser.open;
|
||||
//window.open = cordova.InAppBrowser.open;
|
||||
}
|
||||
// Copy the populated database to mobile device destination
|
||||
//if (window.sqlitePlugin && window.cordova) {
|
||||
@@ -106,26 +107,48 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
|
||||
// org.apache.cordova.statusbar required
|
||||
StatusBar.styleDefault();
|
||||
}
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
.config(function($stateProvider, $urlRouterProvider) {
|
||||
.config(function($stateProvider, $urlRouterProvider,$ionicConfigProvider,$ionicFilterBarConfigProvider) {
|
||||
|
||||
// Ionic uses AngularUI Router which uses the concept of states
|
||||
// Learn more here: https://github.com/angular-ui/ui-router
|
||||
// Set up the various states which the app can be in.
|
||||
// Each state's controller can be found in controllers.js
|
||||
if(ionic.Platform.isAndroid()){
|
||||
$ionicConfigProvider.scrolling.jsScrolling(false);
|
||||
}
|
||||
|
||||
$stateProvider
|
||||
|
||||
.state('init', {
|
||||
url: '/init',
|
||||
templateUrl: 'templates/init.html',
|
||||
controller: 'InitCtrl'
|
||||
})
|
||||
|
||||
.state('firstrun', {
|
||||
url: '/first',
|
||||
templateUrl: 'templates/firstrun.html',
|
||||
controller: 'FirstRunCtrl'
|
||||
})
|
||||
|
||||
.state('imagedownload', {
|
||||
url: '/imagedownload',
|
||||
templateUrl: 'templates/imagedownload.html',
|
||||
controller: 'ImageDownloadCtrl'
|
||||
})
|
||||
|
||||
// setup an abstract state for the tabs directive
|
||||
.state('tab', {
|
||||
.state('tab', {
|
||||
url: '/tab',
|
||||
abstract: true,
|
||||
templateUrl: 'templates/tabs.html'
|
||||
})
|
||||
|
||||
// Each tab has its own nav history stack:
|
||||
|
||||
.state('tab.dash', {
|
||||
url: '/dash',
|
||||
views: {
|
||||
@@ -166,7 +189,7 @@ angular.module('starter', ['ionic', 'ngCordova', 'starter.controllers', 'starter
|
||||
});
|
||||
|
||||
// if none of the above states are matched, use this as the fallback
|
||||
$urlRouterProvider.otherwise('/tab/dash');
|
||||
//$ionicConfigProvider.tabs.position('bottom');
|
||||
$urlRouterProvider.otherwise('/init');
|
||||
$ionicConfigProvider.tabs.position('bottom');
|
||||
|
||||
});
|
||||
|
||||
@@ -1,11 +1,218 @@
|
||||
angular.module('starter.controllers', [])
|
||||
|
||||
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope, $cordovaFileTransfer,$cordovaFile,$ionicLoading,$state,$filter,$ionicModal) {
|
||||
.controller('DashCtrl', function($scope,$ionicPopup,$http, $database, $timeout,$rootScope, $cordovaFileTransfer,$cordovaFile,$ionicLoading,$state,$filter,$ionicModal,$ionicPlatform,$location) {
|
||||
|
||||
|
||||
|
||||
$scope.resetdb = function() {
|
||||
$database.setInitialRun(0);
|
||||
}
|
||||
|
||||
// Open our new task modal
|
||||
$scope.downloadImages = function() {
|
||||
$state.go('imagedownload');
|
||||
};
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
.controller('ChatsCtrl', function($scope,$ionicPopup,$http, $database,$window, $timeout,$rootScope, $cordovaFileTransfer,$cordovaFile,$ionicLoading,$state,$filter,$ionicModal,$ionicFilterBar) {
|
||||
|
||||
var filterBarInstance;
|
||||
|
||||
//View wird zum ersten mal geladen
|
||||
$scope.$on( "$ionicView.loaded", function( scopes, states ) {
|
||||
$scope.items=[];
|
||||
});
|
||||
|
||||
|
||||
|
||||
$scope.$on( "$ionicView.enter", function( scopes, states ) {
|
||||
if ($scope.items.length===0){
|
||||
$scope.show($ionicLoading);
|
||||
$timeout(fill_list, 1000);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
$scope.showFilterBar = function () {
|
||||
filterBarInstance = $ionicFilterBar.show({
|
||||
items: $scope.items,
|
||||
update: function (filteredItems, filterText) {
|
||||
$scope.items = filteredItems;
|
||||
if (filterText) {
|
||||
console.log(filterText);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.refreshItems = function () {
|
||||
if (filterBarInstance) {
|
||||
filterBarInstance();
|
||||
filterBarInstance = null;
|
||||
}
|
||||
|
||||
$timeout(function () {
|
||||
fill_list();
|
||||
$scope.$broadcast('scroll.refreshComplete');
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
function fill_list(){
|
||||
|
||||
$database.getAllPokemon().then(function (result) {
|
||||
|
||||
if(result.length>0){
|
||||
for(i=0;i<result.length;i++){
|
||||
$scope.items.push(result[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$scope.items=[];
|
||||
}
|
||||
});
|
||||
$scope.hide($ionicLoading);
|
||||
}
|
||||
|
||||
|
||||
$scope.show = function() {
|
||||
$ionicLoading.show({
|
||||
template: '<p>Lade...</p><ion-spinner></ion-spinner>'
|
||||
});
|
||||
};
|
||||
|
||||
$scope.hide = function(){
|
||||
$ionicLoading.hide();
|
||||
};
|
||||
|
||||
|
||||
})
|
||||
|
||||
.controller('ChatsCtrl', function($scope, Chats) {
|
||||
|
||||
.controller('InitCtrl', function($scope, $ionicPlatform, $database,$state) {
|
||||
|
||||
$ionicPlatform.ready(function() {
|
||||
|
||||
$database.isInitialRun().then(function (result) {
|
||||
|
||||
if (result==1) {
|
||||
$state.go('tab.dash');
|
||||
}
|
||||
else{
|
||||
$state.go('firstrun');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
|
||||
.controller('FirstRunCtrl', function($scope,$ionicSlideBoxDelegate,$database,$state) {
|
||||
|
||||
|
||||
$scope.options = {
|
||||
loop: false,
|
||||
effect: 'fade',
|
||||
speed: 500,
|
||||
}
|
||||
|
||||
$scope.$on("$ionicSlides.sliderInitialized", function(event, data){
|
||||
// data.slider is the instance of Swiper
|
||||
$scope.slider = data.slider;
|
||||
});
|
||||
|
||||
$scope.$on("$ionicSlides.slideChangeStart", function(event, data){
|
||||
console.log('Slide change is beginning');
|
||||
});
|
||||
|
||||
$scope.$on("$ionicSlides.slideChangeEnd", function(event, data){
|
||||
// note: the indexes are 0-based
|
||||
$scope.activeIndex = data.activeIndex;
|
||||
$scope.previousIndex = data.previousIndex;
|
||||
});
|
||||
|
||||
$scope.firstruncomplete = function() {
|
||||
$database.setInitialRun(1);
|
||||
$state.go('tab.dash');
|
||||
};
|
||||
|
||||
})
|
||||
|
||||
|
||||
.controller('ImageDownloadCtrl', function($scope, $database, $timeout, $cordovaFileTransfer,$cordovaFile,$state,$ionicPlatform) {
|
||||
|
||||
|
||||
$scope.progressval = 0;
|
||||
$scope.currentfile = '';
|
||||
$scope.progressprozent = 0;
|
||||
|
||||
|
||||
// Open our new task modal
|
||||
$scope.downloadImages = function() {
|
||||
$ionicPlatform.ready(function() {
|
||||
//$scope.taskModal.show();
|
||||
var baseurl = "http://assets.pokemon.com/assets/cms2/img/pokedex/full/";
|
||||
var url="";
|
||||
var filename="";
|
||||
var targetPath = "";
|
||||
var downloadprogress = 0;
|
||||
var pokedexid=1;
|
||||
|
||||
//Ordner erstellen auf SD-Karte
|
||||
$cordovaFile.createDir(cordova.file.externalRootDirectory, "PokedexHelperBilder", false)
|
||||
.then(function (success) {
|
||||
// success
|
||||
console.log('Erfolg bei Ordnererstellung. ' + success);
|
||||
}, function (error) {
|
||||
// error
|
||||
console.log('Error bei Ordnererstellung. ' + error);
|
||||
});
|
||||
|
||||
do {
|
||||
filename=pokedexid + ".png";
|
||||
|
||||
if (filename.length==5){
|
||||
filename='00' + filename;
|
||||
}
|
||||
|
||||
if (filename.length==6){
|
||||
filename='0' + filename;
|
||||
}
|
||||
|
||||
url=baseurl;
|
||||
url=encodeURI(url + filename);
|
||||
targetPath = cordova.file.externalRootDirectory + "/PokedexHelperBilder/" + filename;
|
||||
|
||||
//Bild Download
|
||||
$cordovaFileTransfer.download(url, targetPath, {Connection: "close"}, true).then(function (result) {
|
||||
$scope.currentfile=filename;
|
||||
console.log(filename + ' heruntergeladen.' + result);
|
||||
pokedexid=pokedexid + 1;
|
||||
console.log(result);
|
||||
}, function (error) {
|
||||
console.log('Error. ' + error.code + ' ' + error.constant);
|
||||
}, function (progress) {
|
||||
downloadprogress=(progress.loaded / progress.total) * 100;
|
||||
$scope.progressval = pokedexid;
|
||||
$scope.currentfile=filename + downloadprogress;
|
||||
});
|
||||
console.log(pokedexid);
|
||||
} while (pokedexid <= 720);
|
||||
|
||||
console.log(pokedexid);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
.controller('Dummy', function($scope) {
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ angular.module('starter.services', [])
|
||||
initDB: function() {
|
||||
if(window.cordova){
|
||||
//self.db = sqlitePlugin.openDatabase({name: "data.db", location: 2, createFromLocation: 1});
|
||||
self.db = $cordovaSQLite.openDB("pokedex.db");
|
||||
self.db = $cordovaSQLite.openDB({name:"pokedex.db", iosDatabaseLocation:'default'});
|
||||
} else {
|
||||
self.db = window.openDatabase('pokedex.db','1','my',800*1024); // only available when WebSQL is available in Browser
|
||||
}
|
||||
@@ -56,21 +56,43 @@ angular.module('starter.services', [])
|
||||
console.error(error);
|
||||
});
|
||||
},
|
||||
getAllBuys: function(){
|
||||
isInitialRun: function(){
|
||||
var InitilaRun;
|
||||
query="SELECT InitialRun FROM InitialRun";
|
||||
return $cordovaSQLite.execute(self.db,query).
|
||||
then(function(result) {
|
||||
for(j=0;j<result.rows.length;j++){
|
||||
InitilaRun=result.rows.item(j).InitialRun;
|
||||
}
|
||||
console.log('isInitialRun aufgerufen wert : ' + InitilaRun);
|
||||
return InitilaRun;
|
||||
},function(e){
|
||||
console.error(e);
|
||||
return e;
|
||||
});
|
||||
},
|
||||
setInitialRun: function(InitilaRunBool) {
|
||||
query="UPDATE InitialRun Set InitialRun = ?;";
|
||||
return $cordovaSQLite.execute(self.db,query,[InitilaRunBool]).
|
||||
then(function(result) {
|
||||
console.log("Update erfolge auf " + InitilaRunBool);
|
||||
query=null;
|
||||
}, function(error) {
|
||||
console.error(error);
|
||||
});
|
||||
},
|
||||
getAllPokemon: function(){
|
||||
var ArrayQ=[];
|
||||
query="SELECT * FROM buys order by id DESC";
|
||||
query="SELECT * FROM tblPokemon order by POKEDEXID ASC";
|
||||
return $cordovaSQLite.execute(self.db,query).
|
||||
then(function(result) {
|
||||
for(j=0;j<result.rows.length;j++){
|
||||
var List={};
|
||||
//console.log(result.rows.item(j));
|
||||
List.id=result.rows.item(j).id;
|
||||
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;
|
||||
List.ID=result.rows.item(j).ID;
|
||||
List.POKEDEXID=result.rows.item(j).POKEDEXID;
|
||||
List.POKEMONNAME=result.rows.item(j).POKEMONNAME;
|
||||
List.POKEMONTYPA=result.rows.item(j).POKEMONTYPA;
|
||||
List.POKEMONTYPB=result.rows.item(j).POKEMONTYPB;
|
||||
ArrayQ.push(List);
|
||||
}
|
||||
//console.log(ArrayQ);
|
||||
@@ -81,4 +103,4 @@ angular.module('starter.services', [])
|
||||
});
|
||||
}
|
||||
};
|
||||
}]);
|
||||
}]);
|
||||
Reference in New Issue
Block a user