summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-05-26 15:09:04 +0000
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-05-26 15:09:04 +0000
commitb5ea355078589f5002e3601333130350f1a37678 (patch)
treef8855dbb34819f29c56e8dbc87aae156ea5f058c /app
parentb23025b669d7451cfc8c6b55430a8c701022d7b3 (diff)
parent4e2ee018c372b2973001e58e57e2a9747763f284 (diff)
downloadgitlab-ce-b5ea355078589f5002e3601333130350f1a37678.tar.gz
Merge branch 'rs-link_to_label' into 'master'
Add link_to_label helper The primary purpose of this change was to make the actual labels on `Labels#index` clickable. See merge request !690
Diffstat (limited to 'app')
-rw-r--r--app/helpers/labels_helper.rb38
-rw-r--r--app/views/projects/issues/_discussion.html.haml3
-rw-r--r--app/views/projects/issues/_issue.html.haml3
-rw-r--r--app/views/projects/labels/_label.html.haml4
-rw-r--r--app/views/projects/merge_requests/_discussion.html.haml3
-rw-r--r--app/views/projects/merge_requests/_merge_request.html.haml3
6 files changed, 44 insertions, 10 deletions
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb
index 8272c177d59..8036303851b 100644
--- a/app/helpers/labels_helper.rb
+++ b/app/helpers/labels_helper.rb
@@ -1,6 +1,44 @@
module LabelsHelper
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
@project.labels.pluck(:title)
end
diff --git a/app/views/projects/issues/_discussion.html.haml b/app/views/projects/issues/_discussion.html.haml
index 2016f5c709c..48858fa32da 100644
--- a/app/views/projects/issues/_discussion.html.haml
+++ b/app/views/projects/issues/_discussion.html.haml
@@ -30,5 +30,4 @@
%label Labels
.issue-show-labels
- @issue.labels.each do |label|
- = link_to namespace_project_issues_path(@project.namespace, @project, label_name: label.name) do
- = render_colored_label(label)
+ = link_to_label(label)
diff --git a/app/views/projects/issues/_issue.html.haml b/app/views/projects/issues/_issue.html.haml
index ef36d1f9547..a4e25e5ce88 100644
--- a/app/views/projects/issues/_issue.html.haml
+++ b/app/views/projects/issues/_issue.html.haml
@@ -8,8 +8,7 @@
= link_to_gfm issue.title, issue_path(issue), class: "row_title"
.issue-labels
- issue.labels.each do |label|
- = link_to namespace_project_issues_path(issue.project.namespace, issue.project, label_name: label.name) do
- = render_colored_label(label)
+ = link_to_label(label, project: issue.project)
.pull-right.light
- if issue.closed?
%span
diff --git a/app/views/projects/labels/_label.html.haml b/app/views/projects/labels/_label.html.haml
index 82829452862..7fa1ee53f76 100644
--- a/app/views/projects/labels/_label.html.haml
+++ b/app/views/projects/labels/_label.html.haml
@@ -1,8 +1,8 @@
%li{id: dom_id(label)}
- = render_colored_label(label)
+ = link_to_label(label)
.pull-right
%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'
- if can? current_user, :admin_label, @project
diff --git a/app/views/projects/merge_requests/_discussion.html.haml b/app/views/projects/merge_requests/_discussion.html.haml
index 9a2aa9c3de0..eb3dba6858d 100644
--- a/app/views/projects/merge_requests/_discussion.html.haml
+++ b/app/views/projects/merge_requests/_discussion.html.haml
@@ -27,5 +27,4 @@
%label Labels
.merge-request-show-labels
- @merge_request.labels.each do |label|
- = link_to namespace_project_merge_requests_path(@project.namespace, @project, label_name: label.name) do
- = render_colored_label(label)
+ = link_to_label(label)
diff --git a/app/views/projects/merge_requests/_merge_request.html.haml b/app/views/projects/merge_requests/_merge_request.html.haml
index 5d5a23b5409..073476b0d27 100644
--- a/app/views/projects/merge_requests/_merge_request.html.haml
+++ b/app/views/projects/merge_requests/_merge_request.html.haml
@@ -4,8 +4,7 @@
= link_to_gfm merge_request.title, merge_request_path(merge_request), class: "row_title"
.merge-request-labels
- 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
- = render_colored_label(label)
+ = link_to_label(label, project: merge_request.project)
.pull-right.light
- if merge_request.merged?
%span