Skip to content

Commit

Permalink
clean recommender page controllers code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal committed Jan 16, 2024
1 parent 98a1188 commit 9e2ccc3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def annotator_recommender_form
if params[:submit_button] == "annotator"
redirect_to "/annotator?text=#{params[:text]}"
elsif params[:submit_button] == "recommender"
redirect_to "/recommender?text=#{params[:text]}"
redirect_to "/recommender?input=#{params[:input]}"
end
end

Expand Down
20 changes: 2 additions & 18 deletions app/controllers/recommender_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,27 +72,11 @@ def create
end

def recommendation_ontologies(recommendation)
ontologies = []
recommendation.ontologies.each do |ontology|
ont = {
acronym: ontology.acronym,
link: url_to_endpoint(ontology.id)
}
ontologies.push(ont)
end
ontologies
recommendation.ontologies.map { |ont| { acronym: ont.acronym, link: ont.id } }
end

def recommendation_annotations(recommendation)
annotations = []
recommendation.coverageResult.annotations.each do |annotation|
ant = {
text: annotation.text,
link: url_to_endpoint(annotation.annotatedClass.links['self'])
}
annotations.push(ant)
end
annotations
recommendation.coverageResult.annotations.map{|annotation| {text: annotation.text, link: url_to_endpoint(annotation.annotatedClass.links['self'])}}
end

def percentage(string)
Expand Down
14 changes: 14 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -584,4 +584,18 @@ def prefix_property_url(key_string, key = nil)
nil
end
end

def show_advanced_options_button
content_tag(:div, class: 'advanced-options-button', 'data-action': 'click->reveal-component#show', 'data-reveal-component-target': 'showButton') do
inline_svg_tag('icons/settings.svg') +
content_tag(:div, 'Show advanced options', class: 'text')
end
end

def hide_advanced_options_button
content_tag(:div, class: 'advanced-options-button d-none', 'data-action': 'click->reveal-component#hide', 'data-reveal-component-target': 'hideButton') do
inline_svg_tag('icons/hide.svg') +
content_tag(:div, 'Hide advanced options', class: 'text')
end
end
end
7 changes: 1 addition & 6 deletions app/javascript/controllers/recommender_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class extends Controller {
}

handleHighlightedChange(){
let recommandations_area = document.getElementById('recommender-page-result-area')
let recommandations_area = this.resultTarget
let jsonString = document.querySelector('input[name="highlighted_recommendation"]:checked').value;
let jsonStringModified = jsonString.replace(/:text/g, '"text"').replace(/:link/g, '"link"').replace(/=>/g, ':');
let jsonArray = JSON.parse(jsonStringModified);
Expand All @@ -46,9 +46,4 @@ export default class extends Controller {
#toggle(element){
element.classList.toggle('d-none')
}





}
2 changes: 1 addition & 1 deletion app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
%hr.home-section-line/
.home-card{'data-controller': 'sample-text'}
%form{action: "/annotator_recommender_form", method: "post"}
%textarea.home-recommendations-and-annotations{rows: "4" , placeholder: t('home.paste_text_prompt'), name: "text", 'data-sample-text-target': "input"}
%textarea.home-recommendations-and-annotations{rows: "4" , placeholder: t('home.paste_text_prompt'), name: "input", 'data-sample-text-target': "input"}
%input.d-none{type: "submit", name: "submit_button" ,value: "annotator", id: "annotator_submit"}/
%input.d-none{type: "submit" , name: "submit_button" ,value: "recommender", id: "recommender_submit"}/
.home-services-buttons.container
Expand Down
12 changes: 3 additions & 9 deletions app/views/recommender/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Insert sample text
= inline_svg_tag 'icons/arrow-curved-up.svg'

#recommender-page-result-area.recommender-page-text-area-results{class: is_input ? "d-none" : "", 'data-recommender-target': 'result'}
.recommender-page-text-area-results{class: is_input ? "d-none" : "", 'data-recommender-target': 'result'}
.text
= params[:input]
.recommender-page-options
Expand All @@ -46,14 +46,8 @@
= render Input::RadioChipComponent.new(label: 'Ontologies', name: 'output_type', value: '1', checked: check_output)
.ontology-sets-choice
= render Input::RadioChipComponent.new(label: 'Ontology sets', name: 'output_type', value: '2', checked: !check_output)
.advanced-options-button{'data-action': 'click->reveal-component#show', 'data-reveal-component-target': 'showButton'}
= inline_svg_tag "icons/settings.svg"
.text
Show advanced options
.advanced-options-button.d-none{'data-action': 'click->reveal-component#hide', 'data-reveal-component-target': 'hideButton'}
= inline_svg_tag 'icons/hide.svg'
.text
Hide advanced options
= show_advanced_options_button
= hide_advanced_options_button

.recommender-advanced-options.d-none{'data-reveal-component-target': 'item'}
.weights-configuration
Expand Down

0 comments on commit 9e2ccc3

Please sign in to comment.