From fd25ff991ce9f6bd3d0f021cbeb6f91f201dc119 Mon Sep 17 00:00:00 2001 From: Christos Polychronis Date: Thu, 21 Apr 2016 20:45:51 +0300 Subject: [PATCH 1/4] config change for windows --- install.bat | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) From f43df0b74e33d1cc3cccdcbf73fc8ff710f48fe8 Mon Sep 17 00:00:00 2001 From: Christos Polychronis Date: Fri, 22 Apr 2016 01:56:42 +0300 Subject: [PATCH 2/4] fix wordpress http get for single article instead of cached Method used modified the getArticles function to be able to receive id so it makes the request for a single article instead of all and calling it from getArticle function. --- app/scripts/app.js | 2 +- app/scripts/home/menu-items.service.js | 4 + app/scripts/wordpress/wordpress.service.js | 123 ++++++++++----------- 3 files changed, 63 insertions(+), 66 deletions(-) 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..4d79019 100644 --- a/app/scripts/wordpress/wordpress.service.js +++ b/app/scripts/wordpress/wordpress.service.js @@ -1,82 +1,75 @@ (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 service = { getArticles: getArticles, getArticle: getArticle }; return service; - + // ******************************************************* - + // http://stackoverflow.com/questions/17533888/s3-access-control-allow-origin-header - 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; - } - } - - + function getArticles(articleId) { + var editedUrl = (!!articleId) ? url+'&p='+articleId: url; + return $http.get(editedUrl) + .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) { + var tempArticle = getArticles(articleId); + if (tempArticle.length) { + return $q.when(_.find(tempArticle, 'id', articleId)); + } else { + var deferred = $q.defer(); + + getArticles() + .then(function() { + deferred.resolve(_.find(tempArticle, 'id', articleId)); + }); + + return deferred.promise; + } + } + + } })(); From 7689f48cb011d4c36ab484b8378bf7a49c168fd0 Mon Sep 17 00:00:00 2001 From: Christos Polychronis Date: Sun, 24 Apr 2016 14:25:37 +0300 Subject: [PATCH 3/4] feat wordpress-service revamp --- app/scripts/wordpress/wordpress.service.js | 76 ++++++++++------------ 1 file changed, 33 insertions(+), 43 deletions(-) diff --git a/app/scripts/wordpress/wordpress.service.js b/app/scripts/wordpress/wordpress.service.js index 4d79019..3b99e12 100644 --- a/app/scripts/wordpress/wordpress.service.js +++ b/app/scripts/wordpress/wordpress.service.js @@ -10,8 +10,8 @@ /* @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, @@ -20,56 +20,46 @@ return service; // ******************************************************* + 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; + } - // http://stackoverflow.com/questions/17533888/s3-access-control-allow-origin-header function getArticles(articleId) { - var editedUrl = (!!articleId) ? url+'&p='+articleId: url; - return $http.get(editedUrl) + 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 - }); + articles = []; + _.each(response.data.posts, function (item){ + articles = handlePost(articles, item); }); return articles; }); } function getArticle(articleId) { - var tempArticle = getArticles(articleId); - if (tempArticle.length) { - return $q.when(_.find(tempArticle, 'id', articleId)); - } else { - var deferred = $q.defer(); - - getArticles() - .then(function() { - deferred.resolve(_.find(tempArticle, 'id', articleId)); - }); - - return deferred.promise; - } + return $http.get( url+'&p='+articleId) + .then(function(response) { + articles = []; + articles = handlePost(articles, response.data.post) + return articles[0]; + }); } - - } })(); From 298764164d457220b49192131718e311b84d2677 Mon Sep 17 00:00:00 2001 From: Christos Polychronis Date: Sun, 24 Apr 2016 18:20:47 +0300 Subject: [PATCH 4/4] fix wordpress-service cleanup --- app/scripts/wordpress/wordpress.service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/wordpress/wordpress.service.js b/app/scripts/wordpress/wordpress.service.js index 3b99e12..cc53c88 100644 --- a/app/scripts/wordpress/wordpress.service.js +++ b/app/scripts/wordpress/wordpress.service.js @@ -42,7 +42,7 @@ return articles; } - function getArticles(articleId) { + function getArticles() { return $http.get(url) .then(function(response) { articles = [];