Added search by date (Smort search)

master
Davide Bongiovanni 8 years ago
parent fce7ddb723
commit 922fe528e9

@ -1 +1 @@
[{"cardID": "2924385363", "name": "Davide Bon", "time": 1475424208.055737}, {"time": 1475424209.151567, "name": "", "cardID": "0861643457"}, {"cardID": "2924385363", "name": "Davide Bon", "time": 1475424209.758858}, {"time": 1475424211.022202, "name": "Davide Bon", "cardID": "2924385363"}, {"cardID": "0861643457", "name": "", "time": 1475424212.244935}, {"time": 1475424213.343284, "name": "", "cardID": "0861643457"}] [{"cardID": "2924385363", "name": "Davide Bon", "time": 1475424208.055737}, {"time": 1475424209.151567, "name": "", "cardID": "0861643457"}, {"cardID": "2924385363", "name": "Davide Bon", "time": 1475424209.758858}, {"time": 1475424211.022202, "name": "Davide Bon", "cardID": "2924385363"}, {"cardID": "0861643457", "name": "", "time": 1475424212.244935}, {"time": 1475424213.343284, "name": "", "cardID": "0861643457"}, {"time": 1478078555.343284, "name": "", "cardID": "0861643457"}]

@ -78,8 +78,24 @@ $(document).ready(function() {
$('.search-bar').on('keyup', function() { $('.search-bar').on('keyup', function() {
var newHistory = '<div class="event-wrapper">'; var newHistory = '<div class="event-wrapper">';
for (var i = 0; i < eventHistory.length; i++) { for (var i = 0; i < eventHistory.length; i++) {
if (eventHistory[i].name.match($('.search-bar').val())) { var eventDate = new Date(eventHistory[i].time*1000);
var dateString = (new Date(eventHistory[i].time*1000)).toLocaleString(); var mdy = $('.search-bar').val().split('/');
var dateMatch = false;
switch(mdy.length) {
case 1:
dateMatch = parseInt(mdy[0])==(eventDate.getMonth()+1);
break;
case 2:
dateMatch = (parseInt(mdy[0])==(eventDate.getMonth()+1)) && (parseInt(mdy[1])==eventDate.getDate());
break;
case 3:
dateMatch = (parseInt(mdy[0])==(eventDate.getMonth()+1)) && (parseInt(mdy[1])==eventDate.getDate()) && (parseInt(mdy[2])==eventDate.getFullYear());
break;
default:
break;
}
if (eventHistory[i].name.match($('.search-bar').val()) || dateMatch) {
var dateString = eventDate.toLocaleString();
var newElement = '<div class="event" card-id="' + eventHistory[i].cardID + '">\ 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">';

Loading…
Cancel
Save