summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-05-07 19:26:41 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-05-07 19:26:41 +0300
commit03441769dfc09776eb8511275a3f492ded1a7c42 (patch)
treebfc6ed0dae6c8e73a43eae071daf7b7753acb9a0
parentbe68cc461755752697642c58154781ae4ec9ab31 (diff)
downloadgitlab-ce-03441769dfc09776eb8511275a3f492ded1a7c42.tar.gz
Include default labels in issues autocomplete etc. Show colored labels on issues show page
-rw-r--r--app/controllers/labels_controller.rb4
-rw-r--r--app/helpers/issues_helper.rb25
-rw-r--r--app/helpers/labels_helper.rb28
-rw-r--r--app/models/project.rb4
-rw-r--r--app/views/issues/show.html.haml2
-rw-r--r--app/views/labels/_label.html.haml18
-rw-r--r--app/views/labels/index.html.haml9
-rw-r--r--lib/gitlab/issues_labels.rb (renamed from lib/gitlab/labels.rb)9
8 files changed, 53 insertions, 46 deletions
diff --git a/app/controllers/labels_controller.rb b/app/controllers/labels_controller.rb
index cb332a45ed2..0e78cecf4d1 100644
--- a/app/controllers/labels_controller.rb
+++ b/app/controllers/labels_controller.rb
@@ -7,11 +7,11 @@ class LabelsController < ProjectResourceController
respond_to :js, :html
def index
- @labels = @project.issues_labels.order('count DESC')
+ @labels = @project.issues_labels
end
def generate
- Gitlab::Labels.generate(@project)
+ Gitlab::IssuesLabels.generate(@project)
redirect_to project_labels_path(@project)
end
diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb
index ab4ffa855d2..6a4d5a30917 100644
--- a/app/helpers/issues_helper.rb
+++ b/app/helpers/issues_helper.rb
@@ -11,10 +11,6 @@ module IssuesHelper
classes
end
- def issue_tags
- @project.issues.tag_counts_on(:labels).map(&:name)
- end
-
# Returns an OpenStruct object suitable for use by <tt>options_from_collection_for_select</tt>
# to allow filtering issues by an unassigned User or Milestone
def unassigned_filter
@@ -32,12 +28,6 @@ module IssuesHelper
}
end
- def labels_autocomplete_source
- labels = @project.issues_labels.order('count DESC')
- labels = labels.map{ |l| { label: l.name, value: l.name } }
- labels.to_json
- end
-
def issues_active_milestones
@project.milestones.active.order("id desc").all
end
@@ -88,19 +78,4 @@ module IssuesHelper
""
end
end
-
- def label_css_class(name)
- case name
- when *warning_labels
- 'label-warning'
- when *neutral_labels
- 'label-inverse'
- when *positive_labels
- 'label-success'
- when *important_labels
- 'label-important'
- else
- 'label-info'
- end
- end
end
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb
new file mode 100644
index 00000000000..950db0377eb
--- /dev/null
+++ b/app/helpers/labels_helper.rb
@@ -0,0 +1,28 @@
+module LabelsHelper
+ def issue_tags
+ @project.issues.tag_counts_on(:labels).map(&:name)
+ end
+
+ def labels_autocomplete_source
+ labels = @project.issues_labels
+ labels = labels.map{ |l| { label: l.name, value: l.name } }
+ labels.to_json
+ end
+
+ def label_css_class(name)
+ klass = Gitlab::IssuesLabels
+
+ case name
+ when *klass.warning_labels
+ 'label-warning'
+ when *klass.neutral_labels
+ 'label-inverse'
+ when *klass.positive_labels
+ 'label-success'
+ when *klass.important_labels
+ 'label-important'
+ else
+ 'label-info'
+ end
+ end
+end
diff --git a/app/models/project.rb b/app/models/project.rb
index 203ccb8e290..f6d5fe4e1df 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -34,7 +34,7 @@ class Project < ActiveRecord::Base
attr_accessible :namespace_id, :creator_id, as: :admin
- acts_as_taggable_on :labels
+ acts_as_taggable_on :labels, :issues_default_labels
attr_accessor :import_url
@@ -204,7 +204,7 @@ class Project < ActiveRecord::Base
end
def issues_labels
- issues.tag_counts_on(:labels)
+ @issues_labels ||= (issues_default_labels + issues.tags_on(:labels)).uniq.sort_by(&:name)
end
def issue_exists?(issue_id)
diff --git a/app/views/issues/show.html.haml b/app/views/issues/show.html.haml
index 67fe89a761b..2e204b8240d 100644
--- a/app/views/issues/show.html.haml
+++ b/app/views/issues/show.html.haml
@@ -47,7 +47,7 @@
.pull-right
- @issue.labels.each do |label|
- %span.label
+ %span{class: "label #{label_css_class(label.name)}"}
%i.icon-tag
= label.name
&nbsp;
diff --git a/app/views/labels/_label.html.haml b/app/views/labels/_label.html.haml
index 027b041d58e..2b1aafc546b 100644
--- a/app/views/labels/_label.html.haml
+++ b/app/views/labels/_label.html.haml
@@ -1,9 +1,15 @@
+- frequency = @project.issues.tagged_with(label.name).count
%li
%strong
- %i.icon-tag
- = label.name
+ %span{class: "label #{label_css_class(label.name)}"}
+ %i.icon-tag
+ - if frequency.zero?
+ %span.light= label.name
+ - else
+ = label.name
.pull-right
- = link_to project_issues_path(label_name: label.name) do
- %strong
- = pluralize(label.count, 'issue')
- = "»"
+ - unless frequency.zero?
+ = link_to project_issues_path(label_name: label.name) do
+ %strong
+ = pluralize(frequency, 'issue')
+ = "»"
diff --git a/app/views/labels/index.html.haml b/app/views/labels/index.html.haml
index 895ba439bdf..53f411d932c 100644
--- a/app/views/labels/index.html.haml
+++ b/app/views/labels/index.html.haml
@@ -4,12 +4,11 @@
Labels
%br
-.light-well
+- if @labels.present?
%ul.bordered-list.labels-table
- @labels.each do |label|
= render 'label', label: label
- - unless @labels.present?
- %li
- %h3.nothing_here_message Add first label to your issues or #{link_to 'generate', generate_project_labels_path(@project), method: :post} default set of labels
-
+- else
+ .light-well
+ %h3.nothing_here_message Add first label to your issues or #{link_to 'generate', generate_project_labels_path(@project), method: :post} default set of labels
diff --git a/lib/gitlab/labels.rb b/lib/gitlab/issues_labels.rb
index f53223ce690..bc49d27b521 100644
--- a/lib/gitlab/labels.rb
+++ b/lib/gitlab/issues_labels.rb
@@ -1,5 +1,5 @@
module Gitlab
- class Labels
+ class IssuesLabels
class << self
def important_labels
%w(bug critical confirmed)
@@ -17,12 +17,11 @@ module Gitlab
%w(feature enhancement)
end
- def self.generate(project)
+ def generate(project)
labels = important_labels + warning_labels + neutral_labels + positive_labels
- labels.each do |label_name|
- # create tag for project
- end
+ project.issues_default_label_list = labels
+ project.save
end
end
end