add access-token
This commit is contained in:
parent
49fb018703
commit
0e05cdca5c
@ -5,7 +5,7 @@ import store from '../../../store';
|
|||||||
|
|
||||||
var boxes = store.getState().auth.user ? store.getState().auth.user.boxes : null;
|
var boxes = store.getState().auth.user ? store.getState().auth.user.boxes : null;
|
||||||
store.subscribe(() => {
|
store.subscribe(() => {
|
||||||
boxes = store.getState().auth.user ? store.getState().auth.user.boxes : null;
|
boxes = store.getState().auth.user ? store.getState().auth.user.boxes : null;
|
||||||
});
|
});
|
||||||
var selectedBox = '';
|
var selectedBox = '';
|
||||||
|
|
||||||
@ -24,20 +24,20 @@ Blockly.Blocks['sensebox_osem_connection'] = {
|
|||||||
.setAlign(Blockly.ALIGN_LEFT)
|
.setAlign(Blockly.ALIGN_LEFT)
|
||||||
.appendField(Blockly.Msg.senseBox_osem_exposure)
|
.appendField(Blockly.Msg.senseBox_osem_exposure)
|
||||||
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_osem_stationary, 'Stationary'], [Blockly.Msg.senseBox_osem_mobile, 'Mobile']]), "type");
|
.appendField(new Blockly.FieldDropdown([[Blockly.Msg.senseBox_osem_stationary, 'Stationary'], [Blockly.Msg.senseBox_osem_mobile, 'Mobile']]), "type");
|
||||||
if(!boxes){
|
if (!boxes) {
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.setAlign(Blockly.ALIGN_LEFT)
|
.setAlign(Blockly.ALIGN_LEFT)
|
||||||
.appendField("senseBox ID")
|
.appendField("senseBox ID")
|
||||||
.appendField(new Blockly.FieldTextInput("senseBox ID"), "BoxID");
|
.appendField(new Blockly.FieldTextInput("senseBox ID"), "BoxID");
|
||||||
} else {
|
} else {
|
||||||
var dropdown = []
|
var dropdown = []
|
||||||
for (var i = 0; i < boxes.length; i++) {
|
for (var i = 0; i < boxes.length; i++) {
|
||||||
dropdown.push([boxes[i].name, boxes[i]._id])
|
dropdown.push([boxes[i].name, boxes[i]._id])
|
||||||
}
|
}
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.setAlign(Blockly.ALIGN_LEFT)
|
.setAlign(Blockly.ALIGN_LEFT)
|
||||||
.appendField("senseBox ID")
|
.appendField("senseBox ID")
|
||||||
.appendField(new Blockly.FieldDropdown(dropdown), 'BoxID');
|
.appendField(new Blockly.FieldDropdown(dropdown), 'BoxID');
|
||||||
}
|
}
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.setAlign(Blockly.ALIGN_LEFT)
|
.setAlign(Blockly.ALIGN_LEFT)
|
||||||
@ -51,6 +51,16 @@ Blockly.Blocks['sensebox_osem_connection'] = {
|
|||||||
},
|
},
|
||||||
onchange: function (e) {
|
onchange: function (e) {
|
||||||
selectedBox = this.getFieldValue('BoxID');
|
selectedBox = this.getFieldValue('BoxID');
|
||||||
|
console.log(selectedBox)
|
||||||
|
if (selectedBox !== '' && boxes) {
|
||||||
|
var accessToken = boxes.find(element => element._id === selectedBox).access_token
|
||||||
|
if (accessToken !== undefined) {
|
||||||
|
this.getField('access_token').setValue(accessToken)
|
||||||
|
} else {
|
||||||
|
this.getField('access_token').setValue('access_token')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
mutationToDom: function () {
|
mutationToDom: function () {
|
||||||
var container = document.createElement('mutation');
|
var container = document.createElement('mutation');
|
||||||
@ -99,17 +109,17 @@ Blockly.Blocks['sensebox_send_to_osem'] = {
|
|||||||
this.setColour(getColour().sensebox);
|
this.setColour(getColour().sensebox);
|
||||||
this.appendDummyInput()
|
this.appendDummyInput()
|
||||||
.appendField(Blockly.Msg.senseBox_send_to_osem);
|
.appendField(Blockly.Msg.senseBox_send_to_osem);
|
||||||
if(boxes){
|
if (boxes) {
|
||||||
this.appendValueInput('Value')
|
this.appendValueInput('Value')
|
||||||
.appendField('Phänomen')
|
.appendField('Phänomen')
|
||||||
.appendField(new Blockly.FieldDropdown(
|
.appendField(new Blockly.FieldDropdown(
|
||||||
this.generateOptions), 'SensorID');
|
this.generateOptions), 'SensorID');
|
||||||
} else {
|
} else {
|
||||||
this.appendValueInput('Value')
|
this.appendValueInput('Value')
|
||||||
.setAlign(Blockly.ALIGN_LEFT)
|
.setAlign(Blockly.ALIGN_LEFT)
|
||||||
.appendField('Phänomen')
|
.appendField('Phänomen')
|
||||||
.appendField(new Blockly.FieldTextInput(
|
.appendField(new Blockly.FieldTextInput(
|
||||||
'sensorID'), 'SensorID')
|
'sensorID'), 'SensorID')
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setPreviousStatement(true, null);
|
this.setPreviousStatement(true, null);
|
||||||
@ -119,15 +129,15 @@ Blockly.Blocks['sensebox_send_to_osem'] = {
|
|||||||
generateOptions: function () {
|
generateOptions: function () {
|
||||||
var dropdown = [['', '']];
|
var dropdown = [['', '']];
|
||||||
var boxID = selectedBox;
|
var boxID = selectedBox;
|
||||||
if(boxID !== '' && boxes){
|
if (boxID !== '' && boxes) {
|
||||||
|
|
||||||
let box = boxes.find(el => el._id === boxID);
|
let box = boxes.find(el => el._id === boxID);
|
||||||
if (box !== undefined) {
|
if (box !== undefined) {
|
||||||
for (var i = 0; i < box.sensors.length; i++) {
|
for (var i = 0; i < box.sensors.length; i++) {
|
||||||
dropdown.push([box.sensors[i].title, box.sensors[i]._id])
|
dropdown.push([box.sensors[i].title, box.sensors[i]._id])
|
||||||
}
|
}
|
||||||
console.log(dropdown)
|
console.log(dropdown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dropdown
|
return dropdown
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user