Added search feature

master
Davide Bongiovanni 8 years ago
parent c5b9e26971
commit fce7ddb723

@ -33,22 +33,26 @@ function save() {
$(document).ready(function() { $(document).ready(function() {
jQuery.ajaxSetup({ cache: false }); jQuery.ajaxSetup({ cache: false });
$.getJSON('http://127.0.0.1:5000/gethistory', function(data) { $.getJSON('http://127.0.0.1:5000/gethistory', function(data) {
eventHistory = data; eventHistory = data.reverse();
for (var i = 0; i < data.length; i++) { var newHistory = '<div class="event-wrapper">';
var dateString = (new Date(data[i].time*1000)).toLocaleString(); for (var i = 0; i < eventHistory.length; i++) {
var newElement = '<div class="event" card-id="' + data[i].cardID + '">\ var dateString = (new Date(eventHistory[i].time*1000)).toLocaleString();
var newElement = '<div class="event" card-id="' + eventHistory[i].cardID + '">\
<div class="time">' + dateString + '</div>\ <div class="time">' + dateString + '</div>\
<div class="name">'; <div class="name">';
if (data[i].name == "") if (eventHistory[i].name == "")
newElement += '<span class="unknown_card">' + data[i].cardID + '</span>'; newElement += '<span class="unknown_card">' + eventHistory[i].cardID + '</span>';
else else
newElement += data[i].name; newElement += eventHistory[i].name;
newElement += '</div>\ newElement += '</div>\
</div>'; </div>';
var toInsert = $(newElement); newHistory += newElement;
$('.search-bar').after(toInsert);
} }
newHistory += '</div>';
var toInsert = $(newHistory);
$('.search-bar').after(toInsert);
}); });
$('.recent').on('click', '.event', function() { $('.recent').on('click', '.event', function() {
var cardID = $(this).attr('card-id'); var cardID = $(this).attr('card-id');
@ -72,8 +76,23 @@ $(document).ready(function() {
overlay_in(); overlay_in();
}); });
$('.search-bar').on('keyup', function() { $('.search-bar').on('keyup', function() {
if (eventHistory[1].name.match($('.search-bar').val())) { var newHistory = '<div class="event-wrapper">';
alert('match'); for (var i = 0; i < eventHistory.length; i++) {
if (eventHistory[i].name.match($('.search-bar').val())) {
var dateString = (new Date(eventHistory[i].time*1000)).toLocaleString();
var newElement = '<div class="event" card-id="' + eventHistory[i].cardID + '">\
<div class="time">' + dateString + '</div>\
<div class="name">';
if (eventHistory[i].name == "")
newElement += '<span class="unknown_card">' + eventHistory[i].cardID + '</span>';
else
newElement += eventHistory[i].name;
newElement += '</div>\
</div>';
newHistory += newElement;
}
} }
newHistory += '</div>';
$('.event-wrapper').replaceWith(newHistory);
}); });
}) })

@ -21,8 +21,6 @@
<h1>Card access manager</h1> <h1>Card access manager</h1>
<br> <br>
<a href="/users"><div class="big-button">Users list</div></a> <a href="/users"><div class="big-button">Users list</div></a>
<br>
<a href="/history"><div class="big-button">Full history</div></a>
</div> </div>
<div class="shadow" onclick="overlay_out()"></div> <div class="shadow" onclick="overlay_out()"></div>
<div class="overlay"> <div class="overlay">

Loading…
Cancel
Save