• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Simple RSS Reader inspired by Gxxgle Reader


Commit MetaInfo

Revision2073d961269a57f17ebc1e250e1e5bd003a118b9 (tree)
Zeit2013-07-15 22:58:35
Autorhylom <hylom@hylo...>
Commiterhylom

Log Message

implement pager

Ändern Zusammenfassung

Diff

--- a/client/public/js/grdc.js
+++ b/client/public/js/grdc.js
@@ -6,41 +6,61 @@
66
77 function updatePager(total, skip, count) {
88 var totalPage = Math.floor((total - 1) / count + 1);
9- var currentPage = (skip == 0) ? 0 : (skip - 1) / count + 1;
10- var elem = '';
9+ var currentPage = Math.floor((skip - 1) / count + 1);
10+ var pane = $('#contentsPane');
11+ var feedId = Number(pane.attr('feedId'));
12+ var elem;
13+ var anchor;
1114
1215 console.log(skip + ',' + count + '/' + total);
1316 console.log(currentPage + '/' + totalPage);
1417
15- var paging = $('#page-navigation');
16- paging.empty();
17-
18- var pagingFirst = '<li id="paging-first"><a href="#">«</a></li>';
19- paging.append(pagingFirst);
18+ var pagerRange = 2;
19+ var pagerStart = currentPage - pagerRange;
20+ if (pagerStart < 0) {
21+ pagerStart = 0;
22+ }
23+ var pagerEnd = pagerStart + 2 * pagerRange + 1;
24+ if (pagerEnd > totalPage) {
25+ pagerEnd = totalPage;
26+ pagerStart = pagerEnd - 5;
27+ if (pagerStart < 0) {
28+ pagerStart = 0;
29+ }
30+ }
2031
21- if (currentPage > 0) {
22- elem = '<li><a href="#">'
23- + currentPage + '</a></li>';
24- paging.append(elem);
32+ function _genHandler(feedId, skip, count) {
33+ return function(ev) {
34+ showFeed(feedId, skip, count);
35+ }
2536 }
2637
27- elem = '<li class="active"><a href="#">' + (currentPage + 1)
28- + '</a></li>';
29- paging.append(elem);
38+ var paging = $('#page-navigation');
39+ paging.empty();
3040
31- if (currentPage != totalPage) {
32- elem = '<li><a href="#">'
33- + (currentPage + 2) + '</a></li>';
41+ if (pagerStart != 0) {
42+ paging.append($('<li class="disabled"><a href="#">...</a></li>'));
43+ }
44+ for (var i = pagerStart; i < pagerEnd; i++) {
45+ anchor = $('<a href="#">');
46+ anchor.text(i + 1);
47+ anchor.on('click', _genHandler(feedId, count * i, count));
48+ elem = $('<li>');
49+ elem.append(anchor);
50+ if (i == currentPage) {
51+ elem.addClass('disabled');
52+ }
3453 paging.append(elem);
3554 }
36-
37- var pagingLast = $('<li id="paging-last"><a href="#">»</a></li>');
38- paging.append(pagingLast);
55+ if (pagerEnd != totalPage) {
56+ paging.append($('<li class="disabled"><a href="#">...</a></li>'));
57+ }
3958 }
4059
4160 function updateContentsPane(data) {
4261 var pane = $('#contentsPane');
4362 pane.empty();
63+
4464 var tmpl = '<tr class="contentHeader" id="chead{{content_id}}">'
4565 + '<td class="contentTitle"><h4>'
4666 + ' <a href="#" class="contentTitleString" cid="{{content_id}}">{{title}}</a>'
@@ -64,6 +84,7 @@
6484 }
6585 pane.attr('skip', data.skip);
6686 pane.attr('count', data.count);
87+ pane.attr('feedId', data.feedId);
6788 updatePager(data.total, data.skip, data.count);
6889 }
6990
@@ -89,6 +110,8 @@
89110 $('#feedTitle').text(feedTitle);
90111 var pane = $('#contentsPane');
91112 pane.empty();
113+ var paging = $('#page-navigation');
114+ paging.empty();
92115 return false;
93116 });
94117
--- a/client/routes/index.js
+++ b/client/routes/index.js
@@ -90,6 +90,7 @@ exports.feedContents = function (req, res) {
9090 /*
9191 returns json:
9292 {
93+ feedId: Number,
9394 totalCount: Number,
9495 skip: Number,
9596 itemCount: Number,
@@ -152,6 +153,7 @@ exports.feedContents = function (req, res) {
152153 rows[i].formatedTimestamp = formatTimestamp(rows[i].timestamp);
153154 }
154155 var result = {
156+ "feedId": feedId,
155157 "total": totalCount,
156158 "skip": skip,
157159 "count": count,
--- a/client/views/index.jade
+++ b/client/views/index.jade
@@ -15,6 +15,3 @@ block content
1515 table.table#contentsPane
1616 .pagination.pagination-centered
1717 ul#page-navigation
18- li#paging-first.disabled: a(href='#') «
19- li.active: a(href='#') 1
20- li#paging-last.disabled: a(href='#') »