summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNur Rony <pro.nmrony@gmail.com>2016-10-18 18:22:18 +0600
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-12-16 20:28:33 -0200
commit09388b2021034173156ba8958fa290b01e3a447d (patch)
treefb95442652203de49c061de4fe1df52d53250e25
parent12a7e717d7b9fdd265d54a9c5bd07394e304b187 (diff)
downloadgitlab-ce-09388b2021034173156ba8958fa290b01e3a447d.tar.gz
Adds sort dropdown for group members
-rw-r--r--app/assets/stylesheets/pages/members.scss54
-rw-r--r--app/controllers/groups/group_members_controller.rb10
-rw-r--r--app/controllers/projects/project_members_controller.rb5
-rw-r--r--app/helpers/members_helper.rb30
-rw-r--r--app/helpers/sorting_helper.rb41
-rw-r--r--app/views/groups/group_members/index.html.haml1
-rw-r--r--app/views/projects/project_members/index.html.haml1
-rw-r--r--app/views/shared/members/_sort_dropdown.html.haml11
8 files changed, 127 insertions, 26 deletions
diff --git a/app/assets/stylesheets/pages/members.scss b/app/assets/stylesheets/pages/members.scss
index 5f3bbb40ba0..b7521133ce5 100644
--- a/app/assets/stylesheets/pages/members.scss
+++ b/app/assets/stylesheets/pages/members.scss
@@ -78,6 +78,20 @@
float: right;
}
+ .dropdown {
+ width: 100%;
+ margin-top: 5px;
+
+ .dropdown-menu-toggle {
+ width: 100%;
+ }
+
+ @media (min-width: $screen-sm-min) {
+ top: 2.4px;
+ width: 155px;
+ }
+ }
+
.form-control {
width: 100%;
padding-right: 35px;
@@ -85,18 +99,34 @@
@media (min-width: $screen-sm-min) {
width: 350px;
}
+
+ &.input-short {
+ @media (min-width: $screen-md-min) {
+ width: 170px;
+ }
+
+ @media (min-width: $screen-lg-min) {
+ width: 210px;
+ }
+ }
+ }
+
+ .member-search-btn {
+ position: absolute;
+ right: 4px;
+ top: 0;
+ height: 35px;
+ padding-left: 10px;
+ padding-right: 10px;
+ color: $gray-darkest;
+ background: transparent;
+ border: 0;
+ outline: 0;
+
+ @media (min-width: $screen-sm-min) {
+ right: 160px;
+ top: 8px;
+ }
}
-}
-.member-search-btn {
- position: absolute;
- right: 0;
- top: 0;
- height: 35px;
- padding-left: 10px;
- padding-right: 10px;
- color: $gray-darkest;
- background: transparent;
- border: 0;
- outline: 0;
}
diff --git a/app/controllers/groups/group_members_controller.rb b/app/controllers/groups/group_members_controller.rb
index 940a3ad20ba..af8abb96d4a 100644
--- a/app/controllers/groups/group_members_controller.rb
+++ b/app/controllers/groups/group_members_controller.rb
@@ -10,11 +10,15 @@ class Groups::GroupMembersController < Groups::ApplicationController
@members = @members.non_invite unless can?(current_user, :admin_group, @group)
if params[:search].present?
- users = @group.users.search(params[:search]).to_a
- @members = @members.where(user_id: users)
+ @members = @members.joins(:user).merge(User.search(params[:search]))
end
- @members = @members.order('access_level DESC').page(params[:page]).per(50)
+ if params[:sort].present?
+ @members = @members.joins(:user).merge(User.sort(@sort = params[:sort]))
+ end
+
+
+ @members = @members.page(params[:page]).per(50)
@requesters = AccessRequestsFinder.new(@group).execute(current_user)
@group_member = @group.group_members.new
diff --git a/app/controllers/projects/project_members_controller.rb b/app/controllers/projects/project_members_controller.rb
index 53308948f62..e4aba4b700e 100644
--- a/app/controllers/projects/project_members_controller.rb
+++ b/app/controllers/projects/project_members_controller.rb
@@ -1,10 +1,12 @@
class Projects::ProjectMembersController < Projects::ApplicationController
include MembershipActions
+ include SortingHelper
# Authorize
before_action :authorize_admin_project_member!, except: [:index, :leave, :request_access]
def index
+ @sort = params[:sort].presence || sort_value_name
@group_links = @project.project_group_links
@project_members = @project.project_members
@@ -40,7 +42,8 @@ class Projects::ProjectMembersController < Projects::ApplicationController
@project_members = Member.
where(wheres.join(' OR ')).
- order(access_level: :desc).page(params[:page])
+ sort(@sort).
+ page(params[:page])
@requesters = AccessRequestsFinder.new(@project).execute(current_user)
diff --git a/app/helpers/members_helper.rb b/app/helpers/members_helper.rb
index 877c77050be..f1b8962eb36 100644
--- a/app/helpers/members_helper.rb
+++ b/app/helpers/members_helper.rb
@@ -11,17 +11,17 @@ module MembersHelper
text = 'Are you sure you want to '
action =
- if member.request?
- if member.user == user
- 'withdraw your access request for'
+ if member.request?
+ if member.user == user
+ 'withdraw your access request for'
+ else
+ "deny #{member.user.name}'s request to join"
+ end
+ elsif member.invite?
+ "revoke the invitation for #{member.invite_email} to join"
else
- "deny #{member.user.name}'s request to join"
+ "remove #{member.user.name} from"
end
- elsif member.invite?
- "revoke the invitation for #{member.invite_email} to join"
- else
- "remove #{member.user.name} from"
- end
text << action << " the #{member.source.human_name} #{member.real_source_type.humanize(capitalize: false)}?"
end
@@ -36,4 +36,16 @@ module MembersHelper
"Are you sure you want to leave the " \
"\"#{member_source.human_name}\" #{member_source.class.to_s.humanize(capitalize: false)}?"
end
+
+ def filter_group_project_member_path(options = {})
+ exist_opts = {
+ search: params[:search],
+ sort: params[:sort]
+ }
+
+ options = exist_opts.merge(options)
+ path = request.path
+ path << "?#{options.to_param}"
+ path
+ end
end
diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb
index 8b138a8e69f..9c6f9f741ed 100644
--- a/app/helpers/sorting_helper.rb
+++ b/app/helpers/sorting_helper.rb
@@ -25,7 +25,7 @@ module SortingHelper
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_oldest_created => sort_title_oldest_created
}
if current_controller?('admin/projects')
@@ -35,6 +35,17 @@ module SortingHelper
options
end
+ def member_sort_options_hash
+ {
+ sort_value_last_joined => sort_title_last_joined,
+ sort_value_oldest_joined => sort_title_oldest_joined,
+ sort_value_name => sort_title_name_asc,
+ sort_value_name_desc => sort_title_name_desc,
+ sort_value_recently_signin => sort_title_recently_signin,
+ sort_value_oldest_signin => sort_title_oldest_signin
+ }
+ end
+
def sort_title_priority
'Priority'
end
@@ -95,6 +106,34 @@ module SortingHelper
'Most popular'
end
+ def sort_title_last_joined
+ 'Last joined'
+ end
+
+ def sort_title_oldest_joined
+ 'Oldest joined'
+ end
+
+ def sort_title_name_asc
+ 'Name, ascending'
+ end
+
+ def sort_title_name_desc
+ 'Name, descending'
+ end
+
+ def sort_value_last_joined
+ 'last_joined'
+ end
+
+ def sort_value_oldest_joined
+ 'oldest_joined'
+ end
+
+ def sort_value_name_desc
+ 'name_desc'
+ end
+
def sort_value_priority
'priority'
end
diff --git a/app/views/groups/group_members/index.html.haml b/app/views/groups/group_members/index.html.haml
index ebf9aca7700..bc5d3c797ac 100644
--- a/app/views/groups/group_members/index.html.haml
+++ b/app/views/groups/group_members/index.html.haml
@@ -21,6 +21,7 @@
= search_field_tag :search, params[:search], { placeholder: 'Find existing members by name', class: 'form-control', spellcheck: false }
%button.member-search-btn{ type: "submit", "aria-label" => "Submit search" }
= icon("search")
+ = render 'shared/members/sort_dropdown'
.panel.panel-default
.panel-heading
Users with access to
diff --git a/app/views/projects/project_members/index.html.haml b/app/views/projects/project_members/index.html.haml
index bdeb704b6da..4f1cec20f85 100644
--- a/app/views/projects/project_members/index.html.haml
+++ b/app/views/projects/project_members/index.html.haml
@@ -21,6 +21,7 @@
= search_field_tag :search, params[:search], { placeholder: 'Find existing members by name', class: 'form-control', spellcheck: false }
%button.member-search-btn{ type: "submit", "aria-label" => "Submit search" }
= icon("search")
+ = render 'shared/members/sort_dropdown'
- if @group_links.any?
= render 'groups', group_links: @group_links
diff --git a/app/views/shared/members/_sort_dropdown.html.haml b/app/views/shared/members/_sort_dropdown.html.haml
new file mode 100644
index 00000000000..42c09636ba3
--- /dev/null
+++ b/app/views/shared/members/_sort_dropdown.html.haml
@@ -0,0 +1,11 @@
+- @sort ||= sort_value_last_joined
+
+.dropdown.inline
+ = dropdown_toggle(member_sort_options_hash[@sort], { toggle: 'dropdown' }, { id: 'sort-members-dropdown' })
+ %ul.dropdown-menu.dropdown-menu-align-right.dropdown-menu-selectable
+ %li.dropdown-header
+ Sort by
+ - member_sort_options_hash.each do |value, title|
+ %li
+ = link_to filter_group_project_member_path(sort: value), class: ("is-active" if @sort == value) do
+ = title