Skip to content

New type of widget : TemplateListProperty #804

Description

@tfrancart

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.

  1. Modify SparnaturalConfig.ts to declare the new constant TemplateListWidget, as well as the sparnatural-config ontology file to declare the new property type
  2. Add new class TemplateListWidget under components/widgets that relies on select2 templating mechanism
  3. Modify WidgetFactory to add a case to build such a widget. The algorithm to determine the datasource should be identical to the ListWidget
  4. 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.

  1. if an element with the expected id is not found in the page, the widget should default to the same behavior as the ListWidget
  2. 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>
}
  1. 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.
  2. 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.
  3. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions