[#369] projects page: fix paginate
This commit is contained in:
parent
41bfa0136a
commit
530523611c
|
@ -16,7 +16,7 @@ RosaABF.controller('ProjectsCtrl', ['$scope', '$http', function($scope, $http) {
|
||||||
users: $scope.filter_users, groups: $scope.filter_groups };
|
users: $scope.filter_users, groups: $scope.filter_groups };
|
||||||
$http.get(Routes.projects_path(params)).then(function(res) {
|
$http.get(Routes.projects_path(params)).then(function(res) {
|
||||||
$scope.page = res.data.page;
|
$scope.page = res.data.page;
|
||||||
$scope.total_items = parseInt(res.data.projects_count, 10);
|
$scope.total_items = res.data.projects_count;
|
||||||
$scope.projects = res.data.projects;
|
$scope.projects = res.data.projects;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,23 +19,18 @@ module PaginateHelper
|
||||||
super *[collection_or_options, options].compact
|
super *[collection_or_options, options].compact
|
||||||
end
|
end
|
||||||
|
|
||||||
def angularjs_will_paginate(collection_or_options = nil, options = {})
|
def angularjs_paginate(options = {})
|
||||||
if collection_or_options.is_a? Hash
|
return if options[:per_page].blank?
|
||||||
options, collection_or_options = collection_or_options, nil
|
|
||||||
end
|
|
||||||
options.merge!(renderer: AngularjsLinkRenderer) unless options[:renderer]
|
|
||||||
options.merge!(next_label: I18n.t('datatables.next_label')) unless options[:next_label]
|
|
||||||
options.merge!(previous_label: I18n.t('datatables.previous_label')) unless options[:previous_label]
|
|
||||||
will_paginate *[collection_or_options, options].compact
|
|
||||||
end
|
|
||||||
|
|
||||||
def paginate(options)
|
options.reverse_merge!(
|
||||||
return nil if options.blank?
|
{
|
||||||
render 'shared/paginate',
|
total_items: 'total_items',
|
||||||
total_items: options[:total_items],
|
page: 'page',
|
||||||
page: options[:page],
|
ng_show: "total_items > #{options[:per_page]}",
|
||||||
per_page: options[:per_page],
|
select_page: "goToPage(page)"
|
||||||
ng_show: options[:ng_show],
|
}
|
||||||
select_page: options[:select_page]
|
)
|
||||||
|
|
||||||
|
render 'shared/angularjs_paginate', options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,8 +37,4 @@
|
||||||
%span.fa.fa-lg.fa-times.text-danger{ 'confirmed-click' => 'leave_project(item)',
|
%span.fa.fa-lg.fa-times.text-danger{ 'confirmed-click' => 'leave_project(item)',
|
||||||
'ng-show' => 'item.can_leave_project', 'ng-confirm-click' => t('layout.confirm') }
|
'ng-show' => 'item.can_leave_project', 'ng-confirm-click' => t('layout.confirm') }
|
||||||
|
|
||||||
= paginate( total_items: 'total_items',
|
= angularjs_paginate per_page: Project.per_page
|
||||||
page: 'page',
|
|
||||||
per_page: Project.per_page,
|
|
||||||
ng_show: "total_items > #{Project.per_page}",
|
|
||||||
select_page: "goToPage(page)" )
|
|
||||||
|
|
|
@ -13,5 +13,5 @@ json.projects do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
json.page params[:page]
|
json.page params[:page]
|
||||||
json.projects_count @projects_count
|
json.projects_count @projects_count
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
/ Add to controller something like:
|
||||||
|
/ $scope.goToPage = (number) ->
|
||||||
|
/ $location.search('page', number)
|
||||||
|
|
||||||
|
pagination[ boundary-links = 'true'
|
||||||
|
total-items = total_items
|
||||||
|
ng-model = page
|
||||||
|
previous-text = "‹" next-text = "›"
|
||||||
|
first-text = "«" last-text = "»"
|
||||||
|
items-per-page = per_page
|
||||||
|
max-size = 5
|
||||||
|
rotate = 'false'
|
||||||
|
ng-show = ng_show
|
||||||
|
ng-change = select_page ]
|
|
@ -1,20 +0,0 @@
|
||||||
/ Add to controller something like:
|
|
||||||
/ $scope.goToPage = (number) ->
|
|
||||||
/ $location.search('page', number)
|
|
||||||
ul.pagination ng-show='pages'
|
|
||||||
li ng-class="{'disabled': !page.active}" ng-repeat='page in pages' ng-switch='page.type'
|
|
||||||
a ng-switch-when='previous_page' ng-hide='page.active'
|
|
||||||
= t('datatables.previous_label')
|
|
||||||
a ng-switch-when='previous_page' ng-show='page.active' ng-click='goToPage(page.number)'
|
|
||||||
= t('datatables.previous_label')
|
|
||||||
a ng-switch-when='first'
|
|
||||||
| {{page.number}}
|
|
||||||
a ng-switch-when='page' ng-click='goToPage(page.number)'
|
|
||||||
| {{page.number}}
|
|
||||||
a ng-switch-when='more' ng-click='goToPage(page.number)' …
|
|
||||||
a ng-switch-when='last' ng-click='goToPage(page.number)'
|
|
||||||
| {{page.number}}
|
|
||||||
a ng-switch-when='next_page' ng-hide='page.active'
|
|
||||||
= t('datatables.next_label')
|
|
||||||
a ng-switch-when='next_page' ng-show='page.active' ng-click='goToPage(page.number)'
|
|
||||||
= t('datatables.next_label')
|
|
|
@ -1,10 +0,0 @@
|
||||||
%pagination{ 'boundary-links' => 'true',
|
|
||||||
'total-items' => total_items,
|
|
||||||
'page' => page,
|
|
||||||
'previous-text' => "‹", 'next-text' => "›",
|
|
||||||
'first-text' => "«", "last-text" => "»",
|
|
||||||
'items-per-page' => per_page,
|
|
||||||
'max-size' => 5,
|
|
||||||
'rotate' => 'false',
|
|
||||||
'ng-show' => ng_show,
|
|
||||||
'on-select-page' => select_page }
|
|
|
@ -1,41 +0,0 @@
|
||||||
class Array
|
|
||||||
def html_safe
|
|
||||||
self
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class AngularjsLinkRenderer < WillPaginate::ActionView::LinkRenderer
|
|
||||||
|
|
||||||
def to_html
|
|
||||||
pagination.map do |item|
|
|
||||||
item.is_a?(Fixnum) ? page_number(item) : send(item)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def page_number(page)
|
|
||||||
unless page == current_page
|
|
||||||
{active: true, number: page, type: :page}
|
|
||||||
else
|
|
||||||
{active: false, number: page, type: :first}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def gap
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def next_page
|
|
||||||
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
|
|
||||||
previous_or_next_page(num, @options[:next_label], :next_page)
|
|
||||||
end
|
|
||||||
|
|
||||||
def previous_or_next_page(page, text, classname)
|
|
||||||
if page
|
|
||||||
{active: true, number: page, type: classname}
|
|
||||||
else
|
|
||||||
{active: false, number: page, type: classname}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue