summaryrefslogtreecommitdiff
path: root/imdb-lookup
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2014-12-22 20:08:43 +0100
committerYves Fischer <yvesf-git@xapek.org>2014-12-22 20:08:43 +0100
commit38c9d869f3a781bc8e95e7cef0316d203d7ff5e4 (patch)
tree1fadb97b8265801495083a96869aa75f761add84 /imdb-lookup
parent1452c18ab918da9a3cb8965e165d6f0baa0eec26 (diff)
downloadscripts-38c9d869f3a781bc8e95e7cef0316d203d7ff5e4.tar.gz
scripts-38c9d869f3a781bc8e95e7cef0316d203d7ff5e4.zip
improve pagination
Diffstat (limited to 'imdb-lookup')
-rw-r--r--imdb-lookup/index.jinja2.html3
-rw-r--r--imdb-lookup/js/app.js38
2 files changed, 34 insertions, 7 deletions
diff --git a/imdb-lookup/index.jinja2.html b/imdb-lookup/index.jinja2.html
index b2bde45..d02ccf9 100644
--- a/imdb-lookup/index.jinja2.html
+++ b/imdb-lookup/index.jinja2.html
@@ -28,7 +28,8 @@
<div class="box">
<center>
{{#each page in pages}}
- <button {{action 'setPage' page}}>{{page}}</button>
+ <strong>{{page.runningLabel}}</strong>
+ <button {{action 'setPage' page.number}}>{{page.number}}</button>
{{/each}}
</center>
</div>
diff --git a/imdb-lookup/js/app.js b/imdb-lookup/js/app.js
index d5f7c53..c2bcbd1 100644
--- a/imdb-lookup/js/app.js
+++ b/imdb-lookup/js/app.js
@@ -51,24 +51,49 @@ App.Movie = DS.Model.extend({
App.IndexController = Ember.ArrayController.extend({
page: 1,
perPage: "10",
+ sortProperties: ["title"],
visiblePerPage: ["10", "20", "25", "50", "100", "250", "500"],
pages: function() {
var list = [];
+ var prev = null;
+ var sortProperty = this.get("sortProperties")[0];
for (var i = 1; i <= this.get("pagesCount"); i++) {
- list.push(i);
+ var pageContent = this._getPaginatedContent(i);
+ var p1 = pageContent[0].get(sortProperty);
+ var runningLabel = "";
+ if (sortProperty == "title") {
+ p1 = p1[0];
+ } else if (sortProperty == "imdbRating") {
+ p1 = Math.round(p1);
+ } else if (sortProperty == "imdbVotes") {
+ p1 = Math.floor(p1 / 1000) + "k";
+ } else if (sortProperty == "release") {
+ p1 = parseInt(p1.slice(0,4));
+ p1 = Math.floor(p1 / 10) * 10;
+ } else {
+ prev = p1;
+ }
+ if (p1 != prev) {
+ runningLabel = "" + p1;
+ prev = p1;
+ }
+ list.push({number: i, runningLabel: runningLabel});
}
return list;
- }.property('page','perPage'),
+ }.property('page','perPage','sortProperties'),
paginatedContent: function() {
var page = this.get('page');
- var perPage = parseInt(this.get('perPage'));
- var start = (page - 1 ) * perPage;
- var end = page * perPage;
- return this.get('arrangedContent').slice(start, end)
+ return this._getPaginatedContent(page);
}.property('arrangedContent.[]', 'page', 'perPage'),
pagesCount: function() {
return Math.ceil(this.get("content.length") / parseInt(this.get("perPage")))
}.property('content.[]', 'perPage'),
+ _getPaginatedContent: function(page) {
+ var perPage = parseInt(this.get('perPage'));
+ var start = (page - 1 ) * perPage;
+ var end = page * perPage;
+ return this.get('arrangedContent').slice(start, end)
+ },
actions: {
sortBy: function(property) {
this.set('sortProperties', [property]);
@@ -80,6 +105,7 @@ App.IndexController = Ember.ArrayController.extend({
}
});
+
Ember.Handlebars.helper('filelink', function(value, options) {
var escaped = encodeURIComponent(value);
return new Ember.Handlebars.SafeString('<a href="' + escaped + '">' + value + '</span>');