mirror of
https://github.com/bodyrep/DemoApp.git
synced 2025-12-06 06:01:48 +00:00
add exerciselist filters
This commit is contained in:
@@ -1,16 +1,7 @@
|
||||
$(document).ready(function() {
|
||||
|
||||
// $.each($.getValues("/api/exerciselist"), function(i, item) {
|
||||
// console.log("Exercisename = " + item.name);
|
||||
// var newElem = $('<li>'+item.name + ' - ' + item.description + ' - ' + item.keywords +'<button type="button" class="addthisExercise">+</li>');
|
||||
// $(newElem).data('name', item.name);
|
||||
// $(newElem).data('datafields', item.datafields);
|
||||
// console.log("This - " + JSON.stringify($(newElem).data()));
|
||||
// $(newElem).appendTo('#exerciselist');
|
||||
// $("button").button();
|
||||
// });
|
||||
|
||||
$("button.addthisExercise").click(function() {
|
||||
$(document).on('click', '.addthisExercise',(function() {
|
||||
// $("button.addthisExercise").click(function() {
|
||||
console.log("This exercise name li" + JSON.stringify($(this).closest('li').data()));
|
||||
var newElem = $('<li class=ui-state-default ><label for="element">elements[0][exerciseID]<br /></label><input name="elements[][exerciseID]" class="element" value="' + $(this).closest('li').data('name') + '"><button type="button" class="addSet">Add Set</button><button type="button" class="delete">Delete Exercise</button><ul class="sets"><li class="set"><label for="element" name="elements[0][splits][0][reps]">elements[0][splits][0][reps]<br /></label><input name="elements[0][splits][0][reps]" class="element"><label for="element" name="elements[0][splits][0][weight]"><br />elements[0][splits][0][weight]<br /></label><input name="elements[0][splits][0][weight]" class="element"><button type="button" class="delete">Delete Set</button></li></ul></li>');
|
||||
$(newElem).appendTo('ul#exercises');
|
||||
@@ -18,54 +9,68 @@
|
||||
$( "ul#exercises" ).sortable( "refresh" );
|
||||
$( "ul#sets" ).sortable( "refresh" );
|
||||
$('#newworkout').trigger('sortupdate');
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
var exerciselistJSON = $.each($.getValues("/api/exerciselist"), function(i, item) {
|
||||
console.log("Exercisename = " + item.name);
|
||||
var newElem = $('<li>'+item.name + ' - ' + item.description + ' - ' + item.keywords +'<button type="button" class="addthisExercise">+</li>');
|
||||
$(newElem).data('name', item.name);
|
||||
$(newElem).data('datafields', item.datafields);
|
||||
console.log("This - " + JSON.stringify($(newElem).data()));
|
||||
$(newElem).appendTo('#exerciselist');
|
||||
$("button").button();
|
||||
});
|
||||
//filteredExerciseArray = filterarray(originalExerciselist);
|
||||
//PopulateExerciseList(arr);
|
||||
|
||||
$(document).on('click', '.filter',(function (){
|
||||
console.time('Filter');
|
||||
var keyREGEX= "";
|
||||
var len = $('.filter').length;
|
||||
$(".filter").each(function(index, element) {
|
||||
|
||||
if ($(this).is (':checked'))
|
||||
{
|
||||
// Do stuff
|
||||
keyREGEX += '('+ $(this).val() +')';
|
||||
}
|
||||
});
|
||||
//keyREGEX += "'";
|
||||
keyREGEX = keyREGEX.replace(")(", ")|(");
|
||||
console.log("Regex= " + keyREGEX);
|
||||
filteredExerciseArray = filterarray(originalExerciselist, keyREGEX);
|
||||
PopulateExerciseList(filteredExerciseArray);
|
||||
console.timeEnd('Filter');
|
||||
}));
|
||||
|
||||
|
||||
function filterarray(input, regex){
|
||||
console.log('passed regex' + regex);
|
||||
var keyRE=new RegExp(regex);
|
||||
var arr = jQuery.grep(input, function(n, i){
|
||||
return keyRE.test(n.keywords);
|
||||
// return $.grep(n.keywords, function (item, i) {
|
||||
// return keyRE.test(item);
|
||||
// });
|
||||
});
|
||||
console.log("arr " + arr.length);
|
||||
return arr;
|
||||
}
|
||||
|
||||
//// Notes for filter code
|
||||
|
||||
// on .filter click
|
||||
// define grepstring
|
||||
// for each .filter
|
||||
// grepstring += filter value
|
||||
// for each document in $.getValues("/api/exerciselist")
|
||||
// grep doc.keywords
|
||||
// if match
|
||||
// add to array exerciselist
|
||||
// $.each(exerciselist, funciton "updateExerciselistDIV");
|
||||
|
||||
////// Make below standalone funtion "updateExerciselistDIV"
|
||||
function PopulateExerciseList(exerciselist) {
|
||||
var newExerciselist = document.createDocumentFragment();
|
||||
console.time('PopulateExList');
|
||||
var newExerciselist = $('<div></div>');
|
||||
$.each(exerciselist, function (i, item) {
|
||||
console.log("Exercisename = " + item.name);
|
||||
//console.log("Exercisename = " + item.name);
|
||||
var newElem = $('<li>'+item.name + ' - ' + item.description + ' - ' + item.keywords +'<button type="button" class="addthisExercise">+</li>');
|
||||
$(newElem).data('name', item.name);
|
||||
$(newElem).data('datafields', item.datafields);
|
||||
console.log("This - " + JSON.stringify($(newElem).data()));
|
||||
console.log("newexlist = " + newExerciselist);
|
||||
newExerciselist.appendChild($newElem);
|
||||
console.log("newexlist = " + $newExerciselist);
|
||||
|
||||
newExerciselist.append(newElem);
|
||||
});
|
||||
console.log("newexlist outside= " + $newExerciselist);
|
||||
console.log("newexlist outside= " + newExerciselist);
|
||||
$('#exerciselist').empty();
|
||||
// $(newExerciselist).appendTo('#exerciselist');
|
||||
//$('#exerciselist').append($(newExerciselist));
|
||||
$(newExerciselist).appendTo('#exerciselist');
|
||||
$("button").button();
|
||||
console.timeEnd('PopulateExList');
|
||||
}
|
||||
|
||||
var originalExerciselist = $.getValues("/api/exerciselist");
|
||||
PopulateExerciseList(originalExerciselist);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ list-style-type: none;
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
#exerciselist {
|
||||
width : 500px;
|
||||
height : 400px;
|
||||
overflow : auto;
|
||||
}
|
||||
|
||||
label {
|
||||
margin-left: 5px;
|
||||
|
||||
@@ -12,7 +12,15 @@ block content
|
||||
div#filters
|
||||
h3 Filters ( currently just placeholder )
|
||||
label Free Weights
|
||||
input#filter1(type="checkbox", value="Free Weights")
|
||||
input.filter(type="checkbox", checked=true, value="Free Weights")
|
||||
label Bodyweight
|
||||
input.filter(type="checkbox", checked=true, value="Bodyweight")
|
||||
label Exercise Machines
|
||||
input.filter(type="checkbox", checked=true, value='Exercise Machine')
|
||||
label Kettlebells
|
||||
input.filter(type="checkbox", checked=true, value='Kettlebells')
|
||||
label Cardio
|
||||
input.filter(type="checkbox", checked=true, value='Cardio')
|
||||
|
||||
//button#addExercise(type="button") Add Exercise
|
||||
hr
|
||||
|
||||
Reference in New Issue
Block a user