diff --git a/.env.sample b/.env.sample index 94f4a336b4..6a8e41d243 100644 --- a/.env.sample +++ b/.env.sample @@ -39,5 +39,3 @@ OP_API_URL="https://data.bioontology.org" API_IMAGE_REPOSITORY=agroportal ## Image tag/version from which the ontoportal api will be built API_IMAGE_TAG=master - - diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 1a42c65807..52e60fbadd 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,13 +12,9 @@ // //= require bioportal //= require admin/licenses -//= require bp_ajax_controller -//= require bp_notes //= require bp_form_complete //= require bp_admin //= require concepts //= require projects //= require Chart.min //= require application_esbuild - - diff --git a/app/assets/javascripts/bp_ajax_controller.js b/app/assets/javascripts/bp_ajax_controller.js deleted file mode 100644 index a67e66550a..0000000000 --- a/app/assets/javascripts/bp_ajax_controller.js +++ /dev/null @@ -1,187 +0,0 @@ - -"use strict"; - -// Note similar code in concepts_helper.rb mirrors the following code: -function bp_ont_link(ont_acronym){ - return "/ontologies/" + ont_acronym; -} -function bp_cls_link(cls_id, ont_acronym){ - return bp_ont_link(ont_acronym) + "?p=classes&conceptid=" + encodeURIComponent(cls_id); -} -function get_link_for_cls_ajax(cls_id, ont_acronym) { - // ajax call will replace the class label using data attributes (triggered by class='cls4ajax') - let ajax_uri = '/ajax/classes/label' - let data_cls = `data-label-ajax-cls-id-value='${cls_id}' ` - let data_ont = `data-label-ajax-ontology-acronym-value='${ont_acronym}'` - let data_ajax_uri = `data-label-ajax-ajax-uri-value='${ajax_uri}' ` - - let data = `data-controller='label-ajax' ${data_ont} ${data_cls} ${data_ajax_uri}` - - return `${cls_id}` -} - -function get_link_for_ont_ajax(ont_acronym) { - var data_ont = " data-ont='" + ont_acronym + "' "; - return "" + ont_acronym + ""; -} - -var - ajax_process_interportal_cls_interval = null, - ajax_process_ont_interval = null, - ajax_process_timeout = 20, // Timeout after 20 sec. - ajax_process_timing = 250; // It takes about 250 msec to resolve a class ID to a prefLabel - -var ajax_process_init = function () { - ajax_process_ont_init(); - ajax_process_interportal_cls_init(); -}; - -var ajax_process_halt = function () { - ajax_process_ont_halt(); - ajax_process_interportal_cls_halt(); -}; - - -// ************************************************************************************** -// ONTOLOGY NAMES - -// Note: If we don't query every time, using the array should be faster; it -// means the ajax_ont_init must be called after all the elements -// are created because they will not be detected in a dynamic iteration. -var ajax_ont_array = []; -var ajax_process_ont_init = function() { - ajax_ont_array = jQuery("a.ont4ajax").toArray(); - ajax_process_ont_interval = window.setInterval(ajax_process_ont, ajax_process_timing); -}; -var ajax_process_ont_halt = function () { - ajax_ont_array = []; - window.clearInterval(ajax_process_ont_interval); // stop the ajax process - // Note: might leave faulty href links, but it usually means moving on to entirely different content - // so it's not likely those links will be available for interaction. - // clear all the classes and ontologies to be resolved by ajax - //jQuery("a.ont4ajax").removeClass('ont4ajax'); - //jQuery("a.ajax-modified-ont").removeClass('ajax-modified-ont'); -}; -var ajax_process_ont = function() { - if( ajax_ont_array.length === 0 ){ - ajax_process_ont_halt(); - return true; - } - // Note: If we don't query every time, using the array should be faster; it - // means the ajax_ont_init must be called after all the elements - // are created because they will not be detected in a dynamic iteration. - //var linkA = jQuery("a.ont4ajax").first(); - var linkA = ajax_ont_array.shift(); - if(linkA === undefined){ - return true; - } - linkA = jQuery(linkA); - if(linkA.hasClass('ajax-modified-ont') ){ - // How did we get here? It should not have the ont4ajax class! - linkA.removeClass('ont4ajax'); - return true; // processed this one already. - } - linkA.removeClass('ont4ajax'); // processing this one. - var ont_acronym = linkA.attr('data-ont'); - var ajax_uri = "/ajax/json_ontology/?ontology=" + encodeURIComponent(ont_acronym); - jQuery.ajax({ - url: ajax_uri, - timeout: ajax_process_timeout * 1000, - success: function(data){ - if(typeof data !== "undefined" && data.hasOwnProperty('name')){ - var ont_name = data.name; - linkA.text(ont_name); - linkA.addClass('ajax-modified-ont'); // processed this one. - // find and process any identical ontologies - jQuery('a[href="/ontologies/' + data.acronym + '"]').each(function(i,e){ - var link = jQuery(this); - if(! link.hasClass('ajax-modified-ont') ){ - link.removeClass('ont4ajax'); // processing this one. - link.text(ont_name); - link.addClass('ajax-modified-ont'); // processed this one. - } - }); - } - }, - error: function(data){ - linkA.addClass('ajax-error'); // processed this one. - } - }); -}; - - -// ************************************************************************************** -// INTERPORTAL CLASS LABELS - -// Note: If we don't query every time, using the array should be faster; it -// means the ajax_process_init must be called after all the elements -// are created because they will not be detected in a dynamic iteration. -var ajax_interportal_cls_array = []; - -var ajax_process_interportal_cls_init = function() { - ajax_interportal_cls_array = jQuery("a.interportalcls4ajax").toArray(); - ajax_process_interportal_cls_interval = window.setInterval(ajax_process_interportal_cls, ajax_process_timing); -}; - -var ajax_process_interportal_cls_halt = function () { - ajax_interportal_cls_array = []; - window.clearInterval(ajax_process_interportal_cls_interval); // stop the ajax process - // Note: might leave faulty href links, but it usually means moving on to entirely different content - // so it's not likely those links will be available for interaction. - // clear all the classes and ontologies to be resolved by ajax - //jQuery("a.cls4ajax").removeClass('cls4ajax'); - //jQuery("a.ajax-modified-cls").removeClass('ajax-modified-cls'); -}; - -var ajax_process_interportal_cls = function() { - // Check on whether to stop the ajax process - if( ajax_interportal_cls_array.length === 0 ){ - ajax_process_interportal_cls_halt(); - return true; - } - // Note: If we don't query every time, using the array should be faster; it - // means the ajax_process_init must be called after all the elements - // are created because they will not be detected in a dynamic iteration. - //var linkA = jQuery("a.cls4ajax").first(); - var linkA = ajax_interportal_cls_array.shift(); // put first item in linkA and delete it from array - if(linkA === undefined){ - return true; - } - linkA = jQuery(linkA); - if(linkA.hasClass('ajax-modified-cls') ){ - // How did we get here? It should not have the interportalcls4ajax class! - linkA.removeClass('interportalcls4ajax'); - return true; // processing or processed this one already. - } - linkA.removeClass('interportalcls4ajax'); // processing this one. - var unique_id = linkA.attr('href'); - - var portal_acronym = linkA.attr('portal-cls'); - var ajax_uri = linkA.attr('data-cls') + jQuery(document).data().bp.config.interportal_hash[portal_acronym].apikey; - jQuery.ajax({ - url: ajax_uri, - timeout: ajax_process_timeout * 1000, - success: function(data){ - var label = data.prefLabel - if (typeof label !== "undefined" && label.length > 0) { - linkA.html(label); - linkA.addClass('ajax-modified-cls'); - // find and process any identical classes (low probability) - jQuery( 'a[href="' + unique_id + '"]').each(function(i,e){ - var link = jQuery(this); - if(! link.hasClass('ajax-modified-cls') ){ - link.removeClass('interportalcls4ajax'); // processing this one. - link.html(label); - link.addClass('ajax-modified-cls'); // processed this one. - } - }); - } else { - // remove the unique_id separator and the ontology acronym from the href - linkA.addClass('ajax-modified-cls'); - } - }, - error: function(data){ - linkA.addClass('ajax-error'); // processed this one. - } - }); -}; diff --git a/app/assets/javascripts/bp_notes.js b/app/assets/javascripts/bp_notes.js deleted file mode 100644 index 61f9e8f447..0000000000 --- a/app/assets/javascripts/bp_notes.js +++ /dev/null @@ -1,42 +0,0 @@ -function hideOrUnhideArchivedOntNotes() { - if (jQuery("#hide_archived_ont:checked").val() !== undefined) { - // Checked - ontNotesTable.fnFilter('false', ont_columns.archived); - } else { - // Unchecked - ontNotesTable.fnFilter('', ont_columns.archived, true, false); - } -} - -function wireOntTable(ontNotesTableNew, showTarget= true, enableDelete = false) { - jQuery.data(document.body, "ontology_id", "#{@ontology.acronym}"); - - - let ont_columns = { archived: 3, date: 7, subjectSort: 2 }; - var ontNotesTable = ontNotesTableNew; - let columns = [ - { "bVisible": enableDelete }, // Delete - { "iDataSort": ont_columns.subjectSort }, // Subject link - { "bVisible": false }, // Subject for sort - { "bVisible": false }, // Archived for filter - null, // Author - null, // Type - null // Created - ] - - if(showTarget){ - columns.push(null) // Target - }else { - ont_columns.date-- - } - - ontNotesTable.dataTable({ - "iDisplayLength": 50, - "sPaginationType": "full_numbers", - "aaSorting": [[ont_columns.date, 'desc']], - "aoColumns": columns, - }); - // Important! Table is somehow getting set to zero width. Reset here. - jQuery(ontNotesTable).css("width", "100%"); - ontNotesTable.fnFilter('false', ont_columns.archived); -} diff --git a/app/assets/javascripts/bp_ontolobridge.js b/app/assets/javascripts/bp_ontolobridge.js deleted file mode 100644 index d4acc3e977..0000000000 --- a/app/assets/javascripts/bp_ontolobridge.js +++ /dev/null @@ -1,359 +0,0 @@ -function bindAddRequestTermClick() { - jQuery("a.add_request_term").live('click', function(){ - var id = jQuery(this).attr("data-parent-id"); - addRequestTermBox(id); - }); -} - -function bindCancelRequestTermClick() { - jQuery(".request_term_form_div .cancel").live('click', function() { - removeRequestTermBox(); - }); -} - -function bindNewTermInstructionsClick() { - jQuery("#new_term_instructions").live("click", function() { - jQuery(this).trumbowyg({ - btns: [ - ['viewHTML'], - ['undo', 'redo'], // Only supported in Blink browsers - ['formatting'], - ['strong', 'em', 'del'], - ['superscript', 'subscript'], - ['link'], - ['insertImage'], - ['justifyLeft', 'justifyCenter', 'justifyRight', 'justifyFull'], - ['unorderedList', 'orderedList'], - ['horizontalRule'], - ['removeformat'], - ['fullscreen'] - ] - }); - jQuery("#new_term_instructions_submit").show(); - jQuery("#new_term_instructions_cancel").show(); - }); -} - -function bindNewTermInstructionsSubmit() { - jQuery("#new_term_instructions_submit").live("click", function() { - saveNewTermInstructions(); - }); -} - -function bindNewTermInstructionsCancel() { - jQuery("#new_term_instructions_cancel").live("click", function() { - var oldVal = jQuery("#new_term_instructions_old").val().trim(); - var curVal = jQuery('#new_term_instructions').html().trim(); - - if (oldVal != curVal) { - if (confirm('Are you sure you want to discard your changes?')) { - jQuery('#new_term_instructions').trumbowyg('destroy'); - jQuery('#new_term_instructions').html(oldVal); - hideButtons(); - } - } else { - jQuery('#new_term_instructions').trumbowyg('destroy'); - hideButtons(); - } - }); -} - -function preventNewTermInstructionsFormSubmit() { - jQuery("#new_term_instructions_form").submit(function(e) { - e.preventDefault(e); - }); -} - -function clearProgressMessage(parentContainerID) { - var progMsgElem = jQuery("#" + parentContainerID + " #progress_message"); - progMsgElem.hide(); - progMsgElem.html(""); -} - -function showProgressMessage(parentContainerID) { - clearProgressMessage(parentContainerID); - var msg = "Saving..."; - var progMsgElem = jQuery("#" + parentContainerID + " #progress_message"); - progMsgElem.text(msg).html(); - progMsgElem.show(); -} - -function saveNewTermInstructions() { - var params = jQuery('#new_term_instructions_form').serialize(); - var newInstructions = jQuery('#new_term_instructions').html().trim(); - params += '&new_term_instructions=' + newInstructions; - var parentContainerID = 'new_term_instructions_container'; - showProgressMessage(parentContainerID); - - jQuery.ajax({ - type: "POST", - url: "/ontolobridge/save_new_term_instructions", - dataType: "json", - data: params, - success: function(data) { - var status = data[1]; - - if (status && status >= 400 || data[0]['error'].length) { - showStatusMessages('', data[0]['error']); - } else { - jQuery('#new_term_instructions').trumbowyg('destroy'); - jQuery("#new_term_instructions_old").val(newInstructions); - showStatusMessages(data[0]["success"], ''); - setTimeout(function() { clearStatusMessages(); }, 5000); - } - }, - error: function(request, textStatus, errorThrown) { - showStatusMessages('', errorThrown); - }, - complete: function(request, textStatus) { - clearProgressMessage(parentContainerID); - hideButtons(); - } - }); -} - -function hideButtons() { - jQuery("#new_term_instructions_submit").hide(); - jQuery("#new_term_instructions_cancel").hide(); -} - -function bindRequestTermSaveClick() { - var success = ""; - var error = ""; - var user = jQuery(document).data().bp.user; - var ontology_id = jQuery(document).data().bp.ont_viewer.ontology_id; - var params = jQuery("#request_term_form").serialize(); - params += "&ontology=" + ontology_id + "&email=" + user["email"] - - if (user["firstName"] && user["lastName"]) { - params += "&submitter=" + user["firstName"] + " " + user["lastName"]; - } - - var parentContainerID = 'proposal_buttons'; - showProgressMessage(parentContainerID); - - jQuery.ajax({ - type: "POST", - url: "/ontolobridge", - data: params, - dataType: "json", - success: function(data) { - var status = data[1]; - - if (status && status >= 400) { - showStatusMessages('', data[0]["error"]); - } else { - var msg = "A new term request has been submitted successfully:

"; - removeRequestTermBox(); - - for (var i in data[0]) { - msg += i + ": " + data[0][i] + "
"; - } - showStatusMessages(msg, error); - } - }, - error: function(request, textStatus, errorThrown) { - error = "The following error has occurred: " + errorThrown + ". Please try again."; - showStatusMessages(success, error); - }, - complete: function(request, textStatus) { - clearProgressMessage(parentContainerID); - } - }); -} - -function removeRequestTermBox() { - jQuery(".request_term_form_div").html(""); -} - -function addRequestTermBox(id) { - clearStatusMessages(); - var formContainer = jQuery(".request_term_form_div"); - var requestTermForm = requestTermFields(id, formContainer); - var formID = requestTermForm.attr('id'); - var isPopulated = window.localStorage.getItem(formID + '_populated'); - - if (isPopulated) { - for (var key in window.localStorage) { - if (key.startsWith(formID)) { - var elemID = key.replace(formID + '_', ''); - var elem = jQuery('#' + formID + ' #' + elemID); - - if (elem.attr('type') === "checkbox") { - elem.prop("checked", true); - } else if (elem.length > 0) { - var val = window.localStorage.getItem(key); - elem.val(val); - } - window.localStorage.removeItem(key); - } - } - } - formContainer.show(); - jQuery("#label").focus(); -} - -function clearStatusMessages() { - jQuery("#ob_success_message").hide(); - jQuery("#ob_error_message").hide(); - jQuery("#ob_success_message").html(""); - jQuery("#ob_error_message").html(""); -} - -function showStatusMessages(success, error) { - if (success.length > 0) { - let ob = jQuery("#ob_success_message") - console.log('show ob message') - console.log(ob) - ob.html(success); - ob.show(); - } - - if (error.length > 0) { - jQuery("#ob_error_message").text(error).html(); - jQuery("#ob_error_message").show(); - } -} - -function requestTermButtons() { - var buttonSubmit = jQuery("