mdenet / educationplatform

Eclipse Public License 2.0
2 stars 3 forks source link

Add support for URL interpolation when setting up panels #156

Closed szschaler closed 7 months ago

szschaler commented 7 months ago

This PR adds support for interpolation in panel URLs in the activity specification.

This is useful to allow dependent activities to access information from other activities. The concrete motivating example was the generation of Xtext editors, where I may wish to allow students to access the meta-model generated by Xtext in the activity where they can try out their new language. The URL to that file is generated by the platform (specifically, the xtext tool) and so isn't known at the time when the activity specification file is written.

With this PR, I can now write something like:

{
  "id": "panel-mm",
  "name": "The meta-model generated by Xtext",
  "ref": "ecore",
  "file": "{{ID-panel-turtles}}/xtext-resources/generated/meta-model.ecore"
},

and have {{ID-panel-turtles}} replaced from session storage associated with the panel-turtles panel at runtime. For generated editors, the platform stores the editor URL in that session storage key.

This is a somewhat pragmatic change, which could be made more powerful, but for now I suggest we keep things simple. We may need to invest in a more systematic architecture should there be a need for more flexibility at any point down the line.

The change consists of two separate changes:

  1. Changing ActivityManager.js to perform the URL interpolation, and
  2. Changing FileHandler.js to gracefully manage unknown types of URLs even for private repositories.

The latter change isn't strictly related to URL interpolation, but is required so that the generated URL can actually be used by the platform even when the activity lives in a private repository. To make this compatible with how file saving is managed, I have also adjusted the code for canSave in various panel types to ensure we only attempt to save a panel when it actually has an associated SHA and, thus, we know that it came from the original repository. This may make it difficult for the platform to save back to public repositories.

szschaler commented 7 months ago

Documentation on the Wiki still needs updating when this PR is merged.