BIDMCDigitalPsychiatry / LAMP-platform

The LAMP Platform (issues and documentation).
https://docs.lamp.digital/
Other
13 stars 10 forks source link

Load Activity UI from URL in ActivitySpec #467

Closed avaidyam closed 2 years ago

avaidyam commented 2 years ago

Currently the HTML code for an Activity's UI is loaded statically by LAMP-dashboard like so:

let activityURL = "https://raw.githubusercontent.com/BIDMCDigitalPsychiatry/LAMP-activities/"
activityURL += process.env.REACT_APP_GIT_SHA === "dev" ? "dist/out" : "latest/out"

While we require this to still work as a fallback for older dashboard and server versions, the proper way of checking the URL in EmbeddedActivity should be:

let activity = ... // the activity object we need to load as a UI
let activitySpec = LAMP.ActivitySpec.view(activity.spec) // activity.spec === "lamp.tips" for example
// We use ActivitySpec.view() to return the SINGLE ActivitySpec object WITH all image/description/code data.
if (activitySpec?.executable?.startsWith("data:")) {
    iframe.srcdoc = atob(activitySpec.executable) // TODO strip "data:" URI prefix
} else if (activitySpec?.executable?.startsWith("https:")) {
    iframe.srcdoc = atob(await (await fetch(activitySpec.executable)).text())
} else if(fallbackURLs.includes(activitySpec?.executable ?? "")) {
    iframe.srcdoc =  atob(await (await fetch(fallbackURLs[activitySpec.executable])).text()) 
} else {
    iframe.srcdoc = "about:blank" // display an error dialog instead
}

This way, each individual API Server controls the code location. If a staging server requires different versions of the activities, the dashboard will load only what the staging server provides for URLs. Production servers should ideally be loading the code into the ActivitySpec object itself.

divyav2020 commented 2 years ago

We have updated the changes in dashboard-staging. LAMP_Admin Website_Load Activity UI from URL in ActivitySpec.xls

toujames commented 2 years ago

Hi all, Thanks for the progress so far on this issue. Just wanted to see if this is still being worked on or when this change will be pushed to the production dashboard?

avaidyam commented 2 years ago

@toujames This is complete but requires further testing and evaluation -- it will likely be pushed to production early next week.