diff --git a/app/scripts/app.js b/app/scripts/app.js index 1348955..f41ac3e 100755 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -19,7 +19,7 @@ angular.module('starter', [ 'supermodular.native-scrolling', 'supermodular.new-slide-box', 'supermodular.articles', - "supermodular.wordpress", + 'supermodular.wordpress', 'gMaps', 'ngCordova' ]) diff --git a/app/scripts/home/menu-items.service.js b/app/scripts/home/menu-items.service.js index b547262..75c99fc 100755 --- a/app/scripts/home/menu-items.service.js +++ b/app/scripts/home/menu-items.service.js @@ -17,6 +17,10 @@ title: 'Articles', path: 'articles', icon: 'ion-ios-paper-outline' + },{ + title: 'Wordpress', + path: 'wordpress-articles', + icon: 'ion-ios-paper-outline' }, { title: 'Elements', path: 'elements', diff --git a/app/scripts/wordpress/wordpress.service.js b/app/scripts/wordpress/wordpress.service.js index 0800e35..cc53c88 100644 --- a/app/scripts/wordpress/wordpress.service.js +++ b/app/scripts/wordpress/wordpress.service.js @@ -1,82 +1,65 @@ (function() { 'use strict'; - + angular - .module('supermodular.wordpress') - .factory('wordpressService', wordpressService); - + .module('supermodular.wordpress') + .factory('wordpressService', wordpressService); + wordpressService.$inject = ['$http', '$q']; - + /* @ngInject */ function wordpressService($http, $q) { - - var url = 'http://demo.titaniumtemplates.com/wordpress/?json=1'; - var articles = []; - + + var url = 'http://demo.titaniumtemplates.com/wordpress/?json=1', + articles = []; + var service = { getArticles: getArticles, getArticle: getArticle }; return service; - + // ******************************************************* - - // http://stackoverflow.com/questions/17533888/s3-access-control-allow-origin-header + function handlePost(articles, item){ + var imageUrl = item.attachments.length > 0 ? item.attachments[0].images.full.url : null; + var tags = []; + _.each(item.tags, function(tag) { + tags.push(tag.title); + }); + var contentIndex = item.content.indexOf('

') + 4; + var content = contentIndex === -1 ? item.content : item.content.substring(contentIndex); + articles.push({ + id: item.id, + title: item.title, + brief: item.excerpt, + image: imageUrl, + date: item.date, + content: content, + author: item.author.name, + tags: tags, + url: url + }); + return articles; + } + function getArticles() { - - return $http.get(url) - .then(function(response) { - articles = []; - - _.each(response.data.posts, function(item) { - var imageUrl = item.attachments.length > 0 ? item.attachments[0].images.full.url : null; - var tags = []; - _.each(item.tags, function(tag) { - tags.push(tag.title); - }); - - var contentIndex = item.content.indexOf('

') + 4; - var content = contentIndex === -1 ? item.content : item.content.substring(contentIndex); - - articles.push({ - id: item.id, - title: item.title, - brief: item.excerpt, - image: imageUrl, - date: item.date, - content: content, - author: item.author.name, - tags: tags, - url: url - }); - }); - return articles; - }); - } - - - - function getArticle(articleId) { - // TODO: Change the implementation and fetch the requeste article by using - // an HTTP reques - // - // eg: - // http://demo.titaniumtemplates.com/wordpress/?p=38&json=1 - // `p=38` where 38 is the `id` of the article - if (articles.length) { - return $q.when(_.find(articles, 'id', articleId)); - } else { - var deferred = $q.defer(); - - getArticles() - .then(function() { - deferred.resolve(_.find(articles, 'id', articleId)); - }); - - return deferred.promise; - } - } - - + return $http.get(url) + .then(function(response) { + articles = []; + _.each(response.data.posts, function (item){ + articles = handlePost(articles, item); + }); + return articles; + }); + } + + function getArticle(articleId) { + return $http.get( url+'&p='+articleId) + .then(function(response) { + articles = []; + articles = handlePost(articles, response.data.post) + return articles[0]; + }); + } } })(); diff --git a/install.bat b/install.bat index f28410b..1933237 100755 --- a/install.bat +++ b/install.bat @@ -33,9 +33,9 @@ ionic state restore :: Add target platform :: :: Comment out the platform(s) your system supports -:: -grunt platform:add:ios -:: grunt platform:add:android +::grunt platform:add:ios +:: +grunt platform:add:android :: :: Build the project and generate the cordova directory (www)