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

Loading…
Cancel
Save