diff options
Diffstat (limited to 'app/models/label.rb')
-rw-r--r-- | app/models/label.rb | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/app/models/label.rb b/app/models/label.rb index 1c3db3eb35d..3237350ff04 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -11,41 +11,41 @@ class Label < ActiveRecord::Base cache_markdown_field :description, pipeline: :single_line - DEFAULT_COLOR = '#428BCA' - NONE = 'no label' + DEFAULT_COLOR = "#428BCA" + NONE = "no label" default_value_for :color, DEFAULT_COLOR has_many :lists, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent - has_many :priorities, class_name: 'LabelPriority' + has_many :priorities, class_name: "LabelPriority" has_many :label_links, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent - has_many :issues, through: :label_links, source: :target, source_type: 'Issue' - has_many :merge_requests, through: :label_links, source: :target, source_type: 'MergeRequest' + has_many :issues, through: :label_links, source: :target, source_type: "Issue" + has_many :merge_requests, through: :label_links, source: :target, source_type: "MergeRequest" before_validation :strip_whitespace_from_title_and_color validates :color, color: true, allow_blank: false # Don't allow ',' for label titles - validates :title, presence: true, format: { with: /\A[^,]+\z/ } - validates :title, uniqueness: { scope: [:group_id, :project_id] } - validates :title, length: { maximum: 255 } + validates :title, presence: true, format: {with: /\A[^,]+\z/} + validates :title, uniqueness: {scope: [:group_id, :project_id]} + validates :title, length: {maximum: 255} default_scope { order(title: :asc) } scope :templates, -> { where(template: true) } scope :with_title, ->(title) { where(title: title) } scope :with_lists_and_board, -> { joins(lists: :board).merge(List.movable) } - scope :on_project_boards, ->(project_id) { with_lists_and_board.where(boards: { project_id: project_id }) } - scope :on_board, ->(board_id) { with_lists_and_board.where(boards: { id: board_id }) } + scope :on_project_boards, ->(project_id) { with_lists_and_board.where(boards: {project_id: project_id}) } + scope :on_board, ->(board_id) { with_lists_and_board.where(boards: {id: board_id}) } scope :order_name_asc, -> { reorder(title: :asc) } scope :order_name_desc, -> { reorder(title: :desc) } - scope :subscribed_by, ->(user_id) { joins(:subscriptions).where(subscriptions: { user_id: user_id, subscribed: true }) } + scope :subscribed_by, ->(user_id) { joins(:subscriptions).where(subscriptions: {user_id: user_id, subscribed: true}) } def self.prioritized(project) joins(:priorities) - .where(label_priorities: { project_id: project }) - .reorder('label_priorities.priority ASC, labels.title ASC') + .where(label_priorities: {project_id: project}) + .reorder("label_priorities.priority ASC, labels.title ASC") end def self.unprioritized(project) @@ -53,8 +53,8 @@ class Label < ActiveRecord::Base priorities = LabelPriority.arel_table label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin) - .on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id))) - .join_sources + .on(labels[:id].eq(priorities[:label_id]).and(priorities[:project_id].eq(project.id))) + .join_sources joins(label_priorities).where(priorities[:priority].eq(nil)) end @@ -64,8 +64,8 @@ class Label < ActiveRecord::Base priorities = LabelPriority.arel_table label_priorities = labels.join(priorities, Arel::Nodes::OuterJoin) - .on(labels[:id].eq(priorities[:label_id])) - .join_sources + .on(labels[:id].eq(priorities[:label_id])) + .join_sources joins(label_priorities) end @@ -81,7 +81,7 @@ class Label < ActiveRecord::Base alias_attribute :name, :title def self.reference_prefix - '~' + "~" end ## @@ -127,19 +127,19 @@ class Label < ActiveRecord::Base end def open_issues_count(user = nil) - issues_count(user, state: 'opened') + issues_count(user, state: "opened") end def closed_issues_count(user = nil) - issues_count(user, state: 'closed') + issues_count(user, state: "closed") end def open_merge_requests_count(user = nil) params = { subject_foreign_key => subject.id, - label_name: title, - scope: 'all', - state: 'opened' + :label_name => title, + :scope => "all", + :state => "opened", } MergeRequestsFinder.new(user, params.with_indifferent_access).execute.count @@ -157,10 +157,10 @@ class Label < ActiveRecord::Base def priority(project) priority = if priorities.loaded? - priorities.first { |p| p.project == project } - else - priorities.find_by(project: project) - end + priorities.first { |p| p.project == project } + else + priorities.find_by(project: project) + end priority.try(:priority) end @@ -178,7 +178,7 @@ class Label < ActiveRecord::Base end def text_color - LabelsHelper.text_color_for_bg(self.color) + LabelsHelper.text_color_for_bg(color) end def title=(value) @@ -212,7 +212,7 @@ class Label < ActiveRecord::Base def as_json(options = {}) super(options).tap do |json| - json[:type] = self.try(:type) + json[:type] = try(:type) json[:priority] = priority(options[:project]) if options.key?(:project) json[:textColor] = text_color end @@ -225,12 +225,12 @@ class Label < ActiveRecord::Base private def issues_count(user, params = {}) - params.merge!(subject_foreign_key => subject.id, label_name: title, scope: 'all') + params.merge!(subject_foreign_key => subject.id, :label_name => title, :scope => "all") IssuesFinder.new(user, params.with_indifferent_access).execute.count end def label_format_reference(format = :id) - raise StandardError, 'Unknown format' unless [:id, :name].include?(format) + raise StandardError, "Unknown format" unless [:id, :name].include?(format) if format == :name && !name.include?('"') %("#{name}") @@ -244,6 +244,6 @@ class Label < ActiveRecord::Base end def strip_whitespace_from_title_and_color - %w(color title).each { |attr| self[attr] = self[attr]&.strip } + %w[color title].each { |attr| self[attr] = self[attr]&.strip } end end |