add pagination on torrent comment list

This commit is contained in:
OldHawk
2017-04-25 19:22:15 +08:00
parent 5cc02e2d66
commit 4100aa25b9
4 changed files with 54 additions and 5 deletions

View File

@@ -19,7 +19,8 @@
if (value) {
//element[0].scrollIntoView({block: 'end', behavior: 'smooth'});
//$uiViewScroll(element);
window.scrollTo(0, element[0].offsetTop - 60);
var offsetTop = Number(attrs.offsetTop || 0);
window.scrollTo(0, element[0].offsetTop + offsetTop);
}
});
}

View File

@@ -12,6 +12,10 @@
.panel-body {
background-color: @comment-background-default;
}
.pagination {
padding-left: 75px;
margin: 0;
}
}
.tabnav-extra {

View File

@@ -6,11 +6,12 @@
.controller('TorrentsInfoController', TorrentsInfoController);
TorrentsInfoController.$inject = ['$scope', '$state', '$stateParams', '$translate', 'Authentication', 'Notification', 'TorrentsService',
'MeanTorrentConfig', 'DownloadService', '$sce', '$filter', 'CommentsService', 'ModalConfirmService', 'marked', 'Upload', '$timeout',
'MeanTorrentConfig', 'DownloadService', '$sce', '$filter', 'CommentsService', 'ModalConfirmService', 'marked', 'Upload', '$timeout', '$uiViewScroll',
'SubtitlesService'];
function TorrentsInfoController($scope, $state, $stateParams, $translate, Authentication, Notification, TorrentsService, MeanTorrentConfig,
DownloadService, $sce, $filter, CommentsService, ModalConfirmService, marked, Upload, $timeout, SubtitlesService) {
DownloadService, $sce, $filter, CommentsService, ModalConfirmService, marked, Upload, $timeout, SubtitlesService,
$uiViewScroll) {
var vm = this;
vm.user = Authentication.user;
vm.announce = MeanTorrentConfig.meanTorrentConfig.announce;
@@ -21,6 +22,38 @@
vm.torrentTabs = [];
vm.progress = 0;
//page init
vm.commentBuildPager = commentBuildPager;
vm.commentFigureOutItemsToDisplay = commentFigureOutItemsToDisplay;
vm.commentPageChanged = commentPageChanged;
function commentBuildPager() {
vm.commentPagedItems = [];
vm.commentItemsPerPage = 10;
vm.commentCurrentPage = 1;
vm.commentFigureOutItemsToDisplay();
}
function commentFigureOutItemsToDisplay() {
if (vm.torrentLocalInfo && vm.torrentLocalInfo._replies) {
vm.commentFilterLength = vm.torrentLocalInfo._replies.length;
var begin = ((vm.commentCurrentPage - 1) * vm.commentItemsPerPage);
var end = begin + vm.commentItemsPerPage;
vm.commentPagedItems = vm.torrentLocalInfo._replies.slice(begin, end);
}
}
function commentPageChanged() {
var element = angular.element('#top_of_comments');
vm.commentFigureOutItemsToDisplay();
window.scrollTo(0, element[0].offsetTop - 30);
}
$scope.$watch('vm.torrentLocalInfo', function () {
vm.commentFigureOutItemsToDisplay();
});
// If user is not signed in then redirect back home
if (!Authentication.user) {
$state.go('authentication.signin');
@@ -37,6 +70,7 @@
$('.backdrop').css('backgroundImage', 'url(' + vm.tmdbConfig.backdrop_img_base_url + res.torrent_backdrop_img + ')');
}
vm.initInfo(res.torrent_tmdb_id);
vm.commentBuildPager();
vm.torrentTabs.push(
{

View File

@@ -148,13 +148,18 @@
</div>
<div class="padding-top-30">
<div class="padding-top-30" id="top_of_comments">
<div class="container">
<div class="panel panel-default panel-comment">
<div class="panel-heading text-center"><strong>{{ 'USER_COMMENT_LIST' | translate}}</strong> <span
class="badge badge_info">{{vm.torrentLocalInfo._replies.length}}</span></div>
<div class="panel-body">
<div class="comment-list" id="{{item._id}}" scroll-if="item._id==vm.scrollToId" ng-repeat="item in vm.torrentLocalInfo._replies">
<uib-pagination boundary-links="true" max-size="8" items-per-page="vm.commentItemsPerPage" total-items="vm.commentFilterLength"
ng-model="vm.commentCurrentPage" ng-change="vm.commentPageChanged()"
ng-if="vm.torrentLocalInfo._replies.length > 0"></uib-pagination>
<div class="comment-list" id="{{item._id}}" scroll-if="item._id==vm.scrollToId" offset-top="-60"
ng-repeat="item in vm.commentPagedItems">
<div class="timeline-comment-wrapper">
<a class="timeline-comment-avatar" ng-click="vm.replyComment(item);">
<img title="{{item.user.displayName}}" ng-src="/{{item.user.profileImageURL}}">
@@ -224,6 +229,11 @@
</div>
</div>
<uib-pagination boundary-links="true" max-size="8" items-per-page="vm.commentItemsPerPage" total-items="vm.commentFilterLength"
ng-model="vm.commentCurrentPage" ng-change="vm.commentPageChanged()"
ng-if="vm.torrentLocalInfo._replies.length > 0"></uib-pagination>
<div class="padding-top-20"></div>
<div class="comment-new">
<div class="timeline-comment-wrapper">
<a href="#" class="timeline-comment-avatar">