Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ angular.module('starter', [
'supermodular.native-scrolling',
'supermodular.new-slide-box',
'supermodular.articles',
"supermodular.wordpress",
'supermodular.wordpress',
'gMaps',
'ngCordova'
])
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/home/menu-items.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
117 changes: 50 additions & 67 deletions app/scripts/wordpress/wordpress.service.js
Original file line number Diff line number Diff line change
@@ -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('</p>') + 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('</p>') + 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];
});
}
}
})();
6 changes: 3 additions & 3 deletions install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down