diff options
author | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-02-06 21:08:44 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-02-06 21:08:44 +0300 |
commit | dd8dd92e501b7e980e913e7fa3a3efa5824d21fe (patch) | |
tree | 9494c3abe46aff03ad657f7f32ca147845d25232 /app | |
parent | 6b61c9049815cdcc2b22a572441adba0e3dc230d (diff) | |
parent | ce0811ae5cf2c69ccf24e101b1ec1554a42e9856 (diff) |
Merge branch 'api-default-order' into 'master'
Sorting refactoring
* refactor sorting logic for web UI
* refactor and document ordering for API: project, issues, merge requests
* explicitly define ordering in models using default_scope
See merge request !1476
Diffstat (limited to 'app')
39 files changed, 261 insertions, 113 deletions
diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index be19139c9b1..c491e5c7550 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -1,7 +1,7 @@ class Admin::DashboardController < Admin::ApplicationController def index - @projects = Project.order("created_at DESC").limit(10) - @users = User.order("created_at DESC").limit(10) - @groups = Group.order("created_at DESC").limit(10) + @projects = Project.limit(10) + @users = User.limit(10) + @groups = Group.limit(10) end end diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 8c7d90a5d9f..65dc027c8eb 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -2,7 +2,8 @@ class Admin::GroupsController < Admin::ApplicationController before_filter :group, only: [:edit, :show, :update, :destroy, :project_update, :project_teams_update] def index - @groups = Group.order('name ASC') + @groups = Group.all + @groups = @groups.sort(@sort = params[:sort]) @groups = @groups.search(params[:name]) if params[:name].present? @groups = @groups.page(params[:page]).per(20) end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index aea8545d38e..e5d15528d78 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -2,16 +2,16 @@ class Admin::UsersController < Admin::ApplicationController before_filter :user, only: [:show, :edit, :update, :destroy] def index - @users = User.filter(params[:filter]) + @users = User.order_name_asc.filter(params[:filter]) @users = @users.search(params[:name]) if params[:name].present? @users = @users.sort(@sort = params[:sort]) - @users = @users.alphabetically.page(params[:page]) + @users = @users.page(params[:page]) end def show @personal_projects = user.personal_projects @joined_projects = user.projects.joined(@user) - @keys = user.keys.order('id DESC') + @keys = user.keys end def new diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 36e13706768..6553027b430 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -254,7 +254,7 @@ class ApplicationController < ActionController::Base end def set_filters_params - params[:sort] ||= 'newest' + params[:sort] ||= 'created_desc' params[:scope] = 'all' if params[:scope].blank? params[:state] = 'opened' if params[:state].blank? @@ -280,7 +280,7 @@ class ApplicationController < ActionController::Base author_id = @filter_params[:author_id] milestone_id = @filter_params[:milestone_id] - @sort = @filter_params[:sort].try(:humanize) + @sort = @filter_params[:sort] @assignees = User.where(id: collection.pluck(:assignee_id)) @authors = User.where(id: collection.pluck(:author_id)) @milestones = Milestone.where(id: collection.pluck(:milestone_id)) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index cd876024ba3..9e59264e418 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -9,7 +9,7 @@ class DashboardController < ApplicationController # If user needs more - point to Dashboard#projects page @projects_limit = 30 - @groups = current_user.authorized_groups.sort_by(&:human_name) + @groups = current_user.authorized_groups.order_name_asc @has_authorized_projects = @projects.count > 0 @projects_count = @projects.count @projects = @projects.limit(@projects_limit) diff --git a/app/controllers/profiles/keys_controller.rb b/app/controllers/profiles/keys_controller.rb index 88414b13564..4e2bd0a9b4b 100644 --- a/app/controllers/profiles/keys_controller.rb +++ b/app/controllers/profiles/keys_controller.rb @@ -3,7 +3,7 @@ class Profiles::KeysController < ApplicationController skip_before_filter :authenticate_user!, only: [:get_keys] def index - @keys = current_user.keys.order('id DESC') + @keys = current_user.keys end def show diff --git a/app/controllers/projects/commits_controller.rb b/app/controllers/projects/commits_controller.rb index 0a85c36a758..b133afe44b5 100644 --- a/app/controllers/projects/commits_controller.rb +++ b/app/controllers/projects/commits_controller.rb @@ -13,7 +13,7 @@ class Projects::CommitsController < Projects::ApplicationController @commits = @repo.commits(@ref, @path, @limit, @offset) @note_counts = Note.where(commit_id: @commits.map(&:id)). - group(:commit_id).count + group(:commit_id).count respond_to do |format| format.html diff --git a/app/controllers/projects/labels_controller.rb b/app/controllers/projects/labels_controller.rb index 6c7bde9c5d5..b61fef3b627 100644 --- a/app/controllers/projects/labels_controller.rb +++ b/app/controllers/projects/labels_controller.rb @@ -7,7 +7,7 @@ class Projects::LabelsController < Projects::ApplicationController respond_to :js, :html def index - @labels = @project.labels.order_by_name.page(params[:page]).per(20) + @labels = @project.labels.page(params[:page]).per(20) end def new diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 912f9eb5b6b..01be318ede2 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -23,7 +23,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController def show @note_counts = Note.where(commit_id: @merge_request.commits.map(&:id)). - group(:commit_id).count + group(:commit_id).count respond_to do |format| format.html diff --git a/app/finders/notes_finder.rb b/app/finders/notes_finder.rb index 6fe15b41060..e2bd0a2560e 100644 --- a/app/finders/notes_finder.rb +++ b/app/finders/notes_finder.rb @@ -22,6 +22,7 @@ class NotesFinder end # Use overlapping intervals to avoid worrying about race conditions - notes.where('updated_at > ?', last_fetched_at - FETCH_OVERLAP) + notes.where('updated_at > ?', last_fetched_at - FETCH_OVERLAP). + order(created_at: :asc, id: :asc) end end diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb index 492e065b713..bb12d43f397 100644 --- a/app/helpers/sorting_helper.rb +++ b/app/helpers/sorting_helper.rb @@ -1,4 +1,19 @@ module SortingHelper + def sort_options_hash + { + sort_value_name => sort_title_name, + sort_value_recently_updated => sort_title_recently_updated, + sort_value_oldest_updated => sort_title_oldest_updated, + sort_value_recently_created => sort_title_recently_created, + sort_value_oldest_created => sort_title_oldest_created, + sort_value_milestone_soon => sort_title_milestone_soon, + sort_value_milestone_later => sort_title_milestone_later, + sort_value_largest_repo => sort_title_largest_repo, + sort_value_recently_signin => sort_title_recently_signin, + sort_value_oldest_signin => sort_title_oldest_signin, + } + end + def sort_title_oldest_updated 'Oldest updated' end @@ -14,4 +29,68 @@ module SortingHelper def sort_title_recently_created 'Recently created' end + + def sort_title_milestone_soon + 'Milestone due soon' + end + + def sort_title_milestone_later + 'Milestone due later' + end + + def sort_title_name + 'Name' + end + + def sort_title_largest_repo + 'Largest repository' + end + + def sort_title_recently_signin + 'Recent sign in' + end + + def sort_title_oldest_signin + 'Oldest sign in' + end + + def sort_value_oldest_updated + 'updated_asc' + end + + def sort_value_recently_updated + 'updated_desc' + end + + def sort_value_oldest_created + 'created_asc' + end + + def sort_value_recently_created + 'created_desc' + end + + def sort_value_milestone_soon + 'milestone_due_asc' + end + + def sort_value_milestone_later + 'milestone_due_desc' + end + + def sort_value_name + 'name_asc' + end + + def sort_value_largest_repo + 'repository_size_desc' + end + + def sort_value_recently_signin + 'recent_sign_in' + end + + def sort_value_oldest_signin + 'oldest_sign_in' + end end diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb index 4d0c04bcc3d..05f5e979695 100644 --- a/app/models/broadcast_message.rb +++ b/app/models/broadcast_message.rb @@ -14,6 +14,8 @@ # class BroadcastMessage < ActiveRecord::Base + include Sortable + validates :message, presence: true validates :starts_at, presence: true validates :ends_at, presence: true diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index fb038a3cc3f..f5e23e9dc2d 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -29,6 +29,8 @@ module Issuable scope :only_opened, -> { with_state(:opened) } scope :only_reopened, -> { with_state(:reopened) } scope :closed, -> { with_state(:closed) } + scope :order_milestone_due_desc, -> { joins(:milestone).reorder('milestones.due_date DESC, milestones.id DESC') } + scope :order_milestone_due_asc, -> { joins(:milestone).reorder('milestones.due_date ASC, milestones.id ASC') } delegate :name, :email, @@ -55,13 +57,10 @@ module Issuable def sort(method) case method.to_s - when 'newest' then reorder("#{table_name}.created_at DESC") - when 'oldest' then reorder("#{table_name}.created_at ASC") - when 'recently_updated' then reorder("#{table_name}.updated_at DESC") - when 'last_updated' then reorder("#{table_name}.updated_at ASC") - when 'milestone_due_soon' then joins(:milestone).reorder("milestones.due_date ASC") - when 'milestone_due_later' then joins(:milestone).reorder("milestones.due_date DESC") - else reorder("#{table_name}.created_at DESC") + when 'milestone_due_asc' then order_milestone_due_asc + when 'milestone_due_desc' then order_milestone_due_desc + else + order_by(method) end end end diff --git a/app/models/concerns/sortable.rb b/app/models/concerns/sortable.rb new file mode 100644 index 00000000000..cca1ee08fe8 --- /dev/null +++ b/app/models/concerns/sortable.rb @@ -0,0 +1,38 @@ +# == Sortable concern +# +# Set default scope for ordering objects +# +module Sortable + extend ActiveSupport::Concern + + included do + # By default all models should be ordered + # by created_at field starting from newest + default_scope { order(created_at: :desc, id: :desc) } + + scope :order_created_desc, -> { reorder(created_at: :desc, id: :desc) } + scope :order_created_asc, -> { reorder(created_at: :asc, id: :asc) } + scope :order_updated_desc, -> { reorder(updated_at: :desc, id: :desc) } + scope :order_updated_asc, -> { reorder(updated_at: :asc, id: :asc) } + + if column_names.include?('name') + scope :order_name_asc, -> { reorder(name: :asc) } + scope :order_name_desc, -> { reorder(name: :desc) } + end + end + + module ClassMethods + def order_by(method) + case method.to_s + when 'name_asc' then order_name_asc + when 'name_desc' then order_name_desc + when 'updated_asc' then order_updated_asc + when 'updated_desc' then order_updated_desc + when 'created_asc' then order_created_asc + when 'created_desc' then order_created_desc + else + all + end + end + end +end diff --git a/app/models/email.rb b/app/models/email.rb index 57f476bd519..556b0e9586e 100644 --- a/app/models/email.rb +++ b/app/models/email.rb @@ -10,6 +10,8 @@ # class Email < ActiveRecord::Base + include Sortable + belongs_to :user validates :user_id, presence: true diff --git a/app/models/event.rb b/app/models/event.rb index 2a6c690ab91..9a42d380f87 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -15,6 +15,7 @@ # class Event < ActiveRecord::Base + include Sortable default_scope { where.not(author_id: nil) } CREATED = 1 diff --git a/app/models/group.rb b/app/models/group.rb index 042b79a7850..d6ec0be6081 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -28,6 +28,16 @@ class Group < Namespace after_create :post_create_hook after_destroy :post_destroy_hook + class << self + def search(query) + where("LOWER(namespaces.name) LIKE :query or LOWER(namespaces.path) LIKE :query", query: "%#{query.downcase}%") + end + + def sort(method) + order_by(method) + end + end + def human_name name end @@ -88,20 +98,4 @@ class Group < Namespace def system_hook_service SystemHooksService.new end - - class << self - def search(query) - where("LOWER(namespaces.name) LIKE :query or LOWER(namespaces.path) LIKE :query", query: "%#{query.downcase}%") - end - - def sort(method) - case method.to_s - when "newest" then reorder("namespaces.created_at DESC") - when "oldest" then reorder("namespaces.created_at ASC") - when "recently_updated" then reorder("namespaces.updated_at DESC") - when "last_updated" then reorder("namespaces.updated_at ASC") - else reorder("namespaces.path, namespaces.name ASC") - end - end - end end diff --git a/app/models/hooks/web_hook.rb b/app/models/hooks/web_hook.rb index c8fa9c50918..defef7216f2 100644 --- a/app/models/hooks/web_hook.rb +++ b/app/models/hooks/web_hook.rb @@ -16,6 +16,7 @@ # class WebHook < ActiveRecord::Base + include Sortable include HTTParty default_value_for :push_events, true diff --git a/app/models/identity.rb b/app/models/identity.rb index 80e0e3a8a23..b2c3792d1ce 100644 --- a/app/models/identity.rb +++ b/app/models/identity.rb @@ -9,6 +9,7 @@ # class Identity < ActiveRecord::Base + include Sortable belongs_to :user validates :extern_uid, allow_blank: true, uniqueness: { scope: :provider } diff --git a/app/models/issue.rb b/app/models/issue.rb index 8a9e969248c..19e43ebd788 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -24,6 +24,7 @@ class Issue < ActiveRecord::Base include Issuable include InternalId include Taskable + include Sortable ActsAsTaggableOn.strict_case_match = true diff --git a/app/models/key.rb b/app/models/key.rb index d2d1af68822..e2e59296eed 100644 --- a/app/models/key.rb +++ b/app/models/key.rb @@ -15,6 +15,7 @@ require 'digest/md5' class Key < ActiveRecord::Base + include Sortable include Gitlab::Popen belongs_to :user diff --git a/app/models/label.rb b/app/models/label.rb index 2b2b02e0645..9d7099c5652 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -28,7 +28,7 @@ class Label < ActiveRecord::Base format: { with: /\A[^&\?,&]+\z/ }, uniqueness: { scope: :project_id } - scope :order_by_name, -> { reorder("labels.title ASC") } + default_scope { order(title: :asc) } alias_attribute :name, :title diff --git a/app/models/member.rb b/app/models/member.rb index 671ef466baa..fe3d2f40e87 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -14,6 +14,7 @@ # class Member < ActiveRecord::Base + include Sortable include Notifiable include Gitlab::Access diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index ad2e8d7879b..f758126cfeb 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -28,6 +28,7 @@ class MergeRequest < ActiveRecord::Base include Issuable include Taskable include InternalId + include Sortable belongs_to :target_project, foreign_key: :target_project_id, class_name: "Project" belongs_to :source_project, foreign_key: :source_project_id, class_name: "Project" diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index a71122d5e07..acac1ca4cf7 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -14,6 +14,8 @@ require Rails.root.join("app/models/commit") class MergeRequestDiff < ActiveRecord::Base + include Sortable + # Prevent store of diff # if commits amount more then 200 COMMITS_SAFE_SIZE = 200 diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 8fd3e56d2ee..9bbb2bafb98 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -15,6 +15,7 @@ class Milestone < ActiveRecord::Base include InternalId + include Sortable belongs_to :project has_many :issues diff --git a/app/models/namespace.rb b/app/models/namespace.rb index e7fd3024750..ba0b2b71cf9 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -14,6 +14,7 @@ # class Namespace < ActiveRecord::Base + include Sortable include Gitlab::ShellAdapter has_many :projects, dependent: :destroy diff --git a/app/models/project.rb b/app/models/project.rb index 390e1457ca1..a9ead7830ab 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -33,6 +33,7 @@ require 'carrierwave/orm/activerecord' require 'file_size_validator' class Project < ActiveRecord::Base + include Sortable include Gitlab::ShellAdapter include Gitlab::VisibilityLevel include Gitlab::ConfigHelper @@ -53,7 +54,7 @@ class Project < ActiveRecord::Base attr_accessor :new_default_branch # Relations - belongs_to :creator, foreign_key: 'creator_id', class_name: 'User' + belongs_to :creator, foreign_key: 'creator_id', class_name: 'User' belongs_to :group, -> { where(type: Group) }, foreign_key: 'namespace_id' belongs_to :namespace @@ -86,7 +87,7 @@ class Project < ActiveRecord::Base has_many :merge_requests, dependent: :destroy, foreign_key: 'target_project_id' # Merge requests from source project should be kept when source project was removed has_many :fork_merge_requests, foreign_key: 'source_project_id', class_name: MergeRequest - has_many :issues, -> { order 'issues.state DESC, issues.created_at DESC' }, dependent: :destroy + has_many :issues, dependent: :destroy has_many :labels, dependent: :destroy has_many :services, dependent: :destroy has_many :events, dependent: :destroy @@ -139,14 +140,16 @@ class Project < ActiveRecord::Base mount_uploader :avatar, AttachmentUploader # Scopes + scope :sorted_by_activity, -> { reorder(last_activity_at: :desc) } + scope :sorted_by_stars, -> { reorder('projects.star_count DESC') } + scope :sorted_by_names, -> { joins(:namespace).reorder('namespaces.name ASC, projects.name ASC') } + scope :without_user, ->(user) { where('projects.id NOT IN (:ids)', ids: user.authorized_projects.map(&:id) ) } scope :without_team, ->(team) { team.projects.present? ? where('projects.id NOT IN (:ids)', ids: team.projects.map(&:id)) : scoped } scope :not_in_group, ->(group) { where('projects.id NOT IN (:ids)', ids: group.project_ids ) } scope :in_team, ->(team) { where('projects.id IN (:ids)', ids: team.projects.map(&:id)) } scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } scope :in_group_namespace, -> { joins(:group) } - scope :sorted_by_activity, -> { reorder('projects.last_activity_at DESC') } - scope :sorted_by_stars, -> { reorder('projects.star_count DESC') } scope :personal, ->(user) { where(namespace_id: user.namespace_id) } scope :joined, ->(user) { where('namespace_id != ?', user.namespace_id) } scope :public_only, -> { where(visibility_level: Project::PUBLIC) } @@ -228,13 +231,10 @@ class Project < ActiveRecord::Base end def sort(method) - case method.to_s - when 'newest' then reorder('projects.created_at DESC') - when 'oldest' then reorder('projects.created_at ASC') - when 'recently_updated' then reorder('projects.updated_at DESC') - when 'last_updated' then reorder('projects.updated_at ASC') - when 'largest_repository' then reorder('projects.repository_size DESC') - else reorder('namespaces.path, projects.name ASC') + if method == 'repository_size_desc' + reorder(repository_size: :desc, id: :desc) + else + order_by(method) end end end diff --git a/app/models/service.rb b/app/models/service.rb index 15948e63e41..caabe8e971d 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -15,6 +15,7 @@ # To add new service you should build a class inherited from Service # and implement a set of methods class Service < ActiveRecord::Base + include Sortable serialize :properties, JSON default_value_for :active, false diff --git a/app/models/snippet.rb b/app/models/snippet.rb index a3222d29892..82c1ab94446 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -16,6 +16,7 @@ # class Snippet < ActiveRecord::Base + include Sortable include Linguist::BlobHelper include Gitlab::VisibilityLevel diff --git a/app/models/user.rb b/app/models/user.rb index 552a37c9533..ba61ecf3981 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -49,6 +49,7 @@ require 'carrierwave/orm/activerecord' require 'file_size_validator' class User < ActiveRecord::Base + include Sortable include Gitlab::ConfigHelper include TokenAuthenticatable extend Gitlab::ConfigHelper @@ -176,7 +177,6 @@ class User < ActiveRecord::Base scope :admins, -> { where(admin: true) } scope :blocked, -> { with_state(:blocked) } scope :active, -> { with_state(:active) } - scope :alphabetically, -> { order('name ASC') } scope :in_team, ->(team){ where(id: team.member_ids) } scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : all } @@ -199,11 +199,10 @@ class User < ActiveRecord::Base def sort(method) case method.to_s - when 'recent_sign_in' then reorder('users.last_sign_in_at DESC') - when 'oldest_sign_in' then reorder('users.last_sign_in_at ASC') - when 'recently_created' then reorder('users.created_at DESC') - when 'late_created' then reorder('users.created_at ASC') - else reorder("users.name ASC") + when 'recent_sign_in' then reorder(last_sign_in_at: :desc) + when 'oldest_sign_in' then reorder(last_sign_in_at: :asc) + else + order_by(method) end end @@ -290,7 +289,7 @@ class User < ActiveRecord::Base def authorized_groups @authorized_groups ||= begin group_ids = (groups.pluck(:id) + authorized_projects.pluck(:namespace_id)) - Group.where(id: group_ids).order('namespaces.name ASC') + Group.where(id: group_ids) end end @@ -301,7 +300,7 @@ class User < ActiveRecord::Base project_ids = personal_projects.pluck(:id) project_ids.push(*groups_projects.pluck(:id)) project_ids.push(*projects.pluck(:id).uniq) - Project.where(id: project_ids).joins(:namespace).order('namespaces.name ASC') + Project.where(id: project_ids) end end diff --git a/app/views/admin/groups/index.html.haml b/app/views/admin/groups/index.html.haml index 1d7fef43184..8ae9a1edea9 100644 --- a/app/views/admin/groups/index.html.haml +++ b/app/views/admin/groups/index.html.haml @@ -8,10 +8,31 @@ %hr = form_tag admin_groups_path, method: :get, class: 'form-inline' do + = hidden_field_tag :sort, @sort .form-group = text_field_tag :name, params[:name], class: "form-control input-mn-300" = button_tag "Search", class: "btn submit btn-primary" + .pull-right + .dropdown.inline + %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"} + %span.light sort: + - if @sort.present? + = sort_options_hash[@sort] + - else + = sort_title_recently_created + %b.caret + %ul.dropdown-menu + %li + = link_to admin_groups_path(sort: sort_value_recently_created) do + = sort_title_recently_created + = link_to admin_groups_path(sort: sort_value_oldest_created) do + = sort_title_oldest_created + = link_to admin_groups_path(sort: sort_value_recently_updated) do + = sort_title_recently_updated + = link_to admin_groups_path(sort: sort_value_oldest_updated) do + = sort_title_oldest_updated + %hr %ul.bordered-list diff --git a/app/views/admin/projects/index.html.haml b/app/views/admin/projects/index.html.haml index aa59f38d213..36a4a2fb4af 100644 --- a/app/views/admin/projects/index.html.haml +++ b/app/views/admin/projects/index.html.haml @@ -47,24 +47,22 @@ %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"} %span.light sort: - if @sort.present? - = @sort.humanize + = sort_options_hash[@sort] - else - Name + = sort_title_recently_created %b.caret %ul.dropdown-menu %li - = link_to admin_projects_path(sort: nil) do - Name - = link_to admin_projects_path(sort: 'newest') do + = link_to admin_projects_path(sort: sort_value_recently_created) do = sort_title_recently_created - = link_to admin_projects_path(sort: 'oldest') do + = link_to admin_projects_path(sort: sort_value_oldest_created) do = sort_title_oldest_created - = link_to admin_projects_path(sort: 'recently_updated') do + = link_to admin_projects_path(sort: sort_value_recently_updated) do = sort_title_recently_updated - = link_to admin_projects_path(sort: 'last_updated') do + = link_to admin_projects_path(sort: sort_value_oldest_updated) do = sort_title_oldest_updated - = link_to admin_projects_path(sort: 'largest_repository') do - Largest repository + = link_to admin_projects_path(sort: sort_value_largest_repo) do + = sort_title_largest_repo = link_to 'New Project', new_project_path, class: "btn btn-new" %ul.well-list - @projects.each do |project| diff --git a/app/views/admin/users/index.html.haml b/app/views/admin/users/index.html.haml index 8e1ecb41a85..6e15cec467b 100644 --- a/app/views/admin/users/index.html.haml +++ b/app/views/admin/users/index.html.haml @@ -36,22 +36,26 @@ %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"} %span.light sort: - if @sort.present? - = @sort.humanize + = sort_options_hash[@sort] - else - Name + = sort_title_name %b.caret %ul.dropdown-menu %li - = link_to admin_users_path(sort: nil) do - Name - = link_to admin_users_path(sort: 'recent_sign_in') do - Recent sign in - = link_to admin_users_path(sort: 'oldest_sign_in') do - Oldest sign in - = link_to admin_users_path(sort: 'recently_created') do + = link_to admin_users_path(sort: sort_value_name) do + = sort_title_name + = link_to admin_users_path(sort: sort_value_recently_signin) do + = sort_title_recently_signin + = link_to admin_users_path(sort: sort_value_oldest_signin) do + = sort_title_oldest_signin + = link_to admin_users_path(sort: sort_value_recently_created) do = sort_title_recently_created - = link_to admin_users_path(sort: 'late_created') do + = link_to admin_users_path(sort: sort_value_oldest_created) do = sort_title_oldest_created + = link_to admin_users_path(sort: sort_value_recently_updated) do + = sort_title_recently_updated + = link_to admin_users_path(sort: sort_value_oldest_updated) do + = sort_title_oldest_updated = link_to 'New User', new_admin_user_path, class: "btn btn-new" %ul.well-list diff --git a/app/views/dashboard/_projects_filter.html.haml b/app/views/dashboard/_projects_filter.html.haml index 0e990ccfab4..7b5d46072e3 100644 --- a/app/views/dashboard/_projects_filter.html.haml +++ b/app/views/dashboard/_projects_filter.html.haml @@ -82,19 +82,19 @@ %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"} %span.light sort: - if @sort.present? - = @sort.humanize + = sort_options_hash[@sort] - else - Name + = sort_title_recently_created %b.caret %ul.dropdown-menu %li - = link_to projects_dashboard_filter_path(sort: nil) do - Name - = link_to projects_dashboard_filter_path(sort: 'newest') do + = link_to projects_dashboard_filter_path(sort: sort_value_recently_created) do = sort_title_recently_created - = link_to projects_dashboard_filter_path(sort: 'oldest') do + = link_to projects_dashboard_filter_path(sort: sort_value_oldest_created) do = sort_title_oldest_created - = link_to projects_dashboard_filter_path(sort: 'recently_updated') do + = link_to projects_dashboard_filter_path(sort: sort_value_recently_updated) do = sort_title_recently_updated - = link_to projects_dashboard_filter_path(sort: 'last_updated') do + = link_to projects_dashboard_filter_path(sort: sort_value_oldest_updated) do = sort_title_oldest_updated + = link_to projects_dashboard_filter_path(sort: sort_value_name) do + = sort_title_name diff --git a/app/views/explore/groups/index.html.haml b/app/views/explore/groups/index.html.haml index 9b1d7d0416d..5cf514927af 100644 --- a/app/views/explore/groups/index.html.haml +++ b/app/views/explore/groups/index.html.haml @@ -1,6 +1,7 @@ .clearfix .pull-left = form_tag explore_groups_path, method: :get, class: 'form-inline form-tiny' do |f| + = hidden_field_tag :sort, @sort .form-group = search_field_tag :search, params[:search], placeholder: "Filter by name", class: "form-control search-text-input input-mn-300", id: "groups_search" .form-group @@ -11,21 +12,19 @@ %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"} %span.light sort: - if @sort.present? - = @sort.humanize + = sort_options_hash[@sort] - else - Name + = sort_title_recently_created %b.caret %ul.dropdown-menu %li - = link_to explore_groups_path(sort: nil) do - Name - = link_to explore_groups_path(sort: 'newest') do + = link_to explore_groups_path(sort: sort_value_recently_created) do = sort_title_recently_created - = link_to explore_groups_path(sort: 'oldest') do + = link_to explore_groups_path(sort: sort_value_oldest_created) do = sort_title_oldest_created - = link_to explore_groups_path(sort: 'recently_updated') do + = link_to explore_groups_path(sort: sort_value_recently_updated) do = sort_title_recently_updated - = link_to explore_groups_path(sort: 'last_updated') do + = link_to explore_groups_path(sort: sort_value_oldest_updated) do = sort_title_oldest_updated %hr diff --git a/app/views/explore/projects/index.html.haml b/app/views/explore/projects/index.html.haml index 02586077d8c..02d02912791 100644 --- a/app/views/explore/projects/index.html.haml +++ b/app/views/explore/projects/index.html.haml @@ -11,21 +11,19 @@ %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"} %span.light sort: - if @sort.present? - = @sort.humanize + = sort_options_hash[@sort] - else - Name + = sort_title_recently_created %b.caret %ul.dropdown-menu %li - = link_to explore_projects_path(sort: nil) do - Name - = link_to explore_projects_path(sort: 'newest') do + = link_to explore_projects_path(sort: sort_value_recently_created) do = sort_title_recently_created - = link_to explore_projects_path(sort: 'oldest') do + = link_to explore_projects_path(sort: sort_value_oldest_created) do = sort_title_oldest_created - = link_to explore_projects_path(sort: 'recently_updated') do + = link_to explore_projects_path(sort: sort_value_recently_updated) do = sort_title_recently_updated - = link_to explore_projects_path(sort: 'last_updated') do + = link_to explore_projects_path(sort: sort_value_oldest_updated) do = sort_title_oldest_updated %hr diff --git a/app/views/shared/_issuable_filter.html.haml b/app/views/shared/_issuable_filter.html.haml index 4f683258fac..cd97481bb6c 100644 --- a/app/views/shared/_issuable_filter.html.haml +++ b/app/views/shared/_issuable_filter.html.haml @@ -98,7 +98,7 @@ = link_to page_filter_path(label_name: nil) do Any - if @project.labels.any? - - @project.labels.order_by_name.each do |label| + - @project.labels.each do |label| %li = link_to page_filter_path(label_name: label.name) do = render_colored_label(label) diff --git a/app/views/shared/_sort_dropdown.html.haml b/app/views/shared/_sort_dropdown.html.haml index 3e6a62380f3..ba14c8643cd 100644 --- a/app/views/shared/_sort_dropdown.html.haml +++ b/app/views/shared/_sort_dropdown.html.haml @@ -2,21 +2,21 @@ %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"} %span.light sort: - if @sort.present? - = @sort + = sort_options_hash[@sort] - else - Newest + = sort_title_recently_created %b.caret %ul.dropdown-menu.dropdown-menu-align-right %li - = link_to page_filter_path(sort: 'newest') do + = link_to page_filter_path(sort: sort_value_recently_created) do = sort_title_recently_created - = link_to page_filter_path(sort: 'oldest') do + = link_to page_filter_path(sort: sort_value_oldest_created) do = sort_title_oldest_created - = link_to page_filter_path(sort: 'recently_updated') do + = link_to page_filter_path(sort: sort_value_recently_updated) do = sort_title_recently_updated - = link_to page_filter_path(sort: 'last_updated') do + = link_to page_filter_path(sort: sort_value_oldest_updated) do = sort_title_oldest_updated - = link_to page_filter_path(sort: 'milestone_due_soon') do - Milestone due soon - = link_to page_filter_path(sort: 'milestone_due_later') do - Milestone due later + = link_to page_filter_path(sort: sort_value_milestone_soon) do + = sort_title_milestone_soon + = link_to page_filter_path(sort: sort_value_milestone_later) do + = sort_title_milestone_later |