aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
Diffstat (limited to 'web')
-rw-r--r--web/search.js69
-rw-r--r--web/search.php88
2 files changed, 157 insertions, 0 deletions
diff --git a/web/search.js b/web/search.js
new file mode 100644
index 0000000..cf52478
--- /dev/null
+++ b/web/search.js
@@ -0,0 +1,69 @@
+function submitForm() {
+ // Do not send the form
+ event.preventDefault();
+
+ // Read the form
+ const html_form = event.target;
+ const form = new FormData(html_form);
+
+ // Drop empty fields
+ for (const k of getEmptyValues(form)) {
+ form.delete(k);
+ }
+
+ // Prepare the symbols entry
+ if (form.has('symbols')) {
+ const raw_symbols = form.get('symbols');
+ const extracted_symbols = textBoxToDict(raw_symbols);
+ for (const [k, v] of extracted_symbols) {
+ form.append(`symbols[${k}]`, v);
+ }
+ form.delete('symbols');
+ }
+
+ // Charge the requested page
+ if (html_form.method == 'get') {
+ const data = new URLSearchParams(form);
+ const url = html_form.action + '?' + data.toString();
+ window.history.pushState(null, 'Searching...', url);
+ document.location = url;
+ } else {
+ // This approach only works for 'GET' forms.
+ // To handle 'POST' forms, a hidden html form must be
+ // created and filled with the write elements.
+ }
+}
+
+
+/**
+ * Return keys with an empty associated value.
+ * @param {FormData} form Form to extract empty values from.
+ */
+function getEmptyValues(form) {
+ const empty = [];
+ for (const [k, v] of form)
+ if (v == '')
+ empty.push(k);
+ return empty;
+}
+
+
+/**
+ * Parse a multi-line string and generates all couple `key: value` from it.
+ * @param {String} symbols_text String to parse.
+ * @param {String} line_sep Line separator, each lines have at most one couple `key: value`.
+ * @param {String} data_sep Key/value separator.
+ */
+function* textBoxToDict(symbols_text, line_sep='\n', data_sep='=') {
+ const arr = symbols_text.split(line_sep);
+
+ for (const line of arr) {
+ const [sym, ...rest] = line.split(data_sep);
+ const key = sym.trim();
+ if (key == '')
+ continue
+ const value = rest.join(data_sep).trim();
+ yield [key, value];
+ }
+}
+
diff --git a/web/search.php b/web/search.php
new file mode 100644
index 0000000..bcdd62e
--- /dev/null
+++ b/web/search.php
@@ -0,0 +1,88 @@
+<?php
+include("funcs.inc.php");
+
+bab_header("Buildroot tests - Search page");
+?>
+
+<script type='text/javascript' src="search.js"></script>
+
+
+<form action="index.php" method="get" onsubmit="submitForm()">
+ <label>
+ <span>Submitter:</span>
+ <input type="text" name="submitter" placeholder="Submitter">
+ </label>
+
+ <label>
+ <span>Failure reason:</span>
+ <input type="text" name="reason" placeholder="Reason">
+ </label>
+
+ <label>
+ <span>Arch:</span>
+ <input type="text" name="arch" placeholder="Architecture">
+ </label>
+
+ <span>
+ <label>
+ <span>Subarch:</span>
+ <input type="text" name="subarch" placeholder="Sub-Architecture">
+ </label>
+
+ <label>
+ <span>From:</span>
+ <input type="date" name="date[from]" id="date_f" placeholder="From">
+ </label>
+
+ <fieldset>
+ <legend>Static?</legend>
+ <label>
+ <input type="radio" name="static" value="1">
+ <span>Y</span>
+ </label>
+ <label>
+ <input type="radio" name="static" value="0">
+ <span>N</span>
+ </label>
+ </fieldset>
+ </span>
+
+ <label>
+ <span>Symbols:</span>
+ <textarea name="symbols" id="symbols"></textarea>
+ </label>
+
+ <span>
+ <label>
+ <span>C library:</span>
+ <input type="text" name="libc" placeholder="Library">
+ </label>
+
+ <label>
+ <span>To:</span>
+ <input type="date" name="date[to]" id="date_t" placeholder="To">
+ </label>
+
+ <fieldset>
+ <legend>Status?</legend>
+ <label>
+ <input type="radio" name="status" value="OK">
+ <span>OK</span>
+ </label>
+ <label>
+ <input type="radio" name="status" value="NOK">
+ <span>NOK</span>
+ </label>
+ <label>
+ <input type="radio" name="status" value="TIMEOUT">
+ <span>TIMEOUT</span>
+ </label>
+ </fieldset>
+ </span>
+
+ <input type="submit" value="Search!">
+</form>
+
+<?php
+bab_footer();
+?>