From 1cd8a002ff459791967122c2c8be2ccd44dafcf2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 18 Oct 2012 22:33:39 +0200 Subject: [PATCH] journal: implement filtering in browse.html --- src/journal/browse.html | 158 +++++++++++++++++++++++++++++++++------- 1 file changed, 133 insertions(+), 25 deletions(-) diff --git a/src/journal/browse.html b/src/journal/browse.html index 2da0b0a46..3594f70c8 100644 --- a/src/journal/browse.html +++ b/src/journal/browse.html @@ -6,7 +6,7 @@ @@ -110,19 +118,27 @@
+
+ +      + Only current boot +
+
-
- - - - +
+ + + +      - - - + + +
g: First Page      @@ -139,7 +155,7 @@ function getNEntries() { var n; - n = window.localStorage["n_entries"]; + n = localStorage["n_entries"]; if (n == null) return 50; n = parseInt(n); @@ -160,7 +176,7 @@ return 10; if (n > 1000) return 1000; - window.localStorage["n_entries"] = n.toString(); + localStorage["n_entries"] = n.toString(); showNEntries(n); } @@ -221,12 +237,24 @@ function entriesLoad(range) { if (range == null) - range = window.localStorage["cursor"] + ":0"; + range = localStorage["cursor"] + ":0"; if (range == null) range = ""; + var url = "/entries"; + + if (localStorage["filter"] != "" && localStorage["filter"] != null) { + url += "?_SYSTEMD_UNIT=" + escape(localStorage["filter"]); + + if (localStorage["boot"] == "1") + url += "&boot"; + } else { + if (localStorage["boot"] == "1") + url += "?boot"; + } + var request = new XMLHttpRequest(); - request.open("GET", "/entries"); + request.open("GET", url); request.onreadystatechange = entriesOnResult; request.setRequestHeader("Accept", "application/json"); request.setRequestHeader("Range", "entries=" + range + ":" + getNEntries().toString()); @@ -266,8 +294,7 @@ var lc = null; var fc = null; - var i; - var l = event.currentTarget.responseText.split('\n'); + var i, l = event.currentTarget.responseText.split('\n'); if (l.length <= 1) { logs.innerHTML = 'No further entries...'; @@ -337,7 +364,7 @@ if (fc != null) { first_cursor = fc; - window.localStorage["cursor"] = fc; + localStorage["cursor"] = fc; } if (lc != null) last_cursor = lc; @@ -423,14 +450,95 @@ entriesLoadNext(); } + function onResultFilterFocus(event) { + if ((event.currentTarget.readyState != 4) || + (event.currentTarget.status != 200 && event.currentTarget.status != 0)) + return; + + f = document.getElementById("filter"); + + var l = event.currentTarget.responseText.split('\n'); + var buf = ''; + var j = -1; + + for (i in l) { + + if (l[i] == '') + continue; + + var d = JSON.parse(l[i]); + if (d._SYSTEMD_UNIT == undefined) + continue; + + buf += ''; + + if (d._SYSTEMD_UNIT == localStorage["filter"]) + j = i; + } + + if (j < 0) { + if (localStorage["filter"] != null && localStorage["filter"] != "") { + buf += ''; + j = i + 1; + } else + j = 0; + } + + f.innerHTML = buf; + f.selectedIndex = j; + } + + function onFilterFocus(w) { + var request = new XMLHttpRequest(); + request.open("GET", "/fields/_SYSTEMD_UNIT"); + request.onreadystatechange = onResultFilterFocus; + request.setRequestHeader("Accept", "application/json"); + request.send(null); + } + + function onFilterChange(w) { + if (w.selectedIndex <= 0) + localStorage["filter"] = ""; + else + localStorage["filter"] = unescape(w.options[w.selectedIndex].value); + + entriesLoadHead(); + } + + function onBootChange(w) { + localStorage["boot"] = w.checked ? "1" : "0"; + entriesLoadHead(); + } + + function initFilter() { + f = document.getElementById("filter"); + + var buf = ''; + + var filter = localStorage["filter"]; + if (filter != null && filter != "") { + buf += ''; + j = 1; + } else + j = 0; + + f.innerHTML = buf; + f.selectedIndex = j; + } + + function installHandlers() { + document.onkeyup = onKeyUp; + + logs = document.getElementById("divlogs"); + logs.addEventListener("mousewheel", onMouseWheel, false); + logs.addEventListener("DOMMouseScroll", onMouseWheel, false); + } + machineLoad(); entriesLoad(null); showNEntries(getNEntries()); - document.onkeyup = onKeyUp; - - logs = document.getElementById("divlogs"); - logs.addEventListener("mousewheel", onMouseWheel, false); - logs.addEventListener("DOMMouseScroll", onMouseWheel, false); + initFilter(); + installHandlers();