Skip to content

Commit

Permalink
Bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
scottopolis committed Sep 19, 2015
1 parent 9c55861 commit 52eb24a
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 69 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"gulp-util": "^2.2.14",
"shelljs": "^0.3.0"
},
"cordovaPlugins": [],
"cordovaPlugins": [
"[email protected]"
],
"cordovaPlatforms": []
}
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
<body ng-app="wpIonic">
<ion-nav-view></ion-nav-view>
</body>
</html>
</html>
12 changes: 11 additions & 1 deletion www/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down
61 changes: 50 additions & 11 deletions www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
Expand All @@ -36,44 +35,58 @@ 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();
});

} else {
// 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;

$scope.moreItems = false;

$scope.loadPosts = function() {

console.log('loadPosts');

// Get all of our posts
DataLoader.get( postsApi ).then(function(response) {

$scope.posts = response.data;

$scope.moreItems = true;

//console.log(response.data);
//$log.log(response.data);

}, function(response) {
console.log('error', response);
$log.error(response);
});

}
Expand All @@ -92,7 +105,7 @@ angular.module('wpIonic.controllers', [])

var pg = paged++;

console.log('loadMore ' + pg );
$log.log('loadMore ' + pg );

$timeout(function() {

Expand All @@ -107,7 +120,7 @@ angular.module('wpIonic.controllers', [])
}
}, function(response) {
$scope.moreItems = false;
console.log('error');
$log.error(response);
});

$scope.$broadcast('scroll.infiniteScrollComplete');
Expand All @@ -124,7 +137,6 @@ angular.module('wpIonic.controllers', [])
// Pull to refresh
$scope.doRefresh = function() {

console.log('Refreshing!');
$timeout( function() {

$scope.loadPosts();
Expand All @@ -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();
Expand Down
32 changes: 32 additions & 0 deletions www/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions www/templates/bookmarks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<ion-view view-title="Bookmarks">
<ion-content>
<ion-refresher on-refresh="doRefresh()"></ion-refresher>
<ion-list>
<ion-item class="item-icon-right" ng-repeat="post in posts track by $index" href="#/app/posts/{{post.id}}" track>
<!-- <img ng-if="post.featured_image" ng-src="{{post._embedded['http://v2.wp-api.org/attachment'][0][$index].source_url}}" class="alignleft" /> -->
<h2 ng-bind-html="post.title.rendered"></h2>
<p ng-if="post.excerpt.rendered" ng-bind-html="post.excerpt.rendered"></p>
<i class="icon ion-chevron-right icon-accessory"></i>
</ion-item>
</ion-list>

<ion-infinite-scroll
ng-if="moreDataExists()"
on-infinite="loadMore()"
distance="1%">
</ion-infinite-scroll>

</ion-content>
</ion-view>
6 changes: 3 additions & 3 deletions www/templates/intro.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
<ion-slide>
<div class="slide-content">
<h3>This app is built with the Ionic Framework, and integrated with the WordPress WP-API</h3>
<button class="button button-block button-positive" ng-click="next()">Next</button>
<button class="button button-block button-balanced" ng-click="next()">Next</button>
</div>
</ion-slide>
<ion-slide>
<div class="slide-content">
<h3>You can pull in any content from WordPress, including posts, pages, custom post types, and more</h3>
<button class="button button-block button-positive" ng-click="next()">Next</button>
<button class="button button-block button-balanced" ng-click="next()">Next</button>
</div>
</ion-slide>
<ion-slide>
<div class="slide-content">
<h3>What will you make?</h3>
<button class="button button-block button-positive" ng-click="startApp()">
<button class="button button-block button-balanced" ng-click="startApp()">
Get Started
</button>
</div>
Expand Down
42 changes: 0 additions & 42 deletions www/templates/login.html

This file was deleted.

23 changes: 16 additions & 7 deletions www/templates/menu.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ion-side-menus enable-menu-with-back-views="true">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-bar class="bar-balanced">
<ion-nav-back-button>
</ion-nav-back-button>

Expand All @@ -13,24 +13,33 @@
</ion-side-menu-content>

<ion-side-menu side="left">
<ion-header-bar class="bar-stable">
<ion-header-bar class="bar-balanced">

</ion-header-bar>
<ion-content>
<ion-list>
<ion-item nav-clear menu-close href="#/app/intro">
<ion-item class="item item-icon-left" nav-clear menu-close href="#/app/intro">
<i class="icon ion-ios-home-outline"></i>
Intro
</ion-item>
<ion-item nav-clear menu-close href="#/app/posts">
<ion-item class="item item-icon-left" nav-clear menu-close href="#/app/posts">
<i class="icon ion-ios-list-outline"></i>
Posts
</ion-item>
<ion-item nav-clear menu-close href="#/app/tabs">
<ion-item class="item item-icon-left" nav-clear menu-close href="#/app/bookmarks">
<i class="icon ion-ios-star-outline"></i>
Bookmarks
</ion-item>
<ion-item class="item item-icon-left" nav-clear menu-close href="#/app/tabs">
<i class="icon ion-ios-pricetags-outline"></i>
Tabs
</ion-item>
<ion-item nav-clear menu-close href="#/app/settings">
<ion-item class="item item-icon-left" nav-clear menu-close href="#/app/settings">
<i class="icon ion-ios-gear-outline"></i>
Settings
</ion-item>
<ion-item nav-clear menu-close href="#/app/custom">
<ion-item class="item item-icon-left" nav-clear menu-close href="#/app/custom">
<i class="icon ion-ios-information-outline"></i>
Custom Page
</ion-item>
</ion-list>
Expand Down
Loading

0 comments on commit 52eb24a

Please sign in to comment.