mirror of
https://github.com/gsi-upm/senpy
synced 2024-11-22 00:02:28 +00:00
Merge branch '42-add-parameters-to-the-playground'
This commit is contained in:
commit
cd22291dc9
@ -39,6 +39,14 @@ API_PARAMS = {
|
|||||||
"required": True,
|
"required": True,
|
||||||
"options": ["filtered", "nested", "full"],
|
"options": ["filtered", "nested", "full"],
|
||||||
"default": "full"
|
"default": "full"
|
||||||
|
},
|
||||||
|
"help": {
|
||||||
|
"@id": "help",
|
||||||
|
"description": "Show additional help to know more about the possible parameters",
|
||||||
|
"aliases": ["help", "h"],
|
||||||
|
"required": True,
|
||||||
|
"options": ["True", "False"],
|
||||||
|
"default": "False"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ Blueprints for Senpy
|
|||||||
from flask import (Blueprint, request, current_app, render_template, url_for,
|
from flask import (Blueprint, request, current_app, render_template, url_for,
|
||||||
jsonify)
|
jsonify)
|
||||||
from .models import Error, Response, Plugins, read_schema
|
from .models import Error, Response, Plugins, read_schema
|
||||||
from .api import WEB_PARAMS, API_PARAMS, parse_params
|
from .api import WEB_PARAMS, API_PARAMS, CLI_PARAMS, NIF_PARAMS, parse_params
|
||||||
from .version import __version__
|
from .version import __version__
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@ -43,7 +43,6 @@ def get_params(req):
|
|||||||
raise Error(message="Invalid data")
|
raise Error(message="Invalid data")
|
||||||
return indict
|
return indict
|
||||||
|
|
||||||
|
|
||||||
@demo_blueprint.route('/')
|
@demo_blueprint.route('/')
|
||||||
def index():
|
def index():
|
||||||
return render_template("index.html", version=__version__)
|
return render_template("index.html", version=__version__)
|
||||||
@ -117,8 +116,14 @@ def basic_api(f):
|
|||||||
@api_blueprint.route('/', methods=['POST', 'GET'])
|
@api_blueprint.route('/', methods=['POST', 'GET'])
|
||||||
@basic_api
|
@basic_api
|
||||||
def api():
|
def api():
|
||||||
response = current_app.senpy.analyse(**request.params)
|
phelp = request.params.get('help')
|
||||||
return response
|
if phelp == "True":
|
||||||
|
dic = dict(API_PARAMS, **NIF_PARAMS)
|
||||||
|
response = Response(dic)
|
||||||
|
return response
|
||||||
|
else:
|
||||||
|
response = current_app.senpy.analyse(**request.params)
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
@api_blueprint.route('/plugins/', methods=['POST', 'GET'])
|
@api_blueprint.route('/plugins/', methods=['POST', 'GET'])
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
var ONYX = "http://www.gsi.dit.upm.es/ontologies/onyx/ns#";
|
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 RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
|
||||||
var plugins_params={};
|
var plugins_params={};
|
||||||
|
var default_params = JSON.parse($.ajax({type: "GET", url: "/api?help=True" , async: false}).responseText);
|
||||||
function replaceURLWithHTMLLinks(text) {
|
function replaceURLWithHTMLLinks(text) {
|
||||||
console.log('Text: ' + text);
|
console.log('Text: ' + text);
|
||||||
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||||
@ -28,54 +28,68 @@ function hashchanged(){
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var response = JSON.parse($.ajax({type: "GET", url: "/api/plugins/" , async: false}).responseText);
|
var response = JSON.parse($.ajax({type: "GET", url: "/api/plugins/" , async: false}).responseText);
|
||||||
var defaultPlugin= JSON.parse($.ajax({type: "GET", url: "/api/plugins/default" , async: false}).responseText);
|
var defaultPlugin= JSON.parse($.ajax({type: "GET", url: "/api/plugins/default" , async: false}).responseText);
|
||||||
html="";
|
html="";
|
||||||
var availablePlugins = document.getElementById('availablePlugins');
|
var availablePlugins = document.getElementById('availablePlugins');
|
||||||
plugins = response.plugins;
|
plugins = response.plugins;
|
||||||
for (r in plugins){
|
gplugins = {};
|
||||||
plugin = plugins[r]
|
for (r in plugins){
|
||||||
if (plugin["name"]){
|
ptype = plugins[r]['@type'];
|
||||||
if (plugin["name"] == defaultPlugin["name"]){
|
if(gplugins[ptype] == undefined){
|
||||||
if (plugin["is_activated"]){
|
gplugins[ptype] = [r]
|
||||||
html+= "<option value=\""+plugin["name"]+"\" selected=\"selected\">"+plugin["name"]+"</option>"
|
}else{
|
||||||
}else{
|
gplugins[ptype].push(r)
|
||||||
html+= "<option value=\""+plugin["name"]+"\" selected=\"selected\" disabled=\"disabled\">"+plugin["name"]+"</option>"
|
}
|
||||||
}
|
}
|
||||||
}
|
for (g in gplugins){
|
||||||
else{
|
html += "<optgroup label=\""+g+"\">"
|
||||||
if (plugin["is_activated"]){
|
for (r in gplugins[g]){
|
||||||
html+= "<option value=\""+plugin["name"]+"\">"+plugin["name"]+"</option>"
|
plugin = plugins[r]
|
||||||
}
|
if (plugin["name"]){
|
||||||
else{
|
if (plugin["name"] == defaultPlugin["name"]){
|
||||||
html+= "<option value=\""+plugin["name"]+"\" disabled=\"disabled\">"+plugin["name"]+"</option>"
|
if (plugin["is_activated"]){
|
||||||
}
|
html+= "<option value=\""+plugin["name"]+"\" selected=\"selected\">"+plugin["name"]+"</option>"
|
||||||
}
|
}else{
|
||||||
}
|
html+= "<option value=\""+plugin["name"]+"\" selected=\"selected\" disabled=\"disabled\">"+plugin["name"]+"</option>"
|
||||||
if (plugin["extra_params"]){
|
}
|
||||||
plugins_params[plugin["name"]]={};
|
}
|
||||||
for (param in plugin["extra_params"]){
|
else{
|
||||||
if (typeof plugin["extra_params"][param] !="string"){
|
if (plugin["is_activated"]){
|
||||||
var params = new Array();
|
html+= "<option value=\""+plugin["name"]+"\">"+plugin["name"]+"</option>"
|
||||||
var alias = plugin["extra_params"][param]["aliases"][0];
|
}
|
||||||
params[alias]=new Array();
|
else{
|
||||||
for (option in plugin["extra_params"][param]["options"]){
|
html+= "<option value=\""+plugin["name"]+"\" disabled=\"disabled\">"+plugin["name"]+"</option>"
|
||||||
params[alias].push(plugin["extra_params"][param]["options"][option])
|
}
|
||||||
}
|
}
|
||||||
plugins_params[plugin["name"]][alias] = (params[alias])
|
}
|
||||||
}
|
|
||||||
}
|
if (plugin["extra_params"]){
|
||||||
}
|
plugins_params[plugin["name"]]={};
|
||||||
var pluginList = document.createElement('li');
|
for (param in plugin["extra_params"]){
|
||||||
|
if (typeof plugin["extra_params"][param] !="string"){
|
||||||
newHtml = ""
|
var params = new Array();
|
||||||
if(plugin.url) {
|
var alias = plugin["extra_params"][param]["aliases"][0];
|
||||||
newHtml= "<a href="+plugin.url+">" + plugin.name + "</a>";
|
params[alias]=new Array();
|
||||||
}else {
|
for (option in plugin["extra_params"][param]["options"]){
|
||||||
newHtml= plugin["name"];
|
params[alias].push(plugin["extra_params"][param]["options"][option])
|
||||||
}
|
}
|
||||||
newHtml += ": " + replaceURLWithHTMLLinks(plugin.description);
|
plugins_params[plugin["name"]][alias] = (params[alias])
|
||||||
pluginList.innerHTML = newHtml;
|
}
|
||||||
availablePlugins.appendChild(pluginList)
|
}
|
||||||
}
|
}
|
||||||
|
var pluginList = document.createElement('li');
|
||||||
|
|
||||||
|
newHtml = ""
|
||||||
|
if(plugin.url) {
|
||||||
|
newHtml= "<a href="+plugin.url+">" + plugin.name + "</a>";
|
||||||
|
}else {
|
||||||
|
newHtml= plugin["name"];
|
||||||
|
}
|
||||||
|
newHtml += ": " + replaceURLWithHTMLLinks(plugin.description);
|
||||||
|
pluginList.innerHTML = newHtml;
|
||||||
|
availablePlugins.appendChild(pluginList)
|
||||||
|
}
|
||||||
|
html += "</optgroup>"
|
||||||
|
}
|
||||||
document.getElementById('plugins').innerHTML = html;
|
document.getElementById('plugins').innerHTML = html;
|
||||||
change_params();
|
change_params();
|
||||||
|
|
||||||
@ -88,8 +102,23 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
function change_params(){
|
function change_params(){
|
||||||
var plugin = document.getElementById("plugins").options[document.getElementById("plugins").selectedIndex].value;
|
var plugin = document.getElementById("plugins").options[document.getElementById("plugins").selectedIndex].value;
|
||||||
|
|
||||||
html=""
|
html=""
|
||||||
|
for (param in default_params){
|
||||||
|
if ((default_params[param]['options']) && (['help','conversion'].indexOf(param) < 0)){
|
||||||
|
html+= "<label> "+param+"</label>"
|
||||||
|
html+= "<select id=\""+param+"\" name=\""+param+"\">"
|
||||||
|
for (option in default_params[param]['options']){
|
||||||
|
if (default_params[param]['options'][option] == default_params[param]['default']){
|
||||||
|
html+="<option value \""+default_params[param]['options'][option]+"\" selected >"+default_params[param]['options'][option]+"</option>"
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
html+="<option value \""+default_params[param]['options'][option]+"\">"+default_params[param]['options'][option]+"</option>"
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
html+="</select><br>"
|
||||||
|
}
|
||||||
|
}
|
||||||
for (param in plugins_params[plugin]){
|
for (param in plugins_params[plugin]){
|
||||||
if (param || plugins_params[plugin][param].length > 1){
|
if (param || plugins_params[plugin][param].length > 1){
|
||||||
html+= "<label> Parameter "+param+"</label>"
|
html+= "<label> Parameter "+param+"</label>"
|
||||||
@ -120,15 +149,32 @@ function load_JSON(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var response = JSON.parse($.ajax({type: "GET", url: url , async: false}).responseText);
|
|
||||||
|
for (param in default_params){
|
||||||
|
if ((param != null) && (default_params[param]['options']) && (['help','conversion'].indexOf(param) < 0)){
|
||||||
|
var param_value = encodeURIComponent(document.getElementById(param).options[document.getElementById(param).selectedIndex].text);
|
||||||
|
if (param_value){
|
||||||
|
url+="&"+param+"="+param_value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = $.ajax({type: "GET", url: url , async: false}).responseText;
|
||||||
|
rawcontainer.innerHTML = replaceURLWithHTMLLinks(response)
|
||||||
|
|
||||||
|
document.getElementById("input_request").innerHTML = "<a href='"+url+"'>"+url+"</a>"
|
||||||
|
document.getElementById("results-div").style.display = 'block';
|
||||||
|
try {
|
||||||
|
response = JSON.parse(response);
|
||||||
var options = {
|
var options = {
|
||||||
mode: 'view'
|
mode: 'view'
|
||||||
};
|
};
|
||||||
var editor = new JSONEditor(container, options, response);
|
var editor = new JSONEditor(container, options, response);
|
||||||
editor.expandAll();
|
editor.expandAll();
|
||||||
rawcontainer.innerHTML = replaceURLWithHTMLLinks(JSON.stringify(response, undefined, 2))
|
}
|
||||||
document.getElementById("input_request").innerHTML = "<a href='"+url+"'>"+url+"</a>"
|
catch(err){
|
||||||
document.getElementById("results-div").style.display = 'block';
|
console.log("Error decoding JSON (got turtle?)");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user