From 8f326bbb16c001d34271e8f0eead5147134ad2ab Mon Sep 17 00:00:00 2001 From: Maxim Colls Date: Tue, 25 Sep 2018 18:32:58 +0100 Subject: [PATCH 1/9] Do not hide actions in the manage users page --- app/views/users/manage.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/users/manage.html.erb b/app/views/users/manage.html.erb index a02f58d4f..6f37ae995 100644 --- a/app/views/users/manage.html.erb +++ b/app/views/users/manage.html.erb @@ -50,17 +50,17 @@ <%= sort_link @search, :user_username, User.human_attribute_name(:username) %> - + <%= User.human_attribute_name(:email) %> - + <%= User.human_attribute_name(:phone) %> - + <%= sort_link @search, 'account_balance', Account.human_attribute_name(:balance) %> <% if current_user.manages? current_organization %> - + <%= t(".actions") %> From b0d675ce92a5153085411382c372fe9794cb6a73 Mon Sep 17 00:00:00 2001 From: Maxim Colls Date: Tue, 25 Sep 2018 19:01:37 +0100 Subject: [PATCH 2/9] Sort members by last_sign_in_at --- app/controllers/users_controller.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ee0af5f60..db2fe5326 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,11 +2,12 @@ class UsersController < ApplicationController before_filter :authenticate_user! def index - search_and_load_members current_organization.members.active + # I would like nulls to go last but ransack... https://github.com/activerecord-hackery/ransack/issues/443 + search_and_load_members current_organization.members.active, {s: 'user_last_sign_in_at desc'} end def manage - search_and_load_members current_organization.members + search_and_load_members current_organization.members, {s: 'member_uid asc'} end def show @@ -57,8 +58,8 @@ def update private - def search_and_load_members(members_scope) - @search = members_scope.ransack(search_params) + def search_and_load_members(members_scope, default_search_params) + @search = members_scope.ransack(default_search_params.merge(params.fetch(:q, {}))) @members = @search.result.eager_load(:account, :user).page(params[:page]).per(20) @@ -67,10 +68,6 @@ def search_and_load_members(members_scope) @members.map { |m| MemberDecorator.new(m, self.class.helpers) } end - def search_params - {s: 'member_uid asc'}.merge(params.fetch(:q, {})) - end - def scoped_users current_organization.users end From 48540653945dda2d08f1f273d6ee8fbd1f81e4d6 Mon Sep 17 00:00:00 2001 From: Maxim Colls Date: Tue, 25 Sep 2018 19:01:51 +0100 Subject: [PATCH 3/9] Truncate member description --- app/views/users/_member_card.html.erb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/views/users/_member_card.html.erb b/app/views/users/_member_card.html.erb index c6ed0c62c..48551dfd7 100644 --- a/app/views/users/_member_card.html.erb +++ b/app/views/users/_member_card.html.erb @@ -16,7 +16,17 @@
- <%= member.description %> + <%= member.description&.truncate(124) %> +
+
+
+ + <%= phone_to member.phone %> +
+
+ + <%= member.mail_to %> +
From dd5db0a0bf3440125e899fcc38b6c84d91ad508a Mon Sep 17 00:00:00 2001 From: Maxim Colls Date: Tue, 25 Sep 2018 19:02:06 +0100 Subject: [PATCH 4/9] Hide telephone icon when there is no phone number --- app/views/users/_member_card.html.erb | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/app/views/users/_member_card.html.erb b/app/views/users/_member_card.html.erb index 48551dfd7..1ebc02ed1 100644 --- a/app/views/users/_member_card.html.erb +++ b/app/views/users/_member_card.html.erb @@ -19,20 +19,12 @@ <%= member.description&.truncate(124) %>
-
- - <%= phone_to member.phone %> -
-
- - <%= member.mail_to %> -
-
-
-
- - <%= phone_to member.phone %> -
+ <% if member.phone && !member.phone.blank? %> +
+ + <%= phone_to member.phone %> +
+ <% end %>
<%= member.mail_to %> From 3286098ae5488f7df73490e581838d87298c70ce Mon Sep 17 00:00:00 2001 From: Maxim Colls Date: Sat, 6 Oct 2018 20:15:23 +0100 Subject: [PATCH 5/9] Fixed checking phone presence logic --- app/views/users/_member_card.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/_member_card.html.erb b/app/views/users/_member_card.html.erb index 1ebc02ed1..5f4f97b5a 100644 --- a/app/views/users/_member_card.html.erb +++ b/app/views/users/_member_card.html.erb @@ -19,7 +19,7 @@ <%= member.description&.truncate(124) %>
- <% if member.phone && !member.phone.blank? %> + <% if member.phone.present? && !member.phone.blank? %>
<%= phone_to member.phone %> From 67c37dd77d472f3aca2579d5cea46ed4f9de1ec0 Mon Sep 17 00:00:00 2001 From: Maxim Colls Date: Sat, 6 Oct 2018 20:29:41 +0100 Subject: [PATCH 6/9] Fixed specs --- spec/controllers/users_controller_spec.rb | 8 ++++++-- spec/fabricators/user_fabricator.rb | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 552c5f4c5..e8ceab5c4 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -40,12 +40,16 @@ describe "GET #index" do before { login(user) } - it 'sorts the users by their member_uid asc by default' do + it 'sorts the users by their user_last_sign_in_at desc by default' do member.increment!(:member_uid, Member.maximum(:member_uid) + 1) + member.user.update_attribute( + :last_sign_in_at, + DateTime.now + ) get :index - expect(assigns(:members).last).to eq(member) + expect(assigns(:members).first).to eq(member) end it 'allows to sort by member_uid' do diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 99ee3605a..5d0b196da 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -10,6 +10,7 @@ address { Faker::Address.street_address + " " + Faker::Address.zip_code + " " + Faker::Address.city + " (" + Faker::Address.state + ")"} gender { ["male", "female"].shuffle.first } description { Faker::Lorem.paragraph } + last_sign_in_at { DateTime.new(2018, 10, 1) } terms_accepted_at DateTime.now.utc confirmed_at DateTime.now.utc From ecbb5edca9f7b6f15cdea249b19df86d72608e69 Mon Sep 17 00:00:00 2001 From: Maxim Colls Date: Fri, 19 Oct 2018 15:40:54 +0200 Subject: [PATCH 7/9] Do not show email if it is "blank" or example.com --- app/views/users/_member_card.html.erb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/views/users/_member_card.html.erb b/app/views/users/_member_card.html.erb index 5f4f97b5a..0b61420b3 100644 --- a/app/views/users/_member_card.html.erb +++ b/app/views/users/_member_card.html.erb @@ -25,10 +25,12 @@ <%= phone_to member.phone %>
<% end %> -
- - <%= member.mail_to %> -
+ <% if member.mail_to.present? && !member.mail_to.blank? %> +
+ + <%= member.mail_to %> +
+ <% end %>
<%= "Balance: " %> <%= member.account_balance %> From 9208d17bf00ef39e5d8b9d7dace87ccbc795d6df Mon Sep 17 00:00:00 2001 From: Maxim Colls Date: Fri, 19 Oct 2018 17:26:33 +0200 Subject: [PATCH 8/9] Revert sorting by user_last_sign_in_at --- app/controllers/users_controller.rb | 3 +-- spec/controllers/users_controller_spec.rb | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index db2fe5326..4077113dc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -2,8 +2,7 @@ class UsersController < ApplicationController before_filter :authenticate_user! def index - # I would like nulls to go last but ransack... https://github.com/activerecord-hackery/ransack/issues/443 - search_and_load_members current_organization.members.active, {s: 'user_last_sign_in_at desc'} + search_and_load_members current_organization.members.active, {s: 'member_uid asc'} end def manage diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index e8ceab5c4..552c5f4c5 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -40,16 +40,12 @@ describe "GET #index" do before { login(user) } - it 'sorts the users by their user_last_sign_in_at desc by default' do + it 'sorts the users by their member_uid asc by default' do member.increment!(:member_uid, Member.maximum(:member_uid) + 1) - member.user.update_attribute( - :last_sign_in_at, - DateTime.now - ) get :index - expect(assigns(:members).first).to eq(member) + expect(assigns(:members).last).to eq(member) end it 'allows to sort by member_uid' do From 6e817747ba0740388e753a2ccfc089fc9f2d6187 Mon Sep 17 00:00:00 2001 From: Maxim Colls Date: Fri, 19 Oct 2018 17:29:38 +0200 Subject: [PATCH 9/9] Redo not hidding columns in mobile after rebasing conflict --- app/views/users/_user_row.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/users/_user_row.html.erb b/app/views/users/_user_row.html.erb index 29af9c8d2..1e5233cf1 100644 --- a/app/views/users/_user_row.html.erb +++ b/app/views/users/_user_row.html.erb @@ -5,11 +5,11 @@ <%= member.inactive_icon %> <%= member.link_to_self %> - <%= member.mail_to %> - <%= phone_to member.phone %> - <%= member.account_balance %> + <%= member.mail_to %> + <%= phone_to member.phone %> + <%= member.account_balance %> <% if current_user.manages?(current_organization) %> - + <% if member.active? %> <%= render 'toggle_manager_link', member: member if can_toggle_manager?(member) %> <% else %>