Skip to content

Commit

Permalink
Systematically add attributes to <input> elements: "data-rdf-subject"…
Browse files Browse the repository at this point in the history
… , "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
  • Loading branch information
jmvanel committed May 27, 2017
1 parent 2a9fb3e commit 6c2e3f8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -145,4 +146,19 @@ private[html] trait Form2HTMLBase[NODE, URI <: NODE]
<a href={createHyperlinkString(hrefPrefix, uri, blanknode)} style="color: rgb(44,133,254);">
{text}</a>
}

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)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -32,43 +33,41 @@ 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 != "" ) {
<a href={ "#" + id } draggable="true">
<i class="glyphicon glyphicon-link"></i>
</a>
<a id={ id }></a>
} else NodeSeq.Empty
}

val hyperlinkToSubjectURI =
<a href={ createHyperlinkString(hrefPrefix, subjectURIstringValue) }
class={css}
title={
s"""Value ${if (subjectURIstringValue != valueLabel) subjectURIstringValue else ""}
// val atts = new UnprefixedAttribute("", )

val hyperlinkToObjectURI =
addTripleAttributesToXMLElement(
<a href={ createHyperlinkString(hrefPrefix, objectURIstringValue) } class={ css } title={
s"""Value ${if (objectURIstringValue != valueLabel) objectURIstringValue else ""}
of type ${type_.toString()}"""
} draggable="true"
data-uri-subject={resourceEntry.subject.toString()}
data-uri-value={resourceEntry.value.toString()}
data-uri-type={resourceEntry.type_.toString()}
>{
valueLabel
}</a>

val backLinkButton = (if (subjectURIstringValue.size > 0 && showExpertButtons) {
} draggable="true" >{
valueLabel
}</a>,
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) {
<a class="btn btn-primary" href={ subjectURIstringValue } title={ s"Normal HTTP link to $value" }
val normalNavigationButton = (if (objectURIstringValue.size > 0 && showExpertButtons) {
<a class="btn btn-primary" href={ objectURIstringValue } title={ s"Normal HTTP link to $value" }
draggable="true"><i class="glyphicon glyphicon-share-alt"></i> </a>
} else NodeSeq.Empty )

Expand All @@ -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=",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,21 @@ private[html] trait Form2HTMLEdit[NODE, URI <: NODE]
// format: OFF
if (openChoice)
<div class={ css.cssClasses.formDivInputCSSClass }>
{
addTripleAttributesToXMLElement(
<input class={ css.cssClasses.formInputCSSClass +
" " + hasLookup }
value={ value.toString }
name={ makeHTMLNameResource(resourceEntry) }
id={ makeHTML_Id(resourceEntry) }
list={ makeHTMLIdForDatalist(resourceEntry) }
data-type={ type_.toString() }
placeholder={ placeholder }
title={ type_.toString() }
size={inputSize.toString()}
dropzone="copy"
autocomplete={if (lookupActivatedFor(resourceEntry)) "off" else null}
>
</input>
</input> , resourceEntry) }
{makeUserInfoOnTriples(resourceEntry.metadata,resourceEntry.timeMetadata)}
</div>
else new Text("") // format: ON
Expand Down Expand Up @@ -119,18 +120,17 @@ private[html] trait Form2HTMLEdit[NODE, URI <: NODE]
Seq(
if (r.openChoice) {
<div class={ css.cssClasses.formDivInputCSSClass }>
{addTripleAttributesToXMLElement(
<input class={ css.cssClasses.formInputCSSClass } value={
r.value.toString
} name={ makeHTMLNameBN(r) } id={
makeHTML_Id(r)
} data-type={
r.type_.toString()
} size={ inputSize.toString() }
placeholder={ placeholder }
title={ placeholder }
>
</input>
{makeUserInfoOnTriples(r.metadata,r.timeMetadata)}
</input> , r) }
{makeUserInfoOnTriples(r.metadata,r.timeMetadata)}
</div>
}else new Text("\n")
,
Expand Down Expand Up @@ -219,6 +219,7 @@ private[html] trait Form2HTMLEdit[NODE, URI <: NODE]

case _ =>
<div class={ css.cssClasses.formDivInputCSSClass }>
{addTripleAttributesToXMLElement(
<input class={ css.cssClasses.formInputCSSClass } value={
toPlainString(value)
} name={ makeHTMNameLiteral(lit) } type={
Expand All @@ -227,8 +228,10 @@ private[html] trait Form2HTMLEdit[NODE, URI <: NODE]
step = {xsd2html5Step(type_.toString())}
placeholder={ placeholder } title={ placeholder } size={
inputSize.toString()
} dropzone="copy" id={ htmlId } data-uri-property={ lit.property.toString() }>
</input>
} dropzone="copy" id={ htmlId }
>
</input> ,
lit ) }
{ makeUserInfoOnTriples(lit.metadata, lit.timeMetadata) }
</div>
<div class={ css.cssClasses.formDivEditInputCSSClass }>
Expand Down

0 comments on commit 6c2e3f8

Please sign in to comment.