Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
50ac488c
Commit
50ac488c
authored
Aug 16, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a movable scope and a movable? method to List model
parent
c6511235
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
43 additions
and
18 deletions
+43
-18
app/controllers/projects/boards/lists_controller.rb
app/controllers/projects/boards/lists_controller.rb
+2
-2
app/models/list.rb
app/models/list.rb
+5
-0
app/services/boards/issues/list_service.rb
app/services/boards/issues/list_service.rb
+3
-3
app/services/boards/issues/move_service.rb
app/services/boards/issues/move_service.rb
+2
-2
app/services/boards/lists/create_service.rb
app/services/boards/lists/create_service.rb
+1
-1
app/services/boards/lists/destroy_service.rb
app/services/boards/lists/destroy_service.rb
+1
-1
app/services/boards/lists/generate_service.rb
app/services/boards/lists/generate_service.rb
+1
-1
app/services/boards/lists/move_service.rb
app/services/boards/lists/move_service.rb
+8
-8
spec/models/list_spec.rb
spec/models/list_spec.rb
+20
-0
No files found.
app/controllers/projects/boards/lists_controller.rb
View file @
50ac488c
...
...
@@ -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
...
...
app/models/list.rb
View file @
50ac488c
...
...
@@ -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
...
...
app/services/boards/issues/list_service.rb
View file @
50ac488c
...
...
@@ -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
)
...
...
app/services/boards/issues/move_service.rb
View file @
50ac488c
...
...
@@ -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
...
...
app/services/boards/lists/create_service.rb
View file @
50ac488c
...
...
@@ -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
...
...
app/services/boards/lists/destroy_service.rb
View file @
50ac488c
...
...
@@ -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
...
...
app/services/boards/lists/generate_service.rb
View file @
50ac488c
...
...
@@ -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
)
}
...
...
app/services/boards/lists/move_service.rb
View file @
50ac488c
...
...
@@ -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,13 +32,13 @@ module Boards
end
def
decrement_intermediate_lists
board
.
lists
.
label
.
where
(
'position > ?'
,
old_position
)
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
)
board
.
lists
.
movable
.
where
(
'position >= ?'
,
new_position
)
.
where
(
'position < ?'
,
old_position
)
.
update_all
(
'position = position + 1'
)
end
...
...
spec/models/list_spec.rb
View file @
50ac488c
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment