diff --git a/Gemfile b/Gemfile index 30bed7a0fa..541eec85f1 100644 --- a/Gemfile +++ b/Gemfile @@ -13,10 +13,9 @@ gem 'terser' #ugilifer replacent # gem 'duktape' gem 'bootstrap', '~> 4.2.0' -gem 'chart-js-rails' gem 'jquery-rails' gem 'jquery-ui-rails' -gem 'select2-rails' + # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] diff --git a/Gemfile.lock b/Gemfile.lock index efaa59d02e..47421f10d6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -135,8 +135,6 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) - chart-js-rails (0.1.7) - railties (> 3.1) coderay (1.1.3) concurrent-ruby (1.2.2) crass (1.0.6) @@ -146,7 +144,7 @@ GEM daemons (1.4.1) dalli (3.2.6) date (3.3.4) - debug (1.9.0) + debug (1.9.1) irb (~> 1.10) reline (>= 0.3.8) deepl-rb (2.5.3) @@ -176,7 +174,7 @@ GEM flamegraph (0.9.5) globalid (1.2.1) activesupport (>= 6.1) - graphql (2.2.0) + graphql (2.2.3) racc (~> 1.4) graphql-client (0.18.0) activesupport (>= 3.0) @@ -218,7 +216,7 @@ GEM activesupport (>= 3.0) nokogiri (>= 1.6) io-console (0.7.1) - irb (1.10.1) + irb (1.11.0) rdoc reline (>= 0.3.8) iso-639 (0.3.6) @@ -231,7 +229,7 @@ GEM jsbundling-rails (1.2.1) railties (>= 6.0.0) json (2.7.1) - json-jwt (1.16.3) + json-jwt (1.16.4) activesupport (>= 4.2) aes_key_wrap bindata @@ -285,13 +283,14 @@ GEM multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.3.0) + mutex_m (0.2.0) mysql2 (0.5.5) net-ftp (0.2.0) net-protocol time net-http (0.4.0) uri - net-imap (0.4.8) + net-imap (0.4.9) date net-protocol net-pop (0.1.2) @@ -302,7 +301,7 @@ GEM net-ssh (>= 2.6.5, < 8.0.0) net-smtp (0.4.0) net-protocol - net-ssh (7.2.0) + net-ssh (7.2.1) netrc (0.11.0) newrelic_rpm (9.6.0) base64 @@ -319,7 +318,7 @@ GEM rack (>= 1.2, < 4) oj (3.16.3) bigdecimal (>= 3.0) - omniauth (2.1.1) + omniauth (2.1.2) hashie (>= 3.4.6) rack (>= 2.2.3) rack-protection @@ -364,7 +363,8 @@ GEM rack (>= 0.4) rack-mini-profiler (3.3.0) rack (>= 1.2.0) - rack-protection (3.1.0) + rack-protection (3.2.0) + base64 (>= 0.1.0) rack (~> 2.2, >= 2.2.4) rack-test (2.1.0) rack (>= 1.3) @@ -468,7 +468,6 @@ GEM sprockets (> 3.0) sprockets-rails tilt - select2-rails (4.0.13) selenium-webdriver (4.9.0) rexml (~> 3.2, >= 3.2.5) rubyzip (>= 1.2.2, < 3.0) @@ -492,7 +491,8 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sshkit (1.21.6) + sshkit (1.21.7) + mutex_m net-scp (>= 1.1.2) net-ssh (>= 2.8.0) stackprof (0.2.25) @@ -561,7 +561,6 @@ DEPENDENCIES capistrano-rails (~> 1.4) capistrano-yarn capybara - chart-js-rails cube-ruby dalli debug @@ -611,7 +610,6 @@ DEPENDENCIES rspec-rails rubocop sassc-rails - select2-rails selenium-webdriver simplecov simplecov-cobertura diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 93e37e762f..6fee7f7293 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -13,21 +13,16 @@ //= require bioportal //= require admin/licenses //= require bp_ajax_controller -//= require bp_reviews //= require bp_notes -//= require bp_ontolobridge //= require bp_form_complete -//= require bp_analytics //= require bp_search //= require bp_mappings //= require bp_admin //= require bp_recommender //= require bp_property_tree //= require concepts -//= require home //= require_tree ./helpers //= require_tree ./components -//= require ontologies //= require projects //= require application_esbuild customElements.define('data-table-loader', DataTableLoader ); diff --git a/app/assets/javascripts/bioportal.js.erb b/app/assets/javascripts/bioportal.js.erb index 5d679af8a4..b5918c02e4 100644 --- a/app/assets/javascripts/bioportal.js.erb +++ b/app/assets/javascripts/bioportal.js.erb @@ -1,652 +1,153 @@ // BioPortal jQuery Namespace -jQuery.bioportal = {}; +jQuery.bioportal = {} -// Backport function name -jQuery.curCSS = jQuery.css; // CSRF protection support -$(document).ajaxSend(function(e, xhr, options) { - var token = $("meta[name='csrf-token']").attr('content'); - xhr.setRequestHeader('X-CSRF-Token', token); -}); - -// Cache Implementation -var cache = new Object(); -var que= new Array(); -var queIndex = 0; -var thread=0; - -// Invalidate and Refetch - function refreshCache(nodeID){ - cache[nodeID]=null - queData([nodeID],currentOntology) - } - - -// Cache Getter - function getCache(nodeID){ - if(cache[nodeID]!=null){ - return cache[nodeID] - }else{ - return null; - } - } -// Cache Setter - function setCache(nodeID,content){ - cache[nodeID]=content - } - -// Starts the prefetching - function queData(nodes,ontology){ - currentOntology = ontology - // Disables Cache - return false; - - que = nodes.concat(que) - // set how many threads you want fetching data - queIndex = 0 - thread++ - preFetchData(que[queIndex],ontology,thread); - //preFetchData(que[1],ontology) - - } - -// The prefetching function - function preFetchData(node_id,ontology,threadNumber) { - - - var responseSuccess = function(o) - { - var respTxt = o.responseText; - tabData = respTxt.split("|||") - setCache(node_id,tabData) - queIndex++ - - // makes sure the que isnt complete and makes sure that this thread shouldnt die - - if(queIndex < que.length && thread == threadNumber){ - preFetchData(que[queIndex],ontology,threadNumber) - }else if(queIndex >= que.length){ - que = new Array(); - } - - } - - var responseFailure = function(o){ - - } - - var callback = - { - success:responseSuccess, - failure:responseFailure - }; - - - // see's if item is already in cache, if not it makes the ajax call - if(getCache(node_id)==null){ - YAHOO.util.Connect.asyncRequest('GET','/'+ontology+'/'+node_id+"?callback=load",callback); - }else{ - queIndex++ - if(queIndex < que.length && thread == threadNumber){ - preFetchData(que[queIndex],ontology,threadNumber) - }else if(queIndex >= que.length){ - que = new Array(); - } - } - - } - - - - -//------------------------------- - - -function toggleHide(id,name_to_hide){ - toggle = true; - element = document.getElementById(id); - if(element.style.display==""){ - toggle = false; - } - - if(name_to_hide !=null && name_to_hide != ""){ - elements = document.getElementsByName(name_to_hide); - for( var x = 0; x'); - YAHOO.wait.container.wait.render(document.body); - - - -} - -function buildTabWait(){ - YAHOO.namespace("tabwait.container"); - // Initialize the temporary Panel to display while waiting for external content to load - YAHOO.tabwait.container.wait = new YAHOO.widget.Panel("tabwait", - { width:"240px", - fixedcenter:true, - close:false, - draggable:false, - zindex:4, - modal:true, - visible:false - } - ); - - YAHOO.tabwait.container.wait.setHeader("Building Tree, please wait..."); - YAHOO.tabwait.container.wait.setBody(''); - YAHOO.tabwait.container.wait.render(document.body); - - - -} - - - -function buildSearchWait(){ - YAHOO.namespace("wait.container"); - // Initialize the temporary Panel to display while waiting for external content to load - YAHOO.wait.container.wait = new YAHOO.widget.Panel("wait", - { width:"240px", - fixedcenter:true, - close:false, - draggable:false, - zindex:4, - modal:true, - visible:false - } - ); - - YAHOO.wait.container.wait.setHeader("Searching, please wait..."); - YAHOO.wait.container.wait.setBody(''); - YAHOO.wait.container.wait.render(document.body); - - - -} - - - -// Selects the current clicked node. -function toggleSelected(node){ - - var index=1; - - // can get in endless loop if you jump to a node that is free floating. - nullCount = 0; - while (nullCount < 20){ - if(tree.getNodeByIndex(index)!=null){ - if (tree.getNodeByIndex(index).labelStyle=='ygtvlabel-selected'){ - tree.getNodeByIndex(index).labelStyle='ygtvlabel' - break; - } - }else{ - nullCount ++; - } - index++; - } - node.labelStyle="ygtvlabel-selected"; - -} -var tabs=null; - function buildTabs(){ - tabs = new YAHOO.widget.TabView('tabframe'); - - //YAHOO.namespace("feed"); - //YAHOO.feed.feed = new YAHOO.widget.Panel("feedPanel", { context:["feed","tr","br"], width:"320px", visible:false,draggable:false,constraintoviewport:true } ); - //YAHOO.feed.feed.render(); - //YAHOO.util.Event.addListener("feed", "click", YAHOO.feed.feed.show, YAHOO.feed.feed, true); - - var split = new Ext.SplitBar("dragSpot", "leftbar", - Ext.SplitBar.HORIZONTAL, Ext.SplitBar.LEFT); - split.setAdapter(new Ext.SplitBar.AbsoluteLayoutAdapter("container")); - split.minSize = 100; - split.maxSize = 400; - split.animate = true; - split.on('moved', splitterMoved); - } - - function splitterMoved(splitbar,newSize){ - var rightSide = Ext.get('centerContent'); - var tabFrame = Ext.get('tabframe'); - var leftSide = Ext.get('leftbar'); - - } - - function resetNoteForm(uniq){ - document.getElementById("note_subject"+uniq).value="" - document.getElementById("note_comment"+uniq).value="" - document.getElementById('noteParent'+uniq).value=""; - } - - -var myEditor; - - - -function buildEditor(uniq){ - - - - var Dom = YAHOO.util.Dom, - Event = YAHOO.util.Event; - - myEditor = new YAHOO.widget.SimpleEditor('note_comment'+uniq, { - height: '300px', - width: '522px', - dompath: false //Turns on the bar at the bottom -}); -myEditor.render(); -} - -function saveNote(){ - myEditor.saveHTML(); - myEditor.destroy(); - -} - -function destroyEditor(){ - myEditor.clearEditorDoc(); - myEditor.destroy(); - -} - - - - -function updateOntologyList(ontology){ - list = document.getElementById("ontologieslist") - if(ontology.checked){ - var s= document.createElement("LI"); - var v= document.createElement("INPUT"); - v.type="hidden" - v.value=1 - v.name=ontology.name - v.id="hid_"+ontology.nextSibling.nodeValue; - s.id="id_"+ontology.nextSibling.nodeValue; - s.innerHTML= ontology.nextSibling.nodeValue - list.appendChild(s); - list.appendChild(v); - ontology.parentNode.innerHTML = ontology.parentNode.innerHTML.replace(">","checked >") - }else{ - list.removeChild(document.getElementById("id_"+ontology.nextSibling.nodeValue)) - list.removeChild(document.getElementById("hid_"+ontology.nextSibling.nodeValue)) - ontology.parentNode.innerHTML = ontology.parentNode.innerHTML.replace("checked","") - } - - -} - -function hover_on_BG(cell){ - if(!cell.firstChild.checked){ - cell.style.background="#DFDFDF"; - } -} - -function hover_off_BG(cell){ - if(!cell.firstChild.checked){ - cell.style.background="white"; - } -} - -var dialog; - -function toggleBG(cell,bgcolor){ - - if(cell.firstChild.checked){ - cell.style.backgroundColor=bgcolor; - }else{ - cell.style.backgroundColor=bgcolor; - } - - -} - -function updateContent(){ - document.getElementById('ontologies').innerHTML = Dialog.dialog.getContent().innerHTML -} - -//------------------------------------- JQuery Rewrite Functions --------------------------------- - -function ajaxForm(form, target, callback) { - // let's start the jQuery while I wait. - // step 1: onload - capture the submit event on the form. - - // now we're going to capture *all* the fields in the - // form and submit it via ajax. - - // :input is a macro that grabs all input types, select boxes - // textarea, etc. Then I'm using the context of the form from - // the initial '#contactForm' to narrow down our selector - var inputs = []; - - jQuery(form).find(':input').each(function() { - if (this.type == "checkbox" || this.type == "radio" && this.checked) { - inputs.push(this.name + '=' + escape(this.value)); - } else if (this.type != "checkbox" && this.type != "radio") { - inputs.push(this.name + '=' + escape(this.value)); - } - }); - - // now if I join our inputs using '&' we'll have a query string - jQuery.post(form.action, inputs.join('&'), function(data) { - jQuery(target).html(data); - - if (callback) { - callback(); - } - - tb_init('a.thickbox, area.thickbox, input.thickbox'); - }); - - // by default - we'll always return false so it doesn't redirect the user. - return false; -} - -function update_tab(ontology,concept){ - - - jQuery.get("/tab/update/"+ontology+"/"+concept) - - -} - - -function remove_tab(link,ontology,redirect){ - - jQuery.get("/tab/remove/"+ontology,function(){ - if(redirect){ - window.location="/ontologies" - }else{ - jQuery("#tab"+ontology).remove() - - } - - }) - -} - -function selectTab(id,tab){ - nav = document.getElementById(id); - for(var x=0; x jQuery(window).width()) { - popup_list.css("left", "-250px"); + popup_list.css('left', '-250px') } } -var bp_popup_cleanup = function() { - jQuery(".bp_popup_link_container").removeClass("bp_popup_shadow"); - jQuery(".bp_popup_link").css("z-index", "").removeClass("bp_popup_link_active"); - jQuery(".bp_popup_list").hide(); +var bp_popup_cleanup = function () { + jQuery('.bp_popup_link_container').removeClass('bp_popup_shadow') + jQuery('.bp_popup_link').css('z-index', '').removeClass('bp_popup_link_active') + jQuery('.bp_popup_list').hide() } -// Sample object for working with pop-ups -/** -var filter_matched = { - init: function() { - jQuery("#filter_matched").bind("click", function(e){bp_popup_init(e)}); - jQuery(".match_filter").bind("click", function(e){filter_matched.filterMatched(e)}); - this.cleanup(); - }, - - cleanup: function() { - jQuery("html").click(bp_popup_cleanup); - jQuery(document).keyup(function(e) { - if (e.keyCode == 27) { bp_popup_cleanup(); } // esc - }); - }, - - filterMatched: function(e) { - e.preventDefault(); - e.stopPropagation(); - - var matchToFilter = jQuery(e.currentTarget); - var filterText = matchToFilter.attr("data-bp_filter_match"); - - resultsTable.fnFilter(filterText, 1); - - jQuery("#result_stats").html(jQuery(resultsTable).find("tr").length - 1 + " results"); - bp_popup_cleanup(); - } -} -**/ -jQuery(window).ready(function(){ +jQuery(window).ready(function () { // Helper text for advanced search filter - jQuery("input[type=text].help_text, textarea.help_text").each(function(){ - if (jQuery(this).val() == "") { - jQuery(this).val(jQuery(this).attr("title")); - jQuery(this).addClass("help_text_font"); + jQuery('input[type=text].help_text, textarea.help_text').each(function () { + if (jQuery(this).val() == '') { + jQuery(this).val(jQuery(this).attr('title')) + jQuery(this).addClass('help_text_font') } else { - jQuery(this).removeClass("help_text_font"); + jQuery(this).removeClass('help_text_font') } - }); + }) - jQuery("input[type=text].help_text, textarea.help_text").live("focus", (function(){ - var input = jQuery(this); - if (input.attr("title") == input.val()) { - input.val(""); - input.removeClass("help_text_font"); + jQuery('input[type=text].help_text, textarea.help_text').live('focus', (function () { + var input = jQuery(this) + if (input.attr('title') == input.val()) { + input.val('') + input.removeClass('help_text_font') } - })); + })) - jQuery("input[type=text].help_text, textarea.help_text").live("blur", (function(){ - var input = jQuery(this); - if (input.val() == "") { - input.val(input.attr("title")); - input.addClass("help_text_font"); + jQuery('input[type=text].help_text, textarea.help_text').live('blur', (function () { + var input = jQuery(this) + if (input.val() == '') { + input.val(input.attr('title')) + input.addClass('help_text_font') } - })); -}); + })) +}) // Initialize all link buttons using jQuery UI button widget -jQuery(document).ready(function(){ - jQuery("a.link_button, input.link_button").button(); +jQuery(document).ready(function () { + jQuery('a.link_button, input.link_button').button() // Properly define Chosen select width - jQuery(".chzn-container").css("width", "auto"); - jQuery(".chzn-container").css("min-width", "30em"); - jQuery("input.default").css("width", "100%"); - jQuery(".chzn-drop").css({"width": "100%"}); -}); + jQuery('.chzn-container').css('width', 'auto') + jQuery('.chzn-container').css('min-width', '30em') + jQuery('input.default').css('width', '100%') + jQuery('.chzn-drop').css({ 'width': '100%' }) +}) // Truncate more/less show and hide -jQuery(document).ready(function(){ - jQuery("a.truncated_more").live("click", function(){ - var link = jQuery(this); - link.parents("span.more_less_container").find(".truncated_more").hide(); - link.parents("span.more_less_container").find(".truncated_less").show(); +jQuery(document).ready(function () { + jQuery('a.truncated_more').live('click', function () { + var link = jQuery(this) + link.parents('span.more_less_container').find('.truncated_more').hide() + link.parents('span.more_less_container').find('.truncated_less').show() }) - jQuery("a.truncated_less").live("click", function(){ - var link = jQuery(this); - link.parents("span.more_less_container").find(".truncated_less").hide(); - link.parents("span.more_less_container").find(".truncated_more").show(); + jQuery('a.truncated_less').live('click', function () { + var link = jQuery(this) + link.parents('span.more_less_container').find('.truncated_less').hide() + link.parents('span.more_less_container').find('.truncated_more').show() }) }) -// Invoke a loading animation where dots are added to some load text -// Call this like: var loadAni = loadingAnimation("#loading"); -// Where: loading -// To kill the animation, call clearInterval(loadAni); -function loadingAnimation(loadId) { - var originalText = jQuery(loadId).text(), i = 0; - return setInterval(function() { - jQuery(loadId).append("."); - i++; - if(i == 4) { - $(loadId).html(originalText); - i = 0; - } - }, 500); -} + // Enable this to see errors in jQuery(document).ready() code // var oldReady = jQuery.ready; @@ -659,111 +160,52 @@ function loadingAnimation(loadId) { // } // }; - // Automatically get ajax content -jQuery(document).ready(function(){ +jQuery(document).ready(function () { // We do this with a delay to avoid queuing ahead of other async requests - setTimeout(getAjaxContent, 1000); -}); + setTimeout(getAjaxContent, 1000) +}) -function getAjaxContent() { +function getAjaxContent () { // Look for anchors with a get_via_ajax class and replace the parent with the resulting ajax call - $(".get_via_ajax").each(function(){ - let elem = $(this) - let parent = elem.parent() - $.get(elem.attr("href"), (conceptLabel) => { - parent.html(conceptLabel) - }) - }); - setTimeout(getAjaxContent, 500); + $('.get_via_ajax').each(function () { + let elem = $(this) + let parent = elem.parent() + $.get(elem.attr('href'), (conceptLabel) => { + parent.html(conceptLabel) + }) + }) + setTimeout(getAjaxContent, 500) } // Handle will_paginate using ajax -jQuery(".pagination a").live("click", function(e){ - var link = jQuery(this); - var replaceDiv = link.closest(".paginate_ajax"); - e.preventDefault(); +jQuery('.pagination a').live('click', function (e) { + var link = jQuery(this) + var replaceDiv = link.closest('.paginate_ajax') + e.preventDefault() if (replaceDiv.length > 0) { - replaceDiv.load(link.attr("href")); + replaceDiv.load(link.attr('href')) } else { - link.closest("div.pagination").parent().load(link.attr("href")); + link.closest('div.pagination').parent().load(link.attr('href')) } -}); +}) // Facebox settings -jQuery.facebox.settings.closeImage = "<%= asset_path("facebox/closelabel.png") %>"; -jQuery.facebox.settings.loadingImage = "<%= asset_path("facebox/loading.gif") %>"; - -// Cookie handling -var BP_setCookie = function(key, value, options) { - if (typeof options === "undefined") options = {}; - var days = options["days"] || null; - var seconds = options["seconds"] || null; - var expdate = new Date(); - var expires = ""; - - if (seconds !== null) { - expdate.setSeconds(expdate.getSeconds() + seconds); - expires = " expires=" + expdate.toGMTString(); - } +jQuery.facebox.settings.closeImage = "<%= asset_path("facebox/closelabel.png") %>" +jQuery.facebox.settings.loadingImage = "<%= asset_path("facebox/loading.gif") %>" - if (days !== null) { - expdate.setDate(expdate.getDate() + days); - expires = " expires=" + expdate.toGMTString(); - } - document.cookie=key + "=" + value + ";" + expires; -} -var BP_getCookies = function(){ - var pairs = document.cookie.split(";"); - var cookies = {}; - for (var i=0; i 0) - cleanPath.push(path[i]); + cleanPath.push(path[i]) } - return cleanPath; + return cleanPath } -function pageUsesTreeView() { - var usesTreeView = true; - var path = currentPathArray(); - - if (path[0] !== "ontologies") { - usesTreeView = false; - } else if ((path.length !== 2) || (path[1] === "new")) { - /* - * Some ontology pages don't use class trees, e.g.: - * ontologies/BRO/edit - * ontologies/new - */ - usesTreeView = false; - } else { - // Metadata only ontologies don't have class trees. - var metadataOnly = jQuery(document).data().bp.ont_viewer.metadata_only; - if ((metadataOnly != null) && (metadataOnly === "true")) { - usesTreeView = false; - } - } - - return usesTreeView; -} - - diff --git a/app/assets/javascripts/bp_admin.js b/app/assets/javascripts/bp_admin.js index a5f973baac..32537cac67 100644 --- a/app/assets/javascripts/bp_admin.js +++ b/app/assets/javascripts/bp_admin.js @@ -1,9 +1,3 @@ -/** - * Created by mdorf on 3/27/15. - * Updated by Syphax.Bouazzouni on 28/04/21 , users admin part - */ - - var DUMMY_ONTOLOGY = "DUMMY_ONT"; if (window.BP_CONFIG === undefined) { window.BP_CONFIG = jQuery(document).data().bp.config; @@ -663,8 +657,6 @@ function displayOntologies(data, ontology) { _showStatusMessages([], [json.errors], [], false); } setDateGenerated(json); - // Keep header at top of table even when scrolling - // new jQuery.fn.dataTable.FixedHeader(ontTable); }, "columnDefs": [ { diff --git a/app/assets/javascripts/bp_ajax_controller.js b/app/assets/javascripts/bp_ajax_controller.js index 97387071ee..a67e66550a 100644 --- a/app/assets/javascripts/bp_ajax_controller.js +++ b/app/assets/javascripts/bp_ajax_controller.js @@ -110,29 +110,6 @@ var ajax_process_ont = function() { }; -// ************************************************************************************** -// 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_cls_array = []; - -var ajax_process_cls_init = function() { - ajax_cls_array = jQuery("a.cls4ajax").toArray(); -}; - -var ajax_process_cls_halt = function () { - ajax_cls_array = []; - window.clearInterval(ajax_process_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'); -}; - - // ************************************************************************************** // INTERPORTAL CLASS LABELS diff --git a/app/assets/javascripts/bp_analytics.js b/app/assets/javascripts/bp_analytics.js deleted file mode 100644 index 701a03f26f..0000000000 --- a/app/assets/javascripts/bp_analytics.js +++ /dev/null @@ -1,82 +0,0 @@ -jQuery(document).ready(function(){ - new SearchAnalytics().bindTracker(); -}); - -function Analytics() { - this.track = function(segment, analytics_action, params, callback) { - params["segment"] = segment; - params["analytics_action"] = analytics_action; - jQuery.ajax({ - url: "/analytics", - data: params, - type: "POST", - timeout: 100, - success: function(){ - if (typeof callback === "function") callback(); - }, - error: function(){ - if (typeof callback === "function") callback(); - } - }); - }; -} - -function SearchAnalytics() { - this.bindTracker = function() { - jQuery(document).on("click", "#search_results_container div.class_link a", function(e) { - e.preventDefault(); - - var link; - if (e.target.nodeName == "SPAN") { - link = jQuery(e.target.parentElement); - } else { - link = jQuery(e.target); - } - - var href = link.attr("href"); - var params = new SearchAnalytics().linkInformation(link); - new Analytics().track("search", "result_clicked", params, function(){ - window.location.href = href; - }); - }); - }; - - this.linkInformation = function(link) { - var info = {}, resultsIndex = 0; - var ontologyPosition = jQuery("#search_results div.search_result").index(jQuery(link).closest(".search_result")) + 1; - - info.ontology_clicked = link.closest(".search_result").data("bp_ont_id"); - - // Find out the position of the search result in the list - if (link.closest(".additional_results").length === 0) { - info.position = ontologyPosition; - } else { - info.position = link.closest(".additional_results").children(".search_result_additional").index(link.closest(".search_result_additional")) + 1; - } - - // Was this an additional result or a top-level - info.additional_result = link.closest(".additional_results").length > 0; - - // Get the name of ontologies higher in the list - if (info.position > 1 || info.additional_result === true) { - var results = jQuery("#search_results div.search_result"); - info.higher_ontologies = []; - while (resultsIndex < ontologyPosition - 1) { - info.higher_ontologies.push(jQuery(results[resultsIndex]).data("bp_ont_id")); - resultsIndex += 1; - } - } - - // Concept id - info.concept_id = link.data("bp_conceptid"); - - // Search query - info.query = jQuery("#search_keywords").val(); - - // Exact match - info.exact_match = link.data("exact_match"); - - return info; - }; -} - diff --git a/app/assets/javascripts/bp_annotator.js b/app/assets/javascripts/bp_annotator.js index 6f14c66a4d..cb1a3d858e 100644 --- a/app/assets/javascripts/bp_annotator.js +++ b/app/assets/javascripts/bp_annotator.js @@ -509,21 +509,25 @@ function generateParameters() { jQuery(document).ready(function() { "use strict"; jQuery("#annotator_button").click(get_annotations); - - jQuery("#semantic_types").select2({ - allowClear: true, - dropdownParent: jQuery(".annotator form") + + jQuery("#semantic_types").chosen({ + allow_single_deselect: true, + width: '100%', // Adjust the width as needed + dropdown_parent: jQuery(".annotator form") }); - jQuery("#semantic_groups").select2({ - allowClear: true, - dropdownParent: jQuery(".annotator form") + jQuery("#semantic_groups").chosen({ + allow_single_deselect: true, + width: '100%', // Adjust the width as needed + dropdown_parent: jQuery(".annotator form") }); - jQuery("#ontology_ontologyId").select2({ - allowClear: true, - dropdownParent: jQuery(".annotator form") + jQuery("#ontology_ontologyId").chosen({ + allow_single_deselect: true, + width: '100%', // Adjust the width as needed + dropdown_parent: jQuery(".annotator form") }); + jQuery("#insert_text_link").click(insertSampleText); jQuery("#advancedOptionsLink").click(toggle_advanced_options); diff --git a/app/assets/javascripts/bp_annotatorplus.js b/app/assets/javascripts/bp_annotatorplus.js index bc051caa9f..2ee9a78d30 100644 --- a/app/assets/javascripts/bp_annotatorplus.js +++ b/app/assets/javascripts/bp_annotatorplus.js @@ -496,22 +496,27 @@ function generateParameters() { jQuery(document).ready(function() { "use strict"; jQuery("#annotator_button").click(get_annotations); - - jQuery("#semantic_types").select2({ - allowClear: true, - dropdownParent: jQuery(".annotatorplus form") + + + jQuery("#semantic_types").chosen({ + allow_single_deselect: true, + width: '100%', // Adjust the width as needed + dropdown_parent: jQuery(".annotatorplus form") }); - jQuery("#semantic_groups").select2({ - allowClear: true, - dropdownParent: jQuery(".annotatorplus form") + jQuery("#semantic_groups").chosen({ + allow_single_deselect: true, + width: '100%', // Adjust the width as needed + dropdown_parent: jQuery(".annotatorplus form") }); - jQuery("#ontology_ontologyId").select2({ - allowClear: true, - dropdownParent: jQuery(".annotatorplus form") + jQuery("#ontology_ontologyId").chosen({ + allow_single_deselect: true, + width: '100%', // Adjust the width as needed + dropdown_parent: jQuery(".annotatorplus form") }); + jQuery("#insert_text_link").click(insertSampleText); jQuery("#advancedOptionsLink").click(toggle_advanced_options); diff --git a/app/assets/javascripts/bp_resource_index.js.erb b/app/assets/javascripts/bp_resource_index.js.erb deleted file mode 100644 index 1e285eae32..0000000000 --- a/app/assets/javascripts/bp_resource_index.js.erb +++ /dev/null @@ -1,664 +0,0 @@ -// History and navigation management -(function (window, undefined) { - // Establish Variables - var History = window.History; - // History.debug.enable = true; - - // Abort if not right page - var path = currentPathArray(); - if (path[0] !== "resource_index") { - return; - } - - // Bind to State Change - History.Adapter.bind(window, 'statechange', function () { - var state = History.getState(); - if (typeof state.data.route !== "undefined") { - router.route(state.data.route, state.data); - } else { - router.route("index"); - } - }); -}(window)); - -var uri_split_chars = "\t::\t"; - -var uri_split = function(combinedURIs) { - return combinedURIs.split(uri_split_chars); -}; - -var bpResourceIndexEmbedded = false; -jQuery(document).ready(function () { - bpResourceIndexEmbedded = (jQuery("#resource_table").parents("div.resource_index_embed").length > 0); - - // Hide/Show resources - jQuery(".resource_link").live("click", function (event) { - event.preventDefault(); - switchResources(this); - }); - - // Show/Hide advanced options - jQuery("#resource_index_advanced_options").on("click", function(event) { - jQuery("#search_options").toggleClass("not_visible"); - jQuery("#hide_advanced_options").toggleClass("not_visible"); - }); - - // Spinner for pagination - jQuery(".pagination a").live("click", function () { - jQuery(this).parents("div.pagination").append('   loading ' + '<%= image_tag("spinners/spinner_000000_16px.gif", style: "vertical-align: text-bottom;") %>'); - }); - - jQuery("#resources_desc").dataTable({ - "paging": false, - "searching": false, - "columns": [ - { "type": "html" }, - { "orderable": false }, - { "type": "num-fmt", "orderSequence": [ "desc", "asc"] }, - { "orderSequence": [ "desc", "asc" ] } - ] - }); - - function formattedCls(cls) { - return "" + cls.prefLabel + " (" + cls.ontologyName + ")"; - } - - function formatCls(cls) { - var markup = cls.loading ? cls.text : formattedCls(cls); - return markup - } - - function formatClsSelection(cls) { - return formattedCls(cls); - } - - jQuery("#resource_index_classes").select2({ - allowClear: true, - placeholder: "Start typing to find classes to search the index with", - escapeMarkup: function (markup) { return markup; }, - minimumInputLength: 3, - templateResult: formatCls, - templateSelection: formatClsSelection, - - ajax: { - url: jQuery(document).data().bp.config.rest_url + "/search", - dataType: "json", - delay: 500, - data: function (params) { - var searchTerm = params.term; - - if (/[^*]$/.test(searchTerm)) { - searchTerm += '*'; - } - - return { - q: searchTerm, - apikey: jQuery(document).data().bp.config.apikey, - ontologies: currentOntologyAcronyms().join(','), - page: params.page, - }; - }, - processResults: function (data, params) { - params.page = data.page || 1; - - return { - results: $.map(data.collection, function (item) { - var ontId = item.links.ontology; - var ontName = ontId.split('/').slice(-1)[0]; - var clsId = item["@id"]; - - return { - id: ontId + uri_split_chars + clsId, - prefLabel: item.prefLabel, - ontologyName: ontName - } - }), - - pagination: { - more: data.page <= data.pageCount - } - }; - }, - cache: true - } - }); - - // TODO(jvendetti): Currently unused, but perhaps should be added to the formattedCls function - function markupClass(cls) { - // Wrap the class prefLabel in a span, indicating that the class is obsolete if necessary. - var max_word_length = 60; - var label_text = (cls.prefLabel.length > max_word_length) ? cls.prefLabel.substring(0, max_word_length) + "..." : cls.prefLabel; - var label_html = jQuery("").addClass('prefLabel').append(label_text); - if (cls.obsolete === true){ - label_html.removeClass('prefLabel'); - label_html.addClass('obsolete_class'); - label_html.attr('title', 'obsolete class'); - } - return label_html; // returns a jQuery object; use .prop('outerHTML') to get markup text. - } - - // If all classes are removed from the search, put the UI in base state - jQuery("#resource_index_classes").on('select2:unselect', function (evt) { - if(!jQuery('#resource_index_classes').val()) { - pushIndex(); - } - }); - - // Get search results - if (jQuery("#resource_index_button").length > 0) { - jQuery("#resource_index_button").click(function () { - var url = "/resource_index/resources?" + chosenSearchClassesArgs(); - pushDisplayResources(url, {classes: chosenSearchClasses()}); - getSearchResults(); - }); - } - - // Show/Hide results with zero matches - jQuery("#show_hide_no_results").live("click", function () { - jQuery("#resource_table .zero_results").toggleClass("not_visible").effect("highlight", { color: "yellow" }, 500); - jQuery("#show_hide_no_results .show_hide_text").toggleClass("not_visible"); - }); - - jQuery(".show_element_details").live("click", function (e) { - e.preventDefault(); - var el = jQuery(this); - var cleanElementId = el.data().cleanElementId; - var el_text = jQuery("#" + cleanElementId + "_text"); - el_text.toggleClass("not_visible"); - if (el_text.attr("highlighted") !== "true") { - var element = new Element(el.data().elementId, cleanElementId, chosenSearchClasses(), el.data().resourceId); - el.parent().append('highlighting... ' + '<%= image_tag("spinners/spinner_000000_16px.gif", style: "vertical-align: text-bottom;") %>' + ''); - element.highlightAnnotationPositions(); - el_text.attr("highlighted", "true"); - } - }); - - jQuery("#resource-index-help").on("click", bpPopWindow); -}); - -// Get parameters from the URL -var BP_urlParams = {}; -(function () { - var match, hashParamMatch, paramHash, - pl = /\+/g, // Regex for replacing addition symbol with a space - search = /([^&=]+)=?([^&]*)/g, - decode = function (s) { - return decodeURIComponent(s.replace(pl, " ")); - }, - query = window.location.search.substring(1); - queryH = window.location.hash.substring(1); - - while (match = search.exec(query)) { - if (hashParamMatch = /^(\w+)\[(.*)\]$/.exec(match[1])) { - paramHash = BP_urlParams[hashParamMatch[1]]; - if (paramHash === undefined) { - paramHash = {}; - } - if (paramHash[decode(hashParamMatch[2])] === undefined) { - paramHash[decode(hashParamMatch[2])] = []; - } - paramHash[decode(hashParamMatch[2])] = decode(match[2]).split(","); - BP_urlParams[hashParamMatch[1]] = paramHash; - } else { - BP_urlParams[decode(match[1])] = decode(match[2]); - } - } - - while (match = search.exec(queryH)) { - if (hashParamMatch = /^(\w+)\[(.*)\]$/.exec(match[1])) { - paramHash = BP_urlParams[hashParamMatch[1]]; - if (paramHash === undefined) { - paramHash = {}; - } - if (paramHash[decode(hashParamMatch[2])] === undefined) { - paramHash[decode(hashParamMatch[2])] = []; - } - paramHash[decode(hashParamMatch[2])] = decode(match[2]).split(","); - BP_urlParams[hashParamMatch[1]] = paramHash; - } else { - BP_urlParams[decode(match[1])] = decode(match[2]); - } - } -})(); - -function pageInit() { - var state = History.getState(); - var params = {}, paramLocations = ["root", "resources", "acronym"], route, queryString; - route = state.hash.split("?"); - queryString = (typeof route[1] !== "undefined") ? "" : route[1]; - route = route[0].split("/").slice(1); - for (var i = 0; i < route.length; i++) { - params[paramLocations[i]] = route[i]; - } - jQuery.extend(params, BP_urlParams); - BP_urlParams = params; - if (typeof params["acronym"] !== "undefined") { - router.route("resource", params); - } else if (typeof params["resources"] !== "undefined") { - router.route("resources", params); - } -} - -function pushDisplayResource(url, params) { - var route = "resource"; - if (bpResourceIndexEmbedded) { - router.route(route, params); - } else { - params["route"] = route; - History.pushState(params, document.title, url); - } -} - -function pushDisplayResources(url, params) { - var route = "resources"; - if (bpResourceIndexEmbedded) { - router.route(route, params); - } else { - params["route"] = route; - History.pushState(params, document.title, url); - } -} - -function pushIndex() { - var route = "index"; - if (bpResourceIndexEmbedded) { - router.route(route); - } else { - History.pushState(null, document.title, "/resource_index"); - } -} - -function replaceIndex() { - var route = "index"; - if (bpResourceIndexEmbedded) { - router.route(route); - } else { - History.replaceState(null, document.title, "/resource_index"); - } -} - -// This will look up any class labels that haven't already been processed. If there are none it just exits without doing anything. -// To decrease ajax calls, we also use the bp_classes_cache. This method is used via polling. -var bp_classes_cache = {}; -function lookupClassLabels() { - jQuery("#resource_results a.ri_concept[data-applied_label='false']").each(function () { - var link = jQuery(this); - var params = { conceptid: decodeURIComponent(link.data("concept_id")), ontologyid: link.data("ontology_id") }; - link.attr("data-applied_label", "true"); - - // Check to see if another thread is already making an ajax request and start polling - if (bp_classes_cache[params.ontologyid + "/" + params.conceptid] === "getting") { - return setTimeout((function () { - return applyClassLabel(link, params); - }), 100); - } - - if (typeof bp_classes_cache[params.ontologyid + "/" + params.conceptid] === "undefined") { - bp_classes_cache[params.ontologyid + "/" + params.conceptid] = "getting"; - jQuery.ajax({ - url : "/ajax/json_class", - data : params, - dataType: 'json', - success : (function (link) { - return function (data) { - bp_classes_cache[params.ontologyid + "/" + params.conceptid] = data; - if (data !== null) jQuery(link).html(data.prefLabel); - } - })(this) - }); - } - }) -} - -// Poll for class information -jQuery(document).ready(function () { - setInterval((function () { - lookupClassLabels(); - }), 1000); -}); - -// This function will poll to see if class information exists -function applyClassLabel(link, params, calledAgain) { - var class_info = bp_classes_cache[params.ontologyid + "/" + params.conceptid]; - if (class_info === "getting") { - if (typeof calledAgain !== "undefined") calledAgain = 0 - return setTimeout((function () { - return applyClassLabel(link, params, calledAgain += 1); - }), 100); - } - if (class_info !== null) jQuery(link).html(class_info.prefLabel); -} - -function Router() { - this.route = function (route, params) { - switch (route) { - case "index": - this.index(); - break; - case "resource": - this.resource(params); - break; - case "resources": - this.resources(params); - break; - } - }; - - this.index = function () { - jQuery("#results").html(""); - jQuery("#results_error").html(""); - jQuery("#initial_resources").show(); - }; - - this.resource = function (params) { - if (typeof params["classes"] === "undefined" || typeof params["acronym"] === "undefined") { - replaceIndex(); - } - displayResource(params); - }; - - this.resources = function (params) { - if (typeof params["classes"] === "undefined") { - replaceIndex(); - } - displayResources(params["classes"]); - }; - -} -router = new Router(); - -function displayResource(params) { - var resource = params["acronym"]; - if (resource === undefined || resources[resource] === undefined) { - return; - } - var name = resources[resource].name; - // Only retrieve class information if this is an initial load - if (jQuery("#resource_index_classes").val() !== null) { - showResourceResults(resource, name); - return; - } - displayClasses(params["classes"], function () { - showResourceResults(resource, name); - }); -} - -function displayResources(classes) { - // Only retrieve class information if this is an initial load - if (jQuery("#resource_index_classes").val() !== null) { - showAllResources(); - return; - } - displayClasses(classes); -} - -function displayClasses(classes, completedCallback) { - var concept, conceptOpt, ontologyId, conceptId, ontologyName, conceptsLength, params, ontClasses, chsnValue, - conceptRetreivedCount = 0, - ontClassPairs = []; - - for (ontology in classes) { - ontClasses = classes[ontology]; - for (var i = 0; i < ontClasses.length; i++) { - ontClassPairs.push([ontology, ontClasses[i]]); - } - } - conceptsLength = ontClassPairs.length; - - jQuery("#resource_index_classes").html(""); - - for (var i = 0; i < ontClassPairs.length; i++) { - ontClassPair = ontClassPairs[i]; - ontologyId = ontClassPair[0]; - ontologyAcronym = ontClassPair[0].split("/").slice(-1)[0]; - conceptId = ontClassPair[1]; - ontologyName = ont_names[ontologyId]; - params = { ontologyid: ontologyAcronym, conceptid: conceptId }; - chsnValue = ontologyId + uri_split_chars + conceptId; - jQuery.getJSON("/ajax/json_class", params, (function (ontologyAcronym, chsnValue) { - return function (data) { - jQuery("#resource_index_classes") - .append(jQuery("