diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb index bd46a81ff106f605f4f93e7c889ea909230c6e9a..13f634fdd0e06eccac92b012a9dd8ec7463230d1 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 7fd778805588c11ca8f172963946f374e19308cf..9e04c5263bd4afc08e7627a25840e8306577e0f7 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 4b2fb04323ff3f81f8ef34a31efcf1288a8053d5..77c42ec356ddf2bb5a48c1df351ed72ab0b35abb 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