From 14642adc5aff91f10f74f997ed2edf22ba58f29a Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Wed, 2 Aug 2017 00:41:09 +1000 Subject: minimaws web mode enhancements: * Support serving static assets, use for stylesheet, script and images * Better error pages, reject unsupported HTTP methods * Replace lists with sortable tables with more detail (click headings to sort) * Add pages for exploring source files, link from machine pages - Can start from full source file list at http://localhost:8080/sourcefile/ (nw) JavaScript performance can drop when sorting really big tables, e.g. the list of all source files, or the list of machines in some of the fruit machine drivers. This update doesn't expose machine/device information, just consolidating what's there. The wsgiref server is adding headers to prevent caching, I'll look for a workaround. --- scripts/minimaws/lib/assets/common.js | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scripts/minimaws/lib/assets/common.js (limited to 'scripts/minimaws/lib/assets/common.js') diff --git a/scripts/minimaws/lib/assets/common.js b/scripts/minimaws/lib/assets/common.js new file mode 100644 index 00000000000..8ab57941127 --- /dev/null +++ b/scripts/minimaws/lib/assets/common.js @@ -0,0 +1,55 @@ +// license:BSD-3-Clause +// copyright-holders:Vas Crabb + +function sort_table(tbl, col, dir, numeric) +{ + var tbody = tbl.tBodies[0]; + var trows = Array.prototype.slice.call(tbody.rows, 0).sort( + function (x, y) + { + if (numeric) + return dir * (parseInt(x.cells[col].textContent) - parseInt(y.cells[col].textContent)); + else + return dir * x.cells[col].textContent.localeCompare(y.cells[col].textContent); + }) + trows.forEach(function (row) { tbody.appendChild(row); }); +} + + +function make_table_sortable(tbl) +{ + var headers = tbl.tHead.rows[0].cells; + var i; + for (i = 0; i < headers.length; i++) + { + (function (col) + { + var dir = 1; + var sorticon = document.createElement("img"); + sorticon.setAttribute("src", assetsurl + "/sortind.png"); + sorticon.style.cssFloat = "right"; + sorticon.style.marginLeft = "0.5em"; + headers[col].appendChild(sorticon); + headers[col].addEventListener( + 'click', + function () + { + imgsrc = sorticon.getAttribute("src"); + imgsrc = imgsrc.substr(imgsrc.lastIndexOf('/') + 1); + if (imgsrc != 'sortind.png') + dir = -dir; + if (dir < 0) + sorticon.setAttribute("src", assetsurl + "/sortdesc.png"); + else + sorticon.setAttribute("src", assetsurl + "/sortasc.png"); + var i; + for (i = 0; i < headers.length; i++) + { + if (i != col) + headers[i].lastChild.setAttribute("src", assetsurl + "/sortind.png"); + } + sort_table(tbl, col, dir, headers[col].getAttribute("class") == "numeric"); + }); + }(i)); + } +} -- cgit v1.2.3-70-g09d2