Create cloud var from variable modal.
This commit is contained in:
1 parent
3ace717787
commit
9f892e501c
3 files changed
+43
-13
No files matched your search
@@ -397,11 +397,17 @@ class Blocks extends React.Component {
|
||||
handleOpenSoundRecorder () {
|
||||
this.props.onOpenSoundRecorder();
|
||||
}
|
||||
handlePromptCallback (input, optionSelection) {
|
||||
|
||||
/*
|
||||
* Pass along information about proposed name and variable options (scope and isCloud)
|
||||
* and additional potentially conflicting variable names from the VM
|
||||
* to the variable validation prompt callback used in scratch-blocks.
|
||||
*/
|
||||
handlePromptCallback (input, variableOptions) {
|
||||
this.state.prompt.callback(
|
||||
input,
|
||||
this.props.vm.runtime.getAllVarNamesOfType(this.state.prompt.varType),
|
||||
optionSelection);
|
||||
variableOptions);
|
||||
this.handlePromptClose();
|
||||
}
|
||||
handlePromptClose () {
|
||||
|
||||
@@ -24,8 +24,10 @@ class Prompt extends React.Component {
|
||||
if (event.key === 'Enter') this.handleOk();
|
||||
}
|
||||
handleOk () {
|
||||
// TODO CLOUD add cloud variable option info
|
||||
this.props.onOk(this.state.inputValue, (this.state.globalSelected ? 'global' : 'local'));
|
||||
this.props.onOk(this.state.inputValue, {
|
||||
scope: this.state.globalSelected ? 'global' : 'local',
|
||||
isCloud: this.state.cloudSelected
|
||||
});
|
||||
}
|
||||
handleCancel () {
|
||||
this.props.onCancel();
|
||||
|
||||
@@ -44,15 +44,7 @@ class CloudProvider {
|
||||
const messageString = event.data;
|
||||
log.info(`Received websocket message: ${messageString}`);
|
||||
const message = JSON.parse(messageString);
|
||||
if (message.method === 'set') {
|
||||
const varData = {
|
||||
varUpdate: {
|
||||
name: message.name,
|
||||
value: message.value
|
||||
}
|
||||
};
|
||||
this.vm.postIOData('cloud', varData);
|
||||
}
|
||||
this.parseMessage(message);
|
||||
};
|
||||
|
||||
this.connection.onopen = () => {
|
||||
@@ -65,6 +57,26 @@ class CloudProvider {
|
||||
};
|
||||
}
|
||||
|
||||
parseMessage (message) {
|
||||
const varData = {};
|
||||
switch (message.method) {
|
||||
case 'ack': {
|
||||
varData.varCreate = {
|
||||
name: message.name
|
||||
};
|
||||
break;
|
||||
}
|
||||
case 'set': {
|
||||
varData.varUpdate = {
|
||||
name: message.name,
|
||||
value: message.value
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.vm.postIOData('cloud', varData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format and send a message to the cloud data server.
|
||||
* @param {string} methodName The message method, indicating the action to perform.
|
||||
@@ -100,6 +112,16 @@ class CloudProvider {
|
||||
log.info(`Sent message to clouddata server: ${data}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an API for the VM's cloud IO device to create
|
||||
* a new cloud variable on the server.
|
||||
* @param {string} name The name of the variable to create
|
||||
* @param {string | number} value The value of the new cloud variable.
|
||||
*/
|
||||
createVariable (name, value) {
|
||||
this.writeToServer('create', name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides an API for the VM's cloud IO device to update
|
||||
* a cloud variable on the server.
|
||||
|
||||
Reference in new issue
Block a user