diff --git a/app/controllers/extranet/alumni/organizations_controller.rb b/app/controllers/extranet/alumni/organizations_controller.rb index 19ecddd17791eac1648aaa28912005d9ff209f75..c13e2c361ff60c1e1fc900804b233cd34527e10d 100644 --- a/app/controllers/extranet/alumni/organizations_controller.rb +++ b/app/controllers/extranet/alumni/organizations_controller.rb @@ -2,7 +2,9 @@ class Extranet::Alumni::OrganizationsController < Extranet::Alumni::ApplicationC def index @facets = University::Organization::Facets.new params[:facets], { model: about&.university_person_alumni_organizations, - about: about + about: about, + language: current_language, + categories: current_university.organization_categories } @organizations = @facets.results .ordered(current_language) diff --git a/app/controllers/extranet/alumni/persons_controller.rb b/app/controllers/extranet/alumni/persons_controller.rb index 7b73844ddb72f7c485eb90db5a118311c0458503..2c37e2c32612e32d1c416e6987b36f8cd1c31ddc 100644 --- a/app/controllers/extranet/alumni/persons_controller.rb +++ b/app/controllers/extranet/alumni/persons_controller.rb @@ -3,13 +3,14 @@ class Extranet::Alumni::PersonsController < Extranet::Alumni::ApplicationControl @facets = University::Person::Alumnus::Facets.new params[:facets], { model: about&.university_person_alumni, about: about, - language: current_language + language: current_language, + categories: current_university.person_categories } + @count = @facets.results.count @people = @facets.results .ordered(current_language) .page(params[:page]) .per(72) - @count = @people.total_count breadcrumb end diff --git a/app/models/communication/extranet/document.rb b/app/models/communication/extranet/document.rb index 281c659ada35a254acda2b03548897f88207755f..4979fea5f8392c8e01f5136975825c0807fb4149 100644 --- a/app/models/communication/extranet/document.rb +++ b/app/models/communication/extranet/document.rb @@ -36,4 +36,12 @@ class Communication::Extranet::Document < ApplicationRecord validates :category, :kind, presence: true + scope :for_search_term, -> (term, language) { + joins(:localizations) + .where(communication_extranet_document_localizations: { language_id: language.id }) + .where(" + unaccent(communication_extranet_document_localizations.name) ILIKE unaccent(:term) + ", term: "%#{sanitize_sql_like(term)}%") + } + end diff --git a/app/models/communication/extranet/document/facets.rb b/app/models/communication/extranet/document/facets.rb index 96d9ac46d154401ad144d903929fdbf61f0765dd..a8078769287d5ade50d5c17343e7cce3e130dee4 100644 --- a/app/models/communication/extranet/document/facets.rb +++ b/app/models/communication/extranet/document/facets.rb @@ -1,4 +1,6 @@ class Communication::Extranet::Document::Facets < FacetedSearch::Facets + attr_reader :language + def initialize(params, extranet, language) super(params) diff --git a/app/models/university/organization/facets.rb b/app/models/university/organization/facets.rb index 1c6a3e806b6323ec85e1a8134224894a90c7b441..e7771664204fd3a0fb7551c6db2f5a0f40200694 100644 --- a/app/models/university/organization/facets.rb +++ b/app/models/university/organization/facets.rb @@ -1,13 +1,31 @@ class University::Organization::Facets < FacetedSearch::Facets + attr_reader :language, :categories + def initialize(params, options) - super params + super params + @model = options[:model] + @about = options[:about] + @language = options[:language] + @categories = options[:categories] + add_name + add_taxonomies + end - @model = options[:model] - @about = options[:about] + protected + def add_name filter_with_text :name, { title: University::Organization::Localization.human_attribute_name('name') } - + end + + def add_taxonomies + categories.taxonomies.each do |taxonomy| + taxonomy_l10n = taxonomy.localization_for(language) + next if taxonomy_l10n.nil? + add_facet FacetedSearch::Facets::Taxonomy, taxonomy_l10n.slug, { + l10n: taxonomy_l10n + } + end end end diff --git a/app/models/university/person/alumnus/facets.rb b/app/models/university/person/alumnus/facets.rb index 3b1d123bf2a30502026b27ad7c2ec9aac95ff6b0..124e79dd22ae0064fd105fd05041aeb8eb6dd9a8 100644 --- a/app/models/university/person/alumnus/facets.rb +++ b/app/models/university/person/alumnus/facets.rb @@ -1,26 +1,51 @@ class University::Person::Alumnus::Facets < FacetedSearch::Facets + attr_reader :language, :categories + def initialize(params, options) - super params + super params + @model = options[:model] + @about = options[:about] + @language = options[:language] + @categories = options[:categories] + add_name + add_years + add_programs + add_taxonomies + end - @model = options[:model] - @about = options[:about] - @language = options[:language] + protected + def add_name filter_with_text :name, { title: University::Person::Localization.human_attribute_name('name') } + end + def add_years filter_with_list :diploma_years, { source: @about.academic_years.ordered, title: Education::AcademicYear.model_name.human(count: 2), habtm: true } + end + def add_programs + return if @about.is_a? Education::Program filter_with_checkboxes :diploma_programs, { source: @about.programs.ordered(@language), title: Education::Program.model_name.human(count: 2), display_method: Proc.new { |program| program.to_s_in(@language) }, habtm: true - } unless @about.is_a? Education::Program + } + end + + def add_taxonomies + categories.taxonomies.each do |taxonomy| + taxonomy_l10n = taxonomy.localization_for(language) + next if taxonomy_l10n.nil? + add_facet FacetedSearch::Facets::Taxonomy, taxonomy_l10n.slug, { + l10n: taxonomy_l10n + } + end end end diff --git a/app/models/university/person/category.rb b/app/models/university/person/category.rb index dbba705eeb3f54fbd72d97743d29924ea8c91c36..a36bfad675c95c382cb9a7204f9d0b8a77d00040 100644 --- a/app/models/university/person/category.rb +++ b/app/models/university/person/category.rb @@ -26,9 +26,10 @@ class University::Person::Category < ApplicationRecord include Localizable include WithUniversity - has_and_belongs_to_many :people, + has_and_belongs_to_many :university_people, class_name: 'University::Person', join_table: :university_people_categories + alias :people :university_people def dependencies localizations diff --git a/app/services/faceted_search/facets/taxonomy.rb b/app/services/faceted_search/facets/taxonomy.rb new file mode 100644 index 0000000000000000000000000000000000000000..c413da0aec07ea7740d0222cf0d60cbf782977c1 --- /dev/null +++ b/app/services/faceted_search/facets/taxonomy.rb @@ -0,0 +1,83 @@ +module FacetedSearch + class Facets::Taxonomy < Facets::List + attr_reader :l10n, :taxonomy, :language, :university + + def initialize(name, params, facets, options) + @name = name + @params = params + @facets = facets + @options = options + @l10n = options[:l10n] + @taxonomy = @l10n.about + @language = @l10n.language + @university = @taxonomy.university + end + + def title + l10n.to_s + end + + def values + descendants.ordered(language) + end + + # INNER JOIN "university_organizations_categories" "university_organizations_categories_01234567-89ab-cdef-0123-4567890abcde" + # ON "university_organizations_categories_01234567-89ab-cdef-0123-4567890abcde"."organization_id" = "university_organizations"."id" + # WHERE "university_organizations_categories_01234567-89ab-cdef-0123-4567890abcde"."category_id" IN (?) + def add_scope(scope) + return scope if params_array.blank? + + scope + .joins(" + INNER JOIN \"#{association_join_table_name}\" \"#{association_join_table_name_alias}\" + ON \"#{association_join_table_name_alias}\".\"#{join_table_foreign_key}\" = \"#{table_name}\".\"id\" + ") + .where( + "\"#{association_join_table_name_alias}\".\"#{join_table_association_foreign_key}\" IN (?)", + params_array + ) + end + + protected + + def categories_class + taxonomy.class + end + + # university_organizations + def table_name + @facets.model.klass.table_name + end + + def habtm_reflection + @association_reflection ||= @facets.model.klass._reflections[:categories].parent_reflection + end + + # organization_id + def join_table_foreign_key + @join_table_foreign_key ||= habtm_reflection.foreign_key + end + + # category_id + def join_table_association_foreign_key + @join_table_association_foreign_key ||= habtm_reflection.association_foreign_key + end + + # university_organizations_categories + def association_join_table_name + @association_join_table_name ||= habtm_reflection.join_table + end + + # university_organizations_categories_01234567-89ab-cdef-0123-4567890abcde + def association_join_table_name_alias + @association_join_table_name_alias ||= "#{association_join_table_name}_#{taxonomy.id}" + end + + def descendants + categories_class.where( + university: university, + id: taxonomy.descendants.pluck(:id) + ) + end + end +end \ No newline at end of file diff --git a/app/services/faceted_search/facets/text.rb b/app/services/faceted_search/facets/text.rb new file mode 100644 index 0000000000000000000000000000000000000000..bad0c0bdb41bc901f51b9b369196e3f3042114e4 --- /dev/null +++ b/app/services/faceted_search/facets/text.rb @@ -0,0 +1,15 @@ +module FacetedSearch + class Facets::Text < Facets::Default + include ActiveRecord::Sanitization + + def placeholder + @options[:placeholder] + end + + def add_scope(scope) + return scope if params.blank? + language = facets.language + scope.for_search_term(params, language) + end + end +end \ No newline at end of file diff --git a/app/views/extranet/alumni/cohorts/show.html.erb b/app/views/extranet/alumni/cohorts/show.html.erb index 99270e2d45cd8a970c28c347e0c6b59580b42b6a..8e88372f09be0bd626ae908ce6ea537b0f24e8b4 100644 --- a/app/views/extranet/alumni/cohorts/show.html.erb +++ b/app/views/extranet/alumni/cohorts/show.html.erb @@ -6,9 +6,14 @@ </p> <% end %> +<% +subtitle_parts = [] +subtitle_parts << @cohort.program.diploma.to_s_in(current_language) if @cohort.program.diploma.present? +subtitle_parts << @cohort.program.to_s_in(current_language) +%> + <p class="mb-5"> - <%= @cohort.program.diploma.to_s_in(current_language) %> - — <%= @cohort.program.to_s_in(current_language) %> + <%= subtitle_parts.join(' — ') %> </p> <%= render 'extranet/alumni/persons/list', people: @cohort.people %> diff --git a/app/views/extranet/alumni/persons/show.html.erb b/app/views/extranet/alumni/persons/show.html.erb index 39599b1dde6f9a651793d3373a25c302a0713018..a4cd93caf3cb2f013f32de14656230c387354ba7 100644 --- a/app/views/extranet/alumni/persons/show.html.erb +++ b/app/views/extranet/alumni/persons/show.html.erb @@ -18,7 +18,7 @@ <% @person&.cohorts&.each do |cohort| %> <% program_l10n = cohort.program.best_localization_for(current_language) - diploma_l10n = cohort.program.diploma.best_localization_for(current_language) + diploma_l10n = cohort.program.diploma.best_localization_for(current_language) if cohort.program.diploma.present? school_l10n = cohort.school.best_localization_for(current_language) %> <li class="experiences__experience py-4 border-top"> @@ -27,7 +27,9 @@ <p class="mb-0"> <%= link_to [:alumni, cohort] do %> <b><%= program_l10n %></b><br> - <%= diploma_l10n %><br> + <% if diploma_l10n.present? %> + <%= diploma_l10n %><br> + <% end %> <%= cohort.year %> <% end %> </p> diff --git a/app/views/faceted_search/facets/taxonomy/_all.html.erb b/app/views/faceted_search/facets/taxonomy/_all.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..9b01cfde9dc75ca2562925dbd24e48f71226fa05 --- /dev/null +++ b/app/views/faceted_search/facets/taxonomy/_all.html.erb @@ -0,0 +1,20 @@ +<% anchor ||= '' %> +<% if facet.values.any? %> + <li> + <% unless facet.title.blank? %><b><%= facet.title %></b><% end %> + <ol class="faceted__facet__list list-unstyled"> + <% facet.values.each do |taxon| %> + <% + identifier = taxon.id + display_value = taxon.to_s_in(current_language) + %> + <li class="faceted__facet__list__value <%= 'faceted__facet__list__value--selected' if facet.value_selected?(identifier) %>"> + <%= render 'faceted_search/link', + display_value: display_value, + path: facet.facets.path_for(facet, identifier) + anchor, + searchable: facet.searchable %> + </li> + <% end %> + </ol> + </li> +<% end %> \ No newline at end of file diff --git a/app/views/faceted_search/facets/taxonomy/_selected.html.erb b/app/views/faceted_search/facets/taxonomy/_selected.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..46ddb10a292a7eb8b32ab9897638d604b233ed1d --- /dev/null +++ b/app/views/faceted_search/facets/taxonomy/_selected.html.erb @@ -0,0 +1,13 @@ +<% anchor ||= '' %> +<% if facet.values.any? %> + <% facet.values.each do |taxon| %> + <% identifier = taxon.id %> + <% if facet.value_selected?(identifier) %> + <% display_value = taxon.to_s_in(current_language) %> + <%= render 'faceted_search/facets/facet-selected', + title: facet.title, + value: display_value, + path: facet.facets.path_for(facet, identifier) + anchor %> + <% end %> + <% end %> +<% end %> \ No newline at end of file