summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-07-29 22:19:47 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-07-29 22:19:47 +0300
commitb2a6f4e13632c6f00620cdd7116d7b29d257c738 (patch)
tree08c99cbbe20182cb1bf019550ff56b2899f0f122 /app
parentd79c0ea271f20b148ab433c0d510f90f1b807b74 (diff)
downloadgitlab-ce-b2a6f4e13632c6f00620cdd7116d7b29d257c738.tar.gz
Refactor label rendering and default label set generation
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/labels_controller.rb2
-rw-r--r--app/helpers/labels_helper.rb30
-rw-r--r--app/views/projects/issues/_issue.html.haml4
-rw-r--r--app/views/projects/issues/show.html.haml5
-rw-r--r--app/views/projects/merge_requests/_merge_request.html.haml4
-rw-r--r--app/views/projects/merge_requests/show/_participants.html.haml5
-rw-r--r--app/views/shared/_project_filter.html.haml22
7 files changed, 26 insertions, 46 deletions
diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb
index 30fcb64cbb2..d2c5e90b257 100644
--- a/app/controllers/projects/labels_controller.rb
+++ b/app/controllers/projects/labels_controller.rb
@@ -6,7 +6,7 @@ class Projects::LabelsController < Projects::ApplicationController
respond_to :js, :html
def index
- @labels = @project.issues_labels
+ @labels = @project.labels
end
def generate
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb
index 7d72989cb3b..fce0ed6c5d6 100644
--- a/app/helpers/labels_helper.rb
+++ b/app/helpers/labels_helper.rb
@@ -1,28 +1,20 @@
module LabelsHelper
- def issue_label_names
+ def project_label_names
@project.labels.pluck(:title)
end
- def labels_autocomplete_source
- labels = @project.labels
- labels = labels.map { |l| { label: l.name, value: l.name } }
- labels.to_json
- end
-
- def label_css_class(name)
- klass = Gitlab::IssuesLabels
+ def render_colored_label(label)
+ label_color = label.color || "#428bca"
+ r, g, b = label_color.slice(1,7).scan(/.{2}/).map(&:hex)
- case name.downcase
- when *klass.warning_labels
- 'label-warning'
- when *klass.neutral_labels
- 'label-primary'
- when *klass.positive_labels
- 'label-success'
- when *klass.important_labels
- 'label-danger'
+ if (r + g + b) > 500
+ text_color = "#333"
else
- 'label-info'
+ text_color = "#FFF"
+ end
+
+ content_tag :span, class: 'label', style: "background:#{label_color};color:#{text_color}" do
+ label.name
end
end
end
diff --git a/app/views/projects/issues/_issue.html.haml b/app/views/projects/issues/_issue.html.haml
index 8d447da3ae9..db28b831182 100644
--- a/app/views/projects/issues/_issue.html.haml
+++ b/app/views/projects/issues/_issue.html.haml
@@ -31,9 +31,7 @@
.issue-labels
- issue.labels.each do |label|
- %span{class: "label #{label_css_class(label.name)}"}
- %i.icon-tag
- = label.name
+ = render_colored_label(label)
.issue-actions
- if can? current_user, :modify_issue, issue
diff --git a/app/views/projects/issues/show.html.haml b/app/views/projects/issues/show.html.haml
index 695eb225754..bd5f01ff6a7 100644
--- a/app/views/projects/issues/show.html.haml
+++ b/app/views/projects/issues/show.html.haml
@@ -68,9 +68,6 @@
.issue-show-labels.pull-right
- @issue.labels.each do |label|
- %span{class: "label #{label_css_class(label.name)}"}
- %i.icon-tag
- = label.name
- &nbsp;
+ = render_colored_label(label)
.voting_notes#notes= render "projects/notes/notes_with_form"
diff --git a/app/views/projects/merge_requests/_merge_request.html.haml b/app/views/projects/merge_requests/_merge_request.html.haml
index c9a80ec22ef..7f5de232dcf 100644
--- a/app/views/projects/merge_requests/_merge_request.html.haml
+++ b/app/views/projects/merge_requests/_merge_request.html.haml
@@ -34,6 +34,4 @@
.merge-request-labels
- merge_request.labels.each do |label|
- %span{class: "label #{label_css_class(label.name)}"}
- %i.icon-tag
- = label.name
+ = render_colored_label(label)
diff --git a/app/views/projects/merge_requests/show/_participants.html.haml b/app/views/projects/merge_requests/show/_participants.html.haml
index 0dabd965e52..007c111f7fb 100644
--- a/app/views/projects/merge_requests/show/_participants.html.haml
+++ b/app/views/projects/merge_requests/show/_participants.html.haml
@@ -5,7 +5,4 @@
.merge-request-show-labels.pull-right
- @merge_request.labels.each do |label|
- %span{class: "label #{label_css_class(label.name)}"}
- %i.icon-tag
- = label.name
- &nbsp;
+ = render_colored_label(label)
diff --git a/app/views/shared/_project_filter.html.haml b/app/views/shared/_project_filter.html.haml
index 38cb1208cdc..21d45ebe806 100644
--- a/app/views/shared/_project_filter.html.haml
+++ b/app/views/shared/_project_filter.html.haml
@@ -36,21 +36,19 @@
%fieldset
%legend Labels
%ul.nav.nav-pills.nav-stacked.nav-small.labels-filter
- - issue_label_names.each do |label_name|
- %li{class: label_filter_class(label_name)}
- = link_to labels_filter_path(label_name) do
- %span{class: "label #{label_css_class(label_name)}"}
- %i.icon-tag
- = label_name
- - if selected_label?(label_name)
+ - @project.labels.each do |label|
+ %li{class: label_filter_class(label.name)}
+ = link_to labels_filter_path(label.name) do
+ = render_colored_label(label)
+ - if selected_label?(label.name)
.pull-right
%i.icon-remove
- - if issue_label_names.empty?
- .light-well
- Add first label to your issues
- %br
- or #{link_to 'generate', generate_project_labels_path(@project, redirect: redirect), method: :post} default set of labels
+ - if @project.labels.empty?
+ .light-well
+ Add first label to your issues
+ %br
+ or #{link_to 'generate', generate_project_labels_path(@project, redirect: redirect), method: :post} default set of labels
%fieldset
- if %w(state scope milestone_id assignee_id label_name).select { |k| params[k].present? }.any?