-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/wp-api_v2' into develop
- Loading branch information
Showing
50 changed files
with
488 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
}); | ||
} |
Oops, something went wrong.