Skip to content

Commit

Permalink
Merge branch 'feature/wp-api_v2' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
shprink committed Oct 1, 2015
2 parents c98c5b5 + a205bf9 commit ec9482e
Show file tree
Hide file tree
Showing 50 changed files with 488 additions and 204 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<a name="1.6.0"></a>
### 1.7.0 (WIP)
<a name="2.0.0"></a>
### 2.0.0 (WIP)

[milestone](https://github.com/shprink/wordpress-hybrid-client/milestones/1.7.0)
[milestone](https://github.com/shprink/wordpress-hybrid-client/milestones/2.0.0)

* WP-API v2 support <https://github.com/shprink/wordpress-hybrid-client/issues/76>
* Adding German translation <https://github.com/shprink/wordpress-hybrid-client/pull/77>

#### Breaking changes:

* [CONFIG] the new `posts.query` objects replaces `posts.per_page`, `posts.order` etc.
* [CONFIG] `posts.posts_per_page` becomes `posts.query.per_page`

<a name="1.6.0"></a>
### 1.6.0 (2015-09-24)

Expand Down
15 changes: 14 additions & 1 deletion config.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
"trans": "menu.home",
"route": "public.posts",
"icon": "icon ion-home"
},{
"type": "internal",
"trans": "menu.pages",
"route": "public.pages",
"icon": "icon ion-ios-paper"
}, {
"type": "internal",
"trans": "menu.authors",
"route": "public.authors",
"icon": "icon ion-ios-people"
}, {
"type": "folder",
"trans": "menu.categories",
Expand Down Expand Up @@ -146,8 +156,11 @@
"maxAge": 172800000
}
},
"pages": {
"per_page": 6
},
"posts": {
"posts_per_page": 6,
"per_page": 6,
"orderby": "date",
"order": "desc",
"post_status": "publish",
Expand Down
63 changes: 63 additions & 0 deletions lib/abstract/AbstractList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export default class {
constructor($WPHCConfig, $q, $scope) {
'ngInject';

this.type = null;
this.title = null;
this.list = null;
this.service = null;
this.isLoadingMore = false;
this.isPaginationOver = false;
this.config = $WPHCConfig;
this.$q = $q;
this.page = 1;
this.$scope = $scope;
this.loadMore = ionic.throttle(this.doLoadMore, 1000);
}

init() {
this.page = 1;
this.isPaginationOver = false;
return this.doLoadMore();
}

refresh() {
this.init();
this.list = null;
this.doLoadMore().finally(() => this.$scope.$broadcast('scroll.refreshComplete'));
}

doLoadMore() {
let self = this;
// prevent multiple call when the server takes some time to answer
if (this.isLoadingMore || this.isPaginationOver) {
return this.$q.when(null);
}
this.isLoadingMore = true;
return this.service.getList(angular.merge(this.getQuery(), _.get(this.config, `[${this.type}].query`) || {})).then((response) => {
self.page++;
self.list = (self.list) ? self.list.concat(response.data) : response.data;
self.isPaginationOver = (response.data.length === 0 || response.data.length < _.get(this.config, `${this.type}.query.per_page`));
this.$scope.$broadcast('scroll.infiniteScrollComplete');
}).finally(() => this.isLoadingMore = false);
}

getQuery() {
return {
page: this.page,
"_embed": true
}
}

setType(type = null) {
this.type = type;
}

setService(service = null) {
this.service = service;
}

setTitle(title = null) {
this.title = title;
}
}
55 changes: 55 additions & 0 deletions lib/abstract/AbstractTypeService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import md5 from 'MD5';

export default class {
constructor($WPHCConfig, $q, CacheFactory, $log) {
'ngInject';

this.$WPHCConfig = $WPHCConfig;
this.CacheFactory = CacheFactory;
this.$log = $log;
this.$q = $q;
this.type = null;
this.service = null;
}

setType(type = null) {
this.type = type;
}

setService(service = null) {
this.service = service;
}

getCache() {
if (this.CacheFactory.get(this.type)) {
return this.CacheFactory.get(this.type);
}
return this.CacheFactory(this.type, _.set(this.$WPHCConfig, `${this.type}.cache`));
}


clearCache() {
this.CacheFactory.destroy(this.type);
}

getList(query) {
let queryString = JSON.stringify(query);
let deferred = this.$q.defer();
let hash = md5(this.$WPHCConfig.api.baseUrl + queryString);
let listCache = this.getCache().get('list-' + hash);
this.$log.debug(`${this.type} cache`, listCache);
if (listCache) {
deferred.resolve(listCache);
} else {
this.service.getList(query)
.then((response) => {
this.getCache().put('list-' + hash, response);
deferred.resolve(response);
})
.catch((response) => {
deferred.reject(error);
});
}
return deferred.promise;
}
}
13 changes: 13 additions & 0 deletions lib/authors/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function($stateProvider) {
'ngInject';

$stateProvider.state('public.authors', {
url: "/authors",
views: {
'content': {
template: require("./index.html"),
controller: "WPHCAuthorsController as authorsCtrl"
}
}
});
}
14 changes: 14 additions & 0 deletions lib/authors/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import AbstractList from '../abstract/AbstractList.js';

export default class extends AbstractList {

constructor($WPHCAuthors, $WPHCConfig, $q, $scope, $filter) {
'ngInject';

super($WPHCConfig, $q, $scope);
this.showToolbar = true;
this.setType('authors');
this.setTitle($filter('translate')('authors.title'));
this.setService($WPHCAuthors);
}
}
10 changes: 10 additions & 0 deletions lib/authors/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ion-view>
<ion-nav-title>{{ authorsCtrl.title | translate}}</ion-nav-title>
<ion-content class="padding bg-gray-lighter">
<wphc-empty-list list="authorsCtrl.list"></wphc-empty-list>
<wphc-loader ng-if="!authorsCtrl.list" on-load="authorsCtrl.init()"></wphc-loader>
<ion-refresher pulling-text="{{ 'pullToRefresh' | translate}}" on-refresh="authorsCtrl.refresh()"></ion-refresher>
<!-- <wphc-posts show-toolbar="::authorsCtrl.showToolbar" posts="authorsCtrl.list"></wphc-posts> -->
<ion-infinite-scroll immediate-check="true" ng-if="authorsCtrl.list && !authorsCtrl.isPaginationOver" on-infinite="authorsCtrl.loadMore()" distance="1%">test</ion-infinite-scroll>
</ion-content>
</ion-view>
11 changes: 11 additions & 0 deletions lib/authors/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import modConfig from './config.js';
import modController from './controller.js';
import modService from './service.js';

let mod = angular.module('wordpress-hybrid-client.authors', []);

mod.config(modConfig);
mod.controller('WPHCAuthorsController', modController);
mod.service('$WPHCAuthors', modService);

export default mod = mod.name;
11 changes: 11 additions & 0 deletions lib/authors/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import AbstractList from '../abstract/AbstractTypeService.js';

export default class extends AbstractList {
constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiUsers) {
'ngInject';

super($WPHCConfig, $q, CacheFactory, $log);
this.setType('authors');
this.setService($wpApiUsers);
}
}
2 changes: 1 addition & 1 deletion lib/directives/emptyList/emptyList.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div ng-style="::{height:emptyListCtrl.getContentHeight() + 'px'}" class="wphc-empty-list" layout="column" layout-align="center center" layout-fill ng-show="!emptyListCtrl.list.length">
<p class="empty-icon"><i class="{{emptyListCtrl.icon || 'ion-search'}}"></i></p>
<p class="empty-text">{{emptyListCtrl.text || 'posts.empty' | translate}}</p>
<p class="empty-text">{{emptyListCtrl.text || 'emptyList' | translate}}</p>
</div>
3 changes: 1 addition & 2 deletions lib/directives/loader/loader.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = angular.module('wordpress-hybrid-client.directives').directive
$log.info 'wphcLoader controller loaded', $scope.promiseLoad
if !$scope.promiseLoad
return
onLoad = $scope.onLoad()
$scope.attempt = 0
$scope.attemptMax = $WPHCConfig.api.maxAttempt
$scope.isAttemptMaxReached = false
Expand All @@ -38,7 +37,7 @@ module.exports = angular.module('wordpress-hybrid-client.directives').directive
$scope.attempt = 0
$scope.isAttemptMaxReached = false
$log.info 'wphcLoader attempt: ' + $scope.attempt
onLoad().then success
$scope.onLoad().then success
.catch ->
error()
if $scope.attempt < $WPHCConfig.api.maxAttempt
Expand Down
5 changes: 3 additions & 2 deletions lib/directives/posts/posts.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ module.exports = angular.module('wordpress-hybrid-client.directives').directive
restrict: 'E'
transclude: true
scope:
posts: "="
posts: "=",
showToolbar: "="
template: require './posts.html'
bindToController: true
controllerAs: 'postCtrl'
controller: ($log, $scope, $WPHCPost) ->
controller: ($log, $scope, $WPHCPost, $attrs) ->
vm = @
vm.featureImages = []

Expand Down
2 changes: 1 addition & 1 deletion lib/directives/posts/posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1 class="item-title" ng-bind-html="::post.title.rendered"></h1>
<wphc-author author="::post._embedded.author[0]" date="::post.date"></wphc-author>
<div class="item item-text-wrap" ng-if="::post.excerpt.rendered" ng-bind-html="::post.excerpt.rendered"></div>
</div>
<div class="item item-divider item-footer">
<div class="item item-divider item-footer" ng-if="postCtrl.showToolbar">
<wphc-post-toolbar post="::post" show-share show-bookmark></wphc-post-toolbar>
</div>
</div>
Expand Down
10 changes: 8 additions & 2 deletions lib/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ require 'moment'
require './font/font.coffee'
require 'expose?_!lodash'
require 'wp-api-angularjs'
pagesModule = require './pages/index.js'
postsModule = require './posts/index.js'
searchModule = require './search/index.js'
authorsModule = require './authors/index.js'

# Style entry point
require './scss/bootstrap'
Expand All @@ -25,11 +29,13 @@ module.exports = app = angular.module 'wordpress-hybrid-client', [
'angular-cache'
'angularMoment'
'angular.filter'
pagesModule
require('./taxonomies/taxonomies.module').name
require('./bookmark/bookmark.module').name
require('./post/post.module').name
require('./posts/posts.module').name
require('./search/search.module').name
postsModule
searchModule
authorsModule
require('./menu/menu.module').name
require('./cordova/cordova.module').name
require('./params/params.module').name
Expand Down
13 changes: 13 additions & 0 deletions lib/pages/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function($stateProvider) {
'ngInject';

$stateProvider.state('public.pages', {
url: "/pages",
views: {
'content': {
template: require("./index.html"),
controller: "WPHCPagesController as pagesCtrl"
}
}
});
}
14 changes: 14 additions & 0 deletions lib/pages/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import AbstractList from '../abstract/AbstractList.js';

export default class extends AbstractList {

constructor($WPHCPages, $WPHCConfig, $q, $scope, $filter) {
'ngInject';

super($WPHCConfig, $q, $scope);
this.showToolbar = false;
this.setType('pages');
this.setTitle($filter('translate')('pages.title'));
this.setService($WPHCPages);
}
}
10 changes: 10 additions & 0 deletions lib/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ion-view>
<ion-nav-title>{{ pagesCtrl.title | translate}}</ion-nav-title>
<ion-content class="padding bg-gray-lighter">
<wphc-empty-list list="pagesCtrl.list"></wphc-empty-list>
<wphc-loader ng-if="!pagesCtrl.list" on-load="pagesCtrl.init()"></wphc-loader>
<ion-refresher pulling-text="{{ 'pullToRefresh' | translate}}" on-refresh="pagesCtrl.refresh()"></ion-refresher>
<wphc-posts show-toolbar="::pagesCtrl.showToolbar" posts="pagesCtrl.list"></wphc-posts>
<ion-infinite-scroll immediate-check="true" ng-if="pagesCtrl.list && !pagesCtrl.isPaginationOver" on-infinite="pagesCtrl.loadMore()" distance="1%">test</ion-infinite-scroll>
</ion-content>
</ion-view>
11 changes: 11 additions & 0 deletions lib/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import modConfig from './config.js';
import modController from './controller.js';
import modService from './service.js';

let mod = angular.module('wordpress-hybrid-client.pages', []);

mod.config(modConfig);
mod.controller('WPHCPagesController', modController);
mod.service('$WPHCPages', modService);

export default mod = mod.name;
11 changes: 11 additions & 0 deletions lib/pages/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import AbstractList from '../abstract/AbstractTypeService.js';

export default class extends AbstractList {
constructor($WPHCConfig, $q, CacheFactory, $log, $wpApiPages) {
'ngInject';

super($WPHCConfig, $q, CacheFactory, $log);
this.setType('pages');
this.setService($wpApiPages);
}
}
2 changes: 1 addition & 1 deletion lib/post/post.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ion-view>
<ion-nav-title>{{ post.post.title.rendered | translate}}</ion-nav-title>
<wphc-loader ng-if="!post.post" on-load="post.init"></wphc-loader>
<wphc-loader ng-if="!post.post" on-load="post.init()"></wphc-loader>
<ion-content>
<wphc-post post="post.post" ng-if="post.post"></wphc-post>
</ion-content>
Expand Down
13 changes: 13 additions & 0 deletions lib/posts/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function($stateProvider) {
'ngInject';

$stateProvider.state('public.posts', {
url: "/posts",
views: {
'content': {
template: require("./index.html"),
controller: "WPHCPostsController as postsCtrl"
}
}
});
}
Loading

0 comments on commit ec9482e

Please sign in to comment.