A new Sparnatural widget should be implemented, which extends the behavior of ListWidget. Currently ListWidget simply displays the label of entities retrieved from a SPARQL query, associated to their underlying URI. The goal is to build a similar widget that would rely on select2 templating capabilities in order to build dropdown lists in which the visual content could be customized and improved with more data. The data to populate the template will be returned by the underlying SPARQL Datasource.
- Modify SparnaturalConfig.ts to declare the new constant
TemplateListWidget, as well as the sparnatural-config ontology file to declare the new property type
- Add new class
TemplateListWidget under components/widgets that relies on select2 templating mechanism
- Modify WidgetFactory to add a case to build such a widget. The algorithm to determine the datasource should be identical to the ListWidget
TemplateListWidget should read its template string from an external (invisible) HTML element with a known ID. The ID should be the URI of the property received by the widget (objectPropVal variable), which is the URI of a PropertyShape, with -template at the end. e.g. something like:
<!-- our Sparnatural component -->
<spar-natural src="..." lang="fr" />
<!-- an hidden div containing the template associated to the property shape https://data.example.fr/def/myModel#P123 -->
<div style="display:none;" id="https://data.example.fr/def/myModel#P123-template">
<b>${data.firstName}</b> <u>${data.lastName}</u>
</div>
It could also be handlebar template if this is more appropriate. Maybe there should be some hypothesis on the name of the main data variable passed to the template. We can say it is always data for example.
- if an element with the expected id is not found in the page, the widget should default to the same behavior as the ListWidget
- The
RdfTermDatasourceItem which currently provides data to the ListWidget should be extended so that it also includes other values present inside the SPARQL result set as RDFTerms. e.g. for SELECT ?uri ?label ?count the count value should be accessible here. It can be in a new extraBindings variable:
export interface RdfTermDatasourceItem {
term:RDFTerm;
label:string;
group?:string;
itemLabel?:string;
extraBindings: Map<string, RDFTerm>
}
- All data of a
RdfTermDatasourceItem should be exposed to the select2 template in the TemplateListWidget, including term label, group, itemLabel and of course all extra bindings, using the key in the map as the variable name.
SparqlListDataProvider should be extended so that it is capable of reading any additional columns other than uri, value, label, group and itemLabel and return them in the extraBindings map.
- Improve the
widgets.md documentation file to add an extra section, leaving placeholders for screenshots. Explain how the template list widget should be configured and provide an example with the template in HTML and the corresponding SPARQL query.
A new Sparnatural widget should be implemented, which extends the behavior of ListWidget. Currently ListWidget simply displays the label of entities retrieved from a SPARQL query, associated to their underlying URI. The goal is to build a similar widget that would rely on select2 templating capabilities in order to build dropdown lists in which the visual content could be customized and improved with more data. The data to populate the template will be returned by the underlying SPARQL Datasource.
TemplateListWidget, as well as the sparnatural-config ontology file to declare the new property typeTemplateListWidgetundercomponents/widgetsthat relies on select2 templating mechanismTemplateListWidgetshould read its template string from an external (invisible) HTML element with a known ID. The ID should be the URI of the property received by the widget (objectPropValvariable), which is the URI of a PropertyShape, with-templateat the end. e.g. something like:It could also be handlebar template if this is more appropriate. Maybe there should be some hypothesis on the name of the main
datavariable passed to the template. We can say it is alwaysdatafor example.RdfTermDatasourceItemwhich currently provides data to theListWidgetshould be extended so that it also includes other values present inside the SPARQL result set asRDFTerms. e.g. forSELECT ?uri ?label ?countthecountvalue should be accessible here. It can be in a newextraBindingsvariable:RdfTermDatasourceItemshould be exposed to the select2 template in theTemplateListWidget, includingtermlabel,group,itemLabeland of course all extra bindings, using the key in the map as the variable name.SparqlListDataProvidershould be extended so that it is capable of reading any additional columns other thanuri,value,label,groupanditemLabeland return them in theextraBindingsmap.widgets.mddocumentation file to add an extra section, leaving placeholders for screenshots. Explain how the template list widget should be configured and provide an example with the template in HTML and the corresponding SPARQL query.