307 lines
10 KiB
JavaScript
307 lines
10 KiB
JavaScript
//DISCLAIMER HERE//
|
|
|
|
//Main Execution
|
|
$(document).ready(function() {
|
|
console.log("initial state is " + connectState);
|
|
defaultViewState();
|
|
|
|
updateLog("v6 Webclient is loaded.");
|
|
|
|
//Non Stop Events
|
|
setInterval("Loop();", sampleRate);
|
|
|
|
//Listeners
|
|
$("#updateConfig").click(function() {
|
|
getUserInputs();
|
|
updateLog("Connecting as " + userName + "...");
|
|
readProj();
|
|
$("#deleteChannel").show();
|
|
$("#deleteDevice").show();
|
|
});
|
|
|
|
//Main Nav
|
|
$("#v6Configurator").click(function() {
|
|
$("#v6Configurator").addClass("active");
|
|
$("#useCase1").removeClass("active");
|
|
$("#iotGateway").removeClass("active");
|
|
|
|
$("#configurator").show();
|
|
$("#deviceList").show();
|
|
$("#jsonObject").show();
|
|
$("#useCase1Panel").hide();
|
|
$("#iotGatewayPanel").hide();
|
|
});
|
|
|
|
$("#useCase1").click(function() {
|
|
$("#v6Configurator").removeClass("active");
|
|
$("#useCase1").addClass("active");
|
|
$("#iotGateway").removeClass("active");
|
|
|
|
$("#configurator").hide();
|
|
$("#deviceList").show();
|
|
$("#jsonObject").show();
|
|
$("#useCase1Panel").show();
|
|
$("#iotGatewayPanel").hide();
|
|
});
|
|
|
|
$("#iotGateway").click(function() {
|
|
$("#v6Configurator").removeClass("active");
|
|
$("#useCase1").removeClass("active");
|
|
$("#iotGateway").addClass("active");
|
|
|
|
$("#configurator").hide();
|
|
$("#deviceList").show();
|
|
$("#jsonObject").show();
|
|
$("#useCase1Panel").hide();
|
|
$("#iotGatewayPanel").show();
|
|
});
|
|
|
|
//ZE BUTTONS
|
|
$("#createCh").click(function() {
|
|
if (connectState) {
|
|
getUserInputs();
|
|
updateLog("Creating a " + inputChannelType + " named " + inputChannel);
|
|
createChannel(inputServer, inputChannelType, inputChannel);
|
|
} else {
|
|
updateLog("Please connect the server first");
|
|
}
|
|
});
|
|
|
|
$("#createDevice").click(function() {
|
|
if (connectState) {
|
|
getUserInputs();
|
|
updateLog("Creating " + inputDevice + " with ID " + inputDevID + "for driver" + inputDriver);
|
|
createDevice(inputServer, inputChannel, inputDevID, inputDevice, inputDriver);
|
|
} else {
|
|
updateLog("Please connect the server first");
|
|
}
|
|
});
|
|
|
|
$("#createTag").click(function() {
|
|
if (connectState) {
|
|
getUserInputs();
|
|
updateLog("Creating " + inputTag + " with address " + inputTagAddr);
|
|
createTag(inputServer, inputChannel, inputDevice, inputTag, inputTagAddr);
|
|
getTags(inputDevice, inputChannel);
|
|
} else {
|
|
updateLog("Please connect the server first");
|
|
}
|
|
});
|
|
|
|
$("#readProjObj").click(function() {
|
|
updateLog("Reading ProjObj...");
|
|
if (projObj === null) {
|
|
updateLog("ProjObj is not Loaded. Please connect to Server first");
|
|
// your code here.
|
|
} else {
|
|
editor.set(projObj);
|
|
var stringJson = JSON.stringify(projObj, null, 2);
|
|
//Stringify it and update into the text area
|
|
updateText(stringJson);
|
|
updateLog("Please view in in the editor panel");
|
|
}
|
|
});
|
|
|
|
$("#getJSON").click(function() {
|
|
updateLog("Getting the Obj");
|
|
var textInput = document.getElementById("textJsonInput").value;
|
|
var jsonInput = JSON.parse(textInput);
|
|
console.log(jsonInput);
|
|
setJson(jsonInput);
|
|
});
|
|
|
|
//Nav Menus
|
|
$("#displayText").click(function() {
|
|
//Text for the Json Object Viewer
|
|
$("#displayText").addClass("active");
|
|
$("#displayTree").removeClass("active");
|
|
$("#displayTagList").removeClass("active");
|
|
$("#textJsonEditor").show();
|
|
$("#jsonEditorContainer").hide();
|
|
$("#tagListContainer").hide();
|
|
});
|
|
|
|
$("#displayTree").click(function() {
|
|
//jsTree for the Json object view
|
|
$("#displayTree").addClass("active");
|
|
$("#displayText").removeClass("active");
|
|
$("#displayTagList").removeClass("active");
|
|
$("#textJsonEditor").hide();
|
|
$("#jsonEditorContainer").show();
|
|
$("#tagListContainer").hide();
|
|
});
|
|
|
|
$("#displayTagList").click(function() {
|
|
$("#displayTagList").addClass("active");
|
|
$("#displayText").removeClass("active");
|
|
$("#displayTree").removeClass("active");
|
|
$("#textJsonEditor").hide();
|
|
$("#jsonEditorContainer").hide();
|
|
$("#tagListContainer").show();
|
|
|
|
});
|
|
|
|
$("#displayChannelPanel").click(function() {
|
|
$("#displayChannelPanel").addClass("active");
|
|
$("#displayDevicePanel").removeClass("active");
|
|
$("#displayTagPanel").removeClass("active");
|
|
$("#channelPanel").show();
|
|
$("#devicePanel").hide();
|
|
$("#tagPanel").hide();
|
|
});
|
|
|
|
$("#displayDevicePanel").click(function() {
|
|
$("#displayChannelPanel").removeClass("active");
|
|
$("#displayDevicePanel").addClass("active");
|
|
$("#displayTagPanel").removeClass("active");
|
|
$("#channelPanel").hide();
|
|
$("#devicePanel").show();
|
|
$("#tagPanel").hide();
|
|
});
|
|
|
|
$("#displayTagPanel").click(function() {
|
|
$("#displayChannelPanel").removeClass("active");
|
|
$("#displayDevicePanel").removeClass("active");
|
|
$("#displayTagPanel").addClass("active");
|
|
$("#channelPanel").hide();
|
|
$("#devicePanel").hide();
|
|
$("#tagPanel").show();
|
|
});
|
|
|
|
$("#drawTree").click(function() {
|
|
console.log(channelList);
|
|
drawTree(channelList);
|
|
});
|
|
|
|
$("#createDeviceTree").click(function() {
|
|
addChild();
|
|
});
|
|
|
|
$("#deleteChannel").click(function() {
|
|
delChannel(cselected);
|
|
});
|
|
|
|
$("#deleteDevice").click(function() {
|
|
delDevice(dselected, cselected);
|
|
});
|
|
|
|
$('#deleteTag').click(function() {
|
|
delTag(dselected, cselected, tselected);
|
|
updateTags(dselected, cselected);
|
|
});
|
|
|
|
$("#importMdbsJSON").click(function() {
|
|
updateLog("Loading file...");
|
|
$('input[type=file]').trigger('click');
|
|
loadMdbsFile();
|
|
updateLog("File loaded successfully, click the Create button.");
|
|
});
|
|
|
|
$("#importABJSON").click(function() {
|
|
updateLog("Loading file...");
|
|
$('input[type=file]').trigger('click');
|
|
loadABFile();
|
|
updateLog("File loaded successfully, click the Create button.");
|
|
});
|
|
|
|
$("#modCh").click(function() {
|
|
updateLog("Attempting to modify object for " + cselected);
|
|
modChannel(cselected);
|
|
});
|
|
|
|
$("#modDev").click(function() {
|
|
updateLog("Attempting to modify object for " + dselected);
|
|
modDevice(dselected);
|
|
});
|
|
|
|
$("#modTag").click(function() {
|
|
updateLog("Attempting to modify object for " + tselected);
|
|
modTag(tselected, taddrselected);
|
|
});
|
|
|
|
$("#createAll").click(function() {
|
|
updateLog("Attempting to create all objects in template");
|
|
if (connectState) {
|
|
getUserInputs();
|
|
//createChannel(inputServer, inputChannelType, inputChannel);
|
|
//getUserInputs();
|
|
func1 = createChannel(inputServer, inputChannelType, inputChannel);
|
|
func2 = createDevice(inputServer, inputChannel, inputDevID, inputDevice, inputDriver);
|
|
func3 = createTag(inputServer, inputChannel, inputDevice, inputTag, inputTagAddr);
|
|
$when(func1).done($when(func2).done(func3));
|
|
getTags(inputDevice, inputChannel);
|
|
} else {
|
|
updateLog("Please connect the server first");
|
|
}
|
|
});
|
|
|
|
|
|
$('#tagReadResults').on('click', 'tr', function() {
|
|
$("#displayChannelPanel").removeClass("active");
|
|
$("#displayDevicePanel").removeClass("active");
|
|
$("#displayTagPanel").addClass("active");
|
|
$("#channelPanel").hide();
|
|
$("#devicePanel").hide();
|
|
$("#tagPanel").show();
|
|
|
|
var td = this.cells[0]; // the first <td>
|
|
var td2 = this.cells[1];
|
|
var td3 = this.cells[2];
|
|
tselected = $(td).text();
|
|
taddrselected = $(td2).text();
|
|
//ttypeselected = $(td3).text();
|
|
//updateLog(taddrselected + ttypeselected);
|
|
|
|
$("#tag").val(tselected);
|
|
$("#tagAddr").val(taddrselected);
|
|
|
|
if (tselected != "Tag Name") {
|
|
updateLog("Tag " + tselected + " is selected from " + dselected + " under " + cselected);
|
|
var selected = $(this).hasClass("highlight");
|
|
$("#tagReadResults tr").removeClass("highlight");
|
|
if (!selected)
|
|
$(this).addClass("highlight");
|
|
}
|
|
getUserInputs();
|
|
inputTagTypeOld = inputTagType; //Tag data type to modfiy
|
|
});
|
|
|
|
//IoT Gateway
|
|
$("#createRESTServer").click(function() {
|
|
var restnameInput = document.getElementById("restServerName");
|
|
var restport = document.getElementById("restServerPort");
|
|
console.log(restnameInput.value, restport.value);
|
|
createRestServer(restnameInput.value, restport.value);
|
|
});
|
|
|
|
$("#addtoIoTGateway").click(function() {
|
|
var tagAddrString = cselected + '.' + dselected + '.' + tselected;
|
|
var restnameInput = document.getElementById("restServerName");
|
|
console.log("Adding " + tagAddrString + ' to ' + restnameInput.value);
|
|
addRestTag(restnameInput.value, tagAddrString);
|
|
});
|
|
|
|
$("#readTag").click(function() {
|
|
var tagAddrString = cselected + '.' + dselected + '.' + tselected;
|
|
var readNonStop = document.getElementById("readNonStop").checked;
|
|
var restport = document.getElementById("restServerPort");
|
|
var readInterval = setInterval(readLoop, 1000);
|
|
|
|
function readLoop() {
|
|
console.log(readNonStop);
|
|
readNonStop = document.getElementById("readNonStop").checked;
|
|
if (readNonStop) {
|
|
readTag(tagAddrString, restport.value);
|
|
} else {
|
|
readTag(tagAddrString, restport.value);
|
|
clearInterval(readInterval);
|
|
}
|
|
}
|
|
});
|
|
|
|
$("#deleteRESTServer").click(function() {
|
|
var restnameInput = document.getElementById("restServerName");
|
|
deleteRestServer(restnameInput.value);
|
|
});
|
|
|
|
}); /* End of Ready*/ |