diff --git a/app/assets/javascripts/angular-new/issues/issues_controller.js.coffee b/app/assets/javascripts/angular-new/issues/issues_controller.js.coffee index 76830cda7..9d4097b00 100644 --- a/app/assets/javascripts/angular-new/issues/issues_controller.js.coffee +++ b/app/assets/javascripts/angular-new/issues/issues_controller.js.coffee @@ -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 diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index b0d99df32..3b4ab2660 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -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 diff --git a/app/views/projects/issues/_init_service.js.erb b/app/views/projects/issues/_init_service.js.erb index 40bd49a76..b829ac604 100644 --- a/app/views/projects/issues/_init_service.js.erb +++ b/app/views/projects/issues/_init_service.js.erb @@ -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']) %>