[#369] update a project issues/pull_requests page

This commit is contained in:
Alexander Machehin 2014-11-27 16:15:00 +05:00
parent c6c4a9628b
commit 975ae2e314
3 changed files with 48 additions and 47 deletions

View File

@ -78,9 +78,7 @@ IssuesController = (dataservice, $http, $location, Issue, $rootScope) ->
init = (dataservice) ->
vm.project = dataservice.project
vm.issues = dataservice.issues
vm.filter = dataservice.filter
vm.labels = dataservice.labels
vm.filter[dataservice.filter.filter] = true
@ -91,6 +89,7 @@ IssuesController = (dataservice, $http, $location, Issue, $rootScope) ->
vm.filter.status_open = true
setSortClass()
getIssues()
init(dataservice)
true

View File

@ -10,53 +10,58 @@ class Projects::IssuesController < Projects::BaseController
layout false, only: [:update, :search_collaborators]
def index
params[:kind] ||= 'issues'
params[:filter] ||= 'all'
params[:sort] ||= :updated
if params[:kind] == 'pull_requests'
all_issues = @project.issues.joins(:pull_request)
else
all_issues = @project.issues.without_pull_requests
end
@all_issues = all_issues
if current_user
@created_issues = all_issues.where(user_id: current_user)
@assigned_issues = all_issues.where(assignee_id: current_user)
end
case params[:filter]
when 'created'
@issues = @created_issues
when 'assigned'
@issues = @assigned_issues
else
@issues = all_issues
end
if params[:labels].is_a?(Array) && params[:labels].present?
@issues = @issues.joins(:labels).where(labels: {name: params[:labels]})
else
params[:kind] = params[:kind] == 'issues' ? 'issues' : 'pull_requests'
params[:filter] = params[:filter].in?(['created', 'assigned']) ? params[:filter] : 'all'
params[:sort] = params[:sort] == 'submitted' ? 'submitted' : 'updated'
params[:direction] = params[:direction] == 'asc' ? :asc : :desc
params[:status] = params[:status] == 'closed' ? :closed : :open
if !params[:labels].is_a?(Array) || params[:labels].blank?
params[:labels] = []
end
@opened_issues, @closed_issues = @issues.not_closed_or_merged, @issues.closed_or_merged
respond_to do |format|
format.html { render 'index' }
format.json do
if params[:kind] == 'pull_requests'
all_issues = @project.issues.joins(:pull_request)
else
all_issues = @project.issues.without_pull_requests
end
params[:status] = params[:status] == 'closed' ? :closed : :open
@issues = @issues.send( params[:status] == :closed ? :closed_or_merged : :not_closed_or_merged )
@all_issues = all_issues
if current_user
@created_issues = all_issues.where(user_id: current_user)
@assigned_issues = all_issues.where(assignee_id: current_user)
end
params[:direction] = params[:direction] == 'asc' ? :asc : :desc
if params[:sort] == 'submitted'
@issues = @issues.order(created_at: params[:direction])
else
@issues = @issues.order(updated_at: params[:direction])
case params[:filter]
when 'created'
@issues = @created_issues
when 'assigned'
@issues = @assigned_issues
else
@issues = all_issues
end
if params[:labels].is_a?(Array) && params[:labels].present?
@issues = @issues.joins(:labels).where(labels: {name: params[:labels]})
end
@opened_issues, @closed_issues = @issues.not_closed_or_merged, @issues.closed_or_merged
@issues = @issues.send( params[:status] == :closed ? :closed_or_merged : :not_closed_or_merged )
if params[:sort] == 'submitted'
@issues = @issues.order(created_at: params[:direction])
else
@issues = @issues.order(updated_at: params[:direction])
end
@issues = @issues.includes(:assignee, :user, :pull_request).uniq
.paginate(page: current_page)
render 'index'
end
end
@issues = @issues.includes(:assignee, :user, :pull_request).uniq
.paginate(page: current_page)
render 'index'
end
def pull_requests

View File

@ -3,10 +3,7 @@
angular.module('RosaABF').service('IssuesInitializer', function(){
return {
project: '<%= @project.name_with_owner %>',
<% all_issue_ids = @all_issues.not_closed_or_merged.pluck(:id) %>
labels: <%= render('labels.json', project: @project, all_issue_ids: all_issue_ids).html_safe %>,
filter: <%= render('filter.json', all_issues: @all_issues, params: params).html_safe %>,
issues: <%= render('issues.json', issues: @issues).html_safe %>
filter: <%= render('filter.json', all_issues: @all_issues, params: params).html_safe %>
};
});
<% elsif action_name.in?(['new', 'create']) %>