Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-17 21:34:22 +0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-19 19:58:27 +0300
commit530aae9080942646b130510e970d9d82c009d8e5 (patch)
tree149a06878ac9f335ead5db39af4328413bdc8ab1 /app/models/label.rb
parent074c964913218e99c42f0d8b5855c4ad2ad93267 (diff)
Abstract LabelPriority away into methods on Label model
Diffstat (limited to 'app/models/label.rb')
-rw-r--r--app/models/label.rb16
1 files changed, 15 insertions, 1 deletions
diff --git a/app/models/label.rb b/app/models/label.rb
index 6fd45d251a8..ae07e8f60e1 100644
--- a/app/models/label.rb
+++ b/app/models/label.rb
@@ -97,6 +97,20 @@ class Label < ActiveRecord::Base
merge_requests_count(user, project_id: project.try(:id) || project_id, state: 'opened')
end
+ def prioritize!(project, value)
+ label_priority = priorities.find_or_initialize_by(project_id: project.id)
+ label_priority.priority = value
+ label_priority.save!
+ end
+
+ def unprioritize!(project)
+ priorities.where(project: project).delete_all
+ end
+
+ def priority(project)
+ priorities.find_by(project: project).try(:priority)
+ end
+
def template?
template
end
@@ -135,7 +149,7 @@ class Label < ActiveRecord::Base
def as_json(options = {})
super(options).tap do |json|
- json[:priority] = priorities.find_by(project: options[:project]).try(:priority) if options.has_key?(:project)
+ json[:priority] = priority(options[:project]) if options.has_key?(:project)
end
end