Add validations and alert message div

This commit is contained in:
Adwait Patankar 2021-07-30 15:37:54 +05:30
parent 47b8c219ff
commit e822fb7c3d
2 changed files with 18 additions and 7 deletions

View File

@ -14,6 +14,7 @@
<script src="node_modules/xterm/lib/xterm.js"></script> <script src="node_modules/xterm/lib/xterm.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.3/pako.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.0.3/pako.js"></script>
<script src="node_modules/crypto-js/crypto-js.js"></script> <script src="node_modules/crypto-js/crypto-js.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head> </head>
<body> <body>
@ -36,6 +37,12 @@
<input class="btn btn-warning btn-sm" type="button" id="disconnectButton" value="Disconnect" /> <input class="btn btn-warning btn-sm" type="button" id="disconnectButton" value="Disconnect" />
<input class="btn btn-danger btn-sm" type="button" id="eraseButton" value="Erase Flash" /> <input class="btn btn-danger btn-sm" type="button" id="eraseButton" value="Erase Flash" />
<br><br> <br><br>
<div class="alert alert-danger alert-dismissible" id="alertDiv" style="display:none">
<a href="#" class="close" aria-label="close" onclick="$('.alert').hide()">&times;</a>
<span id="alertmsg"></span>
</div>
<div id="files"> <div id="files">
<table class="table table-striped" id="fileTable"> <table class="table table-striped" id="fileTable">
<thead class="thead-light"> <thead class="thead-light">

View File

@ -14,6 +14,7 @@ const lblBaudrate = document.getElementById("lblBaudrate");
const lblConnTo = document.getElementById("lblConnTo"); const lblConnTo = document.getElementById("lblConnTo");
const tableBody = document.getElementById("tableBody"); const tableBody = document.getElementById("tableBody");
const table = document.getElementById('fileTable'); const table = document.getElementById('fileTable');
const alertDiv = document.getElementById('alertDiv');
//import { Transport } from './cp210x-webusb.js' //import { Transport } from './cp210x-webusb.js'
import { Transport } from './webserial.js' import { Transport } from './webserial.js'
@ -54,18 +55,16 @@ function convertBinaryStringToUint8Array(bStr) {
function handleFileSelect(evt) { function handleFileSelect(evt) {
var file = evt.target.files[0]; var file = evt.target.files[0];
console.log(file);
var reader = new FileReader(); var reader = new FileReader();
reader.onload = (function(theFile) { reader.onload = (function(theFile) {
return function(e) { return function(e) {
file1 = e.target.result; file1 = e.target.result;
evt.target.data = file1;
}; };
})(file); })(file);
reader.readAsBinaryString(file); reader.readAsBinaryString(file);
evt.target.data = file1;
} }
@ -185,6 +184,7 @@ disconnectButton.onclick = async () => {
eraseButton.style.display = "none"; eraseButton.style.display = "none";
lblConnTo.style.display = "none"; lblConnTo.style.display = "none";
filesDiv.style.display = "none"; filesDiv.style.display = "none";
alertDiv.style.display = "none";
consoleDiv.style.display = "initial"; consoleDiv.style.display = "initial";
}; };
@ -256,8 +256,12 @@ function validate_program_inputs() {
programButton.onclick = async () => { programButton.onclick = async () => {
var err = validate_program_inputs(); var err = validate_program_inputs();
if (err != "success") if (err != "success") {
alert(err); const alertMsg = document.getElementById("alertmsg");
alertMsg.innerHTML = "<strong>" + err + "</strong>";
alertDiv.style.display = "block";
return;
}
let fileArr = []; let fileArr = [];
let offset = 0x1000; let offset = 0x1000;
@ -272,6 +276,6 @@ programButton.onclick = async () => {
fileArr.push({data:fileObj.data, address:offset}); fileArr.push({data:fileObj.data, address:offset});
} }
esploader.write_flash({fileArray: fileArr, flash_size: 'keep'});
await esploader.write_flash({fileArray: fileArr, flash_size: 'keep'});
} }