From 62c979cfc0b3a716f37edf43eb4453adfeac438d Mon Sep 17 00:00:00 2001 From: Nicolas Florentin Date: Fri, 20 Dec 2019 15:47:42 +0100 Subject: [PATCH] members filters, translations for other languages are still needed --- .../controllers/admin/members.js.erb | 19 +++++++++++++++++- .../templates/admin/members/members.html.erb | 20 ++++++++++++++----- app/controllers/api/members_controller.rb | 2 +- app/models/user.rb | 2 ++ app/services/members/list_service.rb | 3 +++ config/locales/app.admin.fr.yml | 3 +++ 6 files changed, 42 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/controllers/admin/members.js.erb b/app/assets/javascripts/controllers/admin/members.js.erb index 506cae4ee..b83d50008 100644 --- a/app/assets/javascripts/controllers/admin/members.js.erb +++ b/app/assets/javascripts/controllers/admin/members.js.erb @@ -146,7 +146,15 @@ Application.Controllers.controller('AdminMembersController', ['$scope', '$sce', // currently displayed page of members page: 1, // true when all members where loaded - noMore: false + noMore: false, + // default filter for members + memberFilter: 'all', + // options for members filtering + memberFilters: [ + 'all', + 'not_confirmed', + 'inactive_for_3_years' + ] }; // admins list @@ -261,6 +269,14 @@ Application.Controllers.controller('AdminMembersController', ['$scope', '$sce', }, 300); }; + /** + * Callback when the member filter changes: reload the search results + */ + $scope.updateMemberFilter = function () { + resetSearchMember(); + memberSearch(); + }; + /** * Callback to alert the admin that the export request was acknowledged and is * processing right now. @@ -317,6 +333,7 @@ Application.Controllers.controller('AdminMembersController', ['$scope', '$sce', query: { search: $scope.member.searchText, order_by: $scope.member.order, + filter: $scope.member.memberFilter, page: $scope.member.page, size: USERS_PER_PAGE } diff --git a/app/assets/templates/admin/members/members.html.erb b/app/assets/templates/admin/members/members.html.erb index eebaf3b13..209cdc06b 100644 --- a/app/assets/templates/admin/members/members.html.erb +++ b/app/assets/templates/admin/members/members.html.erb @@ -1,8 +1,19 @@
-
-
- - +
+
+
+
+ + +
+
+
+
+
+ +
@@ -21,7 +32,6 @@
- diff --git a/app/controllers/api/members_controller.rb b/app/controllers/api/members_controller.rb index 4949158fd..b411f17a2 100644 --- a/app/controllers/api/members_controller.rb +++ b/app/controllers/api/members_controller.rb @@ -231,6 +231,6 @@ class API::MembersController < API::ApiController end def query_params - params.require(:query).permit(:search, :order_by, :page, :size) + params.require(:query).permit(:search, :filter, :order_by, :page, :size) end end diff --git a/app/models/user.rb b/app/models/user.rb index 96d841d36..c88a44f2e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -77,6 +77,8 @@ class User < ActiveRecord::Base scope :active, -> { where(is_active: true) } scope :without_subscription, -> { includes(statistic_profile: [:subscriptions]).where(subscriptions: { statistic_profile_id: nil }) } scope :with_subscription, -> { joins(statistic_profile: [:subscriptions]) } + scope :not_confirmed, -> { where(confirmed_at: nil) } + scope :inactive_for_3_years, -> { where("users.last_sign_in_at < ?", 3.years.ago) } def to_json(*) ApplicationController.new.view_context.render( diff --git a/app/services/members/list_service.rb b/app/services/members/list_service.rb index 3e67b8c60..b88615586 100644 --- a/app/services/members/list_service.rb +++ b/app/services/members/list_service.rb @@ -34,6 +34,9 @@ class Members::ListService 'plans.base_name ILIKE :search', search: "%#{params[:search]}%") end + filter = params[:filter].presence_in(['inactive_for_3_years', 'not_confirmed']) || nil + @query = @query.send(filter) if filter + @query end diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index 47646a36f..dd0d3b989 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -646,6 +646,9 @@ fr: status_enabled: "Activés" status_disabled: "Désactivés" status_all: "Tous" + member_filter_all: "Tous" + member_filter_not_confirmed: "Non confirmés" + member_filter_inactive_for_3_years: "Inactifs depuis 3 ans" members_new: # ajouter un membre