From 2edd11a92ca6aefbc46551796ad9b9e509fb41f9 Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Sun, 29 Sep 2019 21:45:55 +0200 Subject: [PATCH] make changelog halfway readable --- components/wifi-manager/code.js | 455 ++++++++++++++++---------------- 1 file changed, 228 insertions(+), 227 deletions(-) diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index e6efa95a..4f7d3148 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -279,263 +279,264 @@ $(document).ready(function(){ } }); var [ver, idf, cfg, branch] = release.name.split('#'); - var body = release.body.replace(/\\n/ig, "
").replace(/\'/ig, "\""); - var [date, time] = release.created_at.split('T'); - $("#releaseTable").append( - ""+ - ""+ver+""+ - ""+idf+""+ - ""+date+""+ - ""+cfg+""+ - ""+branch+""+ - ""+ - "" - ); + var body = release.body; + body = body.replace(/\'/ig, "\""); + body = body.replace(/[\s\S]+(### Revision Log[\s\S]+)### ESP-IDF Version Used[\s\S]+/, "$1"); + body = body.replace(/- \(.+?\) /g, "- "); + var [date, time] = release.created_at.split('T'); + $("#releaseTable").append( + ""+ + ""+ver+""+ + ""+idf+""+ + ""+date+""+ + ""+cfg+""+ + ""+branch+""+ + ""+ + "" + ); }); }) - .fail(function() { - alert("failed to fetch release history!"); - }); + .fail(function() { + alert("failed to fetch release history!"); + }); }); - //first time the page loads: attempt to get the connection status and start the wifi scan - refreshAP(); - getConfig(); + //first time the page loads: attempt to get the connection status and start the wifi scan + refreshAP(); + getConfig(); - //start timers - startCheckStatusInterval(); - startRefreshAPInterval(); + //start timers + startCheckStatusInterval(); + startRefreshAPInterval(); - $('[data-toggle="tooltip"]').tooltip({ - html: true, - placement : 'right', - }); + $('[data-toggle="tooltip"]').tooltip({ + html: true, + placement : 'right', + }); }); - function setURL(button) { - var url = button.dataset.url; - $("#fwurl").val(url); +function setURL(button) { + var url = button.dataset.url; + $("#fwurl").val(url); - $('[data-url^="http"]').addClass("btn-success").removeClass("btn-danger"); - $('[data-url="'+url+'"]').addClass("btn-danger").removeClass("btn-success"); + $('[data-url^="http"]').addClass("btn-success").removeClass("btn-danger"); + $('[data-url="'+url+'"]').addClass("btn-danger").removeClass("btn-success"); +} + +function performConnect(conntype){ + //stop the status refresh. This prevents a race condition where a status + //request would be refreshed with wrong ip info from a previous connection + //and the request would automatically shows as succesful. + stopCheckStatusInterval(); + + //stop refreshing wifi list + stopRefreshAPInterval(); + + var pwd; + if (conntype == 'manual') { + //Grab the manual SSID and PWD + selectedSSID=$('#manual_ssid').val(); + pwd = $("#manual_pwd").val(); + }else{ + pwd = $("#pwd").val(); } + //reset connection + $( "#loading" ).show(); + $( "#connect-success" ).hide(); + $( "#connect-fail" ).hide(); - function performConnect(conntype){ - //stop the status refresh. This prevents a race condition where a status - //request would be refreshed with wrong ip info from a previous connection - //and the request would automatically shows as succesful. - stopCheckStatusInterval(); + $( "#ok-connect" ).prop("disabled",true); + $( "#ssid-wait" ).text(selectedSSID); + $( "#connect" ).slideUp( "fast", function() {}); + $( "#connect_manual" ).slideUp( "fast", function() {}); + $( "#connect-wait" ).slideDown( "fast", function() {}); - //stop refreshing wifi list - stopRefreshAPInterval(); + $.ajax({ + url: '/connect.json', + dataType: 'json', + method: 'POST', + cache: false, + headers: { 'X-Custom-ssid': selectedSSID, 'X-Custom-pwd': pwd }, + data: { 'timestamp': Date.now()} + }); - var pwd; - if (conntype == 'manual') { - //Grab the manual SSID and PWD - selectedSSID=$('#manual_ssid').val(); - pwd = $("#manual_pwd").val(); - }else{ - pwd = $("#pwd").val(); - } - //reset connection - $( "#loading" ).show(); - $( "#connect-success" ).hide(); - $( "#connect-fail" ).hide(); + //now we can re-set the intervals regardless of result + startCheckStatusInterval(); + startRefreshAPInterval(); +} - $( "#ok-connect" ).prop("disabled",true); - $( "#ssid-wait" ).text(selectedSSID); - $( "#connect" ).slideUp( "fast", function() {}); - $( "#connect_manual" ).slideUp( "fast", function() {}); - $( "#connect-wait" ).slideDown( "fast", function() {}); - - - $.ajax({ - url: '/connect.json', - dataType: 'json', - method: 'POST', - cache: false, - headers: { 'X-Custom-ssid': selectedSSID, 'X-Custom-pwd': pwd }, - data: { 'timestamp': Date.now()} - }); - - - //now we can re-set the intervals regardless of result - startCheckStatusInterval(); - startRefreshAPInterval(); +function rssiToIcon(rssi){ + if(rssi >= -60){ + return 'w0'; } - - function rssiToIcon(rssi){ - if(rssi >= -60){ - return 'w0'; - } - else if(rssi >= -67){ - return 'w1'; - } - else if(rssi >= -75){ - return 'w2'; - } - else{ - return 'w3'; - } + else if(rssi >= -67){ + return 'w1'; } - - function refreshAP(){ - if (!enableAPTimer) return; - $.getJSON( "/ap.json", function( data ) { - if(data.length > 0){ - //sort by signal strength - data.sort(function (a, b) { - var x = a["rssi"]; var y = b["rssi"]; - return ((x < y) ? 1 : ((x > y) ? -1 : 0)); - }); - apList = data; - refreshAPHTML(apList); - } - }); + else if(rssi >= -75){ + return 'w2'; } - - function refreshAPHTML(data){ - var h = ""; - data.forEach(function(e, idx, array) { - h += '
{3}
'.format(idx === array.length - 1?'':' brdb', rssiToIcon(e.rssi), e.auth==0?'':'pw',e.ssid); - h += "\n"; - }); - - $( "#wifi-list" ).html(h) + else{ + return 'w3'; } +} - function checkStatus(){ - RepeatCheckStatusInterval(); - if (!enableStatusTimer) return; - if (blockAjax) return; - blockAjax = true; - $.getJSON( "/status.json", function( data ) { - if(data.hasOwnProperty('ssid') && data['ssid'] != ""){ - if(data["ssid"] === selectedSSID){ - //that's a connection attempt - if(data["urc"] === 0){ - //got connection - $("#connected-to span").text(data["ssid"]); - $("#connect-details h1").text(data["ssid"]); - $("#ip").text(data["ip"]); - $("#netmask").text(data["netmask"]); - $("#gw").text(data["gw"]); - $("#wifi-status").slideDown( "fast", function() {}); - $("span#foot-wifi").html(", SSID: "+data["ssid"]+", IP: "+data["ip"]+""); +function refreshAP(){ + if (!enableAPTimer) return; + $.getJSON( "/ap.json", function( data ) { + if(data.length > 0){ + //sort by signal strength + data.sort(function (a, b) { + var x = a["rssi"]; var y = b["rssi"]; + return ((x < y) ? 1 : ((x > y) ? -1 : 0)); + }); + apList = data; + refreshAPHTML(apList); + } + }); +} - //unlock the wait screen if needed - $( "#ok-connect" ).prop("disabled",false); +function refreshAPHTML(data){ + var h = ""; + data.forEach(function(e, idx, array) { + h += '
{3}
'.format(idx === array.length - 1?'':' brdb', rssiToIcon(e.rssi), e.auth==0?'':'pw',e.ssid); + h += "\n"; + }); - //update wait screen - $( "#loading" ).hide(); - $( "#connect-success" ).append("

Your IP address now is: " + text(data["ip"]) + "

"); - $( "#connect-success" ).show(); - $( "#connect-fail" ).hide(); + $( "#wifi-list" ).html(h) +} - enableAPTimer = false; - if (!recovery) enableStatusTimer = false; - } - else if(data["urc"] === 1){ - //failed attempt - $("#connected-to span").text(''); - $("#connect-details h1").text(''); - $("#ip").text('0.0.0.0'); - $("#netmask").text('0.0.0.0'); - $("#gw").text('0.0.0.0'); - $("span#foot-wifi").html(""); +function checkStatus(){ + RepeatCheckStatusInterval(); + if (!enableStatusTimer) return; + if (blockAjax) return; + blockAjax = true; + $.getJSON( "/status.json", function( data ) { + if(data.hasOwnProperty('ssid') && data['ssid'] != ""){ + if(data["ssid"] === selectedSSID){ + //that's a connection attempt + if(data["urc"] === 0){ + //got connection + $("#connected-to span").text(data["ssid"]); + $("#connect-details h1").text(data["ssid"]); + $("#ip").text(data["ip"]); + $("#netmask").text(data["netmask"]); + $("#gw").text(data["gw"]); + $("#wifi-status").slideDown( "fast", function() {}); + $("span#foot-wifi").html(", SSID: "+data["ssid"]+", IP: "+data["ip"]+""); - //don't show any connection - $("#wifi-status").slideUp( "fast", function() {}); + //unlock the wait screen if needed + $( "#ok-connect" ).prop("disabled",false); - //unlock the wait screen - $( "#ok-connect" ).prop("disabled",false); + //update wait screen + $( "#loading" ).hide(); + $( "#connect-success" ).append("

Your IP address now is: " + text(data["ip"]) + "

"); + $( "#connect-success" ).show(); + $( "#connect-fail" ).hide(); - //update wait screen - $( "#loading" ).hide(); - $( "#connect-fail" ).show(); - $( "#connect-success" ).hide(); - - enableAPTimer = true; - enableStatusTimer = true; - } - } - else if(data.hasOwnProperty('urc') && data['urc'] === 0){ - //ESP32 is already connected to a wifi without having the user do anything - if( !($("#wifi-status").is(":visible")) ){ - $("#connected-to span").text(data["ssid"]); - $("#connect-details h1").text(data["ssid"]); - $("#ip").text(data["ip"]); - $("#netmask").text(data["netmask"]); - $("#gw").text(data["gw"]); - $("#wifi-status").slideDown( "fast", function() {}); - $("span#foot-wifi").html(", SSID: "+data["ssid"]+", IP: "+data["ip"]+""); - } enableAPTimer = false; if (!recovery) enableStatusTimer = false; } - } - else if(data.hasOwnProperty('urc') && data['urc'] === 2){ - //that's a manual disconnect - if($("#wifi-status").is(":visible")){ - $("#wifi-status").slideUp( "fast", function() {}); + else if(data["urc"] === 1){ + //failed attempt + $("#connected-to span").text(''); + $("#connect-details h1").text(''); + $("#ip").text('0.0.0.0'); + $("#netmask").text('0.0.0.0'); + $("#gw").text('0.0.0.0'); $("span#foot-wifi").html(""); - } - enableAPTimer = true; - enableStatusTimer = true; - } - if (data.hasOwnProperty('recovery')) { - if (data["recovery"] === 1) { - recovery = true; - $("#otadiv").show(); - enableStatusTimer = true; - } else { - recovery = false; - $("#otadiv").hide(); - enableStatusTimer = false; - } - } - if(data.hasOwnProperty('project_name') && data['project_name'] != ''){ - pname = data['project_name']; - } - if(data.hasOwnProperty('version') && data['version'] != ''){ - ver = data['version']; - $("span#foot-fw").html("fw: "+ver+", mode: "+pname+""); - } - if(data.hasOwnProperty('ota_pct') && data['ota_pct'] != 0){ - otapct = data['ota_pct']; - $('.progress-bar').css('width', otapct+'%').attr('aria-valuenow', otapct); - $('.progress-bar').html(otapct+'%'); - } - blockAjax = false; - }) - .fail(function() { - //don't do anything, the server might be down while esp32 recalibrates radio - }); - } - function getConfig() { - $.getJSON("/config.json", function(data) { - if (data.hasOwnProperty('autoexec')) { - if (data["autoexec"] === 1) { - console.log('turn on autoexec'); - $("#autoexec-cb")[0].checked=true; - } else { - console.log('turn off autoexec'); - $("#autoexec-cb")[0].checked=false; + //don't show any connection + $("#wifi-status").slideUp( "fast", function() {}); + + //unlock the wait screen + $( "#ok-connect" ).prop("disabled",false); + + //update wait screen + $( "#loading" ).hide(); + $( "#connect-fail" ).show(); + $( "#connect-success" ).hide(); + + enableAPTimer = true; + enableStatusTimer = true; } } - if (data.hasOwnProperty('list')) { - data.list.forEach(function(line) { - let key = Object.keys(line)[0]; - let val = Object.values(line)[0]; - console.log(key, val); - if (key == 'autoexec1') { - $("#autoexec1").val(val); - } - }); + else if(data.hasOwnProperty('urc') && data['urc'] === 0){ + //ESP32 is already connected to a wifi without having the user do anything + if( !($("#wifi-status").is(":visible")) ){ + $("#connected-to span").text(data["ssid"]); + $("#connect-details h1").text(data["ssid"]); + $("#ip").text(data["ip"]); + $("#netmask").text(data["netmask"]); + $("#gw").text(data["gw"]); + $("#wifi-status").slideDown( "fast", function() {}); + $("span#foot-wifi").html(", SSID: "+data["ssid"]+", IP: "+data["ip"]+""); + } + enableAPTimer = false; + if (!recovery) enableStatusTimer = false; } - }) - .fail(function() { - console.log("failed to fetch config!"); - }); - } + } + else if(data.hasOwnProperty('urc') && data['urc'] === 2){ + //that's a manual disconnect + if($("#wifi-status").is(":visible")){ + $("#wifi-status").slideUp( "fast", function() {}); + $("span#foot-wifi").html(""); + } + enableAPTimer = true; + enableStatusTimer = true; + } + if (data.hasOwnProperty('recovery')) { + if (data["recovery"] === 1) { + recovery = true; + $("#otadiv").show(); + enableStatusTimer = true; + } else { + recovery = false; + $("#otadiv").hide(); + enableStatusTimer = false; + } + } + if(data.hasOwnProperty('project_name') && data['project_name'] != ''){ + pname = data['project_name']; + } + if(data.hasOwnProperty('version') && data['version'] != ''){ + ver = data['version']; + $("span#foot-fw").html("fw: "+ver+", mode: "+pname+""); + } + if(data.hasOwnProperty('ota_pct') && data['ota_pct'] != 0){ + otapct = data['ota_pct']; + $('.progress-bar').css('width', otapct+'%').attr('aria-valuenow', otapct); + $('.progress-bar').html(otapct+'%'); + } + blockAjax = false; + }) + .fail(function() { + //don't do anything, the server might be down while esp32 recalibrates radio + }); +} + +function getConfig() { + $.getJSON("/config.json", function(data) { + if (data.hasOwnProperty('autoexec')) { + if (data["autoexec"] === 1) { + console.log('turn on autoexec'); + $("#autoexec-cb")[0].checked=true; + } else { + console.log('turn off autoexec'); + $("#autoexec-cb")[0].checked=false; + } + } + if (data.hasOwnProperty('list')) { + data.list.forEach(function(line) { + let key = Object.keys(line)[0]; + let val = Object.values(line)[0]; + console.log(key, val); + if (key == 'autoexec1') { + $("#autoexec1").val(val); + } + }); + } + }) + .fail(function() { + console.log("failed to fetch config!"); + }); +}