From patchwork Mon Aug 19 09:00:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Huesca X-Patchwork-Id: 1149128 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46Bnvs00vjz9sMr for ; Mon, 19 Aug 2019 19:00:56 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 2FF2A20338; Mon, 19 Aug 2019 09:00:51 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tRgciCPxJJ5f; Mon, 19 Aug 2019 09:00:47 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 26A5120499; Mon, 19 Aug 2019 09:00:47 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id D0B9D1BF973 for ; Mon, 19 Aug 2019 09:00:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id CA14A87B18 for ; Mon, 19 Aug 2019 09:00:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sktEx+ZZdges for ; Mon, 19 Aug 2019 09:00:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by hemlock.osuosl.org (Postfix) with ESMTPS id 0AF3E87AF3 for ; Mon, 19 Aug 2019 09:00:43 +0000 (UTC) Received: from localhost.localdomain (lfbn-1-17395-211.w86-250.abo.wanadoo.fr [86.250.200.211]) (Authenticated sender: victor.huesca@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id D6BF3240005; Mon, 19 Aug 2019 09:00:41 +0000 (UTC) From: Victor Huesca To: buildroot@buildroot.org Date: Mon, 19 Aug 2019 11:00:36 +0200 Message-Id: <20190819090038.28808-2-victor.huesca@bootlin.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190819090038.28808-1-victor.huesca@bootlin.com> References: <20190819090038.28808-1-victor.huesca@bootlin.com> MIME-Version: 1.0 Subject: [Buildroot] [PATCH buildroot-test v2 1/3] web/request: new page to help making request to the autobuild database X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Victor Huesca , thomas.petazzoni@bootlin.com Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" The current way to make request is to manually pass GET parameters to the URL, which is nice for automation and simple request but it gets messy with more complicated requests -- especially with the introduction of configuration symbols. This patch provides a handy interface to ask more sophisticated configs to the autobuild database. The implementation uses normal HTML forms but implements a hook to the submit method in order to handle config symbols from the textarea and keep the URL clean. Signed-off-by: Victor Huesca --- web/request.js | 69 ++++++++++++++++++++++++++++++++++++++ web/request.php | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 web/request.js create mode 100644 web/request.php diff --git a/web/request.js b/web/request.js new file mode 100644 index 0000000..cf52478 --- /dev/null +++ b/web/request.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/request.php b/web/request.php new file mode 100644 index 0000000..5331ffa --- /dev/null +++ b/web/request.php @@ -0,0 +1,88 @@ + + + + + +
+ + + + + + + + + + + +
+ Static? + + +
+
+ + + + + + + + +
+ Status? + + + +
+
+ + +
+ +