Changeset 2151
- Timestamp:
- Jan 26, 2012, 2:20:59 PM (10 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/generic/AjaxController.groovy
r2150 r2151 92 92 93 93 def studyCount = { 94 println params 95 println params.containsKey('data') 96 // println params['data']['uniqueSpecies'] 97 98 def matched = false 94 def matched = true 99 95 def user = authenticationService.getLoggedInUser() 100 96 def studies = Study.giveReadableStudies(user) 101 97 def matchedStudies = [] 102 98 103 // parameters 104 /* 105 def uniqueSpecies = (params['data']['uniqueSpecies']) ? params['data']['uniqueSpecies'] : [] 106 println uniqueSpecies.class 107 println uniqueSpecies.size() 99 // closure to transform criteria arguments to an array of Longs 100 def getAsArray = { paramText -> 101 def result = [] 108 102 109 // iterate through studies 103 if (paramText == null) { 104 result = [] 105 } else if (paramText.toString().contains(",")) { 106 result = paramText.collect { it as Long } 107 } else { 108 result = [paramText as Long] 109 } 110 111 return result 112 } 113 114 // define criteria arrays based on JSON arguments 115 def uniqueSpecies = (params.containsKey('uniqueSpecies[]')) ? getAsArray(params['uniqueSpecies[]']) : [] 116 def uniqueEventTemplateNames = (params.containsKey('uniqueEventTemplateNames[]')) ? getAsArray(params['uniqueEventTemplateNames[]']) : [] 117 def uniqueSamplingEventTemplateNames = (params.containsKey('uniqueSamplingEventTemplateNames[]')) ? getAsArray(params['uniqueSamplingEventTemplateNames[]']) : [] 118 119 // iterate through readable studies for this user 110 120 studies.each { study -> 111 matched = false 112 // matched = (study.subjects.find{uniqueSpecies.contains(it.species.id)}) ? true : false; 113 println "study: ${study} -> matched: ${matched}" 121 matched = true 114 122 123 // match to selection criteria 124 // 1. if any species were selected, see if this study contains any subject of this species 125 matched = (matched && (!uniqueSpecies.size() || study.subjects.find{uniqueSpecies.contains(it.species.id)})) ? true : false; 126 // 2. if any eventTemplateNames were selected, see if this study contains any of these 127 matched = (matched && (!uniqueEventTemplateNames.size() || study.events.find{uniqueEventTemplateNames.contains(it.template.id)})) ? true : false; 128 // 3. if any samplingEventTemplateNames were selected, see if this study contains any of these 129 matched = (matched && (!uniqueSamplingEventTemplateNames.size() || study.samplingEvents.find{uniqueSamplingEventTemplateNames.contains(it.template.id)})) ? true : false; 130 131 // if criteria are met, add this study to the matchedStudies array 115 132 if (matched) matchedStudies.add(study) 116 133 } 117 */118 println "------"119 134 120 def result = ['count':matchedStudies.size()]; 135 // define json result 136 def result = ['total':studies.size(),'matched':matchedStudies.size()]; 121 137 122 138 // set output header to json -
trunk/grails-app/views/studyCompare/common/_on_page.gsp
r2150 r2151 35 35 var options = '<h2>'+that.getAttribute('name')+'</h2>'; 36 36 for (var i=0;i<data.length;i++) { 37 options += '<input type="checkbox" name="species[]" value="'+data[i].id+'"/>'+data[i].name+' <br/>';37 options += '<input type="checkbox" name="species[]" value="'+data[i].id+'"/>'+data[i].name+' ('+data[i].id+')<br/>'; 38 38 } 39 39 element.removeClass('waitForLoad').html(options); -
trunk/grails-app/views/studyCompare/pages/_page_one.gsp
r2150 r2151 17 17 18 18 function handleCheckEvent(event) { 19 var check = $(event); 20 var value = check.attr('value'); 21 var parent = check.parent(); 22 var parentId = parent.attr('id'); 23 24 if (criteria[parentId] == undefined) criteria[parentId] = []; 25 26 // add or remove data 27 if (check.is(':checked') && criteria[parentId].indexOf(value) < 0) { 28 criteria[parentId].push(value); 29 } else if (criteria[parentId].indexOf(value) >= 0) { 30 criteria[parentId].splice(criteria[parentId].indexOf(value),1); 31 } 32 33 console.log(criteria); 34 35 36 $.getJSON( 37 baseUrl + "/ajax/studyCount", 38 criteria, 39 function(data) { 40 $('#matchedStudies').html(data.matched+' of '+data.total+' readable studies matched your criteria'); 41 } 42 ); 43 44 // $.ajax({ 45 // url: baseUrl + "/ajax/studyCount", 46 // dataType: 'json', 47 // data: criteria, 48 // success: function(data) { 49 // $('#matchedStudies').html(data.matched+' of '+data.total+' readable studies matched your criteria'); 50 // } 51 // }); 52 /* 19 53 var check = $(event); 20 54 var value = check.attr('value'); … … 42 76 ); 43 77 44 // $.ajax({ 45 // url: baseUrl + "/ajax/studyCount", 46 // dataType: 'json', 47 // data: data, 48 // success: function(data) { 49 // $('#matchedStudies').html(data.count+' studies matched your criteria'); 50 // } 51 // }); 78 $.ajax({ 79 url: baseUrl + "/ajax/studyCount", 80 dataType: 'json', 81 data: data, 82 success: function(data) { 83 $('#matchedStudies').html(data.count+' studies matched your criteria'); 84 } 85 }); 86 */ 52 87 53 88 }
Note: See TracChangeset
for help on using the changeset viewer.