diff --git a/app.py b/app.py
index 97ef310..75fe344 100644
--- a/app.py
+++ b/app.py
@@ -568,7 +568,7 @@ def GET(self, name):
alert=block_user, limit=limit,
is_git_auth=is_git_auth,invalid=False,
project=conf.myProject,template=None,
- query_templates=None,knowledge_extractor=False)
+ query_templates=None,knowledge_extractor=set())
def POST(self, name):
""" Submit a new record
@@ -579,7 +579,6 @@ def POST(self, name):
the record ID (a timestamp)
"""
- web.header("X-Forwarded-For", session['ip_address'])
web.header("Content-Type","text/html; charset=utf-8")
web.header('Access-Control-Allow-Origin', '*')
web.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
@@ -597,18 +596,17 @@ def POST(self, name):
u.log_output('SUBMIT INVALID FORM', session['logged_in'], session['username'],name)
return render.record(record_form=f, pageID=name, user=user, alert=block_user,
limit=limit, is_git_auth=is_git_auth,invalid=True,
- project=conf.myProject,template=None,query_templates=None,knowledge_extractor=False)
+ project=conf.myProject,template=None,
+ query_templates=None,knowledge_extractor=set())
else:
recordData = web.input()
- print("inputData", recordData)
-
# load the template selected by the user
if 'res_name' in recordData:
if recordData.res_name != 'None':
f = forms.get_form(recordData.res_name)
query_templates = u.get_query_templates(recordData.res_name)
- extractor = u.has_extractor(recordData.res_name)
+ extractor = u.has_extractor(recordData.res_name)
return render.record(record_form=f, pageID=name, user=user, alert=block_user,
limit=limit, is_git_auth=is_git_auth,invalid=False,
project=conf.myProject,template=recordData.res_name,
@@ -690,7 +688,8 @@ def GET(self, name):
return render.modify(graphdata=data, pageID=recordID, record_form=f,
user=session['username'],ids_dropdown=ids_dropdown,
is_git_auth=is_git_auth,invalid=False,
- project=conf.myProject,template=res_template,query_templates=query_templates,knowledge_extractor=extractor)
+ project=conf.myProject,template=res_template,
+ query_templates=query_templates,knowledge_extractor=extractor)
else:
session['logged_in'] = 'False'
raise web.seeother(prefixLocal+'/')
diff --git a/forms.py b/forms.py
index 8d86672..25b5547 100644
--- a/forms.py
+++ b/forms.py
@@ -216,7 +216,8 @@ def get_form(json_form, from_dict=False, subtemplate=False):
class_= classes,
value=default,
mandatory = mandatory,
- subtemplate = resource_class), ) + get_form(field['import_subtemplate'], subtemplate=True)
+ subtemplate = resource_class,
+ subtemplateID = field['import_subtemplate']), ) + get_form(field['import_subtemplate'], subtemplate=True)
if subtemplate:
return params
diff --git a/static/css/main.css b/static/css/main.css
index 0d2925c..f2273ef 100644
--- a/static/css/main.css
+++ b/static/css/main.css
@@ -776,6 +776,10 @@ span[class^='tag Q']:hover {
margin-left: 20px;
}
+input[type='checkbox'],
+input[type='radio'] {
+ accent-color: rgb(100, 23, 180);
+}
input[type='text'],
input[type='textarea'],
@@ -2009,14 +2013,83 @@ button#showTemplates {
font-size: 85%;
}
-.import_form {
+.import-form {
margin-left: 0px !important;
margin-top: 0.7em;
}
+
.imported_graphs {
margin-top: 0.7em;
}
+.import-form + .block_field {
+ margin-top: 15px;
+ margin-left: 10px;
+}
+
+.import-form + .block_field .btn {
+ max-width: 35%;
+ float: right;
+}
+
+/* new Knowledge Extraction code */
+
+.extraction-form-div {
+ width: 90%;
+ margin-left: 5%;
+ margin-right: 5%;
+}
+
+.extraction-form-div:first-of-type {
+ color: rgb(100, 23, 180);
+ border-bottom: 1px solid rgb(100, 23, 180);
+ margin-top: 0.5em;
+}
+
+.fa-times {
+ position: absolute;
+ right: 50px;
+ margin-top: 12px;
+ color: rgb(100, 23, 180);
+ font-size: 0.9em;
+}
+
+.extraction-form-label:nth-child(2) {
+ margin-left: 3% !important;
+}
+
+.extraction-form-label, .extraction-form-input {
+ width: 48% !important;
+ display: inline-block;
+}
+
+.block_field input[type="text"].extraction-form-input:first-of-type {
+ margin-left: 0px !important;
+}
+
+.block_field input[type="text"].extraction-form-input {
+ margin-left: 3% !important;
+ padding-top: 0.4em;
+}
+
+.add-parameter {
+ display: block;
+ margin-left: 5%;
+ margin-bottom: 1.2em;
+ font-size: 0.8em;
+ color: rgb(100, 23, 180);
+ cursor: pointer;
+}
+
+.extractor-comment {
+ width: 90%;
+ margin-left: 5%;
+ margin-bottom: 0px;
+ padding: 5px;
+ font-size: 0.9em;
+ border-bottom: 1px solid darkgray;
+}
+
/* subtemplates */
.check_subtemplate {
margin-left: 1em;
@@ -2162,10 +2235,10 @@ input[subtemplate]+.fa-plus-circle {
#lang-form {
display: block;
position: absolute;
- background: #eae2f6;
+ background: #ECE0FD;
width: 400px;
padding: 20px;
- border: solid 1px black;
+ border: solid 1px rgb(100, 23, 180);
border-radius: 5px;
z-index: 1023;
}
diff --git a/static/js/main.js b/static/js/main.js
index 277b882..0e039a3 100644
--- a/static/js/main.js
+++ b/static/js/main.js
@@ -2,7 +2,7 @@
if (graph.length) {var in_graph = "FROM <"+graph+">"} else {var in_graph = ""}
const wd_img = ' '
const geo_img = '';
-const viaf_img = '';
+const viaf_img = '';
const wikidataEndpoint = "https://query.wikidata.org/sparql"
$(document).ready(function() {
@@ -2256,114 +2256,108 @@ function replace_existing_subforms() {
}
// create subrecords
-function create_subrecord(resource_class, field_name, el, subform_id=null ) {
+function create_subrecord(resourceClass, fieldName, el, subformId=null ) {
// prepare a new subrecord id
- if (!subform_id) {
+ if (!subformId) {
var now = new Date().valueOf();
- subform_id = (now / 1000).toString().replace('.', '-');
+ subformId = (now / 1000).toString().replace('.', '-');
}
- var form_id = $('.corners').eq(0).find('form').eq(0).attr('id'); // either 'recordForm' or 'modifyForm'
+ var formId = $('.corners').eq(0).find('form').eq(0).attr('id'); // either 'recordForm' or 'modifyForm'
replace_existing_subforms();
// prepare the new subrecord form
- const subrecord_section = $("");
- const subrecord_form = $("");
- subrecord_form.append($("
"+field_name+"
"));
+ const subrecordSection = $("");
+ const subrecordForm = $("");
+ subrecordForm.append($(""+fieldName+"
"));
// create a clone for each input belonging to the requested (sub-)template
- $("[class~='("+resource_class+")'][class~='original_subtemplate']").each(function() {
+ $("[class~='("+resourceClass+")'][class~='original_subtemplate']").each(function() {
// CREATE A CLONE ELEMENT
- const clone_element = $(this).parent().parent().clone();
- clone_element.attr("style", "display: block"); // make it visible
- clone_element.find('input').attr('data-subform',subform_id); // associate the input field with the subrecord id
- clone_element.find('input').removeClass('original_subtemplate');
+ const cloneElement = $(this).parent().parent().clone();
+ cloneElement.attr("style", "display: block"); // make it visible
+ cloneElement.find('input').attr('data-subform',subformId); // associate the input field with the subrecord id
+ cloneElement.find('input').removeClass('original_subtemplate');
// associate proper identifiers to input fields belonging to the subrecord form
- var input_id = clone_element.find('input:not([type="hidden"])').attr('id');
- console.log(input_id)
- clone_element.find('input:not([type="hidden"])').attr('id', input_id+"_"+subform_id.toString());
- clone_element.find('input:not([type="hidden"])').attr('name', input_id+"_"+subform_id.toString());
+ var inputId = cloneElement.find('input:not([type="hidden"])').attr('id');
+ cloneElement.find('input:not([type="hidden"])').attr('id', inputId+"_"+subformId.toString());
+ cloneElement.find('input:not([type="hidden"])').attr('name', inputId+"_"+subformId.toString());
// SET LITERAL INPUT FIELDS
- if (clone_element.find('[lang]').length>0) {
- var literal_input = clone_element.find('[lang]');
- var language_list_section = literal_input.parent().prev();
- language_list_section.find('a').each(function() {
- var onclick_attr = $(this).attr('onclick');
+ if (cloneElement.find('[lang]').length>0) {
+ var literalInput = cloneElement.find('[lang]');
+ var languageListSection = literalInput.parent().prev();
+ languageListSection.find('a').each(function() {
+ var onclickAttr = $(this).attr('onclick');
var regex = /'([^"]*)'/g;
- var original_id_extended = onclick_attr.match(regex)[0];
- var original_id = original_id_extended.substring(1, original_id_extended.length-1)
- $(this).attr('onclick', onclick_attr.replace(original_id, original_id+'_'+subform_id));
+ var originalIdExtended = onclickAttr.match(regex)[0];
+ var originalId = originalIdExtended.substring(1, originalIdExtended.length-1)
+ $(this).attr('onclick', onclickAttr.replace(originalId, originalId+'_'+subformId));
});
}
// add a main-lang hidden input in case of primary key
- if (clone_element.find('input.disambiguate').next('[type="hidden"]').length > 0) {
- var primary_key_lang_id = clone_element.find('input.disambiguate').next('[type="hidden"]').attr('id');
- clone_element.find('input[type="hidden"]').attr('id', primary_key_lang_id+"_"+subform_id.toString());
- clone_element.find('input[type="hidden"]').attr('name', primary_key_lang_id+"_"+subform_id.toString());
+ if (cloneElement.find('input.disambiguate').next('[type="hidden"]').length > 0) {
+ var primaryKeyLangId = cloneElement.find('input.disambiguate').next('[type="hidden"]').attr('id');
+ cloneElement.find('input[type="hidden"]').attr('id', primaryKeyLangId+"_"+subformId.toString());
+ cloneElement.find('input[type="hidden"]').attr('name', primaryKeyLangId+"_"+subformId.toString());
}
// SET SUBTEMPLATE FIELDS '+' BUTTON
- clone_element.find('[subtemplate]').each(function(){
- var subtemplate_class = $(this).attr('subtemplate');
- var field_name = $(this).parent().prev().text();
- var add_subrecord_btn = $(this).next('i');
- add_subrecord_btn.on('click', function(){
- create_subrecord(subtemplate_class,field_name,add_subrecord_btn);
+ cloneElement.find('[subtemplate]').each(function(){
+ var subtemplateClass = $(this).attr('subtemplate');
+ var fieldName = $(this).parent().prev().text();
+ var addSubrecordBtn = $(this).next('i');
+ addSubrecordBtn.on('click', function(){
+ create_subrecord(subtemplateClass,fieldName,addSubrecordBtn);
})
})
- console.log($('[name="'+input_id+'_'+subform_id+'-subrecords"]'))
-
// retrieve previously provided values in case they are available (i.e., modify subrecords):
- let clone_element_values = [];
- // a) single value
- if ($('#'+form_id+' #'+input_id+"_"+subform_id).length >0) {
- const to_be_modified = $('#'+form_id+' #'+input_id+'_'+subform_id);
- clone_element.find('input').val(to_be_modified.val());
+ let clonedElementValues = [];
+ // a) single value fields
+ if ($('#'+formId+' #'+inputId+"_"+subformId).length >0) {
+ const toBeModified = $('#'+form_id+' #'+inputId+'_'+subformId);
+ cloneElement.find('input').val(toBeModified.val());
}
- // b) multiple values
- if ($('#'+form_id+' [name^="'+input_id+'_"][name$="_'+subform_id+'"]:not([name="'+input_id.split('_')[0]+'_'+subform_id+'"])').length >0) {
- var imported_values = $('#'+form_id+' [name^="'+input_id.split('_')[0]+'_"][name$="_'+subform_id+'"]:not([name="'+input_id.split('_')[0]+'_'+subform_id+'"])');
- clone_element.find('.label div a').remove();
- if ($('#'+input_id).hasClass('searchWikidata') || $('#'+input_id).hasClass('searchVocab') || $('#'+input_id).hasClass('searchGeonamaes')) {
- imported_values.each(function(){
+ // b) multiple values fields
+ if ($('#'+formId+' [name^="'+inputId+'_"][name$="_'+subformId+'"]:not([name="'+inputId.split('_')[0]+'_'+subformId+'"])').length >0) {
+ var importedValues = $('#'+formId+' [name^="'+inputId.split('_')[0]+'_"][name$="_'+subformId+'"]:not([name="'+inputId.split('_')[0]+'_'+subformId+'"])');
+ cloneElement.find('.label div a').remove();
+ if ($('#'+inputId).hasClass('searchWikidata') || $('#'+inputId).hasClass('searchVocab') || $('#'+inputId).hasClass('searchGeonamaes')) {
+ importedValues.each(function(){
// imported values and URIs
var value = $(this).val();
var code = value.split(",")[0];
var label = decodeURIComponent(value.split(",")[1]);
- var imported_value_span = $(""+label+"");
- clone_element_values.push(imported_value_span);
- clone_element_values.push($(this));
+ var importedValueSpan = $(""+label+"");
+ clonedElementValues.push(importedValueSpan);
+ clonedElementValues.push($(this));
$(this).remove();
});
} else {
- imported_values.each(function(){
+ importedValues.each(function(){
// multiple-lang literal values
- clone_element_values.push($(this));
- clone_element.find('input').remove();
+ clonedElementValues.push($(this));
+ cloneElement.find('input').remove();
if($(this).attr('lang') != undefined) {
let lang = $(this).attr('lang');
- const new_lang_item = $(''+lang+'');
- clone_element.find('div').append(new_lang_item);
+ const newLangItem = $(''+lang+'');
+ cloneElement.find('div').append(newLangItem);
} else {
- let main_lang = $(this).val();
- clone_element.find('div a[title="text language: '+main_lang.toUpperCase()+'"]').addClass('main-lang');
+ let mainLang = $(this).val();
+ cloneElement.find('div a[title="text language: '+mainLang.toUpperCase()+'"]').addClass('main-lang');
}
});
- clone_element.find('div a').eq(0).addClass('selected-lang');
- clone_element_values[0].show();
- console.log(clone_element_values)
+ cloneElement.find('div a').eq(0).addClass('selected-lang');
+ clonedElementValues[0].show();
}
}
- // c) subrecords
- if ($('[name="'+input_id+'_'+subform_id+'-subrecords"]').length>0) {
+ // c) subrecords fields (inner subrecords)
+ if ($('[name="'+inputId+'_'+subformId+'-subrecords"]').length>0) {
// retrieve subrecords
- var subrecords = $('[name="'+input_id+'_'+subform_id+'-subrecords"]').val().split(',');
- console.log(subrecords)
- var subtemplate_field_id = $(this).attr('name').replace('-subrecords', '');
- console.log($('#'+subtemplate_field_id).attr('class'))
- var subrecord_cls = $('#'+subtemplate_field_id).attr('subtemplate')
+ var subrecords = $('[name="'+inputId+'_'+subformId+'-subrecords"]').val().split(',');
+ var subtemplateFieldId = $(this).attr('name').replace('-subrecords', '');
+ var subrecord_cls = $('#'+subtemplateFieldId).attr('subtemplate')
for (let i=0; i 0) {
- var main_lang = $('#'+subrecord_label_field.attr('id').split('_')[0] + '_mainLang_' + code).val();
- console.log('#'+subrecord_label_field.attr('id').split('_')[0] + '_mainLang_' + code)
- label = $('#'+subrecord_label_field.attr('id').split('_')[0]+'_'+main_lang+'_'+code).val();
- console.log('#'+subrecord_label_field.attr('id').split('_')[0]+'_'+main_lang+'_'+code)
- console.log(label)
+ var subrecordLabelField = $('.original_subtemplate.disambiguate[class*="('+subrecordCls+')"]');
+ if (subrecordLabelField.length > 0) {
+ var mainLang = $('#'+subrecordLabelField.attr('id').split('_')[0] + '_mainLang_' + code).val();
+ label = $('#'+subrecordLabelField.attr('id').split('_')[0]+'_'+mainLang+'_'+code).val();
}
}
- var subrecord_value_span = $(""+label+"")
- var modify_button = $('')
- var delete_button = $('')
- clone_element_values.push(subrecord_value_span, modify_button, delete_button);
+ var subrecordValueSpan = $(""+label+"")
+ var modifyButton = $('')
+ var deleteButton = $('')
+ clonedElementValues.push(subrecordValueSpan, modifyButton, deleteButton);
}
}
- clone_element.find('.input_or_select').eq(0).append(clone_element_values);
- subrecord_form.append(clone_element);
+ cloneElement.find('.input_or_select').eq(0).append(clonedElementValues);
+ subrecordForm.append(cloneElement);
+
})
+ // add knowledge extractor if required
+ var resourceTemplate = $('[subtemplate="'+resourceClass+'"').eq(0).attr('subtemplateid');
+ if (extractorsArray.includes(resourceTemplate)) {
+ generateExtractor(subformId,subrecordForm);
+ }
+
// save or cancel subrecord (buttons)
- const subrecord_buttons = $("");
- const save_subrecord_btn = $("");
- const cancel_subrecord_btn = $("");
+ const subrecordButtons = $("");
+ const saveSubrecordButton = $("");
+ const cancelSubrecordButton = $("");
- console.log(el)
// SAVE SUBRECORD
- save_subrecord_btn.on('click', function(e) {
+ saveSubrecordButton.on('click', function(e) {
// generate a tag
- var is_valid = check_mandatory_fields(this);
- if (is_valid) {
- var label_field = subrecord_form.find('.disambiguate').eq(0);
- var label_main_lang = $('#'+label_field.attr('id').replace(label_field.attr('lang'), 'mainLang')).val();
- var tag_label = subrecord_form.find('.disambiguate[lang="'+label_main_lang+'"]').val() || (field_name + "-" + subform_id);
+ var isValid = check_mandatory_fields(this);
+ if (isValid) {
+ var labelField = subrecordForm.find('.disambiguate').eq(0);
+ var labelMainLang = $('#'+labelField.attr('id').replace(labelField.attr('lang'), 'mainLang')).val();
+ var tagLabel = subrecordForm.find('.disambiguate[lang="'+labelMainLang+'"]').val() || (fieldName + "-" + subformId);
// store all the input ids to be associated with a subrecord
// append those inputs to the main record form to pass their values to the back-end application
let subinputs = [];
- subrecord_form.find('input:not(.btn)').each(function() {
- $('#'+form_id).append($(this));
+ subrecordForm.find('input:not(.btn)').each(function() {
+ $('#'+formId).append($(this));
$(this).hide();
if ($(this).attr('id') !== undefined) {
if($(this).attr('lang')!== undefined) {
@@ -2422,20 +2418,20 @@ function create_subrecord(resource_class, field_name, el, subform_id=null ) {
}
};
});
- el.after("
" + tag_label + "");
+ el.after("
" + tagLabel + "");
// for each subtemplate field, create an hidden input value including a list of related subrecords
// this is needed to streamline the creation of records (back-end application)
- var subrecord_base = $("[subtemplate='"+resource_class+"']").attr('id'); // the 'id' of the 'subtemplate' field (within the main record)
- var created_subrecords = $('[name="'+subrecord_base+'-subrecords"]');
- if (created_subrecords.length) {
- var to_extend_value = created_subrecords.val();
- if (!created_subrecords.val().split(',').includes(subform_id)) {
- created_subrecords.val(to_extend_value + "," + subform_id);
+ var subrecordBase = $("[subtemplate='"+resourceClass+"']").attr('id'); // the 'id' of the 'subtemplate' field (within the main record)
+ var createdSubrecords = $('[name="'+subrecord_base+'-subrecords"]');
+ if (createdSubrecords.length) {
+ var toExtendValue = createdSubrecords.val();
+ if (!createdSubrecords.val().split(',').includes(subformId)) {
+ createdSubrecords.val(toExtendValue + "," + subformId);
}
} else {
- const new_sub = $("");
- $('#'+form_id).append(new_sub);
+ const newSubrecord = $("");
+ $('#'+form_id).append(newSubrecord);
}
// hide_subform
cancel_subrecord(this);
@@ -2443,15 +2439,15 @@ function create_subrecord(resource_class, field_name, el, subform_id=null ) {
});
// CANCEL SUBRECORD
- cancel_subrecord_btn.on('click', function(e) {
+ cancelSubrecordButton.on('click', function(e) {
// hide_subform
cancel_subrecord(this);
});
- subrecord_buttons.append(cancel_subrecord_btn, save_subrecord_btn);
- subrecord_form.append(subrecord_buttons);
- subrecord_section.append(subrecord_form);
- $('.main_content').eq(0).prepend(subrecord_section);
+ subrecordButtons.append(cancelSubrecordButton, saveSubrecordButton);
+ subrecordForm.append(subrecordButtons);
+ subrecordSection.append(subrecordForm);
+ $('.main_content').eq(0).prepend(subrecordSection);
}
// CANCEL SUBRECORD (before adding it to #recordForm)
@@ -3033,12 +3029,11 @@ function add_field(field, res_type, backend_file=null) {
};
function import_subtemplate(el) {
-
var requested_template = el.value;
var requested_name = el.options[el.selectedIndex].text;
- var name_field = $(el).parent().next().find('input').eq(0);
- var class_field = $(el).parent().next().next().find('input').eq(0);
- var edit_field = $(el).parent().next().next().next();
+ var name_field = $(el).parent().next().find('input[type="text"]').eq(0);
+ var class_field = $(el).parent().next().next().find('input[type="text"]').eq(0);
+ var edit_field = $(el).parent().next().next().next('input[type="button"]');
$(name_field).parent().show();
$(class_field).parent().show();
// make fields not modifiable unless creating a new subtemplate
@@ -3124,7 +3119,7 @@ function add_disambiguate(temp_id, el) {
// YASQE editor for SPARQL query patterns
if (el.value == 'URI') {
var field_SPARQL_constraint = $("\
- \
+ \