|
@@ -11,33 +11,36 @@ module.exports = function(crowi, app) {
|
|
|
, MAX_PAGE_LIST = 5
|
|
, MAX_PAGE_LIST = 5
|
|
|
, actions = {};
|
|
, actions = {};
|
|
|
|
|
|
|
|
- function createPager(currentPage, pageCount, itemCount, maxPageList) {
|
|
|
|
|
- var pager = {};
|
|
|
|
|
- pager.currentPage = currentPage;
|
|
|
|
|
- pager.pageCount = pageCount;
|
|
|
|
|
- pager.itemCount = itemCount;
|
|
|
|
|
-
|
|
|
|
|
- pager.previous = null;
|
|
|
|
|
- if (currentPage > 1) {
|
|
|
|
|
- pager.previous = currentPage - 1;
|
|
|
|
|
|
|
+ function createPager(total, limit, page, pagesCount, maxPageList) {
|
|
|
|
|
+ const pager = {
|
|
|
|
|
+ page: page,
|
|
|
|
|
+ pagesCount: pagesCount,
|
|
|
|
|
+ pages: [],
|
|
|
|
|
+ total: total,
|
|
|
|
|
+ previous: null,
|
|
|
|
|
+ previousDots: false,
|
|
|
|
|
+ next: null,
|
|
|
|
|
+ nextDots: false,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ if (page > 1) {
|
|
|
|
|
+ pager.previous = page - 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pager.next = null;
|
|
|
|
|
- if (currentPage < pageCount) {
|
|
|
|
|
- pager.next = currentPage + 1;
|
|
|
|
|
|
|
+ if (page < pagesCount) {
|
|
|
|
|
+ pager.next = page + 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- pager.pages = [];
|
|
|
|
|
- var pagerMin = Math.max(1, Math.ceil(currentPage - maxPageList/2));
|
|
|
|
|
- var pagerMax = Math.min(pageCount, Math.floor(currentPage + maxPageList/2));
|
|
|
|
|
- if (pagerMin == 1) {
|
|
|
|
|
- if (MAX_PAGE_LIST < pageCount) {
|
|
|
|
|
|
|
+ let pagerMin = Math.max(1, Math.ceil(page - maxPageList/2));
|
|
|
|
|
+ let pagerMax = Math.min(pagesCount, Math.floor(page + maxPageList/2));
|
|
|
|
|
+ if (pagerMin === 1) {
|
|
|
|
|
+ if (MAX_PAGE_LIST < pagesCount) {
|
|
|
pagerMax = MAX_PAGE_LIST;
|
|
pagerMax = MAX_PAGE_LIST;
|
|
|
} else {
|
|
} else {
|
|
|
- pagerMax = pageCount;
|
|
|
|
|
|
|
+ pagerMax = pagesCount;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- if (pagerMax == pageCount) {
|
|
|
|
|
|
|
+ if (pagerMax === pagesCount) {
|
|
|
if ((pagerMax - MAX_PAGE_LIST) < 1) {
|
|
if ((pagerMax - MAX_PAGE_LIST) < 1) {
|
|
|
pagerMin = 1;
|
|
pagerMin = 1;
|
|
|
} else {
|
|
} else {
|
|
@@ -51,13 +54,11 @@ module.exports = function(crowi, app) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
pager.nextDots = null;
|
|
pager.nextDots = null;
|
|
|
- if (pagerMax < pageCount) {
|
|
|
|
|
|
|
+ if (pagerMax < pagesCount) {
|
|
|
pager.nextDots = true;
|
|
pager.nextDots = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- for (var i = pagerMin;
|
|
|
|
|
- i <= pagerMax;
|
|
|
|
|
- i++) {
|
|
|
|
|
|
|
+ for (let i = pagerMin; i <= pagerMax; i++) {
|
|
|
pager.pages.push(i);
|
|
pager.pages.push(i);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -208,19 +209,15 @@ module.exports = function(crowi, app) {
|
|
|
if (!data.errors) {
|
|
if (!data.errors) {
|
|
|
debug('Data is successfully indexed.');
|
|
debug('Data is successfully indexed.');
|
|
|
} else {
|
|
} else {
|
|
|
- debug('Data index error.', data);
|
|
|
|
|
|
|
+ debug('Data index error.', data.errors);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- //return res.json(ApiResponse.success({}));
|
|
|
|
|
- req.flash('successMessage', 'Successfully re-build index.');
|
|
|
|
|
- return res.redirect('/admin/search');
|
|
|
|
|
})
|
|
})
|
|
|
.catch(function(err) {
|
|
.catch(function(err) {
|
|
|
debug('Error', err);
|
|
debug('Error', err);
|
|
|
- req.flash('errorMessage', 'Error');
|
|
|
|
|
- return res.redirect('/admin/search');
|
|
|
|
|
- //return res.json(ApiResponse.error(err));
|
|
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ req.flash('successMessage', 'Now re-building index ... this takes a while.');
|
|
|
|
|
+ return res.redirect('/admin/search');
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -228,10 +225,11 @@ module.exports = function(crowi, app) {
|
|
|
actions.user.index = function(req, res) {
|
|
actions.user.index = function(req, res) {
|
|
|
var page = parseInt(req.query.page) || 1;
|
|
var page = parseInt(req.query.page) || 1;
|
|
|
|
|
|
|
|
- User.findUsersWithPagination({page: page}, function(err, users, pageCount, itemCount) {
|
|
|
|
|
- var pager = createPager(page, pageCount, itemCount, MAX_PAGE_LIST);
|
|
|
|
|
|
|
+ User.findUsersWithPagination({page: page}, function(err, result) {
|
|
|
|
|
+ const pager = createPager(result.total, result.limit, result.page, result.pages, MAX_PAGE_LIST);
|
|
|
|
|
+
|
|
|
return res.render('admin/users', {
|
|
return res.render('admin/users', {
|
|
|
- users: users,
|
|
|
|
|
|
|
+ users: result.docs,
|
|
|
pager: pager
|
|
pager: pager
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|