From 6c2e3f8ea4299db63dacc51d4fdaf88d09c4065d Mon Sep 17 00:00:00 2001 From: Jean-Marc Vanel Date: Sat, 27 May 2017 12:19:47 +0200 Subject: [PATCH] Systematically add attributes to elements: "data-rdf-subject" , "data-rdf-property" , "data-rdf-object" , "data-rdf-type" ( pave the way for "User can set the class for dbPedia completion" #163 ) FIX bad name: objectURIstringValue, hyperlinkToObjectURI --- .../runtime/html/Form2HTMLBase.scala | 16 +++++++ .../runtime/html/Form2HTMLDisplay.scala | 45 +++++++++---------- .../runtime/html/Form2HTMLEdit.scala | 19 ++++---- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLBase.scala b/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLBase.scala index c0a594270..5c6c09dce 100644 --- a/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLBase.scala +++ b/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLBase.scala @@ -12,6 +12,7 @@ import deductions.runtime.utils.RDFPrefixes import java.net.URLEncoder import deductions.runtime.utils.CSSClasses import scala.xml.NodeSeq +import scala.xml.Elem /** generate HTML from abstract Form : common parts for Display & edition */ private[html] trait Form2HTMLBase[NODE, URI <: NODE] @@ -145,4 +146,19 @@ private[html] trait Form2HTMLBase[NODE, URI <: NODE] {text} } + + def addTripleAttributesToXMLElement(elem: Elem, entry: FormEntry): Elem = { + import entry._ + addAttributesToXMLElement(elem, Map( + "data-rdf-subject" -> subject.toString(), + "data-rdf-property" -> property.toString(), + "data-rdf-object" -> value.toString(), + "data-rdf-type" -> type_.toString())) + } + + /** add Attributes To XML Element - Note could be reused */ + private def addAttributesToXMLElement(elem: Elem, config: Map[String, String]): Elem = + elem.copy(attributes = config.foldRight(elem.attributes) { + case ((k, v), next) => new scala.xml.UnprefixedAttribute(k, v, next) + }) } diff --git a/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLDisplay.scala b/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLDisplay.scala index 98c6d75d1..5879907e4 100644 --- a/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLDisplay.scala +++ b/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLDisplay.scala @@ -9,6 +9,7 @@ import scala.xml.Text import scala.xml.Unparsed //import deductions.runtime.views.ToolsPage import deductions.runtime.utils.HTTPrequest + import scala.xml.UnprefixedAttribute /** generate HTML from abstract Form for Display (Read only) */ trait Form2HTMLDisplay[NODE, URI <: NODE] @@ -32,15 +33,15 @@ trait Form2HTMLDisplay[NODE, URI <: NODE] import resourceEntry._ - val subjectURIstringValue = value.toString() - val css = cssForURI(subjectURIstringValue) + val objectURIstringValue = value.toString() + val css = cssForURI(objectURIstringValue) /* provide draggable hyperlinks to form's fields, suitable to drop in social media */ val hyperlinkToField = { val id = urlEncode(resourceEntry.property).replace("%", "-") /* ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, * digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). */ - if( subjectURIstringValue != "" ) { + if( objectURIstringValue != "" ) { @@ -48,27 +49,25 @@ trait Form2HTMLDisplay[NODE, URI <: NODE] } else NodeSeq.Empty } - val hyperlinkToSubjectURI = - { - valueLabel - } - - val backLinkButton = (if (subjectURIstringValue.size > 0 && showExpertButtons) { + } draggable="true" >{ + valueLabel + }, + resourceEntry) + + val backLinkButton = (if (objectURIstringValue.size > 0 && showExpertButtons) { val title = s""" Reverse links for "$label" "$value" """ - makeBackLinkButton(subjectURIstringValue, title=title ) + makeBackLinkButton(objectURIstringValue, title=title ) } else NodeSeq.Empty ) - val normalNavigationButton = (if (subjectURIstringValue.size > 0 && showExpertButtons) { - 0 && showExpertButtons) { + } else NodeSeq.Empty ) @@ -86,14 +85,14 @@ trait Form2HTMLDisplay[NODE, URI <: NODE] } hyperlinkToField ++ - hyperlinkToSubjectURI ++ + hyperlinkToObjectURI ++ Text("\n") ++ backLinkButton ++ Text("\n") ++ normalNavigationButton ++ Text("\n") ++ - makeDrawGraphLink(subjectURIstringValue) ++ - makeDrawGraphLink(subjectURIstringValue, + makeDrawGraphLink(objectURIstringValue) ++ + makeDrawGraphLink(objectURIstringValue, toolURLprefix= s"https://scenaristeur.github.io/graphe/?endpoint=${request.localSparqlEndpoint}" + s"&sujet=", diff --git a/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLEdit.scala b/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLEdit.scala index 793d638ef..767829911 100644 --- a/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLEdit.scala +++ b/scala/forms/src/main/scala/deductions/runtime/html/Form2HTMLEdit.scala @@ -63,20 +63,21 @@ private[html] trait Form2HTMLEdit[NODE, URI <: NODE] // format: OFF if (openChoice)
+ { + addTripleAttributesToXMLElement( - + , resourceEntry) } {makeUserInfoOnTriples(resourceEntry.metadata,resourceEntry.timeMetadata)}
else new Text("") // format: ON @@ -119,18 +120,17 @@ private[html] trait Form2HTMLEdit[NODE, URI <: NODE] Seq( if (r.openChoice) {
+ {addTripleAttributesToXMLElement( - - {makeUserInfoOnTriples(r.metadata,r.timeMetadata)} + , r) } + {makeUserInfoOnTriples(r.metadata,r.timeMetadata)}
}else new Text("\n") , @@ -219,6 +219,7 @@ private[html] trait Form2HTMLEdit[NODE, URI <: NODE] case _ =>
+ {addTripleAttributesToXMLElement( - + } dropzone="copy" id={ htmlId } + > + , + lit ) } { makeUserInfoOnTriples(lit.metadata, lit.timeMetadata) }