diff --git a/package.json b/package.json index c1a9433..f0cc236 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,8 @@ "gulp-util": "^2.2.14", "shelljs": "^0.3.0" }, - "cordovaPlugins": [], + "cordovaPlugins": [ + "cordova-plugin-crosswalk-webview@1.2.0" + ], "cordovaPlatforms": [] } \ No newline at end of file diff --git a/www/index.html b/www/index.html index 20eaaaa..578350e 100644 --- a/www/index.html +++ b/www/index.html @@ -30,4 +30,4 @@ - + \ No newline at end of file diff --git a/www/js/app.js b/www/js/app.js index f3c4fd7..cd13446 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -31,7 +31,7 @@ angular.module('wpIonic', ['ionic','ionic.service.core', 'wpIonic.controllers', if( ionic.Platform.isAndroid() ) { $ionicConfigProvider.scrolling.jsScrolling(false); } - + $stateProvider // sets up our default state, all views are loaded through here @@ -63,6 +63,16 @@ angular.module('wpIonic', ['ionic','ionic.service.core', 'wpIonic.controllers', } }) + .state('app.bookmarks', { + url: "/bookmarks", + views: { + 'menuContent': { + templateUrl: "templates/bookmarks.html", + controller: 'BookmarksCtrl' + } + } + }) + .state('app.post', { url: "/posts/:postId", views: { diff --git a/www/js/controllers.js b/www/js/controllers.js index b5230e1..6a9e0e5 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -9,7 +9,7 @@ angular.module('wpIonic.controllers', []) }) -.controller('PostCtrl', function($scope, $stateParams, DataLoader, $ionicLoading, $rootScope, $sce, CacheFactory ) { +.controller('PostCtrl', function($scope, $stateParams, DataLoader, $ionicLoading, $rootScope, $sce, CacheFactory, $log, Bookmark ) { if ( ! CacheFactory.get('postCache') ) { CacheFactory.createCache('postCache'); @@ -24,7 +24,6 @@ angular.module('wpIonic.controllers', []) if( !postCache.get( $scope.itemID ) ) { // cache doesn't exist, so go get post - console.log('cache doesnt exist, so go get post'); $ionicLoading.show({ noBackdrop: true @@ -36,12 +35,14 @@ angular.module('wpIonic.controllers', []) // Don't strip post html $scope.content = $sce.trustAsHtml(response.data.content.rendered); + $scope.comments = $scope.post._embedded['replies'][0]; + // add post to our cache postCache.put( response.data.id, response.data ); $ionicLoading.hide(); }, function(response) { - console.log('error', response); + $log.error('error', response); $ionicLoading.hide(); }); @@ -49,11 +50,25 @@ angular.module('wpIonic.controllers', []) // Item exists, use cached item $scope.post = postCache.get( $scope.itemID ); $scope.content = $sce.trustAsHtml( $scope.post.content.rendered ); + $scope.comments = $scope.post._embedded['replies'][0]; + } + + $scope.bookmarked = Bookmark.check( $scope.itemID ); + + $scope.bookmarkItem = function( id ) { + + if( $scope.bookmarked ) { + Bookmark.remove( id ); + $scope.bookmarked = false; + } else { + Bookmark.set( id ); + $scope.bookmarked = true; + } } }) -.controller('PostsCtrl', function( $scope, $http, DataLoader, $timeout, $ionicSlideBoxDelegate, $rootScope ) { +.controller('PostsCtrl', function( $scope, $http, DataLoader, $timeout, $ionicSlideBoxDelegate, $rootScope, $log ) { var postsApi = $rootScope.url + 'posts?' + $rootScope.callback; @@ -61,8 +76,6 @@ angular.module('wpIonic.controllers', []) $scope.loadPosts = function() { - console.log('loadPosts'); - // Get all of our posts DataLoader.get( postsApi ).then(function(response) { @@ -70,10 +83,10 @@ angular.module('wpIonic.controllers', []) $scope.moreItems = true; - //console.log(response.data); + //$log.log(response.data); }, function(response) { - console.log('error', response); + $log.error(response); }); } @@ -92,7 +105,7 @@ angular.module('wpIonic.controllers', []) var pg = paged++; - console.log('loadMore ' + pg ); + $log.log('loadMore ' + pg ); $timeout(function() { @@ -107,7 +120,7 @@ angular.module('wpIonic.controllers', []) } }, function(response) { $scope.moreItems = false; - console.log('error'); + $log.error(response); }); $scope.$broadcast('scroll.infiniteScrollComplete'); @@ -124,7 +137,6 @@ angular.module('wpIonic.controllers', []) // Pull to refresh $scope.doRefresh = function() { - console.log('Refreshing!'); $timeout( function() { $scope.loadPosts(); @@ -138,6 +150,33 @@ angular.module('wpIonic.controllers', []) }) +.controller('BookmarksCtrl', function( $scope, $http, DataLoader, $timeout, $rootScope, $log, Bookmark, CacheFactory ) { + + $scope.$on('$ionicView.enter', function(e) { + + if ( ! CacheFactory.get('postCache') ) { + CacheFactory.createCache('postCache'); + } + + var postCache = CacheFactory.get( 'postCache' ); + + if ( ! CacheFactory.get('bookmarkCache') ) { + CacheFactory.createCache('bookmarkCache'); + } + + var bookmarkCacheKeys = CacheFactory.get( 'bookmarkCache' ).keys(); + + $scope.posts = []; + + angular.forEach( bookmarkCacheKeys, function( value, key ) { + var newPost = postCache.get( value ); + $scope.posts.push( newPost ); + }); + + }); + +}) + .controller('IntroCtrl', function($scope, $state, $ionicSlideBoxDelegate, $ionicHistory) { // $ionicSlideBoxDelegate.update(); diff --git a/www/js/services.js b/www/js/services.js index 557cc45..f0b2166 100644 --- a/www/js/services.js +++ b/www/js/services.js @@ -14,6 +14,38 @@ angular.module('wpIonic.services', []) }) +.factory('Bookmark', function( CacheFactory ) { + + if ( ! CacheFactory.get('bookmarkCache') ) { + CacheFactory.createCache('bookmarkCache'); + } + + var bookmarkCache = CacheFactory.get( 'bookmarkCache' ); + + return { + set: function(id) { + bookmarkCache.put( id, 'bookmarked' ); + }, + get: function(id) { + bookmarkCache.get( id ); + console.log( id ); + }, + check: function(id) { + var keys = bookmarkCache.keys(); + var index = keys.indexOf(id); + if(index >= 0) { + return true; + } else { + return false; + } + }, + remove: function(id) { + bookmarkCache.remove(id); + } + } + +}) + .factory('$localstorage', ['$window', function($window) { return { set: function(key, value) { diff --git a/www/templates/bookmarks.html b/www/templates/bookmarks.html new file mode 100644 index 0000000..cb6d900 --- /dev/null +++ b/www/templates/bookmarks.html @@ -0,0 +1,20 @@ + + + + + + +

+

+ +
+
+ + + + +
+
diff --git a/www/templates/intro.html b/www/templates/intro.html index c84451e..62be86a 100644 --- a/www/templates/intro.html +++ b/www/templates/intro.html @@ -3,19 +3,19 @@

This app is built with the Ionic Framework, and integrated with the WordPress WP-API

- +

You can pull in any content from WordPress, including posts, pages, custom post types, and more

- +

What will you make?

-
diff --git a/www/templates/login.html b/www/templates/login.html deleted file mode 100644 index 8c9e1cc..0000000 --- a/www/templates/login.html +++ /dev/null @@ -1,42 +0,0 @@ -
- - - -
- -
- -

Login

-
- - -
-
- - - -
-
- -
-
-
-
- -
{{loginMessage}}
- -
-
- -
-
- -
- -
- -
\ No newline at end of file diff --git a/www/templates/menu.html b/www/templates/menu.html index fa4a999..16584bf 100644 --- a/www/templates/menu.html +++ b/www/templates/menu.html @@ -1,6 +1,6 @@ - + @@ -13,24 +13,33 @@ - + - + + Intro - + + Posts - + + + Bookmarks + + + Tabs - + + Settings - + + Custom Page diff --git a/www/templates/post.html b/www/templates/post.html index 4b18b91..e8cbb5c 100644 --- a/www/templates/post.html +++ b/www/templates/post.html @@ -1,13 +1,36 @@ - {{post.title.rendered}} + {{::post.title.rendered}} -
+

-
+ + + + +
+ +