oda-hub / frontend-tab-generator

0 stars 0 forks source link

add Euclid UI element #19

Closed volodymyrss closed 7 months ago

volodymyrss commented 10 months ago

https://github.com/oda-hub/mmoda-frontend-module/issues/197

dsavchenko commented 8 months ago

It's more complicated than I thought. The way @motame proposed in https://github.com/oda-hub/mmoda-frontend-module/issues/197 is following the PHP convention of adding square brackets to the names of the form fields to form-encode complex data structures. But Flask doesn't follow this convention.

If we stick to this convention, the needed adaptations are:

  1. Instead of just taking values in https://github.com/oda-hub/dispatcher-app/blob/f8098edb7c19931fe41e4dc812814e27d54cfedd/cdci_data_analysis/flask_app/dispatcher_query.py#L825, we will need to mimic such behaviour by parsing parameter names and using request.form.getlist where needed. It could be quite complicated to implement a general enough case.
  2. oda_api will also require changes: constructing properly named request parameters from a structured data.

More natural approach is to send structured parameters json-encoded. This still requires adaptations to dispatcher and oda_api, but they seem to be way more straightforward. On the other hand, this requires some JS on the frontend side to encode this argument before submitting the form. Is it achievable, @motame?

motame commented 8 months ago

Yes, it's possible to send the whole parameters as one json object instead. I'll implement it soon and let you know.

motame commented 8 months ago

@dsavchenko, do you prefer only the parameter filters as JSON object or the whole parameters within one JSON object ?

dsavchenko commented 8 months ago

I think, encoding all parameters in one json object will be rather backwards-incompatible change. Whereas, for this single new type of parameters - it's feasible. We can further discuss today

motame commented 8 months ago

Yeah indeed, let us do that for all "array" parameters only.

motame commented 8 months ago

The new feature has been implemented. The multi-valued parameters (fields) are sent as JSON strings to the server. See attached screenshot for an example Mo0Hysz1iO

Pushed to the branch euclid-filter-select-ui (linked to this issue)

dsavchenko commented 8 months ago

Cool! Thanks!

dsavchenko commented 8 months ago

This requires adding the jquery.serializeJSON library to https://github.com/oda-hub/mmoda-frontend-drupal, right?

motame commented 8 months ago

Oups ! sorry, I forgot to mention that. Indeed, yes. It is added under sites/all/libraries ...

sites/all/libraries$ ls -l jquery.serializeJSON
total 104
-rw-rw-r-- 1 meharga www-data   635 Jan 15 17:32 bower.json
-rw-rw-r-- 1 meharga www-data  5716 Jan 15 17:32 CHANGELOG.md
-rw-rw-r-- 1 meharga www-data 15614 Jan 15 17:32 jquery.serializejson.js
-rw-rw-r-- 1 meharga www-data  4635 Jan 15 17:32 jquery.serializejson.min.js
-rw-rw-r-- 1 meharga www-data  1077 Jan 15 17:32 LICENSE.txt
-rw-rw-r-- 1 meharga www-data   969 Jan 15 17:32 package.json
-rw-rw-r-- 1 meharga www-data 34782 Jan 15 17:32 package-lock.json
-rw-rw-r-- 1 meharga www-data 19450 Jan 15 17:32 README.md
drwxrwxr-x 3 meharga www-data  4096 Jan 15 17:32 spec
git clone https://github.com/marioizquierdo/jquery.serializeJSON.git
dsavchenko commented 8 months ago

This basically works, but it relies on the hardcoded parameter name "filter", whereas with nb2workflow plugin the name of this table parameter may be arbitrary.
Both validation code and json-encoding should rely on e.g. class