Storage¶
This page describes everything about the core/storage.js file, which provides functions and classes to handle the multiple projects support.
The first thing to note is that the platform uses LocalStorage to save the projects locally, this means no data is sent to a server and, due to browser policies, the HTTP and HTTPS intances of the platform cannot share the projects, since this would mean sharing data between a secure and non secure connection, even though it is only locally processed.
Also, is based on Google Blockly storage.js, so the classes and functions names are mostly the same, but have been deeply changed to handle multiple projects, the file editor and the Freeboard implementation.
Since LocalStorage is a two column database, where the first is the key and the second is the data, the platform stores the project as the following:
bipes_projects
: JSON structured object with a list of projects with the uid as the key and timestamp as the data;account_user
: The preferred name for the user, setted up in the account panel;UID
: The key for each project is its unique identifier (uid) and the stored data is the platform XML, which includes its tags, the Blockly XML and the Freeboard JSON.
All functions are described below, also see ui.account()
, since it is the class responsible to handle the user interface changes when creating, deleting, importing and switching projects.
- class BlocklyStorage()¶
Create the storage namespace.
- BlocklyStorage.httpRequest_¶
type: XMLHttpRequest
Global reference to current AJAX request.
- BlocklyStorage.alert(message)¶
Present a text message to the user. Designed to be overridden if an app has custom dialogs, or a butter bar.
- Arguments
message (
string()
) – Text to alert.
- BlocklyStorage.backupBlocks_(opt_workspace)¶
Backup code blocks to localStorage.
- Arguments
opt_workspace (
Blockly.WorkspaceSvg()
) – Workspace.
- BlocklyStorage.backupOnUnload(opt_workspace)¶
Bind the localStorage backup function to the unload event.
- Arguments
opt_workspace (
Blockly.WorkspaceSvg()
) – Workspace.
- BlocklyStorage.handleRequest_()¶
Callback function for AJAX call.
- BlocklyStorage.link(opt_workspace)¶
Save blocks to database and return a link containing key to XML.
- Arguments
opt_workspace (
Blockly.WorkspaceSvg()
) – Workspace.
- BlocklyStorage.loadXml_(xml, workspace)¶
Load blocks from XML.
- Arguments
xml (
string()
) – Text representation of XML.workspace (
Blockly.WorkspaceSvg()
) – Workspace.
- BlocklyStorage.makeRequest_(url, name, content, workspace)¶
Fire a new AJAX request.
- Arguments
url (
string()
) – URL to fetch.name (
string()
) – Name of parameter.content (
string()
) – Content of parameter.workspace (
Blockly.WorkspaceSvg()
) – Workspace.
- BlocklyStorage.monitorChanges_(workspace)¶
Start monitoring the workspace. If a change is made that changes the XML, clear the key from the URL. Stop monitoring the workspace once such a change is detected.
- Arguments
workspace (
Blockly.WorkspaceSvg()
) – Workspace.
- BlocklyStorage.restoreBlocks(opt_workspace)¶
Restore code blocks from localStorage.
- Arguments
opt_workspace (
Blockly.WorkspaceSvg()
) – Workspace.
- BlocklyStorage.retrieveXml(key, opt_workspace)¶
Retrieve XML text from database using given key.
- Arguments
key (
string()
) – Key to XML, obtained from href.opt_workspace (
Blockly.WorkspaceSvg()
) – Workspace.