From 41ff49f58edd1a491c572c3a893b4463e158d489 Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Wed, 26 Oct 2016 15:27:58 +0200 Subject: [PATCH] Refactored folia_label calls, function now takes set label into account directly (refactors #37) + Render features in viewer (start of #43) --- flat/style/flat.editor.js | 27 ++++-------------------- flat/style/flat.js | 16 +++++++++++++- flat/style/flat.viewer.js | 44 +++++++++++++-------------------------- 3 files changed, 34 insertions(+), 53 deletions(-) diff --git a/flat/style/flat.editor.js b/flat/style/flat.editor.js index 070dad7..d75780c 100644 --- a/flat/style/flat.editor.js +++ b/flat/style/flat.editor.js @@ -86,11 +86,7 @@ function setaddablefields() { Object.keys(declarations).forEach(function(annotationtype){ Object.keys(declarations[annotationtype]).forEach(function(set){ if ((annotationtype != "correction") && (viewannotations[annotationtype + "/" + set]) && (folia_accepts(editedelementtype,annotationtype))) { - if ((setdefinitions) && (setdefinitions[set]) && (setdefinitions[set].label)) { - label = setdefinitions[set].label; - } else { - label = folia_label(annotationtype); - } + label = folia_label(annotationtype, set); setname = shorten(set); //check if it already exists found = false; @@ -398,11 +394,7 @@ function showeditor(element) { if ((annotation.type != "correction") && ((editannotations[annotation.type+"/" + annotation.set]) || (isannotationfocus))) { //Get the human-presentable label for the annotation type - if ((setdefinitions) && (setdefinitions[annotation.set]) && (setdefinitions[annotation.set].label)) { - label = setdefinitions[annotation.set].label; - } else { - label = folia_label(annotation.type); - } + label = folia_label(annotation.type, annotation.set); if (annotation.set) { setname = annotation.set; @@ -722,13 +714,7 @@ function closeeditor() { function addeditorfield(index) { /* add a new field to the editor, populated by setaddablefields() */ - if ((setdefinitions) && (setdefinitions[editoraddablefields[index].set]) && (setdefinitions[editoraddablefields[index].set].label)) { - label = setdefinitions[editoraddablefields[index].set].label; - } else if (folia_label(editoraddablefields[index].type)) { - label = folia_label(editoraddablefields[index].type); - } else { - label = editoraddablefields[index].type; - } + label = folia_label(editoraddablefields[index].type, editoraddablefields[index].set); if (editoraddablefields[index].set) { setname = editoraddablefields[index].set; } else { @@ -946,11 +932,7 @@ function editor_loadmenus() { if ((configuration.initialeditannotations === true) || (configuration.initialeditannotations.indexOf(annotationtype + '/' + set) != -1) || (configuration.initialeditannotations.indexOf(annotationtype) != -1)) { editannotations[annotationtype + "/" + set] = true; } - if ((setdefinitions) && (setdefinitions[set]) && (setdefinitions[set].label)) { - label = setdefinitions[set].label; - } else { - label = folia_label(annotationtype); - } + label = folia_label(annotationtype, set); s = s + "
  • " + label + "" + set + "
  • "; } }); @@ -1574,7 +1556,6 @@ function editor_oninit() { var s = ""; folia_annotationlist().forEach(function(annotationtype){ - //TODO: restrict using ACCEPTED_DATA s = s + ""; }); $('#newdeclarationannotationtype').html(s); diff --git a/flat/style/flat.js b/flat/style/flat.js index f411869..9cd622c 100644 --- a/flat/style/flat.js +++ b/flat/style/flat.js @@ -34,9 +34,15 @@ function folia_parse(element, ancestors) { } } -function folia_label(tag) { +function folia_label(tag, set) { //Get the human-readable label for an annotation type (corresponding to a FoLiA XML tag), if defined var foliaclass = foliatag2class[tag]; + + if ((set) && (setdefinitions) && (setdefinitions[set]) && (setdefinitions[set].label)) { + //Grab the label from the set definition + return setdefinitions[set].label; + } + if ((foliaelements[foliaclass]) && (foliaelements[foliaclass].properties.label)) { return foliaelements[foliaclass].properties.label; } else { @@ -44,6 +50,14 @@ function folia_label(tag) { } } +function folia_subset_label(set, subset) { + if ((set) && (setdefinitions) && (setdefinitions[set]) && (setdefinitions[set].subsets) && (setdefinitions[set].subsets[subset]) && (setdefinitions[set].subsets[subset].label)) { + return setdefinitions[set].subsets[subset].label; + } else { + return subset; + } +} + function folia_isspan(tag) { //Is the element a first order span element? var foliaclass = foliatag2class[tag]; diff --git a/flat/style/flat.viewer.js b/flat/style/flat.viewer.js index 7203c55..495e1f7 100644 --- a/flat/style/flat.viewer.js +++ b/flat/style/flat.viewer.js @@ -261,7 +261,7 @@ function rendercorrection(correctionid, addlabels, explicitnew) { if (viewannotations[e.type+"/"+e.set]) { s = s + "New"; if (addlabels) { - s = s + " " + folia_label(e.type); + s = s + " " + folia_label(e.type, e.set); } s = s + ": "; s = s + "
    "; @@ -275,7 +275,7 @@ function rendercorrection(correctionid, addlabels, explicitnew) { if (viewannotations[e.type+"/"+e.set]) { s = s + "Current"; if (addlabels) { - s = s + " " + folia_label(e.type); + s = s + " " + folia_label(e.type, e.set); } s = s + ": "; s = s + "
    "; @@ -290,7 +290,7 @@ function rendercorrection(correctionid, addlabels, explicitnew) { if (viewannotations[original.type+"/"+original.set]) { s = s + "Original"; if (addlabels) { - s = s + " " + folia_label(original.type); + s = s + " " + folia_label(original.type, original.set); } s = s + ": "; s = s + "
    "; @@ -309,13 +309,13 @@ function rendercorrection(correctionid, addlabels, explicitnew) { s = s + "
    "; suggestion.children.forEach(function(child){ s = s + ""; - label = folia_label(child.type); + label = folia_label(child.type, child.set); s = s + ""; if ((folia_isstructure(child.type)) && (child.children)) { child.children.forEach(function(subchild){ - s = s + ""; }); @@ -411,7 +411,7 @@ function renderannotation(annotation, norecurse) { if (subannotation.type) { //filter out invalid elements if (subannotation.type != "correction") { s = s + "
    " + label + ""; s = s + renderannotation(child,true); s = s + "
    " + folia_label(subchild.type) + ""; + s = s + "
    " + folia_label(subchild.type, subchild.set) + ""; s = s + renderannotation(subchild,true); s = s + "
    "; - label = folia_label(subannotation.type); + label = folia_label(subannotation.type, subannotation.set); if (subannotation.set) { setname = subannotation.set; } else { @@ -431,12 +431,13 @@ function renderannotation(annotation, norecurse) { s = s + ""; } if (annotation.children) { + //Render higher order annotation for (i = 0; i < annotation.children.length; i++) { if (annotation.children[i].type) { - if (annotation.children[i].type == "comment") { - s = s + "
    Comment: " + annotation.children[i].value + ""; - } else if (annotation.children[i].type == "desc") { - s = s + "
    Description: " + annotation.children[i].value + ""; + if ((annotation.children[i].type == "comment") || (annotation.children[i].type == "desc")) { + s = s + "
    " + folia_label(annotation.children[i].type) + ": " + annotation.children[i].value + ""; + } else if (annotation.children[i].type == "feat") { + s = s + "
    " + folia_label(annotation.children[i].type) + " " + annotation.children[i].subset + ": " + annotation.children[i].class + ""; } } } @@ -473,16 +474,12 @@ function showinfo(element) { if (element.id) { var s = ""; if (annotations[element.id]) { - s = "
    " + folia_label(annotations[element.id].self.type) + " • " + element.id + " • " + annotations[element.id].self.class + "
    "; + s = "
    " + folia_label(annotations[element.id].self.type, annotations[element.id].self.set) + " • " + element.id + " • " + annotations[element.id].self.class + "
    "; Object.keys(annotations[element.id]).forEach(function(annotationid){ annotation = annotations[element.id][annotationid]; if ((annotation.type != 'str') || ((annotation.type == 'str') && (annotationid == hoverstr))) { //strings too if ((viewannotations[annotation.type+"/" + annotation.set]) && (annotation.type != "correction")) { //corrections get special treatment - if ((setdefinitions) && (setdefinitions[annotation.set]) && (setdefinitions[annotation.set].label)) { - label = setdefinitions[annotation.set].label; - } else { - label = folia_label(annotation.type); - } + label = folia_label(annotation.type, annotation.set); if (annotation.set) { setname = annotation.set; } else { @@ -633,14 +630,7 @@ function setclasscolors() { var legendtype = annotationfocus.type; var legendset = annotationfocus.set; - var legendtitle; - if ((setdefinitions[legendset]) && (setdefinitions[legendset].label)) { - legendtitle = setdefinitions[legendset].label; - } else if (folia_label(legendtype)) { - legendtitle = folia_label(legendtype); - } else { - legendtitle = annotationfocus.type; - } + var legendtitle = folia_label(legendtype, legendset); var classfreq = computeclassfreq(); s = "Legend • " + legendtitle + ""; //text for legend @@ -1007,11 +997,7 @@ function viewer_loadmenus() { } else { state = ""; } - if ((setdefinitions) && (setdefinitions[set]) && (setdefinitions[set].label)) { - label = setdefinitions[set].label; - } else { - label = folia_label(annotationtype); - } + label = folia_label(annotationtype, set); s = s + "
  • " + label + "" + set + "
  • "; if (globannotationsorder.indexOf(annotationtype) != -1) { if (('initialglobviewannotations' in configuration ) && ((configuration.initialglobviewannotations === true) || (configuration.initialglobviewannotations.indexOf(annotationtype + '/' + set) != -1) || (configuration.initialglobviewannotations.indexOf(annotationtype) != -1))) {