var ONYX = "http://www.gsi.dit.upm.es/ontologies/onyx/ns#"; var RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"; var plugins_params = default_params = {}; var plugins = []; var defaultPlugin = {}; var gplugins = {}; var pipeline = []; function replaceURLWithHTMLLinks(text) { console.log('Text: ' + text); var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; return text.replace(exp,'$1'); } function encodeHTML(text) { return text.replace(/&/g, '&') .replace(//g, '>') .replace(/"/g, '"') .replace(/'/g, '''); }; function hashchanged(){ var hash = location.hash , hashPieces = hash.split('?'); if( hashPieces[0].length > 0 ){ activeTab = $('[href=' + hashPieces[0] + ']'); activeTab && activeTab.tab('show'); } } function get_plugins(response){ for(ix in response.plugins){ plug = response.plugins[ix]; plugins[plug.name] = plug; } } function get_datasets(response){ datasets = response.datasets } function group_plugins(){ for (r in plugins){ ptype = plugins[r]['@type']; if(gplugins[ptype] == undefined){ gplugins[ptype] = [r]; }else{ gplugins[ptype].push(r); } } } function get_parameters(){ for (p in plugins){ plugin = plugins[p]; if (plugin["extra_params"]){ plugins_params[plugin["name"]] = plugin["extra_params"]; } } } function draw_plugins_selection(){ html=""; group_plugins(); for (g in gplugins){ html += "" for (r in gplugins[g]){ plugin = plugins[gplugins[g][r]] if (!plugin["name"]){ console.log("No name for plugin ", plugin); continue; } html+= "" // Two elements with plugin class // One from the evaluate tab and another one from the analyse tab plugin_lists = document.getElementsByClassName('plugin') for (element in plugin_lists){ plugin_lists[element].innerHTML = html; } draw_plugin_pipeline(); } function draw_plugin_pipeline(){ var pipeHTML = ""; console.log("Drawing pipeline: ", pipeline); for (ix in pipeline){ plug = pipeline[ix]; pipeHTML += ' ' + plug + ' '; } console.log(pipeHTML); $("#pipeline").html(pipeHTML); } function remove_plugin_pipeline(name){ console.log("Removing plugin: ", name); var index = pipeline.indexOf(name); pipeline.splice(index, 1); draw_plugin_pipeline(); } function draw_plugins_list(){ var availablePlugins = document.getElementById('availablePlugins'); for(p in plugins){ var pluginEntry = document.createElement('li'); plugin = plugins[p]; newHtml = "" if(plugin.url) { newHtml= "" + plugin.name + ""; }else { newHtml= plugin["name"]; } newHtml += ": " + replaceURLWithHTMLLinks(plugin.description); pluginEntry.innerHTML = newHtml; availablePlugins.appendChild(pluginEntry) } } function add_plugin_pipeline(){ var selected = get_selected_plugin(); pipeline.push(selected); console.log("Adding ", selected); draw_plugin_pipeline(); } function draw_datasets(){ html = ""; repeated_html = ""+datasets[dataset]["@id"]; html += "
" } document.getElementById("datasets").innerHTML = html; } $(document).ready(function() { var response = JSON.parse($.ajax({type: "GET", url: "/api/plugins/" , async: false}).responseText); defaultPlugin= JSON.parse($.ajax({type: "GET", url: "/api/plugins/default" , async: false}).responseText); get_plugins(response); get_default_parameters(); draw_plugins_list(); draw_plugins_selection(); draw_parameters(); draw_plugin_description(); if (evaluation_enabled) { var response2 = JSON.parse($.ajax({type: "GET", url: "/api/datasets/" , async: false}).responseText); get_datasets(response2); draw_datasets(); } $(window).on('hashchange', hashchanged); hashchanged(); $('.tooltip-form').tooltip(); }); function get_default_parameters(){ default_params = JSON.parse($.ajax({type: "GET", url: "/api?help=true" , async: false}).responseText).valid_parameters; // Remove the parameters that are always added delete default_params["input"]; delete default_params["algorithm"]; delete default_params["help"]; } function get_selected_plugin(){ return document.getElementsByClassName('plugin')[0].options[document.getElementsByClassName('plugin')[0].selectedIndex].value; } function draw_default_parameters(){ var basic_params = document.getElementById("basic_params"); basic_params.innerHTML = params_div(default_params); } function update_params(params, plug){ ep = plugins_params[plug]; for(k in ep){ params[k] = ep[k]; } return params } function draw_extra_parameters(){ var plugin = get_selected_plugin(); get_parameters(); var extra_params = document.getElementById("extra_params"); var params = {}; for (sel in pipeline){ update_params(params, pipeline[sel]); } update_params(params, plugin); extra_params.innerHTML = params_div(params); } function draw_parameters(){ draw_default_parameters(); draw_extra_parameters(); } function add_default_params(){ var html = ""; // html += 'Basic API parameters'; html += ''; html += '