mirror of
https://github.com/deuill/grawkit.git
synced 2024-09-28 08:22:46 +00:00
Alex Palaistras
24d63cd8a9
Running `grawkit` locally can be a hassle for one-off tasks, and can be hard to iterate against when plotting graphs based on complex command-line descriptions. Given recent fixes for POSIX compatibility, this commit implements a basic web-based "playground"-style application that allows for entering command-line descriptions in an HTML textarea, and seeing the results (or errors) instantly. The playground application itself is built in Go (Awk itself would be insufficient for the throughput required, but may be investigated in the future), with the excellent GoAwk library providing parsing and execution duties, therefore making for a pure-Go implementation (other than Grawkit itself). Additional support for setting custom styling and an online deployment with Docker are forthcoming.
43 lines
975 B
JavaScript
43 lines
975 B
JavaScript
var submitForm = function(el) {
|
|
if (!el.action) {
|
|
return false;
|
|
}
|
|
|
|
var req = new XMLHttpRequest();
|
|
req.open('POST', el.action);
|
|
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
|
|
req.onreadystatechange = function() {
|
|
if (this.readyState != 4) {
|
|
return;
|
|
}
|
|
|
|
if (this.status == 200) {
|
|
document.getElementById('generated').innerHTML = this.responseText;
|
|
document.getElementById('error').innerHTML = '';
|
|
} else {
|
|
document.getElementById('error').innerHTML = this.getResponseHeader('X-Error-Message');
|
|
}
|
|
};
|
|
|
|
var data = encodeFormData(new FormData(el)) + '&download';
|
|
req.send(data);
|
|
|
|
return true;
|
|
};
|
|
|
|
var encodeFormData = function(data) {
|
|
var encode = function(s) {
|
|
return encodeURIComponent(s).replace(/%20/g, '+');
|
|
};
|
|
|
|
var result = '';
|
|
for (var entry of data.entries()) {
|
|
if (typeof entry[1] == 'string') {
|
|
result += (result ? '&' : '') + encode(entry[0]) + '=' + encode(entry[1]);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
};
|