mirror of
https://github.com/bodyrep/DemoApp.git
synced 2026-01-25 06:32:11 +00:00
add exerciselist filters
This commit is contained in:
@@ -1,16 +1,7 @@
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
// $.each($.getValues("/api/exerciselist"), function(i, item) {
|
$(document).on('click', '.addthisExercise',(function() {
|
||||||
// console.log("Exercisename = " + item.name);
|
// $("button.addthisExercise").click(function() {
|
||||||
// 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() {
|
|
||||||
console.log("This exercise name li" + JSON.stringify($(this).closest('li').data()));
|
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>');
|
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');
|
$(newElem).appendTo('ul#exercises');
|
||||||
@@ -18,54 +9,68 @@
|
|||||||
$( "ul#exercises" ).sortable( "refresh" );
|
$( "ul#exercises" ).sortable( "refresh" );
|
||||||
$( "ul#sets" ).sortable( "refresh" );
|
$( "ul#sets" ).sortable( "refresh" );
|
||||||
$('#newworkout').trigger('sortupdate');
|
$('#newworkout').trigger('sortupdate');
|
||||||
});
|
})
|
||||||
|
);
|
||||||
|
|
||||||
var exerciselistJSON = $.each($.getValues("/api/exerciselist"), function(i, item) {
|
//filteredExerciseArray = filterarray(originalExerciselist);
|
||||||
console.log("Exercisename = " + item.name);
|
//PopulateExerciseList(arr);
|
||||||
var newElem = $('<li>'+item.name + ' - ' + item.description + ' - ' + item.keywords +'<button type="button" class="addthisExercise">+</li>');
|
|
||||||
$(newElem).data('name', item.name);
|
$(document).on('click', '.filter',(function (){
|
||||||
$(newElem).data('datafields', item.datafields);
|
console.time('Filter');
|
||||||
console.log("This - " + JSON.stringify($(newElem).data()));
|
var keyREGEX= "";
|
||||||
$(newElem).appendTo('#exerciselist');
|
var len = $('.filter').length;
|
||||||
$("button").button();
|
$(".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"
|
////// Make below standalone funtion "updateExerciselistDIV"
|
||||||
function PopulateExerciseList(exerciselist) {
|
function PopulateExerciseList(exerciselist) {
|
||||||
var newExerciselist = document.createDocumentFragment();
|
console.time('PopulateExList');
|
||||||
|
var newExerciselist = $('<div></div>');
|
||||||
$.each(exerciselist, function (i, item) {
|
$.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>');
|
var newElem = $('<li>'+item.name + ' - ' + item.description + ' - ' + item.keywords +'<button type="button" class="addthisExercise">+</li>');
|
||||||
$(newElem).data('name', item.name);
|
$(newElem).data('name', item.name);
|
||||||
$(newElem).data('datafields', item.datafields);
|
$(newElem).data('datafields', item.datafields);
|
||||||
console.log("This - " + JSON.stringify($(newElem).data()));
|
newExerciselist.append(newElem);
|
||||||
console.log("newexlist = " + newExerciselist);
|
|
||||||
newExerciselist.appendChild($newElem);
|
|
||||||
console.log("newexlist = " + $newExerciselist);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
console.log("newexlist outside= " + $newExerciselist);
|
console.log("newexlist outside= " + newExerciselist);
|
||||||
$('#exerciselist').empty();
|
$('#exerciselist').empty();
|
||||||
// $(newExerciselist).appendTo('#exerciselist');
|
$(newExerciselist).appendTo('#exerciselist');
|
||||||
//$('#exerciselist').append($(newExerciselist));
|
|
||||||
$("button").button();
|
$("button").button();
|
||||||
|
console.timeEnd('PopulateExList');
|
||||||
}
|
}
|
||||||
|
|
||||||
var originalExerciselist = $.getValues("/api/exerciselist");
|
var originalExerciselist = $.getValues("/api/exerciselist");
|
||||||
PopulateExerciseList(originalExerciselist);
|
PopulateExerciseList(originalExerciselist);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ list-style-type: none;
|
|||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#exerciselist {
|
||||||
|
width : 500px;
|
||||||
|
height : 400px;
|
||||||
|
overflow : auto;
|
||||||
|
}
|
||||||
|
|
||||||
label {
|
label {
|
||||||
margin-left: 5px;
|
margin-left: 5px;
|
||||||
|
|||||||
@@ -12,7 +12,15 @@ block content
|
|||||||
div#filters
|
div#filters
|
||||||
h3 Filters ( currently just placeholder )
|
h3 Filters ( currently just placeholder )
|
||||||
label Free Weights
|
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
|
//button#addExercise(type="button") Add Exercise
|
||||||
hr
|
hr
|
||||||
|
|||||||
Reference in New Issue
Block a user