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

View File

@ -10,10 +10,18 @@ class Projects::IssuesController < Projects::BaseController
layout false, only: [:update, :search_collaborators] layout false, only: [:update, :search_collaborators]
def index def index
params[:kind] ||= 'issues' params[:kind] = params[:kind] == 'issues' ? 'issues' : 'pull_requests'
params[:filter] ||= 'all' params[:filter] = params[:filter].in?(['created', 'assigned']) ? params[:filter] : 'all'
params[:sort] ||= :updated 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
respond_to do |format|
format.html { render 'index' }
format.json do
if params[:kind] == 'pull_requests' if params[:kind] == 'pull_requests'
all_issues = @project.issues.joins(:pull_request) all_issues = @project.issues.joins(:pull_request)
else else
@ -37,16 +45,11 @@ class Projects::IssuesController < Projects::BaseController
if params[:labels].is_a?(Array) && params[:labels].present? if params[:labels].is_a?(Array) && params[:labels].present?
@issues = @issues.joins(:labels).where(labels: {name: params[:labels]}) @issues = @issues.joins(:labels).where(labels: {name: params[:labels]})
else
params[:labels] = []
end end
@opened_issues, @closed_issues = @issues.not_closed_or_merged, @issues.closed_or_merged @opened_issues, @closed_issues = @issues.not_closed_or_merged, @issues.closed_or_merged
params[:status] = params[:status] == 'closed' ? :closed : :open
@issues = @issues.send( params[:status] == :closed ? :closed_or_merged : :not_closed_or_merged ) @issues = @issues.send( params[:status] == :closed ? :closed_or_merged : :not_closed_or_merged )
params[:direction] = params[:direction] == 'asc' ? :asc : :desc
if params[:sort] == 'submitted' if params[:sort] == 'submitted'
@issues = @issues.order(created_at: params[:direction]) @issues = @issues.order(created_at: params[:direction])
else else
@ -58,6 +61,8 @@ class Projects::IssuesController < Projects::BaseController
render 'index' render 'index'
end end
end
end
def pull_requests def pull_requests
params[:kind] = 'pull_requests' params[:kind] = 'pull_requests'

View File

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