BigW Consortium Gitlab

Commit 3281021e by Dmitriy Zaporozhets

Rewrite issues/mr filtering logic

parent 5b8cc95d
module Issues module Issues
class ListContext < BaseContext class ListContext < BaseContext
include IssuesHelper
attr_accessor :issues attr_accessor :issues
def execute def execute
@issues = case params[:status] @issues = @project.issues
when issues_filter[:all] then @project.issues
when issues_filter[:closed] then @project.issues.closed @issues = case params[:state]
when issues_filter[:to_me] then @project.issues.assigned_to(current_user) when 'all' then @issues
when issues_filter[:by_me] then @project.issues.authored(current_user) when 'closed' then @issues.closed
else @project.issues.opened else @issues.opened
end
@issues = case params[:scope]
when 'assigned-to-me' then @issues.assigned_to(current_user)
when 'created-by-me' then @issues.authored(current_user)
else @issues
end end
@issues = @issues.tagged_with(params[:label_name]) if params[:label_name].present? @issues = @issues.tagged_with(params[:label_name]) if params[:label_name].present?
......
...@@ -2,17 +2,21 @@ ...@@ -2,17 +2,21 @@
# based on filtering passed via params for @project # based on filtering passed via params for @project
class MergeRequestsLoadContext < BaseContext class MergeRequestsLoadContext < BaseContext
def execute def execute
type = params[:status] merge_requests = @project.merge_requests
merge_requests = project.merge_requests merge_requests = case params[:state]
merge_requests = case type
when 'all' then merge_requests when 'all' then merge_requests
when 'closed' then merge_requests.closed when 'closed' then merge_requests.closed
when 'assigned-to-me' then merge_requests.opened.assigned_to(current_user)
else merge_requests.opened else merge_requests.opened
end end
merge_requests = case params[:scope]
when 'assigned-to-me' then merge_requests.assigned_to(current_user)
when 'created-by-me' then merge_requests.authored(current_user)
else merge_requests
end
merge_requests = merge_requests.page(params[:page]).per(20) merge_requests = merge_requests.page(params[:page]).per(20)
merge_requests = merge_requests.includes(:author, :source_project, :target_project).order("created_at desc") merge_requests = merge_requests.includes(:author, :source_project, :target_project).order("created_at desc")
......
...@@ -20,9 +20,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -20,9 +20,7 @@ class Projects::IssuesController < Projects::ApplicationController
@issues = @issues.where("title LIKE ?", "%#{terms}%") if terms.present? @issues = @issues.where("title LIKE ?", "%#{terms}%") if terms.present?
@issues = @issues.page(params[:page]).per(20) @issues = @issues.page(params[:page]).per(20)
assignee_id, milestone_id = params[:assignee_id], params[:milestone_id] assignee_id, milestone_id = params[:assignee_id], params[:milestone_id]
@assignee = @project.team.find(assignee_id) if assignee_id.present? && !assignee_id.to_i.zero? @assignee = @project.team.find(assignee_id) if assignee_id.present? && !assignee_id.to_i.zero?
@milestone = @project.milestones.find(milestone_id) if milestone_id.present? && !milestone_id.to_i.zero? @milestone = @project.milestones.find(milestone_id) if milestone_id.present? && !milestone_id.to_i.zero?
......
...@@ -17,6 +17,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController ...@@ -17,6 +17,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
def index def index
@merge_requests = MergeRequestsLoadContext.new(project, current_user, params).execute @merge_requests = MergeRequestsLoadContext.new(project, current_user, params).execute
assignee_id, milestone_id = params[:assignee_id], params[:milestone_id]
@assignee = @project.team.find(assignee_id) if assignee_id.present? && !assignee_id.to_i.zero?
@milestone = @project.milestones.find(milestone_id) if milestone_id.present? && !milestone_id.to_i.zero?
end end
def show def show
......
module IssuesHelper module IssuesHelper
def project_issues_filter_path project, params = {}
params[:f] ||= cookies['issue_filter']
project_issues_path project, params
end
def issue_css_classes issue def issue_css_classes issue
classes = "issue" classes = "issue"
classes << " closed" if issue.closed? classes << " closed" if issue.closed?
...@@ -18,25 +13,11 @@ module IssuesHelper ...@@ -18,25 +13,11 @@ module IssuesHelper
OpenStruct.new(id: 0, title: 'None (backlog)', name: 'Unassigned') OpenStruct.new(id: 0, title: 'None (backlog)', name: 'Unassigned')
end end
def issues_filter
{
all: "all",
closed: "closed",
to_me: "assigned-to-me",
by_me: "created-by-me",
open: "open"
}
end
def issues_active_milestones
@project.milestones.active.order("id desc").all
end
def url_for_project_issues def url_for_project_issues
return "" if @project.nil? return "" if @project.nil?
if @project.used_default_issues_tracker? if @project.used_default_issues_tracker?
project_issues_filter_path(@project) project_issues_path(@project)
else else
url = Gitlab.config.issues_tracker[@project.issues_tracker]["project_url"] url = Gitlab.config.issues_tracker[@project.issues_tracker]["project_url"]
url.gsub(':project_id', @project.id.to_s) url.gsub(':project_id', @project.id.to_s)
...@@ -78,15 +59,4 @@ module IssuesHelper ...@@ -78,15 +59,4 @@ module IssuesHelper
"" ""
end end
end end
def project_issues_with_filter_path(project, opts)
default_opts = {
status: params[:status],
label_name: params[:label_name],
milestone_id: params[:milestone_id],
assignee_id: params[:assignee_id],
}
project_issues_path(@project, default_opts.merge(opts))
end
end end
...@@ -61,6 +61,25 @@ module ProjectsHelper ...@@ -61,6 +61,25 @@ module ProjectsHelper
project_nav_tabs.include? name project_nav_tabs.include? name
end end
def project_filter_path(options={})
exist_opts = {
state: params[:state],
scope: params[:scope],
label_name: params[:label_name],
milestone_id: params[:milestone_id],
}
options = exist_opts.merge(options)
path = request.path
path << "?#{options.to_param}"
path
end
def project_active_milestones
@project.milestones.active.order("id desc").all
end
private private
def get_project_nav_tabs(project, current_user) def get_project_nav_tabs(project, current_user)
......
...@@ -17,6 +17,7 @@ module Issuable ...@@ -17,6 +17,7 @@ module Issuable
validates :author, presence: true validates :author, presence: true
validates :title, presence: true, length: { within: 0..255 } validates :title, presence: true, length: { within: 0..255 }
scope :authored, ->(user) { where(author_id: user) }
scope :assigned_to, ->(u) { where(assignee_id: u.id)} scope :assigned_to, ->(u) { where(assignee_id: u.id)}
scope :recent, -> { order("created_at DESC") } scope :recent, -> { order("created_at DESC") }
scope :assigned, -> { where("assignee_id IS NOT NULL") } scope :assigned, -> { where("assignee_id IS NOT NULL") }
......
...@@ -35,7 +35,6 @@ class Issue < ActiveRecord::Base ...@@ -35,7 +35,6 @@ class Issue < ActiveRecord::Base
acts_as_taggable_on :labels acts_as_taggable_on :labels
scope :cared, ->(user) { where(assignee_id: user) } scope :cared, ->(user) { where(assignee_id: user) }
scope :authored, ->(user) { where(author_id: user) }
scope :open_for, ->(user) { opened.assigned_to(user) } scope :open_for, ->(user) { opened.assigned_to(user) }
state_machine :state, initial: :opened do state_machine :state, initial: :opened do
......
= form_tag project_issues_path(@project), method: 'get' do = form_tag project_issues_path(@project), method: 'get' do
%fieldset %fieldset
%ul.nav.nav-pills.nav-stacked %ul.nav.nav-pills.nav-stacked
%li{class: ("active" if !params[:status] || params[:status].blank?)} %li{class: ("active" if params[:scope].blank?)}
= link_to project_issues_path(@project, status: nil) do = link_to project_filter_path(scope: nil) do
Open Everyone's
%li{class: ("active" if params[:status] == 'assigned-to-me')} %li{class: ("active" if params[:scope] == 'assigned-to-me')}
= link_to project_issues_path(@project, status: 'assigned-to-me') do = link_to project_filter_path(scope: 'assigned-to-me') do
Assigned to me Assigned to me
%li{class: ("active" if params[:status] == 'created-by-me')} %li{class: ("active" if params[:scope] == 'created-by-me')}
= link_to project_issues_path(@project, status: 'created-by-me') do = link_to project_filter_path(scope: 'created-by-me') do
Created by me Created by me
%li{class: ("active" if params[:status] == 'closed')}
= link_to project_issues_path(@project, status: 'closed') do %ul.nav.nav-pills.nav-stacked
%li{class: ("active" if params[:state].blank?)}
= link_to project_filter_path(state: nil) do
Open
%li{class: ("active" if params[:state] == 'closed')}
= link_to project_filter_path(state: 'closed') do
Closed Closed
%li{class: ("active" if params[:status] == 'all')} %li{class: ("active" if params[:state] == 'all')}
= link_to project_issues_path(@project, status: 'all') do = link_to project_filter_path(state: 'all') do
All All
%fieldset %fieldset
- if %w(status milestone_id assignee_id label_name).select { |k| params[k].present? }.any? - if %w(state scope milestone_id assignee_id label_name).select { |k| params[k].present? }.any?
= link_to project_issues_path(@project), class: 'cgray pull-right' do = link_to project_issues_path(@project), class: 'cgray pull-right' do
%i.icon-remove %i.icon-remove
Clear filter Clear filter
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
%span Update selected issues with &nbsp; %span Update selected issues with &nbsp;
= select_tag('update[status]', options_for_select(['open', 'closed']), prompt: "Status") = select_tag('update[status]', options_for_select(['open', 'closed']), prompt: "Status")
= select_tag('update[assignee_id]', options_from_collection_for_select(@project.team.members, "id", "name", params[:assignee_id]), prompt: "Assignee") = select_tag('update[assignee_id]', options_from_collection_for_select(@project.team.members, "id", "name", params[:assignee_id]), prompt: "Assignee")
= select_tag('update[milestone_id]', options_from_collection_for_select(issues_active_milestones, "id", "title", params[:milestone_id]), prompt: "Milestone") = select_tag('update[milestone_id]', options_from_collection_for_select(project_active_milestones, "id", "title", params[:milestone_id]), prompt: "Milestone")
= hidden_field_tag 'update[issues_ids]', [] = hidden_field_tag 'update[issues_ids]', []
= hidden_field_tag :status, params[:status] = hidden_field_tag :status, params[:status]
= button_tag "Save", class: "btn update_selected_issues btn-small btn-save" = button_tag "Save", class: "btn update_selected_issues btn-small btn-save"
...@@ -24,11 +24,11 @@ ...@@ -24,11 +24,11 @@
%b.caret %b.caret
%ul.dropdown-menu %ul.dropdown-menu
%li %li
= link_to project_issues_with_filter_path(@project, label_name: nil) do = link_to project_filter_path(label_name: nil) do
Any Any
- issue_label_names.each do |label_name| - issue_label_names.each do |label_name|
%li %li
= link_to project_issues_with_filter_path(@project, label_name: label_name) do = link_to project_filter_path(label_name: label_name) do
%span{class: "label #{label_css_class(label_name)}"} %span{class: "label #{label_css_class(label_name)}"}
%i.icon-tag %i.icon-tag
= label_name = label_name
...@@ -45,13 +45,13 @@ ...@@ -45,13 +45,13 @@
%b.caret %b.caret
%ul.dropdown-menu %ul.dropdown-menu
%li %li
= link_to project_issues_with_filter_path(@project, assignee_id: nil) do = link_to project_filter_path(assignee_id: nil) do
Any Any
= link_to project_issues_with_filter_path(@project, assignee_id: 0) do = link_to project_filter_path(assignee_id: 0) do
Unassigned Unassigned
- @project.team.members.sort_by(&:name).each do |user| - @project.team.members.sort_by(&:name).each do |user|
%li %li
= link_to project_issues_with_filter_path(@project, assignee_id: user.id) do = link_to project_filter_path(assignee_id: user.id) do
= image_tag gravatar_icon(user.email), class: "avatar s16", alt: '' = image_tag gravatar_icon(user.email), class: "avatar s16", alt: ''
= user.name = user.name
...@@ -68,13 +68,13 @@ ...@@ -68,13 +68,13 @@
%b.caret %b.caret
%ul.dropdown-menu %ul.dropdown-menu
%li %li
= link_to project_issues_with_filter_path(@project, milestone_id: nil) do = link_to project_filter_path(milestone_id: nil) do
Any Any
= link_to project_issues_with_filter_path(@project, milestone_id: 0) do = link_to project_filter_path(milestone_id: 0) do
None (backlog) None (backlog)
- issues_active_milestones.each do |milestone| - project_active_milestones.each do |milestone|
%li %li
= link_to project_issues_with_filter_path(@project, milestone_id: milestone.id) do = link_to project_filter_path(milestone_id: milestone.id) do
%strong= milestone.title %strong= milestone.title
%small.light= milestone.expires_at %small.light= milestone.expires_at
......
...@@ -18,6 +18,6 @@ ...@@ -18,6 +18,6 @@
.row .row
.span3 .span3
= render 'filter', entity: 'issue' = render 'shared/project_filter', project_entities_path: project_issues_path(@project)
.span9.issues-holder .span9.issues-holder
= render "issues" = render "issues"
...@@ -8,15 +8,57 @@ ...@@ -8,15 +8,57 @@
.row .row
.span3 .span3
= render 'filter' = render 'shared/project_filter', project_entities_path: project_merge_requests_path(@project)
.span9 .span9
.ui-box .ui-box
.title .title
= form_tag project_merge_requests_path(@project), id: "merge_requests_search_form", method: :get, class: :left do .mr-filters
= select_tag(:assignee_id, options_from_collection_for_select([unassigned_filter] + @project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee") %span Filter by
= select_tag(:milestone_id, options_from_collection_for_select([unassigned_filter] + @project.milestones.order("id desc").all, "id", "title", params[:milestone_id]), prompt: "Milestone") .dropdown.inline.prepend-left-10
= hidden_field_tag :f, params[:f] %a.dropdown-toggle.btn.btn-small{href: '#', "data-toggle" => "dropdown"}
.clearfix %i.icon-user
%span.light assignee:
- if @assignee.present?
%strong= @assignee.name
- elsif params[:assignee_id] == "0"
Unassigned
- else
Any
%b.caret
%ul.dropdown-menu
%li
= link_to project_filter_path(assignee_id: nil) do
Any
= link_to project_filter_path(assignee_id: 0) do
Unassigned
- @project.team.members.sort_by(&:name).each do |user|
%li
= link_to project_filter_path(assignee_id: user.id) do
= image_tag gravatar_icon(user.email), class: "avatar s16", alt: ''
= user.name
.dropdown.inline.prepend-left-10
%a.dropdown-toggle.btn.btn-small{href: '#', "data-toggle" => "dropdown"}
%i.icon-time
%span.light milestone:
- if @milestone.present?
%strong= @milestone.title
- elsif params[:milestone_id] == "0"
None (backlog)
- else
Any
%b.caret
%ul.dropdown-menu
%li
= link_to project_filter_path(milestone_id: nil) do
Any
= link_to project_filter_path(milestone_id: 0) do
None (backlog)
- project_active_milestones.each do |milestone|
%li
= link_to project_filter_path(milestone_id: milestone.id) do
%strong= milestone.title
%small.light= milestone.expires_at
%ul.well-list.mr-list %ul.well-list.mr-list
= render @merge_requests = render @merge_requests
......
...@@ -25,5 +25,5 @@ ...@@ -25,5 +25,5 @@
- if params[:status].present? || params[:project_id].present? - if params[:status].present? || params[:project_id].present?
= link_to filter_path(entity, status: nil, project_id: nil), class: 'pull-right cgray' do = link_to filter_path(entity, status: nil, project_id: nil), class: 'pull-right cgray' do
%i.icon-remove %i.icon-remove
Clear filter %strong Clear filter
= form_tag project_entities_path, method: 'get' do
%fieldset
%ul.nav.nav-pills.nav-stacked
%li{class: ("active" if params[:scope].blank?)}
= link_to project_filter_path(scope: nil) do
Everyone's
%li{class: ("active" if params[:scope] == 'assigned-to-me')}
= link_to project_filter_path(scope: 'assigned-to-me') do
Assigned to me
%li{class: ("active" if params[:scope] == 'created-by-me')}
= link_to project_filter_path(scope: 'created-by-me') do
Created by me
%ul.nav.nav-pills.nav-stacked
%li{class: ("active" if params[:state].blank?)}
= link_to project_filter_path(state: nil) do
Open
%li{class: ("active" if params[:state] == 'closed')}
= link_to project_filter_path(state: 'closed') do
Closed
%li{class: ("active" if params[:state] == 'all')}
= link_to project_filter_path(state: 'all') do
All
%fieldset
- if %w(state scope milestone_id assignee_id label_name).select { |k| params[k].present? }.any?
= link_to project_entities_path, class: 'cgray pull-right' do
%i.icon-remove
%strong Clear filter
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment