[#369] refactoring; add pagination
This commit is contained in:
parent
8d211e5a75
commit
2ef938a389
|
@ -4,14 +4,14 @@ RosaABF.controller('ActivityCtrl', ['$scope', '$http', '$timeout', '$q', '$filte
|
||||||
all: {}, code: {}, tracker: {}, build: {}, wiki: {} };
|
all: {}, code: {}, tracker: {}, build: {}, wiki: {} };
|
||||||
$scope.tracker_tab = { title: 'activity_menu.tracker', content: [] , active: false,
|
$scope.tracker_tab = { title: 'activity_menu.tracker', content: [] , active: false,
|
||||||
filter: { all: true, assigned: false, created: false, name: 'all',
|
filter: { all: true, assigned: false, created: false, name: 'all',
|
||||||
all_count: 0, assigned_count: 0, created_count: 0 },
|
all_count: 0, assigned_count: 0, created_count: 0, closed_count: 0 },
|
||||||
sort: { sort: 'updated', direction: 'desc', updated_class: 'fa-chevron-up' },
|
sort: { sort: 'updated', direction: 'desc', updated_class: 'fa-chevron-up' },
|
||||||
status: 'open' };
|
status: 'open', pagination: { page: 1, total_count: 0 } };
|
||||||
$scope.pull_requests_tab = { title: 'activity_menu.pull_requests', content: [] , active: false,
|
$scope.pull_requests_tab = { title: 'activity_menu.pull_requests', content: [] , active: false,
|
||||||
filter: { all: true, assigned: false, created: false, name: 'all',
|
filter: { all: true, assigned: false, created: false, name: 'all',
|
||||||
all_count: 0, assigned_count: 0, created_count: 0 },
|
all_count: 0, assigned_count: 0, created_count: 0, closed_count: 0 },
|
||||||
sort: { sort: 'updated', direction: 'desc', updated_class: 'fa-chevron-up' },
|
sort: { sort: 'updated', direction: 'desc', updated_class: 'fa-chevron-up' },
|
||||||
status: 'open' };
|
status: 'open', pagination: { page: 1, total_count: 0 } };
|
||||||
|
|
||||||
$scope.getContent = function(tab){
|
$scope.getContent = function(tab){
|
||||||
var cur_tab = $scope.$eval(tab+'_tab');
|
var cur_tab = $scope.$eval(tab+'_tab');
|
||||||
|
@ -30,6 +30,15 @@ RosaABF.controller('ActivityCtrl', ['$scope', '$http', '$timeout', '$q', '$filte
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getIssuesTab = function(kind) {
|
||||||
|
if(kind === 'tracker') {
|
||||||
|
return $scope.tracker_tab;
|
||||||
|
}
|
||||||
|
else if(kind === 'pull_requests') {
|
||||||
|
return $scope.pull_requests_tab;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
$scope.getTimeLinefaClass = function(content) {
|
$scope.getTimeLinefaClass = function(content) {
|
||||||
var template = 'btn-warning fa-question';
|
var template = 'btn-warning fa-question';
|
||||||
|
|
||||||
|
@ -96,12 +105,7 @@ RosaABF.controller('ActivityCtrl', ['$scope', '$http', '$timeout', '$q', '$filte
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.setIssuesFilter = function(kind, issues_filter) {
|
$scope.setIssuesFilter = function(kind, issues_filter) {
|
||||||
if(kind === 'tracker') {
|
var filter = getIssuesTab(kind).filter;
|
||||||
var filter = $scope.tracker_tab.filter;
|
|
||||||
}
|
|
||||||
else if(kind === 'pull_requests') {
|
|
||||||
var filter = $scope.pull_requests_tab.filter;
|
|
||||||
};
|
|
||||||
|
|
||||||
filter.all = false;
|
filter.all = false;
|
||||||
filter.assigned = false;
|
filter.assigned = false;
|
||||||
|
@ -118,6 +122,7 @@ RosaABF.controller('ActivityCtrl', ['$scope', '$http', '$timeout', '$q', '$filte
|
||||||
sort: tab.sort.sort,
|
sort: tab.sort.sort,
|
||||||
direction: tab.sort.direction,
|
direction: tab.sort.direction,
|
||||||
status: tab.status,
|
status: tab.status,
|
||||||
|
page: tab.pagination.page,
|
||||||
format: 'json' });
|
format: 'json' });
|
||||||
}
|
}
|
||||||
else if($scope.pull_requests_tab.active) {
|
else if($scope.pull_requests_tab.active) {
|
||||||
|
@ -126,24 +131,24 @@ RosaABF.controller('ActivityCtrl', ['$scope', '$http', '$timeout', '$q', '$filte
|
||||||
sort: tab.sort.sort,
|
sort: tab.sort.sort,
|
||||||
direction: tab.sort.direction,
|
direction: tab.sort.direction,
|
||||||
status: tab.status,
|
status: tab.status,
|
||||||
|
page: tab.pagination.page,
|
||||||
format: 'json' });
|
format: 'json' });
|
||||||
};
|
};
|
||||||
|
|
||||||
$http.get(path).then(function(res) {
|
$http.get(path).then(function(res) {
|
||||||
tab.content = res.data.content;
|
tab.content = res.data.content;
|
||||||
tab.filter.all_count = res.data.all_count;
|
tab.filter.all_count = res.data.all_count;
|
||||||
tab.filter.assigned_count = res.data.assigned_count;
|
tab.filter.assigned_count = res.data.assigned_count;
|
||||||
tab.filter.created_count = res.data.created_count;
|
tab.filter.created_count = res.data.created_count;
|
||||||
|
tab.filter.closed_count = res.data.closed_count;
|
||||||
|
tab.filter.open_count = res.data.open_count;
|
||||||
|
tab.pagination.page = res.data.page;
|
||||||
|
tab.pagination.total_items = parseInt(res.data.issues_count, 10);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.setIssuesSort = function(kind, issues_sort) {
|
$scope.setIssuesSort = function(kind, issues_sort) {
|
||||||
if(kind === 'tracker') {
|
var tab = getIssuesTab(kind);
|
||||||
var tab = $scope.tracker_tab;
|
|
||||||
}
|
|
||||||
else if(kind === 'pull_requests') {
|
|
||||||
var tab = $scope.pull_requests_tab;
|
|
||||||
};
|
|
||||||
if(tab.sort.direction === 'desc') {
|
if(tab.sort.direction === 'desc') {
|
||||||
tab.sort = { sort: issues_sort, direction: 'asc' };
|
tab.sort = { sort: issues_sort, direction: 'asc' };
|
||||||
var sort_class = 'fa-chevron-down';
|
var sort_class = 'fa-chevron-down';
|
||||||
|
@ -157,13 +162,13 @@ RosaABF.controller('ActivityCtrl', ['$scope', '$http', '$timeout', '$q', '$filte
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.setIssuesStatus = function(kind, issues_status) {
|
$scope.setIssuesStatus = function(kind, issues_status) {
|
||||||
if(kind === 'tracker') {
|
var tab = getIssuesTab(kind);
|
||||||
var tab = $scope.tracker_tab;
|
|
||||||
}
|
|
||||||
else if(kind === 'pull_requests') {
|
|
||||||
var tab = $scope.pull_requests_tab;
|
|
||||||
};
|
|
||||||
tab.status = issues_status;
|
tab.status = issues_status;
|
||||||
$scope.getIssuesContent();
|
$scope.getIssuesContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.selectPage = function(kind, page) {
|
||||||
|
getIssuesTab(kind).pagination.page = page;
|
||||||
|
$scope.getIssuesContent();
|
||||||
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -45,6 +45,7 @@ footer {
|
||||||
.offset20 { margin-top: 20px; }
|
.offset20 { margin-top: 20px; }
|
||||||
.boffset20 { margin-bottom: 20px; }
|
.boffset20 { margin-bottom: 20px; }
|
||||||
.boffset10 { margin-bottom: 10px; }
|
.boffset10 { margin-bottom: 10px; }
|
||||||
|
.loffset5 { margin-left: 5px; }
|
||||||
|
|
||||||
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
|
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
|
|
|
@ -124,4 +124,10 @@ class ApplicationController < ActionController::Base
|
||||||
def not_found
|
def not_found
|
||||||
raise ActionController::RoutingError.new('Not Found')
|
raise ActionController::RoutingError.new('Not Found')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def current_page
|
||||||
|
params[:page] = 1 if params[:page].to_i < 1
|
||||||
|
|
||||||
|
params[:page]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@ class HomeController < ApplicationController
|
||||||
@filter = t('feed_menu').has_key?(params[:filter].try(:to_sym)) ? params[:filter].to_sym : :all
|
@filter = t('feed_menu').has_key?(params[:filter].try(:to_sym)) ? params[:filter].to_sym : :all
|
||||||
@activity_feeds = current_user.activity_feeds
|
@activity_feeds = current_user.activity_feeds
|
||||||
@activity_feeds = @activity_feeds.where(kind: "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all
|
@activity_feeds = @activity_feeds.where(kind: "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all
|
||||||
@activity_feeds = @activity_feeds.paginate page: params[:page]
|
@activity_feeds = @activity_feeds.paginate page: current_page
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { request.xhr? ? render('_list', layout: false) : render('activity') }
|
format.html { request.xhr? ? render('_list', layout: false) : render('activity') }
|
||||||
|
@ -45,7 +45,7 @@ class HomeController < ApplicationController
|
||||||
@issues = @all_issues
|
@issues = @all_issues
|
||||||
end
|
end
|
||||||
@filter = params[:filter]
|
@filter = params[:filter]
|
||||||
@opened_issues, @closed_issues = @issues.not_closed_or_merged.count, @issues.closed_or_merged.count
|
@opened_issues, @closed_issues = @issues.not_closed_or_merged, @issues.closed_or_merged
|
||||||
|
|
||||||
@status = params[:status] == 'closed' ? :closed : :open
|
@status = params[:status] == 'closed' ? :closed : :open
|
||||||
@issues = @issues.send( (@status == :closed) ? :closed_or_merged : :not_closed_or_merged )
|
@issues = @issues.send( (@status == :closed) ? :closed_or_merged : :not_closed_or_merged )
|
||||||
|
@ -54,7 +54,7 @@ class HomeController < ApplicationController
|
||||||
@direction = params[:direction] == 'asc' ? :asc : :desc
|
@direction = params[:direction] == 'asc' ? :asc : :desc
|
||||||
@issues = @issues.order("issues.#{@sort}_at #{@direction}")
|
@issues = @issues.order("issues.#{@sort}_at #{@direction}")
|
||||||
.includes(:assignee, :user, :pull_request).uniq
|
.includes(:assignee, :user, :pull_request).uniq
|
||||||
.paginate per_page: 20, page: params[:page]
|
.paginate page: current_page
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { request.xhr? ? render('issues', layout: 'with_sidebar') : render('issues', layout: 'application') }
|
format.html { request.xhr? ? render('issues', layout: 'with_sidebar') : render('issues', layout: 'application') }
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
class Issue < ActiveRecord::Base
|
class Issue < ActiveRecord::Base
|
||||||
include Feed::Issue
|
include Feed::Issue
|
||||||
STATUSES = ['open', 'closed']
|
STATUSES = ['open', 'closed']
|
||||||
|
self.per_page = 20
|
||||||
|
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
|
@ -11,7 +11,9 @@
|
||||||
.col-md-9.col-sm-8.offset20
|
.col-md-9.col-sm-8.offset20
|
||||||
%tabset.boffset10
|
%tabset.boffset10
|
||||||
- %w(open closed).each do |status|
|
- %w(open closed).each do |status|
|
||||||
%tab{ 'heading' => t("layout.issues.statuses.#{status}"), 'active' => "#{kind}_tab.status.#{status}.active",
|
- count_issues = "({{#{kind}_tab.filter.#{status}_count}})"
|
||||||
|
%tab{ 'heading' => "#{t "layout.issues.statuses.#{status}"} #{count_issues}",
|
||||||
|
'active' => "#{kind}_tab.status.#{status}.active",
|
||||||
'ng-click' => "setIssuesStatus('#{kind}', '#{status}')" }
|
'ng-click' => "setIssuesStatus('#{kind}', '#{status}')" }
|
||||||
|
|
||||||
.pull-right.boffset10
|
.pull-right.boffset10
|
||||||
|
@ -23,8 +25,11 @@
|
||||||
%tr{ 'ng-repeat' => "issue in #{kind}_tab.content" }
|
%tr{ 'ng-repeat' => "issue in #{kind}_tab.content" }
|
||||||
%td
|
%td
|
||||||
%a{ 'ng-href' => "{{issue.issue_url}}" }
|
%a{ 'ng-href' => "{{issue.issue_url}}" }
|
||||||
%span.text-muted {{issue.project_name}}
|
%span.text-info {{issue.project_name}}
|
||||||
{{issue.title}}
|
{{issue.title}}
|
||||||
|
%span.label.small.loffset5{ 'ng-repeat' => "label in issue.labels",
|
||||||
|
'ng-style' => "{background: label.color}" }
|
||||||
|
{{label.name}}
|
||||||
.small
|
.small
|
||||||
= t 'layout.issues.created_by'
|
= t 'layout.issues.created_by'
|
||||||
%a{ 'ng-href' => "{{issue.user.link}}" } {{issue.user.uname}}
|
%a{ 'ng-href' => "{{issue.user.link}}" } {{issue.user.uname}}
|
||||||
|
@ -40,3 +45,14 @@
|
||||||
%a{ 'ng-href' => '{{issue.assignee.link}}',
|
%a{ 'ng-href' => '{{issue.assignee.link}}',
|
||||||
'title' => "#{t('layout.issues.assigned_to')} {{issue.assignee.fullname}}" }
|
'title' => "#{t('layout.issues.assigned_to')} {{issue.assignee.fullname}}" }
|
||||||
%img{ 'ng-src' => '{{issue.assignee.image}}' }
|
%img{ 'ng-src' => '{{issue.assignee.image}}' }
|
||||||
|
|
||||||
|
%pagination.pagination-sm{ 'boundary-links' => 'true',
|
||||||
|
'total-items' => "#{kind}_tab.pagination.total_items",
|
||||||
|
'page' => "#{kind}_tab.pagination.page",
|
||||||
|
'previous-text' => "‹", 'next-text' => "›",
|
||||||
|
'first-text' => "«", "last-text" => "»",
|
||||||
|
'items-per-page' => Issue.per_page,
|
||||||
|
'max-size' => 5,
|
||||||
|
'rotate' => 'false',
|
||||||
|
'ng-show' => "#{kind}_tab.pagination.total_items > #{Issue.per_page}",
|
||||||
|
'on-select-page' => "selectPage('#{kind}', page)" }
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
json.all_count @all_issues.not_closed_or_merged.count
|
json.all_count @all_issues.not_closed_or_merged.count
|
||||||
|
json.open_count @opened_issues.count
|
||||||
|
json.closed_count @closed_issues.count
|
||||||
json.assigned_count @assigned_issues.not_closed_or_merged.count
|
json.assigned_count @assigned_issues.not_closed_or_merged.count
|
||||||
json.created_count @created_issues.not_closed_or_merged.count
|
json.created_count @created_issues.not_closed_or_merged.count
|
||||||
|
json.page params[:page]
|
||||||
|
json.issues_count @issues.count
|
||||||
|
|
||||||
json.content do
|
json.content do
|
||||||
json.array!(@issues) do |issue|
|
json.array!(@issues) do |issue|
|
||||||
|
@ -19,5 +23,11 @@ json.content do
|
||||||
json.image avatar_url(issue.assignee, :micro) if issue.assignee
|
json.image avatar_url(issue.assignee, :micro) if issue.assignee
|
||||||
json.fullname issue.assignee.fullname if issue.assignee
|
json.fullname issue.assignee.fullname if issue.assignee
|
||||||
end
|
end
|
||||||
|
json.labels do
|
||||||
|
json.array!(issue.labels) do |label|
|
||||||
|
json.name label.name
|
||||||
|
json.color "##{label.color}"
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue