From 5fcca0c58ae6f45deaf79747b7865860bd34102a Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Mon, 11 Dec 2023 12:57:14 +0000 Subject: [PATCH] some final tidying up, in particualr removed the fetch ols as JSON #1691 --- .../javascripts/controlled_vocabs.js.erb | 26 ---------- .../sample_controlled_vocabs_controller.rb | 25 ---------- .../sample_controlled_vocabs/_form.html.erb | 1 - config/routes.rb | 1 - ...ample_controlled_vocabs_controller_test.rb | 50 +------------------ 5 files changed, 1 insertion(+), 102 deletions(-) diff --git a/app/assets/javascripts/controlled_vocabs.js.erb b/app/assets/javascripts/controlled_vocabs.js.erb index 46f9c17fb9..4d1d0ddd1b 100644 --- a/app/assets/javascripts/controlled_vocabs.js.erb +++ b/app/assets/javascripts/controlled_vocabs.js.erb @@ -89,30 +89,6 @@ CVTerms = { handleOntologyTermsHTMLResponse: function (html) { $j('#add-term-button-row').before(html); }, - // processes the JSON response when fetching terms, and populates the term list - handleOntologyTermsJSONResponse: function (json) { - let index=0 - $j.each(json, function (key, term) { - //make a new term - let newTerm = $j('#new-term-row tbody').clone().html(); - - newTerm = newTerm.replace(/--index--/g, index); - $j('#add-term-button-row').before($j(newTerm)); - - let row = $j('table#new-terms tr.sample-cv-term').last(); - - let inputs = $j(row).find('td input'); - $j(inputs).prop('readonly',true); - - //inputs 0,1,2 are label, iri, and parent_iri - - $j(inputs[0]).val(term.label); - $j(inputs[1]).val(term.iri); - $j(inputs[2]).val(term.parent_iri); - - index++; - }); - }, // adds a new blank row to the terms list addNewTermRow: function () { let newTerm = $j('#new-term-row tbody').clone().html(); @@ -130,8 +106,6 @@ CVTerms = { }, // reports the error when the ajax method to fetch the terms is unsuccessful reportFetchError: function (error_message) { -// let json = JSON.parse(response); -// const error_message = json.errors[0].details; $j('div#fetch-error-message').text("An error occurred fetching the terms: " + error_message); $j('div#fetch-error-message').show(); }, diff --git a/app/controllers/sample_controlled_vocabs_controller.rb b/app/controllers/sample_controlled_vocabs_controller.rb index 2b8182e0b2..05b65f3d77 100644 --- a/app/controllers/sample_controlled_vocabs_controller.rb +++ b/app/controllers/sample_controlled_vocabs_controller.rb @@ -85,31 +85,6 @@ def destroy end end - def fetch_ols_terms - error_msg = nil - begin - source_ontology = params[:source_ontology_id] - root_uri = params[:root_uri] - - raise 'No root URI provided' if root_uri.blank? - - client = Ebi::OlsClient.new - terms = client.all_descendants(source_ontology, root_uri) - terms.reject! { |t| t[:iri] == root_uri } unless params[:include_root_term] == '1' - error_msg = "There are no descendant terms to populate the list." unless terms.present? - rescue StandardError => e - error_msg = e.message - end - - respond_to do |format| - if error_msg - format.json { render json: { errors: [{ details: error_msg }] }, status: :unprocessable_entity } - else - format.json { render json: terms.to_json } - end - end - end - def fetch_ols_terms_html error_msg = nil begin diff --git a/app/views/sample_controlled_vocabs/_form.html.erb b/app/views/sample_controlled_vocabs/_form.html.erb index b95507ac58..a79d14aed1 100644 --- a/app/views/sample_controlled_vocabs/_form.html.erb +++ b/app/views/sample_controlled_vocabs/_form.html.erb @@ -31,7 +31,6 @@
- <%#= f.select :source_ontology, Ebi::OlsClient.ontology_choices, { include_blank: 'No Ontology' }, class: 'form-control' -%> <%= select_cv_source_ontology(@sample_controlled_vocab) %>
diff --git a/config/routes.rb b/config/routes.rb index dc76ec4094..095c9b460a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -699,7 +699,6 @@ resources :sample_controlled_vocabs do collection do get :typeahead - get :fetch_ols_terms get :fetch_ols_terms_html end end diff --git a/test/functional/sample_controlled_vocabs_controller_test.rb b/test/functional/sample_controlled_vocabs_controller_test.rb index 0a8e24b5c3..c8659b5320 100644 --- a/test/functional/sample_controlled_vocabs_controller_test.rb +++ b/test/functional/sample_controlled_vocabs_controller_test.rb @@ -1,6 +1,7 @@ require 'test_helper' class SampleControlledVocabsControllerTest < ActionController::TestCase + include AuthenticatedTestHelper test 'show' do @@ -267,55 +268,6 @@ class SampleControlledVocabsControllerTest < ActionController::TestCase end end - test 'fetch ols terms as JSON with root term included' do - person = FactoryBot.create(:person) - login_as(person) - VCR.use_cassette('ols/fetch_obo_plant_cell_papilla') do - get :fetch_ols_terms, params: { source_ontology_id: 'go', - root_uri: 'http://purl.obolibrary.org/obo/GO_0090395', - include_root_term: '1' }, format: :json - - assert_response :success - res = JSON.parse(response.body) - assert_equal 4, res.length - iris = res.map { |term| term['iri'] } - assert_includes iris, 'http://purl.obolibrary.org/obo/GO_0090395' - assert_includes iris, 'http://purl.obolibrary.org/obo/GO_0090396' - assert_includes iris, 'http://purl.obolibrary.org/obo/GO_0090397' - end - end - - test 'fetch ols terms as JSON without root term included' do - person = FactoryBot.create(:person) - login_as(person) - VCR.use_cassette('ols/fetch_obo_plant_cell_papilla') do - get :fetch_ols_terms, params: { source_ontology_id: 'go', - root_uri: 'http://purl.obolibrary.org/obo/GO_0090395' }, format: :json - - assert_response :success - res = JSON.parse(response.body) - assert_equal 3, res.length - iris = res.map { |term| term['iri'] } - refute_includes iris, 'http://purl.obolibrary.org/obo/GO_0090395' - assert_includes iris, 'http://purl.obolibrary.org/obo/GO_0090396' - assert_includes iris, 'http://purl.obolibrary.org/obo/GO_0090397' - end - end - - test 'fetch ols terms as JSON with wrong URI' do - person = FactoryBot.create(:person) - login_as(person) - VCR.use_cassette('ols/fetch_obo_bad_term') do - get :fetch_ols_terms, params: { source_ontology_id: 'go', - root_uri: 'http://purl.obolibrary.org/obo/banana', - include_root_term: '1' }, format: :json - - assert_response :unprocessable_entity - res = JSON.parse(response.body) - assert_equal '404 Not Found', res.dig('errors', 0, 'details') - end - end - test 'fetch ols terms as HTML with wrong URI' do person = FactoryBot.create(:person) login_as(person)