jamesaoverton / cmi-pb-terminology

CMI-PB Controlled Terminology
0 stars 0 forks source link

Use metatable information to support autocomplete #51

Closed jamesaoverton closed 2 years ago

jamesaoverton commented 2 years ago

As @beckyjackson works on forms for editing rows with HTML forms (related to #35), it would be good to add support for autocomplete text fields. We tend to use Typeahead, which expects data in a simple JSON format, e.g. Gizmos search. The format is simple enough once we know what the available values are, and that should be guided by the metatable information. For a given field that we're editing:

  1. if the datatype condition is in("A", "B", "C") then the autocomplete should provide: "A", "B", "C"
  2. if the column structure is from(foo.bar), the autocomplete should provide values from the foo.bar column
  3. if the column structure is under(foo.bar, "baz"), the autocomplete should provide values from the "baz" branch of the foo.bar tree

So I think we need a function in the validate module that takes a table, column, and the string to complete, and returns a JSON array formatted for Typeagead.

lmcmicu commented 2 years ago

1, 2, and 3 could conceivably conflict, for instance a column might have a datatype condition like in("A", "B", "C") and also have an associated from() or under() structure. In such a case, which one should take priority?

jamesaoverton commented 2 years ago

Here's the relevant bit of Gizmos search using SQL's LIKE functionality to match substrings: https://github.com/ontodev/gizmos/blob/36a0c0ea678da2d8bdc2fc9f0dd8c09d964c2faa/gizmos/search.py#L95-L100