debian-mirror-gitlab/app/services/boards/issues/list_service.rb

77 lines
1.9 KiB
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
module Boards
module Issues
2018-03-17 18:26:18 +05:30
class ListService < Boards::BaseService
2016-09-13 17:45:13 +05:30
def execute
issues = IssuesFinder.new(current_user, filter_params).execute
2017-09-10 17:25:29 +05:30
issues = without_board_labels(issues) unless movable_list? || closed_list?
2017-08-17 22:00:37 +05:30
issues = with_list_label(issues) if movable_list?
issues.order_by_position_and_priority
2016-09-13 17:45:13 +05:30
end
private
2016-11-03 12:29:30 +05:30
def board
2018-03-17 18:26:18 +05:30
@board ||= parent.boards.find(params[:board_id])
2016-11-03 12:29:30 +05:30
end
2016-09-13 17:45:13 +05:30
def list
2017-08-17 22:00:37 +05:30
return @list if defined?(@list)
@list = board.lists.find(params[:id]) if params.key?(:id)
end
def movable_list?
2017-09-10 17:25:29 +05:30
return @movable_list if defined?(@movable_list)
@movable_list = list.present? && list.movable?
end
def closed_list?
return @closed_list if defined?(@closed_list)
@closed_list = list.present? && list.closed?
2016-09-13 17:45:13 +05:30
end
def filter_params
2018-03-17 18:26:18 +05:30
set_parent
2016-09-13 17:45:13 +05:30
set_state
params
end
2018-03-17 18:26:18 +05:30
def set_parent
2018-03-27 19:54:05 +05:30
if parent.is_a?(Group)
params[:group_id] = parent.id
else
params[:project_id] = parent.id
end
2016-09-13 17:45:13 +05:30
end
def set_state
2017-08-17 22:00:37 +05:30
params[:state] = list && list.closed? ? 'closed' : 'opened'
2016-09-13 17:45:13 +05:30
end
def board_label_ids
@board_label_ids ||= board.lists.movable.pluck(:label_id)
end
def without_board_labels(issues)
return issues unless board_label_ids.any?
2018-03-17 18:26:18 +05:30
issues.where.not(issues_label_links.limit(1).arel.exists)
end
def issues_label_links
LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id").where(label_id: board_label_ids)
2016-09-13 17:45:13 +05:30
end
def with_list_label(issues)
issues.where(
LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id")
.where("label_links.label_id = ?", list.label_id).limit(1).arel.exists
)
end
end
end
end