Added search feature

master
Davide Bongiovanni 8 years ago
parent c5b9e26971
commit fce7ddb723

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

Loading…
Cancel
Save