From 95917ba45f0181e022ce61d8bb45cc10e5c5feef Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Thu, 28 Apr 2022 14:37:01 +0200 Subject: [PATCH] wip #279 --- app/controllers/admin/education/schools_controller.rb | 3 +++ .../admin/education/teachers_controller.rb | 4 +++- app/controllers/admin/research/journals_controller.rb | 4 +++- .../admin/research/laboratories_controller.rb | 4 +++- .../admin/research/researchers_controller.rb | 4 +++- app/controllers/admin/research/theses_controller.rb | 4 +++- .../admin/university/person/alumni_controller.rb | 5 ++++- app/models/education/school.rb | 10 ++++++++++ app/models/research/journal.rb | 8 ++++++++ app/models/research/laboratory.rb | 11 +++++++++++ app/models/research/thesis.rb | 6 ++++++ app/views/admin/education/schools/index.html.erb | 5 +++++ app/views/admin/education/teachers/index.html.erb | 6 +++--- app/views/admin/research/journals/index.html.erb | 2 ++ app/views/admin/research/laboratories/index.html.erb | 2 ++ app/views/admin/research/researchers/index.html.erb | 7 ++++--- app/views/admin/research/theses/index.html.erb | 2 ++ .../admin/university/person/alumni/index.html.erb | 2 ++ .../university/person/alumnus/imports/new.html.erb | 2 +- 19 files changed, 78 insertions(+), 13 deletions(-) diff --git a/app/controllers/admin/education/schools_controller.rb b/app/controllers/admin/education/schools_controller.rb index 7152bbd27..f4c52f96a 100644 --- a/app/controllers/admin/education/schools_controller.rb +++ b/app/controllers/admin/education/schools_controller.rb @@ -3,7 +3,10 @@ class Admin::Education::SchoolsController < Admin::Education::ApplicationControl through: :current_university, through_association: :education_schools + has_scope :for_search_term + def index + @schools = apply_scopes(@schools).ordered.page(params[:page]) breadcrumb end diff --git a/app/controllers/admin/education/teachers_controller.rb b/app/controllers/admin/education/teachers_controller.rb index fe56c928e..49e506997 100644 --- a/app/controllers/admin/education/teachers_controller.rb +++ b/app/controllers/admin/education/teachers_controller.rb @@ -1,8 +1,10 @@ class Admin::Education::TeachersController < Admin::Education::ApplicationController before_action :load_teacher, only: [:show, :edit, :update] + has_scope :for_search_term + def index - @teachers = current_university.people.teachers.accessible_by(current_ability).ordered.page(params[:page]) + @teachers = apply_scopes(current_university.people.teachers.accessible_by(current_ability)).ordered.page(params[:page]) breadcrumb end diff --git a/app/controllers/admin/research/journals_controller.rb b/app/controllers/admin/research/journals_controller.rb index 4cecdb213..0fb198f42 100644 --- a/app/controllers/admin/research/journals_controller.rb +++ b/app/controllers/admin/research/journals_controller.rb @@ -3,8 +3,10 @@ class Admin::Research::JournalsController < Admin::Research::ApplicationControll through: :current_university, through_association: :research_journals + has_scope :for_search_term + def index - @journals = @journals.ordered.page(params[:page]) + @journals = apply_scopes(@journals).ordered.page(params[:page]) breadcrumb add_breadcrumb Research::Journal.model_name.human(count: 2), admin_research_journals_path end diff --git a/app/controllers/admin/research/laboratories_controller.rb b/app/controllers/admin/research/laboratories_controller.rb index 49cb0d3f3..67621fc64 100644 --- a/app/controllers/admin/research/laboratories_controller.rb +++ b/app/controllers/admin/research/laboratories_controller.rb @@ -3,8 +3,10 @@ class Admin::Research::LaboratoriesController < Admin::Research::ApplicationCont through: :current_university, through_association: :research_laboratories + has_scope :for_search_term + def index - @laboratories = @laboratories.ordered.page(params[:page]) + @laboratories = apply_scopes(@laboratories).ordered.page(params[:page]) breadcrumb add_breadcrumb Research::Laboratory.model_name.human(count: 2), admin_research_laboratories_path end diff --git a/app/controllers/admin/research/researchers_controller.rb b/app/controllers/admin/research/researchers_controller.rb index ae994e920..b192fc776 100644 --- a/app/controllers/admin/research/researchers_controller.rb +++ b/app/controllers/admin/research/researchers_controller.rb @@ -1,7 +1,9 @@ class Admin::Research::ResearchersController < Admin::Research::ApplicationController + has_scope :for_search_term + def index - @researchers = current_university.people.researchers.accessible_by(current_ability).ordered.page(params[:page]) + @researchers = apply_scopes(current_university.people.researchers.accessible_by(current_ability)).ordered.page(params[:page]) breadcrumb end diff --git a/app/controllers/admin/research/theses_controller.rb b/app/controllers/admin/research/theses_controller.rb index 114e1238e..b043a530b 100644 --- a/app/controllers/admin/research/theses_controller.rb +++ b/app/controllers/admin/research/theses_controller.rb @@ -3,8 +3,10 @@ class Admin::Research::ThesesController < Admin::Research::ApplicationController through: :current_university, through_association: :research_theses + has_scope :for_search_term + def index - @theses = @theses.ordered.page(params[:page]) + @theses = apply_scopes(@theses).ordered.page(params[:page]) breadcrumb end diff --git a/app/controllers/admin/university/person/alumni_controller.rb b/app/controllers/admin/university/person/alumni_controller.rb index f86a16f46..80931367b 100644 --- a/app/controllers/admin/university/person/alumni_controller.rb +++ b/app/controllers/admin/university/person/alumni_controller.rb @@ -2,8 +2,11 @@ class Admin::University::Person::AlumniController < Admin::University::Applicati load_and_authorize_resource class: University::Person::Alumnus, through: :current_university, through_association: :people + + has_scope :for_search_term + def index - @alumni = @alumni.alumni + @alumni = apply_scopes(@alumni).alumni .accessible_by(current_ability) .ordered .page(params[:page]) diff --git a/app/models/education/school.rb b/app/models/education/school.rb index 7149a637c..fdfbb5bab 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -91,6 +91,16 @@ class Education::School < ApplicationRecord validates :name, :address, :city, :zipcode, :country, presence: true scope :ordered, -> { order(:name) } + scope :for_search_term, -> (term) { + where(" + unaccent(education_schools.address) ILIKE unaccent(:term) OR + unaccent(education_schools.city) ILIKE unaccent(:term) OR + unaccent(education_schools.country) ILIKE unaccent(:term) OR + unaccent(education_schools.name) ILIKE unaccent(:term) OR + unaccent(education_schools.phone) ILIKE unaccent(:term) OR + unaccent(education_schools.zipcode) ILIKE unaccent(:term) + ", term: "%#{sanitize_sql_like(term)}%") + } def to_s "#{name}" diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb index 08cbbc495..2ed942814 100644 --- a/app/models/research/journal.rb +++ b/app/models/research/journal.rb @@ -34,6 +34,14 @@ class Research::Journal < ApplicationRecord has_many :people_through_published_articles, -> { distinct }, through: :published_articles, source: :people scope :ordered, -> { order(:title) } + scope :for_search_term, -> (term) { + where(" + unaccent(research_journals.description) ILIKE unaccent(:term) OR + unaccent(research_journals.issn) ILIKE unaccent(:term) OR + unaccent(research_journals.repository) ILIKE unaccent(:term) OR + unaccent(research_journals.title) ILIKE unaccent(:term) + ", term: "%#{sanitize_sql_like(term)}%") + } def to_s "#{title}" diff --git a/app/models/research/laboratory.rb b/app/models/research/laboratory.rb index 6ec50a9ba..2908de92a 100644 --- a/app/models/research/laboratory.rb +++ b/app/models/research/laboratory.rb @@ -34,7 +34,18 @@ class Research::Laboratory < ApplicationRecord foreign_key: :research_laboratory_id, dependent: :destroy + validates :name, :address, :city, :zipcode, :country, presence: true + scope :ordered, -> { order(:name) } + scope :for_search_term, -> (term) { + where(" + unaccent(research_laboratories.address) ILIKE unaccent(:term) OR + unaccent(research_laboratories.city) ILIKE unaccent(:term) OR + unaccent(research_laboratories.country) ILIKE unaccent(:term) OR + unaccent(research_laboratories.name) ILIKE unaccent(:term) OR + unaccent(research_laboratories.zipcode) ILIKE unaccent(:term) + ", term: "%#{sanitize_sql_like(term)}%") + } def to_s "#{name}" diff --git a/app/models/research/thesis.rb b/app/models/research/thesis.rb index e8fea9e2f..361daf38e 100644 --- a/app/models/research/thesis.rb +++ b/app/models/research/thesis.rb @@ -38,6 +38,12 @@ class Research::Thesis < ApplicationRecord belongs_to :director, class_name: 'University::Person' scope :ordered, -> { order(:title) } + scope :for_search_term, -> (term) { + where(" + unaccent(research_theses.abstract) ILIKE unaccent(:term) OR + unaccent(research_theses.title) ILIKE unaccent(:term) + ", term: "%#{sanitize_sql_like(term)}%") + } def to_s "#{title}" diff --git a/app/views/admin/education/schools/index.html.erb b/app/views/admin/education/schools/index.html.erb index 60026b10e..0e30adb40 100644 --- a/app/views/admin/education/schools/index.html.erb +++ b/app/views/admin/education/schools/index.html.erb @@ -1,5 +1,7 @@ <% content_for :title, Education::School.model_name.human(count: 2) %> +<%= render 'filters', current_path: admin_education_schools_path, filters: @filters if @filters.any? %> + <table class="table"> <thead> <tr> @@ -28,6 +30,9 @@ </tbody> </table> +<%= paginate @schools, theme: 'bootstrap-5' %> + + <% content_for :action_bar_right do %> <%= create_link Education::School %> <% end %> diff --git a/app/views/admin/education/teachers/index.html.erb b/app/views/admin/education/teachers/index.html.erb index 44222c52b..973534e4e 100644 --- a/app/views/admin/education/teachers/index.html.erb +++ b/app/views/admin/education/teachers/index.html.erb @@ -1,10 +1,10 @@ <% content_for :title, "#{t('education.teachers', count: 2)} (#{@teachers.total_count})" %> +<%= render 'filters', current_path: admin_education_teachers_path, filters: @filters if @filters.any? %> + <%= render 'admin/education/teachers/list', teachers: @teachers %> -<% if @teachers.total_pages > 1 %> - <%= paginate @teachers, theme: 'bootstrap-5' %> -<% end %> +<%= paginate @teachers, theme: 'bootstrap-5' %> <% content_for :action_bar_right do %> <%= link_to t('education.manage_teachers'), admin_university_people_path, class: button_classes if can?(:read, University::Person) %> diff --git a/app/views/admin/research/journals/index.html.erb b/app/views/admin/research/journals/index.html.erb index 51577a58d..e5fff3497 100644 --- a/app/views/admin/research/journals/index.html.erb +++ b/app/views/admin/research/journals/index.html.erb @@ -1,5 +1,7 @@ <% content_for :title, Research::Journal.model_name.human(count: 2) %> +<%= render 'filters', current_path: admin_research_journals_path, filters: @filters if @filters.any? %> + <table class="table"> <thead> <tr> diff --git a/app/views/admin/research/laboratories/index.html.erb b/app/views/admin/research/laboratories/index.html.erb index 5f6bfcc14..7ee9816c4 100644 --- a/app/views/admin/research/laboratories/index.html.erb +++ b/app/views/admin/research/laboratories/index.html.erb @@ -1,5 +1,7 @@ <% content_for :title, Research::Laboratory.model_name.human(count: 2) %> +<%= render 'filters', current_path: admin_research_laboratories_path, filters: @filters if @filters.any? %> + <table class="table"> <thead> <tr> diff --git a/app/views/admin/research/researchers/index.html.erb b/app/views/admin/research/researchers/index.html.erb index 2a56d4f11..d0256588d 100644 --- a/app/views/admin/research/researchers/index.html.erb +++ b/app/views/admin/research/researchers/index.html.erb @@ -1,5 +1,7 @@ <% content_for :title, t('research.researchers', count: 2) %> +<%= render 'filters', current_path: admin_research_researchers_path, filters: @filters if @filters.any? %> + <table class="table"> <thead> <tr> @@ -19,9 +21,8 @@ <% end %> </tbody> </table> -<% if @researchers.total_pages > 1 %> - <%= paginate @researchers, theme: 'bootstrap-5' %> -<% end %> + +<%= paginate @researchers, theme: 'bootstrap-5' %> <% content_for :action_bar_right do %> diff --git a/app/views/admin/research/theses/index.html.erb b/app/views/admin/research/theses/index.html.erb index bba33c839..7f13d5247 100644 --- a/app/views/admin/research/theses/index.html.erb +++ b/app/views/admin/research/theses/index.html.erb @@ -1,5 +1,7 @@ <% content_for :title, Research::Thesis.model_name.human(count: 2) %> +<%= render 'filters', current_path: admin_research_theses_path, filters: @filters if @filters.any? %> + <table class="table"> <thead> <tr> diff --git a/app/views/admin/university/person/alumni/index.html.erb b/app/views/admin/university/person/alumni/index.html.erb index 81016b583..fcc1509bd 100644 --- a/app/views/admin/university/person/alumni/index.html.erb +++ b/app/views/admin/university/person/alumni/index.html.erb @@ -1,5 +1,7 @@ <% content_for :title, "#{University::Person::Alumnus.model_name.human(count: 2)} (#{@alumni.total_count})" %> +<%= render 'filters', current_path: admin_university_person_alumni_path, filters: @filters if @filters.any? %> + <%= render 'admin/university/person/alumni/list', alumni: @alumni %> <%= paginate @alumni, theme: 'bootstrap-5' %> diff --git a/app/views/admin/university/person/alumnus/imports/new.html.erb b/app/views/admin/university/person/alumnus/imports/new.html.erb index ca77bb651..78665920c 100644 --- a/app/views/admin/university/person/alumnus/imports/new.html.erb +++ b/app/views/admin/university/person/alumnus/imports/new.html.erb @@ -7,7 +7,7 @@ La première ligne doit être dédiée aux entêtes.<br> Les noms des entêtes sont obligatoires et doivent être respectés strictement.<br> Les champs marqués d'une astérisque sont obligatoires.<br> - Les caractères doivent être encodés en UTF-8. + Les caractères doivent être encodés en UTF-8.<br> Les valeurs pour gender peuvent être m (masculin), f (féminin) et n (non binaire). </p> <%= simple_form_for [:admin, @import] do |f| %> -- GitLab