Post getvars + fixed colors.py valid hex
This commit is contained in:
@ -270,6 +270,34 @@ function reqJSON(s, url, successHandler, errorHandler) {
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function reqJSONPOST(s, url, parameters, successHandler, errorHandler) {
|
||||
var xhr = typeof XMLHttpRequest != 'undefined' ? new XMLHttpRequest()
|
||||
: new ActiveXObject('Microsoft.XMLHTTP');
|
||||
if (debugCommunication) {
|
||||
console.log("%cto server (reqJSON): " + url,
|
||||
"color:white;background:lightgreen");
|
||||
}
|
||||
xhr.open('post', url, true);
|
||||
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
xhr.onreadystatechange = function() {
|
||||
// console.log(xhr)
|
||||
var status;
|
||||
var data;
|
||||
// https://xhr.spec.whatwg.org/#dom-xmlhttprequest-readystate
|
||||
if (xhr.readyState == 4) { // `DONE`
|
||||
status = xhr.status;
|
||||
if (status == 200) {
|
||||
data = JSON.parse(xhr.responseText);
|
||||
successHandler && successHandler(s, data);
|
||||
} else {
|
||||
errorHandler && errorHandler(status);
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.send(parameters);
|
||||
}
|
||||
|
||||
|
||||
function successHandler(s, message) {
|
||||
// Handles incoming XMLHttp-messages depending on type of message.
|
||||
// s: slide number or -1 for replacing slide in all slider instances
|
||||
@ -350,8 +378,8 @@ function successHandler(s, message) {
|
||||
begin = timeRange[0] - timeRange[1];
|
||||
select.value = begin;
|
||||
// Server-request for variable-list.*/
|
||||
reqJSON(0, "http://" + hostPort + "/getvars?time=" + timeRange + "&userconfiguration=" + encodeURIComponent(JSON.stringify(getFormattedUserConfigurationFromLocalStorage())) + "&id="
|
||||
+ clientID, successHandler, errorHandler);
|
||||
reqJSONPOST(0, "http://" + hostPort + "/getvars", "time=" + timeRange + "&userconfiguration=" + JSON.stringify(getFormattedUserConfigurationFromLocalStorage()) + "&id="
|
||||
+ clientID, successHandler, errorHandler);
|
||||
break;
|
||||
// Response to a "getvars"-server-request.
|
||||
case "var_list":
|
||||
|
@ -96,6 +96,20 @@ function AJAX(addr){
|
||||
});
|
||||
}
|
||||
|
||||
this.postForm = function(args){
|
||||
xhr.open("POST", addr, true);
|
||||
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
xhr.send(args);
|
||||
return new Promise(function(resolve, reject){
|
||||
xhr.addEventListener('load', function(){
|
||||
if(this.status == 200){
|
||||
if (debugCommunication) console.log('A RES', JSON.parse(this.responseText));
|
||||
resolve(JSON.parse(this.responseText));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
this.get = function(responseType = "text"){
|
||||
xhr.open("GET", addr, true);
|
||||
xhr.responseType = responseType;
|
||||
@ -831,7 +845,7 @@ let graphs = (function (){
|
||||
msRightTimestampGetVars = dateTimestampMs + timeValueMs;
|
||||
msRightTimestampGetGraph = dateTimestampMs + 24*60*60*1000;
|
||||
|
||||
AJAX("http://" + hostPort + "/getvars?time=" + msLeftTimestampGetVars/1000 + "," + msRightTimestampGetVars/1000 + "&userconfiguration=" + encodeURIComponent(JSON.stringify(getFormattedUserConfigurationFromLocalStorage())) + "&id="+ clientID).getJSON().then(function(data){
|
||||
AJAX("http://" + hostPort + "/getvars").postForm("time=" + msLeftTimestampGetVars/1000 + "," + msRightTimestampGetVars/1000 + "&userconfiguration=" + JSON.stringify(getFormattedUserConfigurationFromLocalStorage()) + "&id="+ clientID).then(function(data){
|
||||
blocks = data.blocks;
|
||||
document.getElementById("device").innerHTML = data.device
|
||||
maxTime = msRightTimestampGetGraph;
|
||||
@ -901,7 +915,7 @@ let graphs = (function (){
|
||||
let msLeftTimestamp = msRightTimestamp - 30*60*1000;
|
||||
cursorLine(null);
|
||||
|
||||
AJAX("http://" + hostPort + "/getvars?time=" + msLeftTimestamp/1000 + "," + msRightTimestamp/1000 + "&userconfiguration=" + encodeURIComponent(JSON.stringify(getFormattedUserConfigurationFromLocalStorage())) + "&id="+ clientID).getJSON().then(function(data){
|
||||
AJAX("http://" + hostPort + "/getvars").postForm("time=" + msLeftTimestamp/1000 + "," + msRightTimestamp/1000 + "&userconfiguration=" + JSON.stringify(getFormattedUserConfigurationFromLocalStorage()) + "&id="+ clientID).then(function(data){
|
||||
currentMaxTime = msRightTimestamp + 60000;
|
||||
currentMinTime = msLeftTimestamp;
|
||||
|
||||
@ -1212,7 +1226,7 @@ let graphs = (function (){
|
||||
function applySettingsCallback(userConfiguration){
|
||||
cursorLine(null);
|
||||
|
||||
AJAX("http://" + hostPort + "/getvars?time=" + currentMinTime/1000 + "," + currentMaxTime/1000 + "&userconfiguration=" + encodeURIComponent(JSON.stringify(userConfiguration)) + "&id="+ clientID).getJSON().then(function(data){
|
||||
AJAX("http://" + hostPort + "/getvars").postForm("time=" + currentMinTime/1000 + "," + currentMaxTime/1000 + "&userconfiguration=" + JSON.stringify(userConfiguration) + "&id="+ clientID).then(function(data){
|
||||
blocks = data.blocks;
|
||||
document.getElementById("device").innerHTML = data.device
|
||||
maxTime = currentMaxTime;
|
||||
|
@ -104,7 +104,7 @@ class ColorMap(object):
|
||||
if len(code) != 7:
|
||||
return None
|
||||
try:
|
||||
int(code[1:]) # we have a valid hex color code
|
||||
int(code[1:], 16) # we have a valid hex color code
|
||||
return code
|
||||
except ValueError:
|
||||
return None
|
||||
|
@ -155,9 +155,9 @@ def export():
|
||||
@app.route('/graph')
|
||||
@app.route('/updategraph')
|
||||
@app.route('/gettime')
|
||||
@app.route('/getvars')
|
||||
@app.route('/getvars', methods=["GET", "POST"])
|
||||
def reply():
|
||||
args = flask.request.args
|
||||
args = flask.request.values
|
||||
kwargs = dict((k, args.get(k)) for k in args)
|
||||
path = flask.request.path
|
||||
logging.info('GET %s %s', path, repr(kwargs))
|
||||
|
Reference in New Issue
Block a user