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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
67314e95
Commit
67314e95
authored
Oct 14, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support to group labels prioritization on project level
parent
29789201
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
15 deletions
+17
-15
app/controllers/projects/labels_controller.rb
app/controllers/projects/labels_controller.rb
+7
-6
app/models/label.rb
app/models/label.rb
+6
-4
spec/features/projects/labels/update_prioritization_spec.rb
spec/features/projects/labels/update_prioritization_spec.rb
+4
-4
spec/models/label_priority_spec.rb
spec/models/label_priority_spec.rb
+0
-1
No files found.
app/controllers/projects/labels_controller.rb
View file @
67314e95
...
@@ -12,8 +12,8 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -12,8 +12,8 @@ class Projects::LabelsController < Projects::ApplicationController
respond_to
:js
,
:html
respond_to
:js
,
:html
def
index
def
index
@prioritized_labels
=
@available_labels
.
prioritized
@prioritized_labels
=
@available_labels
.
prioritized
(
@project
)
@labels
=
@available_labels
.
unprioritized
.
page
(
params
[
:page
])
@labels
=
@available_labels
.
unprioritized
(
@project
)
.
page
(
params
[
:page
])
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
...
@@ -84,11 +84,10 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -84,11 +84,10 @@ class Projects::LabelsController < Projects::ApplicationController
respond_to
do
|
format
|
respond_to
do
|
format
|
label
=
@available_labels
.
find
(
params
[
:id
])
label
=
@available_labels
.
find
(
params
[
:id
])
if
label
.
update_attribute
(
:priority
,
nil
)
if
label
.
priorities
.
where
(
project_id:
project
).
delete_all
format
.
json
{
render
json:
label
}
format
.
json
{
render
json:
label
}
else
else
message
=
label
.
errors
.
full_messages
.
uniq
.
join
(
'. '
)
format
.
json
{
head
:unprocessable_entity
}
format
.
json
{
render
json:
{
message:
message
},
status: :unprocessable_entity
}
end
end
end
end
end
end
...
@@ -100,7 +99,9 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -100,7 +99,9 @@ class Projects::LabelsController < Projects::ApplicationController
params
[
:label_ids
].
each_with_index
do
|
label_id
,
index
|
params
[
:label_ids
].
each_with_index
do
|
label_id
,
index
|
next
unless
label_ids
.
include?
(
label_id
.
to_i
)
next
unless
label_ids
.
include?
(
label_id
.
to_i
)
Label
.
where
(
id:
label_id
).
update_all
(
priority:
index
)
label_priority
=
LabelPriority
.
find_or_initialize_by
(
project_id:
@project
.
id
,
label_id:
label_id
)
label_priority
.
priority
=
index
label_priority
.
save!
end
end
end
end
...
...
app/models/label.rb
View file @
67314e95
...
@@ -32,12 +32,14 @@ class Label < ActiveRecord::Base
...
@@ -32,12 +32,14 @@ class Label < ActiveRecord::Base
scope
:templates
,
->
{
where
(
template:
true
)
}
scope
:templates
,
->
{
where
(
template:
true
)
}
scope
:with_title
,
->
(
title
)
{
where
(
title:
title
)
}
scope
:with_title
,
->
(
title
)
{
where
(
title:
title
)
}
def
self
.
prioritized
def
self
.
prioritized
(
project
)
where
.
not
(
priority:
nil
).
reorder
(
:priority
,
:title
)
joins
(
:priorities
)
.
where
(
label_priorities:
{
project_id:
project
})
.
reorder
(
'label_priorities.priority ASC, labels.title ASC'
)
end
end
def
self
.
unprioritized
def
self
.
unprioritized
(
project
)
where
(
priority:
nil
)
where
.
not
(
id:
prioritized
(
project
).
select
(
:id
)
)
end
end
alias_attribute
:name
,
:title
alias_attribute
:name
,
:title
...
...
spec/features/projects/labels/update_prioritization_spec.rb
View file @
67314e95
...
@@ -35,7 +35,7 @@ feature 'Prioritize labels', feature: true do
...
@@ -35,7 +35,7 @@ feature 'Prioritize labels', feature: true do
end
end
scenario
'user can unprioritize a group label'
,
js:
true
do
scenario
'user can unprioritize a group label'
,
js:
true
do
feature
.
update
(
priority:
1
)
create
(
:label_priority
,
project:
project
,
label:
feature
,
priority:
1
)
visit
namespace_project_labels_path
(
project
.
namespace
,
project
)
visit
namespace_project_labels_path
(
project
.
namespace
,
project
)
...
@@ -70,7 +70,7 @@ feature 'Prioritize labels', feature: true do
...
@@ -70,7 +70,7 @@ feature 'Prioritize labels', feature: true do
end
end
scenario
'user can unprioritize a project label'
,
js:
true
do
scenario
'user can unprioritize a project label'
,
js:
true
do
bug
.
update
(
priority:
1
)
create
(
:label_priority
,
project:
project
,
label:
bug
,
priority:
1
)
visit
namespace_project_labels_path
(
project
.
namespace
,
project
)
visit
namespace_project_labels_path
(
project
.
namespace
,
project
)
...
@@ -89,8 +89,8 @@ feature 'Prioritize labels', feature: true do
...
@@ -89,8 +89,8 @@ feature 'Prioritize labels', feature: true do
end
end
scenario
'user can sort prioritized labels and persist across reloads'
,
js:
true
do
scenario
'user can sort prioritized labels and persist across reloads'
,
js:
true
do
bug
.
update
(
priority:
1
)
create
(
:label_priority
,
project:
project
,
label:
bug
,
priority:
1
)
feature
.
update
(
priority:
2
)
create
(
:label_priority
,
project:
project
,
label:
feature
,
priority:
2
)
visit
namespace_project_labels_path
(
project
.
namespace
,
project
)
visit
namespace_project_labels_path
(
project
.
namespace
,
project
)
...
...
spec/models/label_priority_spec.rb
View file @
67314e95
...
@@ -9,7 +9,6 @@ describe LabelPriority, models: true do
...
@@ -9,7 +9,6 @@ describe LabelPriority, models: true do
describe
'validations'
do
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_presence_of
(
:label
)
}
it
{
is_expected
.
to
validate_presence_of
(
:label
)
}
it
{
is_expected
.
to
validate_presence_of
(
:priority
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:priority
).
only_integer
.
is_greater_than_or_equal_to
(
0
)
}
it
{
is_expected
.
to
validate_numericality_of
(
:priority
).
only_integer
.
is_greater_than_or_equal_to
(
0
)
}
it
'validates uniqueness of label_id scoped to project_id'
do
it
'validates uniqueness of label_id scoped to project_id'
do
...
...
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