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
Kazuhiko Shiozaki
gitlab-ce
Commits
9bdd7f34
Commit
9bdd7f34
authored
May 21, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add link_to_label helper
parent
2b1b026a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
109 additions
and
11 deletions
+109
-11
app/helpers/labels_helper.rb
app/helpers/labels_helper.rb
+38
-0
app/views/projects/issues/_discussion.html.haml
app/views/projects/issues/_discussion.html.haml
+1
-2
app/views/projects/issues/_issue.html.haml
app/views/projects/issues/_issue.html.haml
+1
-2
app/views/projects/labels/_label.html.haml
app/views/projects/labels/_label.html.haml
+1
-1
app/views/projects/merge_requests/_discussion.html.haml
app/views/projects/merge_requests/_discussion.html.haml
+1
-2
app/views/projects/merge_requests/_merge_request.html.haml
app/views/projects/merge_requests/_merge_request.html.haml
+1
-2
spec/helpers/labels_helper_spec.rb
spec/helpers/labels_helper_spec.rb
+66
-2
No files found.
app/helpers/labels_helper.rb
View file @
9bdd7f34
module
LabelsHelper
module
LabelsHelper
include
ActionView
::
Helpers
::
TagHelper
include
ActionView
::
Helpers
::
TagHelper
# Link to a Label
#
# label - Label object to link to
# project - Project object which will be used as the context for the label's
# link. If omitted, defaults to `@project`, or the label's own
# project.
# block - An optional block that will be passed to `link_to`, forming the
# body of the link element. If omitted, defaults to
# `render_colored_label`.
#
# Examples:
#
# # Allow the generated link to use the label's own project
# link_to_label(label)
#
# # Force the generated link to use @project
# @project = Project.first
# link_to_label(label)
#
# # Force the generated link to use a provided project
# link_to_label(label, project: Project.last)
#
# # Customize link body with a block
# link_to_label(label) { "My Custom Label Text" }
#
# Returns a String
def
link_to_label
(
label
,
project:
nil
,
&
block
)
project
||=
@project
||
label
.
project
link
=
namespace_project_issues_path
(
project
.
namespace
,
project
,
label_name:
label
.
name
)
if
block_given?
link_to
link
,
&
block
else
link_to
render_colored_label
(
label
),
link
end
end
def
project_label_names
def
project_label_names
@project
.
labels
.
pluck
(
:title
)
@project
.
labels
.
pluck
(
:title
)
end
end
...
...
app/views/projects/issues/_discussion.html.haml
View file @
9bdd7f34
...
@@ -30,5 +30,4 @@
...
@@ -30,5 +30,4 @@
%label
Labels
%label
Labels
.issue-show-labels
.issue-show-labels
-
@issue
.
labels
.
each
do
|
label
|
-
@issue
.
labels
.
each
do
|
label
|
=
link_to
namespace_project_issues_path
(
@project
.
namespace
,
@project
,
label_name:
label
.
name
)
do
=
link_to_label
(
label
)
=
render_colored_label
(
label
)
app/views/projects/issues/_issue.html.haml
View file @
9bdd7f34
...
@@ -8,8 +8,7 @@
...
@@ -8,8 +8,7 @@
=
link_to_gfm
issue
.
title
,
issue_path
(
issue
),
class:
"row_title"
=
link_to_gfm
issue
.
title
,
issue_path
(
issue
),
class:
"row_title"
.issue-labels
.issue-labels
-
issue
.
labels
.
each
do
|
label
|
-
issue
.
labels
.
each
do
|
label
|
=
link_to
namespace_project_issues_path
(
issue
.
project
.
namespace
,
issue
.
project
,
label_name:
label
.
name
)
do
=
link_to_label
(
label
,
project:
issue
.
project
)
=
render_colored_label
(
label
)
.pull-right.light
.pull-right.light
-
if
issue
.
closed?
-
if
issue
.
closed?
%span
%span
...
...
app/views/projects/labels/_label.html.haml
View file @
9bdd7f34
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
=
render_colored_label
(
label
)
=
render_colored_label
(
label
)
.pull-right
.pull-right
%strong
.append-right-20
%strong
.append-right-20
=
link_to
namespace_project_issues_path
(
@project
.
namespace
,
@project
,
label_name:
label
.
name
)
do
=
link_to
_label
(
label
)
do
=
pluralize
label
.
open_issues_count
,
'open issue'
=
pluralize
label
.
open_issues_count
,
'open issue'
-
if
can?
current_user
,
:admin_label
,
@project
-
if
can?
current_user
,
:admin_label
,
@project
...
...
app/views/projects/merge_requests/_discussion.html.haml
View file @
9bdd7f34
...
@@ -27,5 +27,4 @@
...
@@ -27,5 +27,4 @@
%label
Labels
%label
Labels
.merge-request-show-labels
.merge-request-show-labels
-
@merge_request
.
labels
.
each
do
|
label
|
-
@merge_request
.
labels
.
each
do
|
label
|
=
link_to
namespace_project_merge_requests_path
(
@project
.
namespace
,
@project
,
label_name:
label
.
name
)
do
=
link_to_label
(
label
)
=
render_colored_label
(
label
)
app/views/projects/merge_requests/_merge_request.html.haml
View file @
9bdd7f34
...
@@ -4,8 +4,7 @@
...
@@ -4,8 +4,7 @@
=
link_to_gfm
merge_request
.
title
,
merge_request_path
(
merge_request
),
class:
"row_title"
=
link_to_gfm
merge_request
.
title
,
merge_request_path
(
merge_request
),
class:
"row_title"
.merge-request-labels
.merge-request-labels
-
merge_request
.
labels
.
each
do
|
label
|
-
merge_request
.
labels
.
each
do
|
label
|
=
link_to
namespace_project_merge_requests_path
(
merge_request
.
project
.
namespace
,
merge_request
.
project
,
label_name:
label
.
name
)
do
=
link_to_label
(
label
,
project:
merge_request
.
project
)
=
render_colored_label
(
label
)
.pull-right.light
.pull-right.light
-
if
merge_request
.
merged?
-
if
merge_request
.
merged?
%span
%span
...
...
spec/helpers/labels_helper_spec.rb
View file @
9bdd7f34
require
'spec_helper'
require
'spec_helper'
describe
LabelsHelper
do
describe
LabelsHelper
do
it
{
expect
(
text_color_for_bg
(
'#EEEEEE'
)).
to
eq
(
'#333333'
)
}
describe
'link_to_label'
do
it
{
expect
(
text_color_for_bg
(
'#222E2E'
)).
to
eq
(
'#FFFFFF'
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:label
)
{
create
(
:label
,
project:
project
)
}
context
'with @project set'
do
before
do
@project
=
project
end
it
'uses the instance variable'
do
expect
(
label
).
not_to
receive
(
:project
)
link_to_label
(
label
)
end
end
context
'without @project set'
do
it
"uses the label's project"
do
expect
(
label
).
to
receive
(
:project
).
and_return
(
project
)
link_to_label
(
label
)
end
end
context
'with a named project argument'
do
it
'uses the provided project'
do
arg
=
double
(
'project'
)
expect
(
arg
).
to
receive
(
:namespace
).
and_return
(
'foo'
)
expect
(
arg
).
to
receive
(
:to_param
).
and_return
(
'foo'
)
link_to_label
(
label
,
project:
arg
)
end
it
'takes precedence over other types'
do
@project
=
project
expect
(
@project
).
not_to
receive
(
:namespace
)
expect
(
label
).
not_to
receive
(
:project
)
arg
=
double
(
'project'
,
namespace:
'foo'
,
to_param:
'foo'
)
link_to_label
(
label
,
project:
arg
)
end
end
context
'with block'
do
it
'passes the block to link_to'
do
link
=
link_to_label
(
label
)
{
'Foo'
}
expect
(
link
).
to
match
(
'Foo'
)
end
end
context
'without block'
do
it
'uses render_colored_label as the link content'
do
expect
(
self
).
to
receive
(
:render_colored_label
).
with
(
label
).
and_return
(
'Foo'
)
expect
(
link_to_label
(
label
)).
to
match
(
'Foo'
)
end
end
end
describe
'text_color_for_bg'
do
it
'uses light text on dark backgrounds'
do
expect
(
text_color_for_bg
(
'#222E2E'
)).
to
eq
(
'#FFFFFF'
)
end
it
'uses dark text on light backgrounds'
do
expect
(
text_color_for_bg
(
'#EEEEEE'
)).
to
eq
(
'#333333'
)
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