Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-07-28 11:36:04 +0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-08-17 18:58:57 +0300
commit35420cec0bf511af662e09cbd8664720c58fa187 (patch)
tree199e6d43084028e4947263d917b086faf2e6ab0b /app/services
parent260f1593bf68a36363b3381f5a1566729f660f0f (diff)
Respect Backlog/Done positions when creating a new list
Diffstat (limited to 'app/services')
-rw-r--r--app/services/boards/lists/create_service.rb22
1 files changed, 19 insertions, 3 deletions
diff --git a/app/services/boards/lists/create_service.rb b/app/services/boards/lists/create_service.rb
index c6b74148ee1..42ab93ad8c4 100644
--- a/app/services/boards/lists/create_service.rb
+++ b/app/services/boards/lists/create_service.rb
@@ -7,15 +7,31 @@ module Boards
end
def execute
- board.lists.create(params.merge(position: position))
+ List.transaction do
+ position = find_next_position
+ increment_higher_lists(position)
+ create_list_at(position)
+ end
end
private
attr_reader :board, :params
- def position
- board.lists.size
+ def find_next_position
+ return 0 unless board.lists.any?
+
+ records = board.lists.where.not(list_type: List.list_types[:done])
+ records.maximum(:position).to_i + 1
+ end
+
+ def create_list_at(position)
+ board.lists.create(params.merge(list_type: :label, position: position))
+ end
+
+ def increment_higher_lists(position)
+ board.lists.where('position >= ?', position)
+ .update_all('position = position + 1')
end
end
end