marksherman/snapshot-service

Getting the Component JSON into snapshot

Closed this issue · 1 comments

Challenge

Getting the component descriptions, such as the JSON found in the scm file of an aia.

Goal

make that data available to Blockly.Snapshot.

This has been tricky, as that data exists in GWT-land, not in Blockly-land. There is no static method to get this in GWT, nor does the data ever get stored in Blockly.

Example

It should look something like this:

{"YaVersion":"130","Source":"Form","Properties":{"$Name":"level_2","$Type":"Form","$Version":"16","AppName":"Health","Title":"level_2","Uuid":"0","$Components":[{"$Name":"TextBox1","$Type":"TextBox","$Version":"5","Width":"200","Hint":"Hint for TextBox1","Text":"Which is the least healthiest?","Uuid":"1461121210"},{"$Name":"HorizontalArrangement1","$Type":"HorizontalArrangement","$Version":"2","Height":"-2","Width":"-2","Uuid":"516944001","$Components":[{"$Name":"Button2","$Type":"Button","$Version":"6","Height":"100","Width":"90","Text":"sweet potato","Uuid":"1324024303"},{"$Name":"Button1","$Type":"Button","$Version":"6","Height":"100","Width":"90","Text":"chocolate milk","Uuid":"-5647348"},{"$Name":"Button3","$Type":"Button","$Version":"6","Height":"100","Width":"90","Text":"cheese cake","Uuid":"-14857495"}]}]}}

Progress

In talking with @fturbak he pointed me towards the upgrader, which lives in versioning.js. We need to trace where the parameter preUpgradeFormJsonString comes from, as that's the source we need.

The upgrade function is called from savefile.js:39, within the load function. The load function is also handed the preUpgradeFormJson data as a parameter. So who calls load?

The ultimate source of that data is in GWT, in YaFormEditor.java

The load functions are called somewhere in YaFormEditor.java and YaBlocksEditor.java, (I believe the latter), and here's what we need to do.

What we need to do

When the java method calls the javascript, we need to stash the finished, post-upgrade JSON in a global variable, which will persist inside that form editor. Then, when we take a snapshot, it's already there in the variable. This will result in the data being accessible, and, as a bonus, fast.

Current task is to engineer this, which might require changes to the java, or maybe just the load functions in blockly.

Solution may include modification to YaFormEditor, YaBlocksEditor, savfile.js, or maybe versioning.js.

How to test success

Collecting the data at this point in snapshot.js:61, such that the form field in that object is filled by the desired component data. It should look like the example JSON above when the snapshot runs.

Snapshots are visible in the javascript console of the browser, and in the console running the snapshot service. I recommend running the snapshot service node server and a test instance of AI locally. The snapshot system will currently fail if the server can't be found.

A sucessful snapshot will look like this in the node server terminal, where the last field, form: is followed by the component JSON data:

Snapshot (blocklyWorkspaceChange) recieved at Mon Sep 14 2015 13:45:11 GMT-0400 (EDT)
Codename: TinyAnteater
{ userName: 'test@example.com',
  projectName: 'ya6',
  projectId: '5629499534213120',
  screenName: '5629499534213120_Screen1',
  sessionId: '722ec839-397d-43bc-a6c0-4b72e9267fc2',
  yaversion: 138,
  languageVersion: 19,
  eventType: 'blocklyWorkspaceChange' }
{ blocks: '<xml xmlns="http://www.w3.org/1999/xhtml">\n  <block type="logic_boolean" id="1" x="114" y="169">\n    <field name="BOOL">TRUE</field>\n  </block>\n  <block type="text" id="2" x="171" y="241">\n    <field name="TEXT"></field>\n  </block>\n  <yacodeblocks ya-version="138" language-version="19"></yacodeblocks>\n</xml>',
  form: {"YaVersion":"130","Source":"Form","Properties":{"$Name":"level_2","$Type":"Form","$Version":"16","AppName":"Health","Title":"level_2","Uuid":"0","$Components":[{"$Name":"TextBox1","$Type":"TextBox","$Version":"5","Width":"200","Hint":"Hint for TextBox1","Text":"Which is the least healthiest?","Uuid":"1461121210"},{"$Name":"HorizontalArrangement1","$Type":"HorizontalArrangement","$Version":"2","Height":"-2","Width":"-2","Uuid":"516944001","$Components":[{"$Name":"Button2","$Type":"Button","$Version":"6","Height":"100","Width":"90","Text":"sweet potato","Uuid":"1324024303"},{"$Name":"Button1","$Type":"Button","$Version":"6","Height":"100","Width":"90","Text":"chocolate milk","Uuid":"-5647348"},{"$Name":"Button3","$Type":"Button","$Version":"6","Height":"100","Width":"90","Text":"cheese cake","Uuid":"-14857495"}]}]}} }

@cecetsui @emeryotopalik

Fixed by #7