2016-08-02 20:14:50 -04:00
|
|
|
module Boards
|
|
|
|
module Issues
|
2016-10-07 15:46:32 -04:00
|
|
|
class ListService < BaseService
|
2016-08-02 20:14:50 -04:00
|
|
|
def execute
|
2016-08-16 18:47:55 -04:00
|
|
|
issues = IssuesFinder.new(current_user, filter_params).execute
|
2017-06-19 10:56:22 -04:00
|
|
|
issues = without_board_labels(issues) unless movable_list? || closed_list?
|
2017-01-27 13:21:11 -05:00
|
|
|
issues = with_list_label(issues) if movable_list?
|
2017-03-07 11:04:44 -05:00
|
|
|
issues.order_by_position_and_priority
|
2016-08-02 20:14:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-10-05 13:26:28 -04:00
|
|
|
def board
|
|
|
|
@board ||= project.boards.find(params[:board_id])
|
|
|
|
end
|
|
|
|
|
2016-08-02 20:14:50 -04:00
|
|
|
def list
|
2017-01-27 13:21:11 -05:00
|
|
|
return @list if defined?(@list)
|
|
|
|
|
|
|
|
@list = board.lists.find(params[:id]) if params.key?(:id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def movable_list?
|
2017-06-19 10:56:22 -04:00
|
|
|
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-08-02 20:14:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def filter_params
|
|
|
|
set_project
|
|
|
|
set_state
|
|
|
|
|
|
|
|
params
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_project
|
|
|
|
params[:project_id] = project.id
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_state
|
2017-03-24 08:40:35 -04:00
|
|
|
params[:state] = list && list.closed? ? 'closed' : 'opened'
|
2016-08-02 20:14:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def board_label_ids
|
2016-08-16 13:38:43 -04:00
|
|
|
@board_label_ids ||= board.lists.movable.pluck(:label_id)
|
2016-08-02 20:14:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def without_board_labels(issues)
|
|
|
|
return issues unless board_label_ids.any?
|
|
|
|
|
|
|
|
issues.where.not(
|
|
|
|
LabelLink.where("label_links.target_type = 'Issue' AND label_links.target_id = issues.id")
|
|
|
|
.where(label_id: board_label_ids).limit(1).arel.exists
|
|
|
|
)
|
|
|
|
end
|
2016-08-09 15:09:30 -04:00
|
|
|
|
|
|
|
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
|
2016-08-02 20:14:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|