[#369] update project pull requests page

This commit is contained in:
Alexander Machehin 2014-11-27 14:42:32 +05:00
parent b57dbb1a90
commit c6c4a9628b
9 changed files with 95 additions and 97 deletions

View File

@ -91,7 +91,6 @@ IssuesController = (dataservice, $http, $location, Issue, $rootScope) ->
vm.filter.status_open = true
setSortClass()
getIssues()
init(dataservice)
true

View File

@ -9,57 +9,59 @@ class Projects::IssuesController < Projects::BaseController
layout false, only: [:update, :search_collaborators]
def index(status = 200)
def index
params[:kind] ||= 'issues'
params[:filter] ||= 'all'
params[:sort] ||= :updated
respond_to do |format|
format.html {}
format.json do
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[:labels] = []
end
@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 )
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])
end
@issues = @issues.includes(:assignee, :user, :pull_request).uniq
.paginate(page: current_page)
end
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[:labels] = []
end
@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 )
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])
end
@issues = @issues.includes(:assignee, :user, :pull_request).uniq
.paginate(page: current_page)
render 'index'
end
def pull_requests
params[:kind] = 'pull_requests'
index
end
def new

View File

@ -95,12 +95,6 @@ class Projects::PullRequestsController < Projects::BaseController
end
end
def index(status = 200)
params[:kind] = 'pull_requests'
params[:filter] ||= 'all'
params[:sort] ||= :updated
end
def autocomplete_to_project
items = []
term = params[:term].to_s.strip.downcase

View File

@ -29,9 +29,9 @@
= link_to t('project_menu.builds'), project_build_lists_path(@project)
- if @project.has_issues
%li{ class: ('active' if contr == :issues) }
%li{ class: ('active' if contr == :issues && act == :index) }
= link_to t('project_menu.tracker', count: @opened_issues_count), project_issues_path(@project)
%li{ class: ('active' if contr == :pull_requests) }
%li{ class: ('active' if contr == :issues && act == :pull_requests) }
=link_to t('project_menu.pull_requests', count: @opened_pull_requests_count), project_pull_requests_path(@project)
- if @project.has_wiki
%li{ class: ('active' if contr == :wiki) }

View File

@ -1,28 +0,0 @@
- render 'submenu'
.container ng-controller = 'IssuesController as issuesCtrl' ng-cloak = true
.row
.col-md-3.col-sm-4.offset20
== render 'projects/issues/index_sidebar', project: @project
.col-md-9.col-sm-8.offset20
tabset.boffset10
tab[ heading = "#{t "layout.issues.statuses.open"} ({{issuesCtrl.filter.opened_count}})"
active = 'issuesCtrl.filter.status_open'
ng-click = "issuesCtrl.setIssuesStatus('open')" ]
tab[ heading = "#{t "layout.issues.statuses.closed"} ({{issuesCtrl.filter.closed_count}})"
active = 'issuesCtrl.filter.status_closed'
ng-click = "issuesCtrl.setIssuesStatus('closed')" ]
.pull-right.boffset10
button.btn.btn-default.roffset5[ type = 'button'
ng-click = "issuesCtrl.setIssuesSort('updated')" ]
span.fa ng-class = "issuesCtrl.updated_class"
=> t('layout.issues.sort.updated')
button.btn.btn-default[ type = 'button'
ng-click = "issuesCtrl.setIssuesSort('submitted')" ]
span.fa ng-class = "issuesCtrl.submitted_class"
=> t('layout.issues.sort.submitted')
== render 'projects/issues/issues_table'
- content_for :additional_scripts do
== render 'projects/issues/init_service.js.erb'

View File

@ -1,9 +1,12 @@
<script>
<% if action_name == 'index' %>
<% if action_name.in?(['index', 'pull_requests']) %>
angular.module('RosaABF').service('IssuesInitializer', function(){
return {
project: '<%= @project.name_with_owner %>',
filter: <%= render('projects/issues/filter.json', params: params).html_safe %>
<% 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 %>
};
});
<% elsif action_name.in?(['new', 'create']) %>
@ -14,11 +17,12 @@
};
});
<% end %>
angular.module('RosaABF').service('LabelsInitializer', function(){
return {
project: '<%= @project.name_with_owner %>',
labels: <%= render('projects/issues/labels.json', project: @project).html_safe %>
};
});
<% if action_name == 'index' %>
angular.module('RosaABF').service('LabelsInitializer', function(){
return {
project: '<%= @project.name_with_owner %>',
labels: <%= render('projects/issues/labels.json', project: @project).html_safe %>
};
});
<% end %>
</script>

View File

@ -1,2 +1,29 @@
- set_meta_tags title: [title_object(@project), t('.title')]
== render 'index'
- set_meta_tags title: [title_object(@project), t("projects.#{params[:kind]}.title")]
- render 'submenu'
.container ng-controller = 'IssuesController as issuesCtrl' ng-cloak = true
.row
.col-md-3.col-sm-4.offset20
== render 'index_sidebar', project: @project
.col-md-9.col-sm-8.offset20
tabset.boffset10
tab[ heading = "#{t "layout.issues.statuses.open"} ({{issuesCtrl.filter.opened_count}})"
active = 'issuesCtrl.filter.status_open'
ng-click = "issuesCtrl.setIssuesStatus('open')" ]
tab[ heading = "#{t "layout.issues.statuses.closed"} ({{issuesCtrl.filter.closed_count}})"
active = 'issuesCtrl.filter.status_closed'
ng-click = "issuesCtrl.setIssuesStatus('closed')" ]
.pull-right.boffset10
button.btn.btn-default.roffset5[ type = 'button'
ng-click = "issuesCtrl.setIssuesSort('updated')" ]
span.fa ng-class = "issuesCtrl.updated_class"
=> t('layout.issues.sort.updated')
button.btn.btn-default[ type = 'button'
ng-click = "issuesCtrl.setIssuesSort('submitted')" ]
span.fa ng-class = "issuesCtrl.submitted_class"
=> t('layout.issues.sort.submitted')
== render 'issues_table'
- content_for :additional_scripts do
== render 'init_service.js.erb'

View File

@ -1,2 +0,0 @@
- set_meta_tags title: [title_object(@project), t('.title')]
== render 'projects/issues/index'

View File

@ -327,6 +327,8 @@ Rosa::Application.routes.draw do
get :search_collaborators
end
end
get 'pull_requests' => 'issues#pull_requests', as: :pull_requests
post "/labels/:label_id" => "issues#destroy_label", as: :issues_delete_label
post "/labels/:label_id/update" => "issues#update_label", as: :issues_update_label
@ -337,7 +339,7 @@ Rosa::Application.routes.draw do
get :find, on: :collection
end
resources :hooks, except: :show
resources :pull_requests, except: :destroy do
resources :pull_requests, except: [:index, :destroy] do
get :autocomplete_to_project, on: :collection
put :merge, on: :member
end