diff --git a/WebContent/html/javascript/listing.jsp b/WebContent/html/javascript/listing.jsp
index 2aaff0b..6aeb139 100644
--- a/WebContent/html/javascript/listing.jsp
+++ b/WebContent/html/javascript/listing.jsp
@@ -33,6 +33,10 @@ for(var a = 0; a < hardwareOptions.length; a++){
for(var a = 0; a < softwareOptions.length; a++){
softwareOptions[a].addEventListener('click', refresh);
}
+// searchbar listener
+var searchbar = document.getElementsByName('searchBar');
+searchbar[0].onkeyup = refresh;
+
showAll();
function showAll(){
var html = '';
@@ -57,7 +61,7 @@ function showAll(){
}
}
function refresh() {
- var filteredDevices = applyFilter();
+ var filteredDevices = fuzzyFilter(applyFilter());
show(filteredDevices);
}
function show(deviceArray){
@@ -130,10 +134,39 @@ function applyFilter() {
return filteredDevices;
}
+function fuzzyFilter(deviceList) {
+ var searchText = document.getElementsByName('searchBar')[0].value;
+ var options = {
+ pre: '',
+ post: '',
+ extract: function(arg) {return arg.name;}
+ }
+ var fuzzyResults = fuzzy.filter(searchText, deviceList, options);
+ // this returns a filtered array of objects with attributes 'index', 'original', 'score', and 'string'
+ // I am interested in the 'original' attribute, which is the relevant object exactly as it was submitted,
+ // and the 'string' attribute, which is the attribute that was compared against with matching characters conveniantly bolded
+ var results = new Array(fuzzyResults.length);
+ // so I'm going to rebuild a filtered device array in the same format as we've been using,
+ // substituting the 'name' attribute with the 'string' attribute returned by fuzzy
+ for (var i = 0; i < fuzzyResults.length; i++) {
+ results[i] = {
+ name:fuzzyResults[i].string, //This one is being replaced
+ id:fuzzyResults[i].original.id,
+ description:fuzzyResults[i].original.description,
+ hardware:fuzzyResults[i].original.hardware,
+ status:fuzzyResults[i].original.status,
+ model:fuzzyResults[i].original.model,
+ manufacturer:fuzzyResults[i].original.manufacturer,
+ };
+ }
+
+ return results;
+}
function makeDeviceArray(){
window.json = '<%=deviceString%>';
return JSON.parse(window.json);
}
+