Added args functionality to search bar

master
Davide Bongiovanni 8 years ago
parent 8d04651c08
commit 0f0f5e7b4b

@ -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"}, {"time": 1478078555.343284, "name": "", "cardID": "0861643457"}] [{"cardID": "2924385363", "name": "Davide Bon", "time": 147542.055737}, {"cardID": "2924385363", "name": "Davide Bon", "time": 1475478000}, {"cardID": "2924385363", "name": "Davide Bon", "time": 147542420.055737}, {"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"}]

@ -37,7 +37,7 @@ $(document).ready(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++) {
var dateString = (new Date(eventHistory[i].time*1000)).toLocaleString(); var dateString = (new Date(eventHistory[i].time*1000)).toLocaleString('sv-SE');
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">';
@ -77,25 +77,42 @@ $(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++) { var args = $('.search-bar').val().split(' ');
var eventDate = new Date(eventHistory[i].time*1000); var toMatch = [-1,-1,-1];
var mdy = $('.search-bar').val().split('/'); var nameToMatch = '';
var dateMatch = false; for (var j = 0; j < args.length; j++) {
switch(mdy.length) { if(args[j].charAt(0) == '-') {
case 1: switch(args[j].charAt(1)) {
dateMatch = parseInt(mdy[0])==(eventDate.getMonth()+1); case 'y':
toMatch[0] = parseInt(args[j].substring(2));
break; break;
case 2: case 'm':
dateMatch = (parseInt(mdy[0])==(eventDate.getMonth()+1)) && (parseInt(mdy[1])==eventDate.getDate()); toMatch[1] = parseInt(args[j].substring(2));
break; break;
case 3: case 'd':
dateMatch = (parseInt(mdy[0])==(eventDate.getMonth()+1)) && (parseInt(mdy[1])==eventDate.getDate()) && (parseInt(mdy[2])==eventDate.getFullYear()); toMatch[2] = parseInt(args[j].substring(2));
break; break;
default: default:
break; break;
} }
if (eventHistory[i].name.match($('.search-bar').val()) || dateMatch) { } else {
var dateString = eventDate.toLocaleString(); nameToMatch += args[j] + ' ';
}
}
nameToMatch = nameToMatch.substring(0, nameToMatch.length - 1);
for (var i = 0; i < eventHistory.length; i++) {
var dateMatch = true;
var eventDate = new Date(eventHistory[i].time*1000);
if (toMatch[0] > 0)
dateMatch = dateMatch && (toMatch[0] == eventDate.getFullYear());
if (toMatch[1] > 0)
dateMatch = dateMatch && (toMatch[1] == (eventDate.getMonth() + 1));
if (toMatch[2] > 0)
dateMatch = dateMatch && (toMatch[2] == eventDate.getDate());
/*if (toMatch[0]<0 && toMatch[1]<0 && toMatch[2]<0)
dateMatch = false;*/
if ((eventHistory[i].name.match(nameToMatch) != null) && dateMatch) {
var dateString = eventDate.toLocaleString('sv-SE');
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