Skip to content

Commit

Permalink
add language selector component
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Sep 5, 2023
1 parent 4c1f6b1 commit c5fede7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/bp_search.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ function performSearch() {
includeNonProduction = jQuery("#search_include_non_production").is(":checked"),
includeOnlyDefinitions = jQuery("#search_require_definition").is(":checked"),
exactMatch = jQuery("#search_exact_match").is(":checked"),
categories = jQuery("#search_categories").val() || "";
categories = jQuery("#search_categories").val() || "",
language = jQuery("#select_search_language").val() || "";

// Set the list of search words to be blacklisted for the ontology ownership algorithm
Expand Down
25 changes: 25 additions & 0 deletions app/components/input/language_selector_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

class Input::LanguageSelectorComponent < ViewComponent::Base

def initialize(languages:, id: '', name: '' )
super
@languages = languages
@id = id
@name = languages
end

def languages_options
values = [['All languages', 'all']]

@languages.each do |key, label|
option = "<div>#{render(LanguageFieldComponent.new(value: key.to_s.downcase, label: label))}</div>"
values += [[option, key.to_s.downcase]]
end
values
end

def call
render SelectInputComponent.new(id: @id, name: @name, values: languages_options, placeholder: 'Select a language')
end
end
6 changes: 3 additions & 3 deletions app/views/search/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- @title = t("search.title")

%div.container.mt-5
%h1.display-4
%h1.display-4
= t("search.class_search")

= form_tag("/search", method: "post") do
Expand All @@ -20,7 +20,7 @@
%div.col-sm-2.mb-4 Search language
%div.col-sm-10.mb-4
%div.w-25
= render SelectInputComponent.new(id: "search_language", name: "search_language", values: [{id: "fr", title: "French", icon: "fi fi-fr fis"}, {id: "en", title: "English", icon: "fi fi-us fis"}], withIcon: true, placeholder: "Choose language")
= render Input::LanguageSelectorComponent.new(id:'search_language' , name:'search_language', languages: {fr: 'French', en: 'English'})
%div.col-sm-2= t("search.include_in_search") + ":"
%div.col-sm-10
%div.form-check
Expand All @@ -32,7 +32,7 @@
%div.form-check
= check_box(:search, :include_views, class: "form-check-input")
= label(:search, :include_views, t('search.ontology_views'), class: "form-check-label")

%div.col-sm-2= t("search.narrow_search_to") + ":"
%div.col-sm-10
%div.form-check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ def text(label: "Label", placeholder: "", error_message: "", helper_text: "")
def text_area(label: "Label", placeholder: "", error_message: "", helper_text: "", rows: 5)
render Input::TextAreaComponent.new(label: label, name: "name",value: '', placeholder: placeholder, error_message: error_message, helper_text: helper_text, rows: rows)
end

def language_input
render Input::LanguageSelectorComponent.new(languages: {fr: 'French', en: 'English'})
end
end

0 comments on commit c5fede7

Please sign in to comment.