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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
0e2f26dd
Commit
0e2f26dd
authored
May 02, 2016
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prioritize labels functionality
parent
4d4a9b7c
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
146 additions
and
12 deletions
+146
-12
app/assets/javascripts/LabelManager.js.coffee
app/assets/javascripts/LabelManager.js.coffee
+79
-0
app/assets/javascripts/dispatcher.js.coffee
app/assets/javascripts/dispatcher.js.coffee
+2
-0
app/assets/stylesheets/pages/labels.scss
app/assets/stylesheets/pages/labels.scss
+12
-0
app/controllers/projects/labels_controller.rb
app/controllers/projects/labels_controller.rb
+21
-1
app/models/label.rb
app/models/label.rb
+2
-0
app/views/projects/labels/_label.html.haml
app/views/projects/labels/_label.html.haml
+10
-2
app/views/projects/labels/index.html.haml
app/views/projects/labels/index.html.haml
+18
-9
config/routes.rb
config/routes.rb
+2
-0
No files found.
app/assets/javascripts/LabelManager.js.coffee
0 → 100644
View file @
0e2f26dd
class
@
LabelManager
constructor
:
(
opts
=
{})
->
# Defaults
{
@
togglePriorityButton
=
$
(
'.js-toggle-priority'
)
@
prioritizedLabels
=
$
(
'.js-prioritized-labels'
)
@
otherLabels
=
$
(
'.js-other-labels'
)
}
=
opts
@
prioritizedLabels
.
sortable
(
items
:
'li'
update
:
@
onPrioritySortUpdate
.
bind
(
@
)
)
@
bindEvents
()
bindEvents
:
->
@
togglePriorityButton
.
on
'click'
,
@
,
@
onTogglePriorityClick
onTogglePriorityClick
:
(
e
)
->
e
.
preventDefault
()
_this
=
e
.
data
$btn
=
$
(
e
.
currentTarget
)
$label
=
$
(
"#
#{
$btn
.
data
(
'domId'
)
}
"
)
action
=
if
$btn
.
parents
(
'.js-prioritized-labels'
).
length
then
'remove'
else
'add'
_this
.
toggleLabelPriority
(
$label
,
action
)
toggleLabelPriority
:
(
$label
,
action
,
pasive
=
false
)
->
_this
=
@
url
=
$label
.
find
(
'.js-toggle-priority'
).
data
'url'
$target
=
@
prioritizedLabels
$from
=
@
otherLabels
# Optimistic update
if
action
is
'remove'
$target
=
@
otherLabels
$from
=
@
prioritizedLabels
if
$from
.
find
(
'li'
).
length
is
1
$from
.
find
(
'.empty-message'
).
show
()
if
not
$target
.
find
(
'li'
).
length
$target
.
find
(
'.empty-message'
).
hide
()
$label
.
detach
().
appendTo
(
$target
)
# Return if we are not persisting state
return
if
pasive
xhr
=
$
.
post
url
# If request fails, put label back to Other labels group
xhr
.
fail
->
_this
.
toggleLabelPriority
(
$label
,
'remove'
,
true
)
# Show a message
new
Flash
(
'Unable to update label prioritization at this time'
,
'alert'
)
onPrioritySortUpdate
:
->
@
savePrioritySort
()
savePrioritySort
:
->
xhr
=
$
.
post
url
:
@
prioritizedLabels
.
data
(
'url'
)
data
:
label_ids
:
@
getSortedLabelsIds
()
xhr
.
done
->
console
.
log
'done'
xhr
.
fail
->
console
.
log
'fail'
getSortedLabelsIds
:
->
sortedIds
=
[]
@
prioritizedLabels
.
find
(
'li'
).
each
->
sortedIds
.
push
$
(
@
).
data
'id'
sortedIds
\ No newline at end of file
app/assets/javascripts/dispatcher.js.coffee
View file @
0e2f26dd
...
@@ -100,6 +100,8 @@ class Dispatcher
...
@@ -100,6 +100,8 @@ class Dispatcher
shortcut_handler
=
new
ShortcutsNavigation
()
shortcut_handler
=
new
ShortcutsNavigation
()
when
'projects:labels:new'
,
'projects:labels:edit'
when
'projects:labels:new'
,
'projects:labels:edit'
new
Labels
()
new
Labels
()
when
'projects:labels:index'
new
LabelManager
()
when
'projects:network:show'
when
'projects:network:show'
# Ensure we don't create a particular shortcut handler here. This is
# Ensure we don't create a particular shortcut handler here. This is
# already created, where the network graph is created.
# already created, where the network graph is created.
...
...
app/assets/stylesheets/pages/labels.scss
View file @
0e2f26dd
...
@@ -138,3 +138,15 @@
...
@@ -138,3 +138,15 @@
}
}
}
}
}
}
.prioritized-labels
{
.add-priority
{
display
:
none
;
}
}
.other-labels
{
.remove-priority
{
display
:
none
;
}
}
app/controllers/projects/labels_controller.rb
View file @
0e2f26dd
...
@@ -11,7 +11,8 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -11,7 +11,8 @@ class Projects::LabelsController < Projects::ApplicationController
respond_to
:js
,
:html
respond_to
:js
,
:html
def
index
def
index
@labels
=
@project
.
labels
.
page
(
params
[
:page
])
@labels
=
@project
.
labels
.
prioritized
(
false
).
page
(
params
[
:page
])
@prioritized
=
@project
.
labels
.
prioritized
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
...
@@ -71,6 +72,25 @@ class Projects::LabelsController < Projects::ApplicationController
...
@@ -71,6 +72,25 @@ class Projects::LabelsController < Projects::ApplicationController
end
end
end
end
def
toggle_priority
priority
=
label
.
priority
respond_to
do
|
format
|
if
label
.
update_attributes
(
priority:
!
priority
)
format
.
json
{
render
json:
label
}
else
message
=
label
.
errors
.
full_messages
.
uniq
.
join
(
'. '
)
format
.
json
{
render
json:
{
message:
message
},
status: :unprocessable_entity
}
end
end
end
def
set_sorting
respond_to
do
|
format
|
format
.
json
{
render
json:
{
message:
'success'
}}
end
end
protected
protected
def
module_enabled
def
module_enabled
...
...
app/models/label.rb
View file @
0e2f26dd
...
@@ -19,6 +19,7 @@ class Label < ActiveRecord::Base
...
@@ -19,6 +19,7 @@ class Label < ActiveRecord::Base
validates
:color
,
color:
true
,
allow_blank:
false
validates
:color
,
color:
true
,
allow_blank:
false
validates
:project
,
presence:
true
,
unless:
Proc
.
new
{
|
service
|
service
.
template?
}
validates
:project
,
presence:
true
,
unless:
Proc
.
new
{
|
service
|
service
.
template?
}
validates
:priority
,
presence:
false
,
default:
false
# Don't allow '?', '&', and ',' for label titles
# Don't allow '?', '&', and ',' for label titles
validates
:title
,
validates
:title
,
...
@@ -29,6 +30,7 @@ class Label < ActiveRecord::Base
...
@@ -29,6 +30,7 @@ class Label < ActiveRecord::Base
default_scope
{
order
(
title: :asc
)
}
default_scope
{
order
(
title: :asc
)
}
scope
:templates
,
->
{
where
(
template:
true
)
}
scope
:templates
,
->
{
where
(
template:
true
)
}
scope
:prioritized
,
->
(
value
=
true
)
{
where
(
priority:
value
)
}
alias_attribute
:name
,
:title
alias_attribute
:name
,
:title
...
...
app/views/projects/labels/_label.html.haml
View file @
0e2f26dd
%li
{
id:
dom_id
(
label
),
data:
{
id:
label
.
id
}
}
-
label_css_id
=
dom_id
(
label
)
%li
{
id:
label_css_id
,
:"data-id"
=>
label
.
id
}
%a
.js-toggle-priority
{
:href
=>
"#"
,
:"data-url"
=>
toggle_priority_namespace_project_label_path
(
@project
.
namespace
,
@project
,
label
),
:"data-dom-id"
=>
"#{label_css_id}"
}
%span
.add-priority
(+)
%span
.remove-priority
(-)
=
render
"shared/label_row"
,
label:
label
=
render
"shared/label_row"
,
label:
label
.pull-info-right
.pull-info-right
%span
.append-right-20
%span
.append-right-20
...
@@ -24,4 +32,4 @@
...
@@ -24,4 +32,4 @@
-
if
current_user
-
if
current_user
:javascript
:javascript
new
Subscription
(
'
##{
dom_id(label)
} .label-subscription
'
);
new
Subscription
(
'
##{
label_css_id
} .label-subscription
'
);
app/views/projects/labels/index.html.haml
View file @
0e2f26dd
...
@@ -10,8 +10,17 @@
...
@@ -10,8 +10,17 @@
New label
New label
.labels
.labels
.prioritized-labels
%h5
Prioritized Label
%ul
.content-list.manage-labels-list.js-prioritized-labels
{
"data-url"
=>
set_sorting_namespace_project_labels_path
(
@project
.
namespace
,
@project
)
}
-
if
@prioritized
.
present?
=
render
@prioritized
-
else
%p
.empty-message
No prioritized labels yet
.other-labels
%h5
Other Labels
-
if
@labels
.
present?
-
if
@labels
.
present?
%ul
.content-list.manage-labels-list
%ul
.content-list.manage-labels-list.js-other-labels
=
render
@labels
=
render
@labels
=
paginate
@labels
,
theme:
'gitlab'
=
paginate
@labels
,
theme:
'gitlab'
-
else
-
else
...
...
config/routes.rb
View file @
0e2f26dd
...
@@ -719,10 +719,12 @@ Rails.application.routes.draw do
...
@@ -719,10 +719,12 @@ Rails.application.routes.draw do
resources
:labels
,
constraints:
{
id:
/\d+/
}
do
resources
:labels
,
constraints:
{
id:
/\d+/
}
do
collection
do
collection
do
post
:generate
post
:generate
post
:set_sorting
end
end
member
do
member
do
post
:toggle_subscription
post
:toggle_subscription
post
:toggle_priority
end
end
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