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
304851dc
Commit
304851dc
authored
Jan 04, 2018
by
Jarka Kadlecová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor RelativePositioning so that it can be used by other classes
parent
1560c234
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
7 deletions
+17
-7
app/models/concerns/relative_positioning.rb
app/models/concerns/relative_positioning.rb
+11
-7
app/models/issue.rb
app/models/issue.rb
+6
-0
No files found.
app/models/concerns/relative_positioning.rb
View file @
304851dc
...
@@ -10,12 +10,12 @@ module RelativePositioning
...
@@ -10,12 +10,12 @@ module RelativePositioning
after_save
:save_positionable_neighbours
after_save
:save_positionable_neighbours
end
end
def
project_ids
def
min_relative_position
[
project
.
id
]
self
.
class
.
in_parents
(
parent_ids
).
minimum
(
:relative_position
)
end
end
def
max_relative_position
def
max_relative_position
self
.
class
.
in_p
rojects
(
projec
t_ids
).
maximum
(
:relative_position
)
self
.
class
.
in_p
arents
(
paren
t_ids
).
maximum
(
:relative_position
)
end
end
def
prev_relative_position
def
prev_relative_position
...
@@ -23,7 +23,7 @@ module RelativePositioning
...
@@ -23,7 +23,7 @@ module RelativePositioning
if
self
.
relative_position
if
self
.
relative_position
prev_pos
=
self
.
class
prev_pos
=
self
.
class
.
in_p
rojects
(
projec
t_ids
)
.
in_p
arents
(
paren
t_ids
)
.
where
(
'relative_position < ?'
,
self
.
relative_position
)
.
where
(
'relative_position < ?'
,
self
.
relative_position
)
.
maximum
(
:relative_position
)
.
maximum
(
:relative_position
)
end
end
...
@@ -36,7 +36,7 @@ module RelativePositioning
...
@@ -36,7 +36,7 @@ module RelativePositioning
if
self
.
relative_position
if
self
.
relative_position
next_pos
=
self
.
class
next_pos
=
self
.
class
.
in_p
rojects
(
projec
t_ids
)
.
in_p
arents
(
paren
t_ids
)
.
where
(
'relative_position > ?'
,
self
.
relative_position
)
.
where
(
'relative_position > ?'
,
self
.
relative_position
)
.
minimum
(
:relative_position
)
.
minimum
(
:relative_position
)
end
end
...
@@ -63,7 +63,7 @@ module RelativePositioning
...
@@ -63,7 +63,7 @@ module RelativePositioning
pos_after
=
before
.
next_relative_position
pos_after
=
before
.
next_relative_position
if
before
.
shift_after?
if
before
.
shift_after?
issue_to_move
=
self
.
class
.
in_p
rojects
(
projec
t_ids
).
find_by!
(
relative_position:
pos_after
)
issue_to_move
=
self
.
class
.
in_p
arents
(
paren
t_ids
).
find_by!
(
relative_position:
pos_after
)
issue_to_move
.
move_after
issue_to_move
.
move_after
@positionable_neighbours
=
[
issue_to_move
]
# rubocop:disable Gitlab/ModuleWithInstanceVariables
@positionable_neighbours
=
[
issue_to_move
]
# rubocop:disable Gitlab/ModuleWithInstanceVariables
...
@@ -78,7 +78,7 @@ module RelativePositioning
...
@@ -78,7 +78,7 @@ module RelativePositioning
pos_before
=
after
.
prev_relative_position
pos_before
=
after
.
prev_relative_position
if
after
.
shift_before?
if
after
.
shift_before?
issue_to_move
=
self
.
class
.
in_p
rojects
(
projec
t_ids
).
find_by!
(
relative_position:
pos_before
)
issue_to_move
=
self
.
class
.
in_p
arents
(
paren
t_ids
).
find_by!
(
relative_position:
pos_before
)
issue_to_move
.
move_before
issue_to_move
.
move_before
@positionable_neighbours
=
[
issue_to_move
]
# rubocop:disable Gitlab/ModuleWithInstanceVariables
@positionable_neighbours
=
[
issue_to_move
]
# rubocop:disable Gitlab/ModuleWithInstanceVariables
...
@@ -92,6 +92,10 @@ module RelativePositioning
...
@@ -92,6 +92,10 @@ module RelativePositioning
self
.
relative_position
=
position_between
(
max_relative_position
||
START_POSITION
,
MAX_POSITION
)
self
.
relative_position
=
position_between
(
max_relative_position
||
START_POSITION
,
MAX_POSITION
)
end
end
def
move_to_start
self
.
relative_position
=
position_between
(
min_relative_position
||
START_POSITION
,
MIN_POSITION
)
end
# Indicates if there is an issue that should be shifted to free the place
# Indicates if there is an issue that should be shifted to free the place
def
shift_after?
def
shift_after?
next_pos
=
next_relative_position
next_pos
=
next_relative_position
...
...
app/models/issue.rb
View file @
304851dc
...
@@ -35,6 +35,8 @@ class Issue < ActiveRecord::Base
...
@@ -35,6 +35,8 @@ class Issue < ActiveRecord::Base
validates
:project
,
presence:
true
validates
:project
,
presence:
true
alias_attribute
:parent_id
,
:project_id
scope
:in_projects
,
->
(
project_ids
)
{
where
(
project_id:
project_ids
)
}
scope
:in_projects
,
->
(
project_ids
)
{
where
(
project_id:
project_ids
)
}
scope
:assigned
,
->
{
where
(
'EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id)'
)
}
scope
:assigned
,
->
{
where
(
'EXISTS (SELECT TRUE FROM issue_assignees WHERE issue_id = issues.id)'
)
}
...
@@ -78,6 +80,10 @@ class Issue < ActiveRecord::Base
...
@@ -78,6 +80,10 @@ class Issue < ActiveRecord::Base
acts_as_paranoid
acts_as_paranoid
class
<<
self
alias_method
:in_parents
,
:in_projects
end
def
self
.
reference_prefix
def
self
.
reference_prefix
'#'
'#'
end
end
...
...
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