App is now based on categories
Now the entry point of the app is the categories page and user can browse them until the articles
This commit is contained in:
parent
6b0d08f28d
commit
e81bd87919
4 changed files with 64 additions and 32 deletions
|
@ -258,7 +258,7 @@ canvas {
|
||||||
#categories li:after {
|
#categories li:after {
|
||||||
content: "";
|
content: "";
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: -18px;
|
top: 0px;
|
||||||
right: 7px;
|
right: 7px;
|
||||||
font-weight: 100;
|
font-weight: 100;
|
||||||
font-size: 3em;
|
font-size: 3em;
|
||||||
|
|
|
@ -19,10 +19,10 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<section id="list" class="active">
|
<section id="list">
|
||||||
<header class="bar">
|
<header class="bar">
|
||||||
<a class="button icon settings" href="#settings">⚙</a>
|
<a class="button icon settings" href="#settings">⚙</a>
|
||||||
<a class="button icon categories" href="#categories">⚙</a>
|
<a class="button icon back" href="#categories">⚙</a>
|
||||||
<a class="button icon reload" href="#reload">🔄</a>
|
<a class="button icon reload" href="#reload">🔄</a>
|
||||||
<a class="button icon all-read inactive" href="#all-read" id="all-read">✓</a>
|
<a class="button icon all-read inactive" href="#all-read" id="all-read">✓</a>
|
||||||
<canvas width="40" height="40"></canvas>
|
<canvas width="40" height="40"></canvas>
|
||||||
|
@ -32,10 +32,10 @@
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="categories">
|
<section id="categories" class="active">
|
||||||
<header class="bar">
|
<header class="bar">
|
||||||
<a class="button icon settings" href="#settings">⚙</a>
|
<a class="button icon settings" href="#settings">⚙</a>
|
||||||
<a class="button icon list" href="#list">⚙</a>
|
<a class="button icon back" href="#categories-back">⚙</a>
|
||||||
<a class="button icon reload" href="#reload">🔄</a>
|
<a class="button icon reload" href="#reload">🔄</a>
|
||||||
<a class="button icon all-read inactive" href="#all-read" id="all-read">✓</a>
|
<a class="button icon all-read inactive" href="#all-read" id="all-read">✓</a>
|
||||||
<canvas width="40" height="40"></canvas>
|
<canvas width="40" height="40"></canvas>
|
||||||
|
|
66
js/App.js
66
js/App.js
|
@ -40,13 +40,21 @@ App.prototype.after_login = function(backend) {
|
||||||
if(url == "#list") {
|
if(url == "#list") {
|
||||||
_this.setCurrentRead();
|
_this.setCurrentRead();
|
||||||
_this.changeToPage("#list");
|
_this.changeToPage("#list");
|
||||||
|
} if(url.indexOf("#list-") == 0) {
|
||||||
|
var feedId = parseInt(url.replace("#list-", ""), 10);
|
||||||
|
_this.reload(feedId);
|
||||||
|
_this.changeToPage("#list");
|
||||||
} else if(url == "#reload") {
|
} else if(url == "#reload") {
|
||||||
_this.reload();
|
_this.reload();
|
||||||
} else if(url == "#settings") {
|
} else if(url == "#settings") {
|
||||||
_this.changeToPage("#settings");
|
_this.changeToPage("#settings");
|
||||||
} else if(url == "#categories") {
|
} else if(url == "#categories" || url == "#categories-back") {
|
||||||
_this.changeToPage("#categories");
|
_this.changeToPage("#categories");
|
||||||
_this.loadCategories();
|
var isComingBack = (url == "#categories-back") ? true : false;
|
||||||
|
_this.loadCategories(isComingBack);
|
||||||
|
} else if (url.indexOf("#categories-") == 0) {
|
||||||
|
var categoryId = parseInt(url.replace("#categories-", ""), 10);
|
||||||
|
_this.loadCategoryFeeds(categoryId);
|
||||||
} else if(url.indexOf("#color-") == 0) {
|
} else if(url.indexOf("#color-") == 0) {
|
||||||
var color = url.replace("#color-", "");
|
var color = url.replace("#color-", "");
|
||||||
_this.setColor(color);
|
_this.setColor(color);
|
||||||
|
@ -106,8 +114,6 @@ App.prototype.after_login = function(backend) {
|
||||||
hammertime.on("swipeleft", function(ev){ _this.showNext(); ev.gesture.preventDefault(); });
|
hammertime.on("swipeleft", function(ev){ _this.showNext(); ev.gesture.preventDefault(); });
|
||||||
hammertime.on("swiperight", function(ev){ _this.showPrevious(); ev.gesture.preventDefault(); });
|
hammertime.on("swiperight", function(ev){ _this.showPrevious(); ev.gesture.preventDefault(); });
|
||||||
|
|
||||||
this.changeToPage("#list");
|
|
||||||
|
|
||||||
if(backend == "OwnCloud") {
|
if(backend == "OwnCloud") {
|
||||||
this.backend = new OwnCloud(this, localStorage.server_url, localStorage.session_id);
|
this.backend = new OwnCloud(this, localStorage.server_url, localStorage.session_id);
|
||||||
} else if (backend == "Pond") {
|
} else if (backend == "Pond") {
|
||||||
|
@ -117,6 +123,9 @@ App.prototype.after_login = function(backend) {
|
||||||
$("#setpublished").removeClass("invisible");
|
$("#setpublished").removeClass("invisible");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.changeToPage("#categories");
|
||||||
|
this.loadCategories();
|
||||||
|
|
||||||
var numArticles = localStorage.numArticles;
|
var numArticles = localStorage.numArticles;
|
||||||
if(!numArticles) numArticles = 50;
|
if(!numArticles) numArticles = 50;
|
||||||
this.numArticles(numArticles);
|
this.numArticles(numArticles);
|
||||||
|
@ -159,21 +168,25 @@ App.prototype.setColor = function(color) {
|
||||||
this.updatePieChart();
|
this.updatePieChart();
|
||||||
};
|
};
|
||||||
|
|
||||||
App.prototype.reload = function() {
|
App.prototype.reload = function(feedId) {
|
||||||
this.unread_articles = [];
|
this.unread_articles = [];
|
||||||
$("#all-read").addClass('inactive');
|
$("#all-read").addClass('inactive');
|
||||||
var number=parseInt(localStorage.numArticles);
|
var number=parseInt(localStorage.numArticles);
|
||||||
this.backend.reload(this.gotUnreadFeeds.bind(this),number);
|
this.backend.reload(this.gotUnreadFeeds.bind(this),number, feedId);
|
||||||
};
|
};
|
||||||
|
|
||||||
App.prototype.loadCategories = function () {
|
App.prototype.loadCategories = function (isComingBack) {
|
||||||
if (this.categories) {
|
if (this.categories && isComingBack != true) {
|
||||||
populateCategoryList();
|
populateCategoryList();
|
||||||
} else {
|
} else {
|
||||||
this.backend.getCategories(this.gotCategories.bind(this));
|
this.backend.getCategories(this.gotCategories.bind(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App.prototype.loadCategoryFeeds = function (categoryId) {
|
||||||
|
this.backend.getFeedsByCategory(categoryId, this.gotCategoryFeeds.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
App.prototype.gotUnreadFeeds = function(new_articles) {
|
App.prototype.gotUnreadFeeds = function(new_articles) {
|
||||||
|
|
||||||
if(new_articles == null || !this.validate(new_articles)) {
|
if(new_articles == null || !this.validate(new_articles)) {
|
||||||
|
@ -193,6 +206,7 @@ App.prototype.gotUnreadFeeds = function(new_articles) {
|
||||||
this.unread_articles = JSON.parse(old_articles);
|
this.unread_articles = JSON.parse(old_articles);
|
||||||
}
|
}
|
||||||
this.populateList();
|
this.populateList();
|
||||||
|
this.isShowingFeeds = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -200,21 +214,8 @@ App.prototype.gotUnreadFeeds = function(new_articles) {
|
||||||
this.unread_articles = this.unread_articles.concat(new_articles);
|
this.unread_articles = this.unread_articles.concat(new_articles);
|
||||||
|
|
||||||
if(new_articles.length > 0) {
|
if(new_articles.length > 0) {
|
||||||
try {
|
|
||||||
//To check if when it fails it is the same
|
|
||||||
localStorage.unread_articles = JSON.stringify(this.unread_articles);
|
|
||||||
var size = parseInt(localStorage.maxDownload);
|
|
||||||
if(localStorage.unread_articles.length < size) {
|
|
||||||
var num = parseInt(localStorage.numArticles);
|
|
||||||
this.backend.getUnreadFeeds(this.gotUnreadFeeds.bind(this), this.unread_articles,num);
|
|
||||||
} else {
|
|
||||||
alert("Limit size reached: Downloaded: " + this.unread_articles.length + " articles. Reached: " + localStorage.unread_articles.length +" bytes");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
alert("Reached maximum memory by app " + e.name + " " + e.message + ". We will keep working in anycase with: " + localStorage.unread_articles.length);
|
|
||||||
}
|
|
||||||
this.populateList();
|
this.populateList();
|
||||||
|
this.isShowingFeeds = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -245,6 +246,11 @@ App.prototype.gotCategories = function (categories) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
App.prototype.gotCategoryFeeds = function (feeds) {
|
||||||
|
this.feeds = feeds;
|
||||||
|
this.populateFeedList();
|
||||||
|
};
|
||||||
|
|
||||||
App.prototype.validate = function(articles) {
|
App.prototype.validate = function(articles) {
|
||||||
|
|
||||||
if(articles.length == 0) return true;
|
if(articles.length == 0) return true;
|
||||||
|
@ -301,7 +307,23 @@ App.prototype.populateCategoryList = function () {
|
||||||
for (var i = 0; i < this.categories.length; i++) {
|
for (var i = 0; i < this.categories.length; i++) {
|
||||||
var category = this.categories[i];
|
var category = this.categories[i];
|
||||||
html_str += "<li>";
|
html_str += "<li>";
|
||||||
|
html_str += "<a href='#categories-"+category.id+"'>";
|
||||||
html_str += "<p class='title'>" + category.title + "</p>";
|
html_str += "<p class='title'>" + category.title + "</p>";
|
||||||
|
html_str += "</a>";
|
||||||
|
html_str += "</li>";
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#categories ul").innerHTML = html_str;
|
||||||
|
};
|
||||||
|
|
||||||
|
App.prototype.populateFeedList = function () {
|
||||||
|
var html_str = "";
|
||||||
|
for (var i = 0; i < this.feeds.length; i++) {
|
||||||
|
var feed = this.feeds[i];
|
||||||
|
html_str += "<li>";
|
||||||
|
html_str += "<a href='#list-"+feed.id+"'>";
|
||||||
|
html_str += "<p class='title'>" + feed.title + "</p>";
|
||||||
|
html_str += "</a>";
|
||||||
html_str += "</li>";
|
html_str += "</li>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,17 +54,17 @@ TinyTinyRSS.prototype.doOperation = function(operation, new_options, callback) {
|
||||||
xhr.send(JSON.stringify(options));
|
xhr.send(JSON.stringify(options));
|
||||||
}
|
}
|
||||||
|
|
||||||
TinyTinyRSS.prototype.reload = function(callback,limit) {
|
TinyTinyRSS.prototype.reload = function(callback,limit, feedId) {
|
||||||
this.getUnreadFeeds(callback, 0, limit);
|
this.getUnreadFeeds(callback, 0, limit, feedId);
|
||||||
};
|
};
|
||||||
|
|
||||||
TinyTinyRSS.prototype.getUnreadFeeds = function(callback, skip, limit) {
|
TinyTinyRSS.prototype.getUnreadFeeds = function(callback, skip, limit, feedId) {
|
||||||
skip = skip.length;
|
skip = skip.length;
|
||||||
var options = {
|
var options = {
|
||||||
show_excerpt: false,
|
show_excerpt: false,
|
||||||
view_mode: "unread",
|
view_mode: "unread",
|
||||||
show_content: true,
|
show_content: true,
|
||||||
feed_id: -4,
|
feed_id: feedId || -4,
|
||||||
limit: limit || 0,
|
limit: limit || 0,
|
||||||
skip: skip || 0
|
skip: skip || 0
|
||||||
};
|
};
|
||||||
|
@ -72,6 +72,16 @@ TinyTinyRSS.prototype.getUnreadFeeds = function(callback, skip, limit) {
|
||||||
this.doOperation("getHeadlines", options, callback);
|
this.doOperation("getHeadlines", options, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TinyTinyRSS.prototype.getFeedsByCategory = function (categoryId, callback) {
|
||||||
|
var options = {
|
||||||
|
cat_id: categoryId,
|
||||||
|
unread_only: true,
|
||||||
|
include_nested: false
|
||||||
|
};
|
||||||
|
|
||||||
|
this.doOperation("getFeeds", options, callback);
|
||||||
|
};
|
||||||
|
|
||||||
TinyTinyRSS.prototype.setArticlesRead = function(articles, callback) {
|
TinyTinyRSS.prototype.setArticlesRead = function(articles, callback) {
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
|
|
Reference in a new issue