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/controllers/projects/labels_controller.rb
parent074c964913218e99c42f0d8b5855c4ad2ad93267 (diff)
Abstract LabelPriority away into methods on Label model
Diffstat (limited to 'app/controllers/projects/labels_controller.rb')
-rw-r--r--app/controllers/projects/labels_controller.rb14
1 files changed, 6 insertions, 8 deletions
diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb
index f453b70fb5d..42fd09e9b7e 100644
--- a/app/controllers/projects/labels_controller.rb
+++ b/app/controllers/projects/labels_controller.rb
@@ -84,7 +84,7 @@ class Projects::LabelsController < Projects::ApplicationController
respond_to do |format|
label = @available_labels.find(params[:id])
- if label.priorities.where(project_id: project).delete_all
+ if label.unprioritize!(project)
format.json { render json: label }
else
format.json { head :unprocessable_entity }
@@ -94,14 +94,12 @@ class Projects::LabelsController < Projects::ApplicationController
def set_priorities
Label.transaction do
- label_ids = @available_labels.where(id: params[:label_ids]).pluck(:id)
+ available_labels_ids = @available_labels.where(id: params[:label_ids]).pluck(:id)
+ label_ids = params[:label_ids].select { |id| available_labels_ids.include?(id.to_i) }
- params[:label_ids].each_with_index do |label_id, index|
- next unless label_ids.include?(label_id.to_i)
-
- label_priority = LabelPriority.find_or_initialize_by(project_id: @project.id, label_id: label_id)
- label_priority.priority = index
- label_priority.save!
+ label_ids.each_with_index do |label_id, index|
+ label = @available_labels.find(label_id)
+ label.prioritize!(project, index)
end
end