edina / fieldtrip-cobweb-project

A cobweb theme for fieldtrip app
BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

Import Interoperability Profile data as radio buttons #152

Closed xmichael closed 8 years ago

xmichael commented 8 years ago

We were asked to provide a way for the following JSON to be used for the initialization of a survey. This will hopefully help in the brainstorming process of what comes next.

To implement this, one needs to work with the example bellow. It is essentially just an import of an external ad-hoc json to create a Survey Designer json:

The sample external JSON is as follows:

{
    "profiles": [
        {
            "label": "COBWEB Invasive Species Profile (GBIF)",
            "url": "http://prophet.ucd.ie/ontology/cobweb/profiles/prof#cobweb_invasive"
        }
    ],
    "requirements": [
        {
            "id": "http://prophet.ucd.ie/ontology/cobweb/profiles/prof#dim_invasive",
            "label": "GBIF Invasive Species Code",
            "meta": {
                "collection": "http://prophet.ucd.ie/ontology/cobweb/skos_gbif#Invasive_Plant_Species",
                "range": "http://prophet.ucd.ie/ontology/cobweb/skos/gbif#PhysicalEntity",
                "property": null,
                "inverseProperty": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
            },
            "required": true,
            "type": "list",
            "entries": [
                {
                    "id": "http://prophet.ucd.ie/ontology/cobweb/skos_gbif#JapaneseKnotweed",
                    "label": "Japanese Knotweed"
                },
                {
                    "id": "http://prophet.ucd.ie/ontology/cobweb/skos_gbif#GiantKnotweed",
                    "label": "Giant Knotweed"
                }
            ]
        }
    ]
}

One should be able to load the above onto the survey designer as an optional GET request profile e.g. http://surveydesigner/url?profile=http%3A//somedomain.com/widget/someprofile

Which will be used to pre-initialize a COBWEB survey with the a radio button and couple of custom attributes as follows:

{
   "fields" : [
      {
         "required" : true,
         "label" : "GBIF Invasive Species Code",
         "properties" : {
            "options" : [
               {
                  "value" : "Japanese Knotweed"
               },
               {
                  "value" : "Giant Knotweed"
               }
            ],
            "other" : false
         },
         "id" : "radio-1",
         "persistent" : false,
         "type" : "radio"
      }
   ],
   "geoms" : ["point"],
   "recordLayout" : {
      "headers" : []
   },
   "extra" : [
      {"http://prophet.ucd.ie/ontology/cobweb/profiles/prof#cobweb_invasive" : "COBWEB Invasive Species Profile (GBIF)"},
      {"http://prophet.ucd.ie/ontology/cobweb/skos_gbif#JapaneseKnotweed" : "Japanese Knotweed"},
       {"http://prophet.ucd.ie/ontology/cobweb/skos_gbif#GiantKnotweed" : "Giant Knotweed"}
   ],
   "title" : "Demo Survey"
}

This example is all we have and given that there are no solid rules about how to generalize the above approach we can "guess" that we should always:

  1. Parse the json file
  2. For each x in the array requirements create a radio button with values from requirement[x]["entries"]["label"]
  3. Create a custom attribute on the survey with key requirements[x]["entries"]["id"] and value requirements["entries"]["label"]
xmichael commented 8 years ago

Update

Instead of receiving the external JSON as a URL, it should be passed to a function directly as an argument e.g. initFromIP(json) would initialize the survey using the aforementioned radio buttons directly from the json parameter.

xmichael commented 8 years ago

Last tweaks based on last-minute feedback:

The above will be refactored in a more generic way only if there is an actual use-case or testbed to plan on.

gmh04 commented 8 years ago

above commit has been deployed