diff --git a/common.blocks/pager/pager.bemhtml.js b/common.blocks/pager/pager.bemhtml.js
index 506cf97..64ed315 100644
--- a/common.blocks/pager/pager.bemhtml.js
+++ b/common.blocks/pager/pager.bemhtml.js
@@ -1,4 +1,7 @@
-block('pager').elem('item').match(function() { return this.ctx.url !== true; }).replace()(function() {
+block('pager')
+.elem('item')
+.match(node => node.ctx.url !== true)
+.replace()(node => {
const type2caption = {
first: '<<',
prev: '<',
@@ -7,14 +10,14 @@ block('pager').elem('item').match(function() { return this.ctx.url !== true; }).
last: '>>'
};
- const elemMods = this.elemMods;
+ const elemMods = node.elemMods;
const type = elemMods.type;
return {
block: 'button',
mods: { theme: 'islands', size: 'm', type: 'link', disabled: type === 'current' },
- mix: { block: this.block, elem: this.elem, elemMods },
- url: this.ctx.url,
- text: type2caption[type]
+ mix: { block: node.block, elem: node.elem, elemMods },
+ url: node.ctx.url,
+ text: type2caption[type] || node.ctx.number
};
});
diff --git a/common.blocks/pager/pager.bemtree.js b/common.blocks/pager/pager.bemtree.js
index 54d153e..3760cb7 100644
--- a/common.blocks/pager/pager.bemtree.js
+++ b/common.blocks/pager/pager.bemtree.js
@@ -1,13 +1,32 @@
-block('pager').content()(function() {
- var pagination = Object.assign({ current: true }, this.data.pagination);
+block('pager').content()(node => {
+ const { data } = node;
+ const pagination = data.pagination;
+ const result = [];
- return ['first', 'prev', 'current', 'next', 'last'].reduce((acc, type) => {
- pagination[type] && acc.push({
+ const createItem = (type, index) => {
+ return {
elem: 'item',
+ mix: { block, elem: 'item' },
elemMods: { type: type },
- url: pagination[type]
- });
+ url: pagination[type] || `${data.exceptPaginationUrl}&page=${index}`,
+ number: index
+ };
+ };
- return acc;
- }, []);
+ for (let i = 1; i <= data.pageCount; i++) {
+ result.push(createItem('number', i));
+ }
+
+ // gather arrows and numbers correct way
+ return [
+ ['first', 'prev'].reduce((acc, type, index) => {
+ pagination[type] && acc.push(createItem(type, index));
+ return acc;
+ }, []),
+ result,
+ ['next', 'last'].reduce((acc, type, index) => {
+ pagination[type] && acc.push(createItem(type, index));
+ return acc;
+ }, [])
+ ];
});
diff --git a/common.blocks/sidebar/__sorting/sidebar__sorting.js b/common.blocks/sidebar/__sorting/sidebar__sorting.js
index af03bc8..ccd947b 100644
--- a/common.blocks/sidebar/__sorting/sidebar__sorting.js
+++ b/common.blocks/sidebar/__sorting/sidebar__sorting.js
@@ -21,14 +21,19 @@ modules.define(
direction = 'asc';
}
- Location.change({ params: this._getParams(sortType, direction) });
+ var params = this._getParams(sortType, direction);
+ delete params.page;
+
+ Location.change({ params: params });
},
_getParams: function(sort, direction) {
return Object.assign(
Location.getUri().queryParams,
- { sort, direction },
- { pagination: undefined }
+ {
+ sort: sort,
+ direction: direction
+ }
);
}
diff --git a/server/controllers/gh.js b/server/controllers/gh.js
index c7e59be..82b57f2 100644
--- a/server/controllers/gh.js
+++ b/server/controllers/gh.js
@@ -56,11 +56,15 @@ function getIndex(req, res) {
const issuesData = responses[0];
const labelsData = responses[1];
+ const paginationData = getPaginationData(issuesData.pagination);
+
render(req, res, {
view: 'page-index',
issues: issuesData.issues,
pagination: issuesData.pagination,
- labels: labelsData
+ labels: labelsData,
+ pageCount: paginationData.pageCount,
+ exceptPaginationUrl: paginationData.exceptPaginationUrl
});
}).catch(err => onError(req, res, err));
}
@@ -69,16 +73,41 @@ function getIssues(req, res) {
logger.log('getIssues');
makeIssueRequest(issuesRequestUrl, { query: req.query, token: getToken(req.user) })
- .then(issuesData => render(req, res, {
- view: 'page-index',
- issues: issuesData.issues,
- pagination: issuesData.pagination
- }, {
- block: 'issues'
- }))
+ .then(issuesData => {
+ const paginationData = getPaginationData(issuesData.pagination);
+
+ render(req, res,
+ {
+ view: 'page-index',
+ issues: issuesData.issues,
+ pagination: issuesData.pagination,
+ pageCount: paginationData.pageCount,
+ exceptPaginationUrl: paginationData.exceptPaginationUrl
+ }, {
+ block: 'issues'
+ }
+ );
+ })
.catch(err => onError(req, res, err));
}
+function getPaginationData(issuesPag) {
+ const querystring = require('querystring'),
+ pageCount = issuesPag.last ?
+ querystring.parse(issuesPag.last).page :
+ parseInt(querystring.parse(issuesPag.prev).page) + 1;
+
+ let exceptPaginationUrl = querystring.parse(issuesPag.last && issuesPag.last.substr(1) || issuesPag.prev.substr(1));
+ delete exceptPaginationUrl.page;
+
+ exceptPaginationUrl = '?' + querystring.stringify(exceptPaginationUrl);
+
+ return {
+ exceptPaginationUrl: exceptPaginationUrl,
+ pageCount: pageCount
+ };
+}
+
function getComplexIssue(req, res) {
logger.log('getComplexIssue', req.params.id);
@@ -127,8 +156,8 @@ function getComments(req, res) {
comments,
issueId: req.params.id
}, {
- block: 'comments'
- }))
+ block: 'comments'
+ }))
.catch(err => onError(req, res, err));
}
@@ -152,24 +181,21 @@ function _getData(req, res, dataType, urlPart) {
makeCommentRequest(requestPath, { token })
)
.then(response => {
- const data = dataType === 'issue' ? response.issues[0] : response;
-
- type === 'form' ?
- render(req, res, {
- view: 'page-post'
- },
- Object.assign({
- block: 'send-form',
- mix: { block: dataType, elem: 'send-form' },
- formType: dataType,
- reqType: 'edit',
- js: {
+ const data = dataType === 'issue' ? response.issues[0] : response;
+
+ type === 'form' ?
+ render(req, res, {
+ view: 'page-post'
+ }, {
+ block: 'send-form',
+ mix: { block: dataType, elem: 'send-form' },
formType: dataType,
- reqType: 'edit'
- }
- }, dataType === 'issue' ? { issue: data } : { comment: data })) :
- res.json(data);
- }).catch(err => onError(req, res, err));
+ reqType: 'edit',
+ issue: data,
+ comment: data
+ }) :
+ res.json(data);
+ }).catch(err => onError(req, res, err));
}
function addComment(req, res) {