Giter VIP home page Giter VIP logo

shapeforms's Introduction

shapeForms

This project can generate UI forms from ShEx schemas.

It takes annotations from the UI ontology which can, for example, customize labels.

Functionality

Two functions are provided in order to build a form from a given Shape Expression.

shexToForm(shex)

Takes as a parameter the Shape Expression to transform, as a String. Returns the HTML Form with the equivalent fields, as a String.

postProcess()

Once the form HTML has been integrated in a page, this function looks for and assigns events to the elements which require it ("New", "Check" buttons)

A simple example of use:

let html = sf.shexToForm(text);
	
$("#resultform").html(html);

sf.postProcess();

Adoption

The project has been deployed in RDFShape.

Requirements/limitations

It is necessary to declare the start shape.

Example

You can try it in RDFShape

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vc: <http://www.w3.org/2006/vcard/ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX ui: <http://www.w3.org/ns/ui#>
PREFIX : <http://janeirodigital.com/layout#>
PREFIX solid: <http://www.w3.org/ns/solid/terms#>

start=@<#UserProfile>

<#UserProfile> {
  solid:webid IRI
    // ui:label "profile webid"
    // :readonly true ;
  vc:age xsd:int MinInclusive 18;
  :dni xsd:string Length 9;
  (   foaf:name xsd:string MinLength 2
    | foaf:givenName xsd:string ;
      foaf:familyName xsd:string
  )? ;
  vc:telephone IRI /^tel:\+?[0-9.-]/ + ;
  vc:hasAddress @<#vcard_street-address> * ;
  vc:organization-name xsd:string ?
    // ui:label "company" ;
  vc:someInt xsd:integer ;
} // ui:label "User Profile"

<#vcard_street-address> CLOSED {
  a [vc:Home vc:Postal] ?
    // ui:from vc:Type ;
  vc:street-address xsd:string ? // ui:label "street" ;
  (   vc:locality xsd:string ? ;
    | vc:region xsd:string ?
  ) ;
  vc:country-name @<#vcard_country-name>
    // ui:label "country" ;
  vc:postal-code xsd:string ?
} // ui:label "Address"

<#vcard_country-name> [
  "Afghanistan"
  "Belgium"
  "CR"
  "France"
  "日本"
  "United Kingdom"
  "United States"
  "Zimbabwe"
]

shapeforms's People

Contributors

exarcafidalgo avatar labra avatar

Stargazers

Ross Spencer avatar Álvaro Baños Gómez avatar Pablo Menéndez ◔_◔  avatar Othmane Bakhtaoui avatar  avatar

Watchers

 avatar James Cloos avatar Guillermo Facundo (Willy) avatar Pablo Menéndez ◔_◔  avatar  avatar

Forkers

herculescrue

shapeforms's Issues

Delete option

When adding a new element through +, implement the possibility to remove it as well.

Show property in referenced shapes

The following shape:

PREFIX ui: <http://www.w3.org/ns/ui#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#> 
prefix : <http://example.org/>


start=@:User

:User {
  :name     xsd:string ;
  :father @:Person   ;
  :mother @:Person
}

:Person {
  :name xsd:string
}

doesn't show the properties :father and :mother which makes it impossible to know to which one a name refers.

Recursividad

El funcionamiento estándar con las ShapeRef (ahora mismo) es que genere un mini-formulario con los correspondientes campos del referido. Esto está muy bien si, digamos, es un Usuario con una Dirección, pero cuando una Shape nos hace algo así:

<human> EXTRA wdt:P31 {
  wdt:P22 @<human> *;             # father
  wdt:P25 @<human> *;             # mother
}

Intenta generar formularios de aquí hasta la reunificación china, lo cual es excesivo, naturalmente.

Podríamos detectar que está referenciandose a sí mismo e imponer un límite... pero yo me pregunto, ¿no sería lógico dar la posibilidad de señalar como padre a una "entidad" de Humano ya creada? En un caso como este, ante un nuevo nacimiento de una figura pública sería algo esperable... Así que no todo son formularios simples, digo yo. Pero bueno, por ahora quizá con que estos campos se generen de manera gandul (lazy para los corsarios), un "Añadir Padre" supongo que será suficiente.

Ahora que me fijo, y lo anoto por curiosidad, se pueden tener varios padres. Imagino que se refiere pues a una cuestion legal, y no biológica.

Facetas

Otro detalle relativamente relevante (y este sí lo tiene nuestra contraparte). Así, si la Shape define:

foaf:name xsd:string MinLength 2

El correspondiente campo de tipo texto debiera incorporar tal limitación.
Si no me equivoco, en total tenemos:

	:name xsd:string /[a-z]+/;
	:age xsd:int MinInclusive/MinExclusive/MaxInclusive/MaxExclusive 18;
	:c xsd:int TotalDigits 3;
	:d xsd:int FractionDigits 4;
	:e xsd:string Length 6;
	:f xsd:string MinLength 3;
	:g xsd:string MaxLength 15;

Que serían aplicables a campos textuales y numéricos de manera no indistinta.

Cardinalidad

Por el momento, toda TripleConstraint se trata como si fuera campo único y obligatorio. Es necesario que las cardinalidades de las mismas repercutan en el formulario. Diría que sería algo así:

  • "?" : required=false.
  • "+" : mostrar el campo, incluir una opción para replicarlo cuanto se desee.
  • "*" : únicamente la opción de infinitud.
  • n : mostrarlo n veces.
  • {n,m} : mostrarlo n veces, ofrecer la opción de marras hasta un máximo de m totales.

Embedded valuesets seem to be ignored.

The following shape:

PREFIX ui: <http://www.w3.org/ns/ui#>
prefix : <http://example.org/>

start=@:Author

:Author {
  :p @:Values // ui:label "values" ;
}

:Values [ "0" ]

seems to work as expected (see this).

However, if the value set is embedded as:

PREFIX ui: <http://www.w3.org/ns/ui#>
prefix : <http://example.org/>

start=@:Author

:Author {
  :p [ "0" ] // ui:label "values" ;
}

the declaration is ignored. See here

Recursion

Handle recursion on-demand

A simple shape with recursion like:

PREFIX ui: <http://www.w3.org/ns/ui#>
prefix xsd: <http://www.w3.org/2001/XMLSchema#> 
prefix : <http://example.org/>

start=@:User

:User {
  :name  xsd:string ;
  :knows @:User*   ;
}

is not represented properly. I think it could be handled by showing the required elements of the referenced shape on demand.

It seems that it is not shown also by Eric's project. See recursion example here.

Improve README

Improve the information that is available in the README to facilitate a newcomer what the project is about.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.