summaryrefslogtreecommitdiff
path: root/app/controllers/projects/labels_controller.rb
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-14 18:32:44 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-10-19 14:58:27 -0200
commit67314e95ae836365fa1989439a6379aac781a0b4 (patch)
tree7f364243353cbc8ac311fc54119ad64ec41452b0 /app/controllers/projects/labels_controller.rb
parent297892011330ecdd2fa7cbe47fbc6fd4f3b62171 (diff)
downloadgitlab-ce-67314e95ae836365fa1989439a6379aac781a0b4.tar.gz
Add support to group labels prioritization on project level
Diffstat (limited to 'app/controllers/projects/labels_controller.rb')
-rw-r--r--app/controllers/projects/labels_controller.rb13
1 files changed, 7 insertions, 6 deletions
diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb
index f4ad503c9a6..f453b70fb5d 100644
--- a/app/controllers/projects/labels_controller.rb
+++ b/app/controllers/projects/labels_controller.rb
@@ -12,8 +12,8 @@ class Projects::LabelsController < Projects::ApplicationController
respond_to :js, :html
def index
- @prioritized_labels = @available_labels.prioritized
- @labels = @available_labels.unprioritized.page(params[:page])
+ @prioritized_labels = @available_labels.prioritized(@project)
+ @labels = @available_labels.unprioritized(@project).page(params[:page])
respond_to do |format|
format.html
@@ -84,11 +84,10 @@ class Projects::LabelsController < Projects::ApplicationController
respond_to do |format|
label = @available_labels.find(params[:id])
- if label.update_attribute(:priority, nil)
+ if label.priorities.where(project_id: project).delete_all
format.json { render json: label }
else
- message = label.errors.full_messages.uniq.join('. ')
- format.json { render json: { message: message }, status: :unprocessable_entity }
+ format.json { head :unprocessable_entity }
end
end
end
@@ -100,7 +99,9 @@ class Projects::LabelsController < Projects::ApplicationController
params[:label_ids].each_with_index do |label_id, index|
next unless label_ids.include?(label_id.to_i)
- Label.where(id: label_id).update_all(priority: index)
+ label_priority = LabelPriority.find_or_initialize_by(project_id: @project.id, label_id: label_id)
+ label_priority.priority = index
+ label_priority.save!
end
end