From 8f0bf297676dac33ecc8ced10da5ae88f36a9ab0 Mon Sep 17 00:00:00 2001
From: Alfredo Sumaran <alfredo@gitlab.com>
Date: Thu, 2 Jun 2016 14:57:31 -0500
Subject: [PATCH] Add unprioritized scope

---
 app/controllers/projects/labels_controller.rb | 4 ++--
 app/models/label.rb                           | 8 +++++---
 app/views/projects/labels/index.html.haml     | 4 ++--
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb
index bd46a81ff10..13f634fdd0e 100644
--- a/app/controllers/projects/labels_controller.rb
+++ b/app/controllers/projects/labels_controller.rb
@@ -11,8 +11,8 @@ class Projects::LabelsController < Projects::ApplicationController
   respond_to :js, :html
 
   def index
-    @labels = @project.labels.prioritized(false).page(params[:page])
-    @prioritized = @project.labels.prioritized
+    @labels = @project.labels.unprioritized.page(params[:page])
+    @prioritized_labels = @project.labels.prioritized
 
     respond_to do |format|
       format.html
diff --git a/app/models/label.rb b/app/models/label.rb
index 7fd77880558..9e04c5263bd 100644
--- a/app/models/label.rb
+++ b/app/models/label.rb
@@ -32,10 +32,12 @@ class Label < ActiveRecord::Base
 
   scope :templates, ->  { where(template: true) }
 
-  def self.prioritized(bool = true)
-    query = bool ? where.not(priority: nil) : where(priority: nil)
+  def self.prioritized
+     where.not(priority: nil).reorder(Gitlab::Database.nulls_last_order(:priority), :title)
+  end
 
-    query.reorder(Gitlab::Database.nulls_last_order(:priority), :title)
+  def self.unprioritized
+    where(priority: nil).reorder(Gitlab::Database.nulls_last_order(:priority), :title)
   end
 
   alias_attribute :name, :title
diff --git a/app/views/projects/labels/index.html.haml b/app/views/projects/labels/index.html.haml
index 4b2fb04323f..77c42ec356d 100644
--- a/app/views/projects/labels/index.html.haml
+++ b/app/views/projects/labels/index.html.haml
@@ -14,8 +14,8 @@
   .prioritized-labels{ class: hide_class }
     %h5 Prioritized Label
     %ul.content-list.manage-labels-list.js-prioritized-labels{ "data-url" => set_sorting_namespace_project_labels_path(@project.namespace, @project) }
-      - if @prioritized.present?
-        = render @prioritized
+      - if @prioritized_labels.present?
+        = render @prioritized_labels
       - else
         %p.empty-message No prioritized labels yet
   .other-labels
-- 
GitLab