feat(forum): topic replies list pagination nav

This commit is contained in:
OldHawk
2017-07-18 17:02:25 +08:00
parent 61d8209d4b
commit f08ad7a158
3 changed files with 52 additions and 3 deletions

View File

@@ -185,6 +185,7 @@ module.exports = {
},
itemsPerPage: {
topics_per_page: 10,
replies_per_page: 10,
torrents_per_page: 15,
torrents_comments_per_page: 10
},

View File

@@ -12,11 +12,15 @@
marked, ModalConfirmService, $stateParams, TopicsService, localStorageService, $compile, RepliesService, $filter, Upload, DownloadService) {
var vm = this;
vm.forumsConfig = MeanTorrentConfig.meanTorrentConfig.forumsConfig;
vm.itemsPerPageConfig = MeanTorrentConfig.meanTorrentConfig.itemsPerPage;
vm.appConfig = MeanTorrentConfig.meanTorrentConfig.app;
vm.user = Authentication.user;
vm.forumPath = [];
vm.postReplyFields = {};
vm.pagedItems = [];
vm.itemsPerPage = vm.itemsPerPageConfig.replies_per_page;
vm.currentPage = 1;
/**
* If user is not signed in then redirect back home
*/
@@ -24,6 +28,49 @@
$state.go('authentication.signin');
}
/**
* buildPager
* pagination init
*/
vm.buildPager = function () {
vm.figureOutItemsToDisplay();
};
/**
* figureOutItemsToDisplay
* @param callback
*/
vm.figureOutItemsToDisplay = function (callback) {
vm.filterLength = vm.topic._replies.length;
var begin = ((vm.currentPage - 1) * vm.itemsPerPage);
var end = begin + vm.itemsPerPage;
vm.pagedItems = vm.topic._replies.slice(begin, end);
if (callback) callback();
};
/**
* pageChanged
*/
vm.pageChanged = function () {
var element = angular.element('#top_of_reply_list');
vm.figureOutItemsToDisplay(function () {
$timeout(function () {
$('html,body').animate({scrollTop: element[0].offsetTop - 60}, 200);
}, 10);
});
};
/**
* $watch 'vm.torrentLocalInfo'
*/
$scope.$watch('vm.topic', function (newValue, oldValue) {
if (newValue) {
vm.pageChanged();
}
});
/**
* init
*/
@@ -395,9 +442,10 @@
function successCallback(res) {
vm.postReplyFields = {};
vm.topic = res;
$scope.uFiles = [];
$scope.uImages = [];
vm.currentPage = Math.ceil(vm.topic._replies.length / vm.itemsPerPage);
vm.topic = res;
$scope.$broadcast('show-errors-reset', 'vm.replyForm');
NotifycationService.showSuccessNotify('FORUMS.POST_REPLY_SUCCESSFULLY');

View File

@@ -37,7 +37,7 @@
</div>
<div>
<div id="top_of_reply_list">
<div class="row">
<div class="col-sm-12">
<div class="box-uib-and-post-btn">
@@ -157,7 +157,7 @@
</div>
<!-- topic replies -->
<div class="reply-wrapper" ng-repeat="rep in vm.topic._replies">
<div class="reply-wrapper" ng-repeat="rep in vm.pagedItems">
<span user-info="rep.user" info-class="reply-avatar" info-avatar></span>
<div class="reply-comment">