Skip to content

Commit

Permalink
Merge to master: Release 2.7.4.1 - Fix annotator fast context & add s…
Browse files Browse the repository at this point in the history
…earch json icon (#563)

* Fix: Annotator fast context special chars issues & statistics page syntax error (#561)

* fix statistics page syntax error

* update ontoportal instances home section title

* fix fast context option in annotator page

* remove special chars from annotator's input on submit to avoid errors

* Feature: Add json button to search page (#562)

* add json button ui to search page

* extract json_link method from annotator controller to application controller

* build the search page json link using json_link method

* move the search json button down besides the advanced options button

* remove this usage of api_params instead of direct params in search controller

---------

Co-authored-by: Syphax Bouazzouni <[email protected]>

---------

Co-authored-by: Bilel Kihal <[email protected]>
  • Loading branch information
syphax-bouazzouni and Bilelkihal authored Apr 5, 2024
1 parent 03d2f2e commit f550d83
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 29 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
}
.search-page-advanced-button{
display: flex;
align-items: center;
}
.search-page-advanced-button :hover{
cursor: pointer;
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/annotator_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def annotator_results(uri)
if params[:text] && !params[:text].empty?
@init_whole_word_only = true
api_params = {
text: escape(params[:text]),
text: remove_special_chars(params[:text]),
ontologies: params[:ontologies],
semantic_types: params[:semantic_types],
semantic_groups: params[:semantic_groups],
Expand Down Expand Up @@ -201,13 +201,13 @@ def empty_advanced_options
params[:fast_context].nil? &&
params[:lemmatize].nil?
end


def json_link(url, optional_params)
base_url = "#{url}?"
filtered_params = optional_params.reject { |_, value| value.nil? }
optional_params_str = filtered_params.map { |param, value| "#{param}=#{value}" }.join("&")
return base_url + optional_params_str + "&apikey=#{$API_KEY}"
def remove_special_chars(input)
regex = /^[a-zA-Z0-9\s]*$/
unless input.match?(regex)
input.gsub!(/[^\w\s]/, '')
end
input
end

end
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,13 @@ def request_lang
helpers.request_lang
end

def json_link(url, optional_params)
base_url = "#{url}?"
filtered_params = optional_params.reject { |_, value| value.nil? }
optional_params_str = filtered_params.map { |param, value| "#{param}=#{value}" }.join("&")
return base_url + optional_params_str + "&apikey=#{$API_KEY}"
end

private
def not_found_record(exception)
@error_message = exception.message
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def index
params[:query] = nil
@advanced_options_open = false
@search_results = []
@json_url = json_link("#{rest_url}/search", {})

return if @search_query.empty?

Expand All @@ -19,6 +20,7 @@ def index

@advanced_options_open = !search_params_empty?
@search_results = aggregate_results(@search_query, results)
@json_url = json_link("#{rest_url}/search", params.permit!.to_h)
end

def json_search
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def url_to_endpoint(url)
endpoint
end

def search_json_link(link = @json_url, style: '')
custom_style = "font-size: 50px; line-height: 0.5; margin-left: 6px; #{style}".strip
render IconWithTooltipComponent.new(icon: "json.svg",link: link, target: '_blank', title: t('fair_score.go_to_api'), size:'small', style: custom_style)
end

def resolve_namespaces
RESOLVE_NAMESPACE
Expand Down
37 changes: 20 additions & 17 deletions app/views/search/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
= render Buttons::RegularButtonComponent.new(id:'search-page-button', value: "Search", variant: "primary", type: "submit") do |btn|
= btn.icon_right do
= inline_svg_tag "icons/search.svg"


.search-page-advanced{'data-reveal-component-target': 'item', class: "#{@advanced_options_open ? '' : 'd-none'}"}
.left
Expand All @@ -17,14 +17,14 @@
= t('search.advanced_options.search_language')
.field
= search_language_selector(name: 'lang', selected: params[:lang])

.filter-container
.title
= t("search.advanced_options.ontologies")
.field
= ontologies_selector(id:'search_page_ontologies' ,name: 'ontologies[]', selected: params[:ontologies]&.split(','))

.right
.right
.filter-container
.title
= t("search.advanced_options.include_in_search_title")
Expand All @@ -40,20 +40,23 @@
= render(ChipsComponent.new(name: 'require_exact_match', label: t('search.advanced_options.show_only_values.exact_matches'), checked: params[:require_exact_match]))
= render(ChipsComponent.new(name: 'require_definition', label: t('search.advanced_options.show_only_values.classes_with_definitions'), checked: params[:require_definition]))

.search-page-options
- if @search_results
.search-page-number-of-results
.search-page-options{class: @search_results.empty? ? 'justify-content-end': ''}
- unless @search_results.empty?
.search-page-number-of-results
= "#{t('search.match_in')} #{@search_results.length} #{t('search.ontologies')}"
.search-page-advanced-button.show-options{class: "#{@advanced_options_open ? 'd-none' : ''}",'data': {'action': 'click->reveal-component#show', 'reveal-component-target': 'showButton'}}
.icon
=inline_svg_tag 'icons/settings.svg'
.text
= t('search.show_advanced_options')
.search-page-advanced-button.hide-options{class: "#{@advanced_options_open ? '' : 'd-none'}", 'data': {'action': 'click->reveal-component#hide', 'reveal-component-target': 'hideButton'}}
.icon
=inline_svg_tag 'icons/hide.svg'
.text
= t('search.hide_advanced_options')
%div.d-flex
.search-page-json.mx-4
= search_json_link
.search-page-advanced-button.show-options{class: "#{@advanced_options_open ? 'd-none' : ''}",'data': {'action': 'click->reveal-component#show', 'reveal-component-target': 'showButton'}}
.icon
=inline_svg_tag 'icons/settings.svg'
.text
= t('search.show_advanced_options')
.search-page-advanced-button.hide-options{class: "#{@advanced_options_open ? '' : 'd-none'}", 'data': {'action': 'click->reveal-component#hide', 'reveal-component-target': 'hideButton'}}
.icon
=inline_svg_tag 'icons/hide.svg'
.text
= t('search.hide_advanced_options')
- if @search_results
.search-page-results-container
- number = 0
Expand All @@ -69,7 +72,7 @@
- number = number + 1
- c.reuse(r[:root].merge(is_sub_component: true, number: number)) do |b|
- r[:descendants].each { |dd| b.subresult(dd.merge(is_sub_component: true))}

- if @search_results.empty? && !@search_query.empty?
.browse-empty-illustration
%img{:src => "#{asset_path("empty-box.svg")}"}
Expand Down
6 changes: 3 additions & 3 deletions app/views/statistics/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
= t('statistics.lead', last_years: Date.today.year - Date.parse(@merged_data[:labels].first).year)
%div.container
%div
= chart_component(title: nil, type: 'line', show_legend: true,
labels: @merged_data[:labels],
datasets: visits_chart_dataset_array({ t('statistics.ontologies'): @merged_data[:visits][2] ,t('statistics.users'): @merged_data[:visits][0], t('statistics.projects'): @merged_data[:visits][1]}, fill: false))
= chart_component(title: nil, type: 'line', show_legend: true,
labels: @merged_data[:labels], datasets: visits_chart_dataset_array({ t('statistics.ontologies') => @merged_data[:visits][2],
t('statistics.users') => @merged_data[:visits][0], t('statistics.projects') => @merged_data[:visits][1] }, fill: false))

%div.pb-3.pb-md-4
- size = @merged_data[:labels].size - 1
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ en:
paste_text_prompt: Enter a paragraph of text or some keywords...
recommender_annotator: Recommender and Annotator
support_and_collaborations: Support & Collaborations
ontoportal_instances: Ontoportal Instances
ontoportal_instances: Other OntoPortal Instances
see_details: See details
info_tooltip_text: "You are seing the average scores for all the public ontologies in AgroPortal. FAIR scores are computed with the O'FAIRe methodology. More details here: https://github.com/agroportal/fairness"
average: Average
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ fr:
</blockquote>
home:
ontoportal_instances: "Instances d'Ontoportal"
ontoportal_instances: "Autres installations d’OntoPortal"
bug: Bug
proposition: Proposition
question: Question
Expand Down

0 comments on commit f550d83

Please sign in to comment.