mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Added search functionality back in. It's much snappier now.
- Is now case-insensitive. - And regex.
This commit is contained in:
1 parent
bdf4225dec
commit
000b2fc147
2 files changed
+24
-4
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
<!doctype HTML>
|
<!doctype HTML>
|
||||||
<head>
|
<head>
|
||||||
<%- include("head.html") %>
|
<%- include("head.html") %>
|
||||||
<script src="storage.js"></script>
|
<script defer src="storage.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
+23
-3
@@ -1,9 +1,20 @@
|
|||||||
// function to draw data we recieve from ajax requests
|
// function to draw data we recieve from ajax requests
|
||||||
|
_lastData = [];
|
||||||
function drawcontents(data) {
|
function drawcontents(data) {
|
||||||
|
data = data || _lastData; //Cache data so we can drawcontents without waiting for the server, for the search box.
|
||||||
|
_lastData = data;
|
||||||
|
|
||||||
|
const search = new RegExp(document.querySelector("#search").value, 'i');
|
||||||
|
data = data.filter(function(item) {
|
||||||
|
return search.test(item.name);
|
||||||
|
})
|
||||||
|
|
||||||
|
sortByKey(data, "count");
|
||||||
|
|
||||||
const table = document.querySelector("#contents tbody"); //tables have tbody inserted automatically
|
const table = document.querySelector("#contents tbody"); //tables have tbody inserted automatically
|
||||||
const rows = table.children;
|
const rows = table.children;
|
||||||
|
|
||||||
sortByKey(data, "count");
|
//update existing rows or create new ones
|
||||||
data.forEach(function(item, i) {
|
data.forEach(function(item, i) {
|
||||||
let row = rows[i];
|
let row = rows[i];
|
||||||
if(!row) {
|
if(!row) {
|
||||||
@@ -27,7 +38,12 @@ function drawcontents(data) {
|
|||||||
if(count.textContent !== ''+item.count) {
|
if(count.textContent !== ''+item.count) {
|
||||||
count.textContent = item.count;
|
count.textContent = item.count;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
|
//remove excess rows, for example, after filtering
|
||||||
|
while (data.length < rows.length) {
|
||||||
|
table.removeChild(rows[data.length]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get cluster inventory from master
|
// get cluster inventory from master
|
||||||
@@ -53,4 +69,8 @@ function sortByKey(array, key) {
|
|||||||
array.sort(function(a, b) {
|
array.sort(function(a, b) {
|
||||||
return b[key] - a[key];
|
return b[key] - a[key];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.querySelector("#search").addEventListener('input', function() {
|
||||||
|
drawcontents();
|
||||||
|
})
|
||||||
Reference in new issue
Block a user