Add a movable scope and a movable? method to List model
This commit is contained in:
parent
c6511235e4
commit
50ac488c73
9 changed files with 43 additions and 18 deletions
|
@ -19,7 +19,7 @@ module Projects
|
|||
end
|
||||
|
||||
def update
|
||||
list = project.board.lists.find(params[:id])
|
||||
list = project.board.lists.movable.find(params[:id])
|
||||
service = ::Boards::Lists::MoveService.new(project, current_user, move_params)
|
||||
|
||||
if service.execute(list)
|
||||
|
@ -44,7 +44,7 @@ module Projects
|
|||
service = ::Boards::Lists::GenerateService.new(project, current_user)
|
||||
|
||||
if service.execute
|
||||
render json: serialize_as_json(project.board.lists.label)
|
||||
render json: serialize_as_json(project.board.lists.movable)
|
||||
else
|
||||
head :unprocessable_entity
|
||||
end
|
||||
|
|
|
@ -12,11 +12,16 @@ class List < ActiveRecord::Base
|
|||
before_destroy :can_be_destroyed
|
||||
|
||||
scope :destroyable, -> { where(list_type: list_types[:label]) }
|
||||
scope :movable, -> { where(list_type: list_types[:label]) }
|
||||
|
||||
def destroyable?
|
||||
label?
|
||||
end
|
||||
|
||||
def movable?
|
||||
label?
|
||||
end
|
||||
|
||||
def title
|
||||
label? ? label.name : list_type.humanize
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ module Boards
|
|||
class ListService < Boards::BaseService
|
||||
def execute
|
||||
issues = IssuesFinder.new(user, filter_params).execute
|
||||
issues = without_board_labels(issues) unless list.label?
|
||||
issues = with_list_label(issues) if list.label?
|
||||
issues = without_board_labels(issues) unless list.movable?
|
||||
issues = with_list_label(issues) if list.movable?
|
||||
issues
|
||||
end
|
||||
|
||||
|
@ -40,7 +40,7 @@ module Boards
|
|||
end
|
||||
|
||||
def board_label_ids
|
||||
@board_label_ids ||= board.lists.label.pluck(:label_id)
|
||||
@board_label_ids ||= board.lists.movable.pluck(:label_id)
|
||||
end
|
||||
|
||||
def without_board_labels(issues)
|
||||
|
|
|
@ -45,10 +45,10 @@ module Boards
|
|||
|
||||
def remove_label_ids
|
||||
label_ids =
|
||||
if moving_to_list.label?
|
||||
if moving_to_list.movable?
|
||||
moving_from_list.label_id
|
||||
else
|
||||
board.lists.label.pluck(:label_id)
|
||||
board.lists.movable.pluck(:label_id)
|
||||
end
|
||||
|
||||
Array(label_ids).compact
|
||||
|
|
|
@ -10,7 +10,7 @@ module Boards
|
|||
private
|
||||
|
||||
def next_position
|
||||
max_position = board.lists.label.maximum(:position)
|
||||
max_position = board.lists.movable.maximum(:position)
|
||||
max_position.nil? ? 0 : max_position.succ
|
||||
end
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ module Boards
|
|||
private
|
||||
|
||||
def decrement_higher_lists(list)
|
||||
board.lists.label.where('position > ?', list.position)
|
||||
board.lists.movable.where('position > ?', list.position)
|
||||
.update_all('position = position - 1')
|
||||
end
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ module Boards
|
|||
module Lists
|
||||
class GenerateService < Boards::BaseService
|
||||
def execute
|
||||
return false unless board.lists.label.empty?
|
||||
return false unless board.lists.movable.empty?
|
||||
|
||||
List.transaction do
|
||||
label_params.each { |params| create_list(params) }
|
||||
|
|
|
@ -5,7 +5,7 @@ module Boards
|
|||
@old_position = list.position
|
||||
@new_position = params[:position]
|
||||
|
||||
return false unless list.label?
|
||||
return false unless list.movable?
|
||||
return false unless valid_move?
|
||||
|
||||
list.with_lock do
|
||||
|
@ -20,7 +20,7 @@ module Boards
|
|||
|
||||
def valid_move?
|
||||
new_position.present? && new_position != old_position &&
|
||||
new_position >= 0 && new_position < board.lists.label.size
|
||||
new_position >= 0 && new_position < board.lists.movable.size
|
||||
end
|
||||
|
||||
def reorder_intermediate_lists
|
||||
|
@ -32,15 +32,15 @@ module Boards
|
|||
end
|
||||
|
||||
def decrement_intermediate_lists
|
||||
board.lists.label.where('position > ?', old_position)
|
||||
.where('position <= ?', new_position)
|
||||
.update_all('position = position - 1')
|
||||
board.lists.movable.where('position > ?', old_position)
|
||||
.where('position <= ?', new_position)
|
||||
.update_all('position = position - 1')
|
||||
end
|
||||
|
||||
def increment_intermediate_lists
|
||||
board.lists.label.where('position >= ?', new_position)
|
||||
.where('position < ?', old_position)
|
||||
.update_all('position = position + 1')
|
||||
board.lists.movable.where('position >= ?', new_position)
|
||||
.where('position < ?', old_position)
|
||||
.update_all('position = position + 1')
|
||||
end
|
||||
|
||||
def update_list_position(list)
|
||||
|
|
|
@ -74,6 +74,26 @@ describe List do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#movable?' do
|
||||
it 'retruns true when list_type is set to label' do
|
||||
subject.list_type = :label
|
||||
|
||||
expect(subject).to be_movable
|
||||
end
|
||||
|
||||
it 'retruns false when list_type is set to backlog' do
|
||||
subject.list_type = :backlog
|
||||
|
||||
expect(subject).not_to be_movable
|
||||
end
|
||||
|
||||
it 'retruns false when list_type is set to done' do
|
||||
subject.list_type = :done
|
||||
|
||||
expect(subject).not_to be_movable
|
||||
end
|
||||
end
|
||||
|
||||
describe '#title' do
|
||||
it 'returns label name when list_type is set to label' do
|
||||
subject.list_type = :label
|
||||
|
|
Loading…
Reference in a new issue