diff --git a/INSTALLATION.md b/INSTALLATION.md index 47c410573..ca200162d 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -48,7 +48,7 @@ There are two config files, ```config.json``` for the application configuration ### Installing the Web service -Install this plugin (only version 1.2.x) to your WordPress website then add the address to the ```config.json``` file: +Install this plugin (v2.x) to your WordPress website then add the address to the ```config.json``` file: ``` "api": { diff --git a/config.json.dist b/config.json.dist index 35d600660..46039cc3b 100644 --- a/config.json.dist +++ b/config.json.dist @@ -127,7 +127,8 @@ "post": { "comments": { "enabled": true, - "depth": 2 + "depth": 2, + "per_page": 50 }, "cache": { "maxAge": 172800000, @@ -148,7 +149,7 @@ "posts": { "posts_per_page": 6, "orderby": "date", - "orderby": "desc", + "order": "desc", "post_status": "publish", "cache": { "capacity": 25, diff --git a/lib/directives/comment/comment.html b/lib/directives/comment/comment.html index 9199d1574..e3da49e59 100644 --- a/lib/directives/comment/comment.html +++ b/lib/directives/comment/comment.html @@ -1,8 +1,8 @@
- +

{{::commentCtrl.comment.author.name}}

-
+

diff --git a/lib/directives/comments/comments.coffee b/lib/directives/comments/comments.coffee index 86216313a..87a437cfa 100644 --- a/lib/directives/comments/comments.coffee +++ b/lib/directives/comments/comments.coffee @@ -14,10 +14,11 @@ module.exports = angular.module('wordpress-hybrid-client.directives').directive depth = _.get($WPHCConfig, 'post.comments.depth') || 2 $WPHCPost.getComments vm.postId .then (comments) -> + console.log('comments', comments) if !comments.lenght vm.comments = [] commentsTemp = [] - for comment in comments by -1 + for comment in comments commentsTemp[comment.id] = comment comment.children = [] if comment.parent is 0 diff --git a/lib/directives/post/post.coffee b/lib/directives/post/post.coffee index 9436e3257..bc423ce1d 100644 --- a/lib/directives/post/post.coffee +++ b/lib/directives/post/post.coffee @@ -9,7 +9,12 @@ module.exports = angular.module('wordpress-hybrid-client.directives').directive template: require './post.html' bindToController: true controllerAs: 'postCtrl' - controller: ($WPHCConfig) -> + controller: ($WPHCConfig, $WPHCPost) -> vm = @ + vm.featured_image = undefined vm.enabled = _.get($WPHCConfig, 'post.comments.enabled') + $WPHCPost.getFeatureImage vm.post.featured_image + .then (image) -> + return if !image + vm.featured_image = image.media_details.sizes.medium.source_url return @ diff --git a/lib/directives/post/post.html b/lib/directives/post/post.html index beb6fa9d7..45f7d5334 100644 --- a/lib/directives/post/post.html +++ b/lib/directives/post/post.html @@ -1,8 +1,9 @@
-
+

+

diff --git a/lib/directives/post/style.scss b/lib/directives/post/style.scss index cdec5d000..fec7d274a 100644 --- a/lib/directives/post/style.scss +++ b/lib/directives/post/style.scss @@ -5,14 +5,22 @@ margin-bottom: 20px; margin-top: -10px; } + .item-toolbar { margin: 15px 0; } + + .item-title-without-image { + line-height: 35px; + margin-top: 10px; + } + section.footer { text-align: center; border-top: 1px solid $gray-lighter; padding-top: 15px; margin-top: 5px; + .button-open-browser { } diff --git a/lib/directives/posts/posts.coffee b/lib/directives/posts/posts.coffee index 5dc3db478..f1e69dbae 100644 --- a/lib/directives/posts/posts.coffee +++ b/lib/directives/posts/posts.coffee @@ -7,10 +7,24 @@ Display posts list @example "
"
 ###
-module.exports = angular.module('wordpress-hybrid-client.directives').directive 'wphcPosts', ($log) ->
+module.exports = angular.module('wordpress-hybrid-client.directives').directive 'wphcPosts', () ->
     restrict: 'E'
     transclude: true
     scope:
         posts: "="
-        layout: '='
     template: require './posts.html'
+    bindToController: true
+    controllerAs: 'postCtrl'
+    controller: ($log, $scope, $WPHCPost) ->
+        vm = @
+        vm.featureImages = []
+
+        $scope.$watchCollection 'postCtrl.posts', (newValue, oldValue) ->
+            return if !newValue
+            _.each newValue, (post) ->
+                return if vm.featureImages[post.id]
+                $WPHCPost.getFeatureImage post.featured_image
+                .then (image) ->
+                    return if !image
+                    vm.featureImages[post.id] = image.media_details.sizes.medium.source_url
+        return @
diff --git a/lib/directives/posts/posts.html b/lib/directives/posts/posts.html
index f1b901ef8..9b03dacd6 100644
--- a/lib/directives/posts/posts.html
+++ b/lib/directives/posts/posts.html
@@ -1,7 +1,7 @@
 
-
+
-
+

@@ -10,7 +10,7 @@

-
+

diff --git a/lib/post/post.service.coffee b/lib/post/post.service.coffee index 45d758957..0bd0c83d5 100644 --- a/lib/post/post.service.coffee +++ b/lib/post/post.service.coffee @@ -1,6 +1,6 @@ md5 = require 'MD5' -module.exports = angular.module('wordpress-hybrid-client.post').factory '$WPHCPost', ($log, $wpApiPosts, $wpApiComments, $q, $WPHCConfig, CacheFactory) -> +module.exports = angular.module('wordpress-hybrid-client.post').factory '$WPHCPost', ($log, $wpApiPosts, $wpApiMedia, $wpApiComments, $q, $WPHCConfig, CacheFactory) -> $log.info '$WPHCPost' getCommentsCache = () -> @@ -13,6 +13,12 @@ module.exports = angular.module('wordpress-hybrid-client.post').factory '$WPHCPo return CacheFactory.get 'post' CacheFactory 'post', _.get $WPHCConfig, 'post.cache' + getFeatureImage: (featureImageId) -> + return $q.when(null) if !featureImageId or featureImageId is 0 + return $wpApiMedia.get featureImageId + .then (response) -> + response.data + getComments: (id) -> deferred = $q.defer() hash = md5 $WPHCConfig.api.baseUrl + id @@ -25,6 +31,9 @@ module.exports = angular.module('wordpress-hybrid-client.post').factory '$WPHCPo post: id status: "approved" type: "comment" + orderby: 'date' + order: 'asc' + per_page: _.get($WPHCConfig, 'post.comments.per_page') || 50 .then (response) -> getCommentsCache().put 'item-comments-' + hash, response.data deferred.resolve response.data diff --git a/lib/posts/posts.service.coffee b/lib/posts/posts.service.coffee index 7a8c38112..60f37e4f0 100644 --- a/lib/posts/posts.service.coffee +++ b/lib/posts/posts.service.coffee @@ -15,10 +15,10 @@ module.exports = angular.module('wordpress-hybrid-client.posts') getQuery: (page) -> page: page "_embed": true - "filter[posts_per_page]": $WPHCConfig.posts.posts_per_page - "filter[orderby]": $WPHCConfig.posts.orderby - "filter[order]": $WPHCConfig.posts.order - "filter[post_status]": $WPHCConfig.posts.post_status + "filter[posts_per_page]": _.get($WPHCConfig, 'posts.per_page') || 5 + "filter[orderby]": _.get($WPHCConfig, 'posts.orderby') || 'date' + "filter[order]": _.get($WPHCConfig, 'posts.order') || 'desc' + "filter[post_status]": _.get($WPHCConfig, 'posts.post_status') || 'publish' getList: (query) -> queryString = JSON.stringify query diff --git a/package.json b/package.json index f2c0775a6..ae04b1c15 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,6 @@ "moment": "^2.9.0", "ng-cordova": "^0.1.20-alpha", "v-accordion": "~1.3.1", - "wp-api-angularjs": "^2.0.0-alpha2" + "wp-api-angularjs": "^2.0.0-alpha3" } }