Changeset 1798
- Timestamp:
- May 2, 2011, 11:55:13 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 10 10 .settings 11 11 *.log 12 dtd
-
- Property svn:ignore
-
trunk/grails-app/controllers/dbnp/exporter/ExporterController.groovy
r1794 r1798 51 51 def export = { 52 52 def ids = params.list( 'ids' ); 53 def tokens = params.list( 'tokens' ); 53 54 def studies = [] 54 55 … … 59 60 studies << study 60 61 } 62 } 63 64 // Also accept tokens for defining studies 65 tokens.each { 66 def study = Study.findByStudyUUID( it ); 67 if( study ) 68 studies << study; 61 69 } 62 70 -
trunk/grails-app/controllers/dbnp/query/AdvancedQueryController.groovy
r1752 r1798 125 125 def view = determineView( s.entity ); 126 126 render( view: view, model: [search: s, queryId: queryId, actions: determineActions(s)] ); 127 }128 129 /**130 * Performs an action on specific searchResults131 * @param queryId queryId of the search to show132 * @param id list with the ids of the results to perform the action on133 * @param actionName Name of the action to perform134 */135 def performAction = {136 def queryId = params.int( 'queryId' );137 def selectedIds = params.list( 'id' ).findAll { it.isLong() }.collect { Long.parseLong(it) }138 def actionName = params.actionName;139 def moduleName = params.moduleName;140 141 if( !queryId ) {142 flash.error = "Incorrect search ID given to show"143 redirect( action: "index" );144 return145 }146 147 // Retrieve the search from session148 Search s = retrieveSearch( queryId );149 if( !s ) {150 flash.message = "Specified search could not be found"151 redirect( action: "list" );152 return;153 }154 155 // Determine the possible actions and build correct urls156 def actions = determineActions(s, selectedIds );157 158 // Find the right action to perform159 def redirectUrl;160 for( action in actions ) {161 if( action.module == moduleName && action.name == actionName ) {162 redirectUrl = action.url;163 break;164 }165 }166 167 if( !redirectUrl ) {168 flash.error = "No valid action is given to perform";169 redirect( action: "show", id: queryId );170 return;171 }172 173 redirect( url: redirectUrl );174 127 } 175 128 … … 578 531 * Determine a list of actions that can be performed on specific entities by GSCF 579 532 * @param entity Name of the entity that the actions could be performed on 580 * @param selected Ids List with idsof the selected items to perform an action on581 */ 582 protected List gscfActions(Search s, def selected Ids = null) {533 * @param selectedTokens List with tokens (UUID) of the selected items to perform an action on 534 */ 535 protected List gscfActions(Search s, def selectedTokens = null) { 583 536 switch(s.entity) { 584 537 case "Study": 585 538 def ids = [] 586 s.filterResults(selected Ids).each {539 s.filterResults(selectedTokens).each { 587 540 ids << it.id 588 541 } 542 543 def paramString = ids.collect { return 'ids=' + it }.join( '&' ); 589 544 590 545 return [[ … … 592 547 name:"simpletox", 593 548 description: "Export as SimpleTox", 594 url: createLink( controller: "exporter", action: "export", params: [ 'format': 'list', 'ids' : ids ] ) 549 url: createLink( controller: "exporter", action: "export", params: [ 'format': 'list', 'ids' : ids ] ), 550 submitUrl: createLink( controller: "exporter", action: "export", params: [ 'format': 'list' ] ), 551 paramString: paramString 595 552 ], [ 596 553 module: "gscf", 597 554 name:"excel", 598 555 description: "Export as Excel", 599 url: createLink( controller: "study", action: "exportToExcel", params: [ 'format': 'list', 'ids' : ids ] ) 556 url: createLink( controller: "study", action: "exportToExcel", params: [ 'format': 'list', 'ids' : ids ] ), 557 submitUrl: createLink( controller: "study", action: "exportToExcel", params: [ 'format': 'list' ] ), 558 paramString: paramString 600 559 ]] 601 560 case "Assay": 602 561 def ids = [] 603 s.filterResults(selected Ids).each {562 s.filterResults(selectedTokens).each { 604 563 ids << it.id 605 564 } 565 566 def paramString = ids.collect { return 'ids=' + it }.join( '&' ); 606 567 607 568 return [[ … … 609 570 name:"excel", 610 571 description: "Export as Excel", 611 url: createLink( controller: "assay", action: "exportToExcel", params: [ 'format': 'list', 'ids' : ids ] ) 572 url: createLink( controller: "assay", action: "exportToExcel", params: [ 'format': 'list', 'ids' : ids ] ), 573 submitUrl: createLink( controller: "assay", action: "exportToExcel", params: [ 'format': 'list' ] ), 574 paramString: paramString 612 575 ]] 613 576 case "Sample": … … 622 585 * @param entity Name of the entity that the actions could be performed on 623 586 */ 624 protected List moduleActions(Search s, def selected Ids = null) {587 protected List moduleActions(Search s, def selectedTokens = null) { 625 588 def actions = [] 626 589 … … 639 602 if( json[ s.entity ] ) { 640 603 json[ s.entity ].each { action -> 641 def url = action.url ?: module.url + "/action/" + action.name 604 def baseUrl = action.url ?: module.url + "/action/" + action.name 605 def paramString = s.filterResults(selectedTokens).collect { "tokens=" + it.giveUUID() }.join( "&" ) 642 606 643 if( url.find( /\?/ ) )644 url += "&"607 if( baseUrl.find( /\?/ ) ) 608 baseUrl += "&" 645 609 else 646 url += "?"610 baseUrl += "?" 647 611 648 url += "entity=" + s.entity 649 url += "&" + s.filterResults(selectedIds).collect { "tokens=" + it.giveUUID() }.join( "&" ) 612 baseUrl += "entity=" + s.entity 613 614 def url = baseUrl; 615 650 616 actions << [ 651 617 module: moduleName, 652 618 name: action.name, 653 619 description: action.description + " (" + moduleName + ")", 654 url: url 620 url: url + "&" + paramString, 621 submitUrl: baseUrl, 622 paramString: paramString 655 623 ]; 656 624 } -
trunk/grails-app/controllers/dbnp/studycapturing/AssayController.groovy
r1790 r1798 5 5 def assayService 6 6 def authenticationService 7 7 def fileService 8 8 9 9 static allowedMethods = [save: "POST", update: "POST", delete: "POST"] … … 174 174 flow.rowData = assayService.convertColumnToRowStructure(assayData) 175 175 176 177 176 def previewRows = Math.min(flow.rowData.size() as int, 5) - 1 177 def previewCols = Math.min(flow.rowData[0].size() as int, 5) - 1 178 178 179 179 flow.assayDataPreview = flow.rowData[0..previewRows].collect{ it[0..previewCols] as ArrayList } … … 198 198 } 199 199 200 201 202 203 200 /** 201 * Export the row data in session.rowData to the outputStream of the http 202 * response. 203 */ 204 204 def doExport = { 205 205 … … 209 209 try { 210 210 211 // assayService.exportRowWiseDataToExcelFile(session.rowData, response.outputStream)211 // assayService.exportRowWiseDataToExcelFile(session.rowData, response.outputStream) 212 212 assayService.exportRowWiseDataToCSVFile(session.rowData, response.outputStream) 213 213 214 215 214 // clear the data from the session 215 session.removeAttribute('rowData') 216 216 217 217 } catch (Exception e) { … … 245 245 */ 246 246 def exportToExcelAsSheets = { 247 def ids = params.list( 'ids' ).findAll { it.isLong() }.collect { Long.valueOf( it ) }; 248 249 if( !ids ) { 250 flash.errorMessage = "No assay ids given"; 251 redirect( action: "errorPage" ); 247 def assays = getAssaysFromParams( params ); 248 249 if( !assays ) 252 250 return; 253 }254 255 // Find all assays for the given ids256 def assays = ids.unique().collect { id -> Assay.get( id ) }.findAll { it }257 251 258 252 // Send headers to the browser so the user can download the file … … 293 287 */ 294 288 def exportToExcelAsList = { 295 def ids = params.list( 'ids' ).findAll { it.isLong() }.collect { Long.valueOf( it ) }; 296 297 if( !ids ) { 298 flash.errorMessage = "No assay ids given"; 299 redirect( action: "errorPage" ); 289 def assays = getAssaysFromParams( params ); 290 291 if( !assays ) 300 292 return; 301 }302 293 303 294 // If only 1 assay is asked for, don't bother with merging multiple assays. 304 295 // In that case just use the export method to export one assay per sheet 305 if( ids.size() == 1 )296 if( assays.size() == 1 ) 306 297 return exportToExcelAsSheets( params ); 307 308 // Find all assays for the given ids309 def assays = ids.unique().collect { id -> Assay.get( id ) }.findAll { it }310 298 311 299 // Send headers to the browser so the user can download the file … … 325 313 // Retrieve row based data for this assay 326 314 def assayData = assayService.collectAssayData( assay, fieldMap, measurementTokens ); 327 315 328 316 // Prepend study and assay data to the list 329 317 assayData = assayService.prependAssayData( assayData, assay, assay.samples?.size() ) 330 318 assayData = assayService.prependStudyData( assayData, assay, assay.samples?.size() ) 331 319 332 320 // Put each assay on another sheet 333 321 columnWiseAssayData << assayData; 334 322 } 335 323 336 324 // Merge data from all assays 337 325 def mergedColumnWiseData = assayService.mergeColumnWiseDataOfMultipleStudies( columnWiseAssayData ); … … 347 335 } 348 336 337 def getAssaysFromParams( params ) { 338 def ids = params.list( 'ids' ).findAll { it.isLong() }.collect { Long.valueOf( it ) }; 339 def tokens = params.list( 'tokens' ); 340 341 if( !ids && !tokens ) { 342 flash.errorMessage = "No assay ids given"; 343 redirect( action: "errorPage" ); 344 return []; 345 } 346 347 // Find all assays for the given ids 348 def assays = []; 349 ids.each { id -> 350 def assay = Assay.get( id ); 351 if( assay ) 352 assays << assay; 353 } 354 355 // Also accept tokens for defining studies 356 tokens.each { token -> 357 def assay = Assay.findByAssayUUID( token ); 358 if( assay ) 359 assays << assay; 360 } 361 362 if( !assays ) { 363 flash.errorMessage = "No assays found"; 364 redirect( action: "errorPage" ); 365 return []; 366 } 367 368 return assays.unique(); 369 } 349 370 350 371 def errorPage = { -
trunk/grails-app/controllers/dbnp/studycapturing/StudyController.groovy
r1794 r1798 396 396 def exportToExcel = { 397 397 def ids = params.list( 'ids' ).findAll { it.isLong() }.collect { Long.valueOf( it ) }; 398 399 if( !ids ) { 398 def tokens = params.list( 'tokens' ); 399 400 if( !ids && !tokens ) { 400 401 flash.errorMessage = "No study ids given"; 401 402 redirect( controller: "assay", action: "errorPage" ); … … 404 405 405 406 // Find all assay ids for these studies 406 def assayIds = ids.collect { id -> 407 def assayIds = []; 408 ids.each { id -> 407 409 def study = Study.get( id ); 408 410 if( study ) { 409 return study.assays.collect { assay -> assay.id } 410 } else { 411 return [] 411 assayIds += study.assays.collect { assay -> assay.id } 412 412 } 413 } .flatten()413 } 414 414 415 // Also accept tokens for defining studies 416 tokens.each { token -> 417 def study = Study.findByStudyUUID( token ); 418 if( study ) 419 assayIds += study.assays.collect { assay -> assay.id } 420 } 421 415 422 if( !assayIds ) { 416 423 flash.errorMessage = "No assays found for the given studies"; -
trunk/grails-app/views/advancedQuery/_resultbuttons.gsp
r1581 r1798 18 18 </g:if> 19 19 <g:else> 20 <a class="performAction ${action.name}" href="${action.url}" onClick="performAction( $('form#results'), '${action.name}', '${action.module}' ); return false;">${action.description}</a>20 <a class="performAction ${action.name}" href="${action.url}" onClick="performAction( $('form#results'), '${action.name}', '${action.module}', '${action.submitUrl}' ); return false;">${action.description}</a> 21 21 </g:else> 22 22 <br /> -
trunk/grails-app/views/advancedQuery/assayresults.gsp
r1649 r1798 41 41 also http://datatables.net/examples/api/form.html and advancedQueryResults.js 42 42 */ %> 43 <g:checkBox name=" id" value="${assayInstance.id}" checked="${false}" onClick="updateCheckAll(this);" />43 <g:checkBox name="uuid" value="${assayInstance.giveUUID()}" checked="${false}" onClick="updateCheckAll(this);" /> 44 44 </td> 45 45 <td> -
trunk/grails-app/views/advancedQuery/results.gsp
r1548 r1798 40 40 also http://datatables.net/examples/api/form.html and advancedQueryResults.js 41 41 */ %> 42 <g:checkBox name=" id" value="${result.id}" checked="${false}" onClick="updateCheckAll(this);" />42 <g:checkBox name="uuid" value="${result.giveUUID()}" checked="${false}" onClick="updateCheckAll(this);" /> 43 43 </td> 44 44 <td>${search.entity}</td> -
trunk/grails-app/views/advancedQuery/sampleresults.gsp
r1548 r1798 41 41 also http://datatables.net/examples/api/form.html and advancedQueryResults.js 42 42 */ %> 43 <g:checkBox name=" id" value="${sampleInstance.id}" checked="${false}" onClick="updateCheckAll(this);" />43 <g:checkBox name="uuid" value="${sampleInstance.giveUUID()}" checked="${false}" onClick="updateCheckAll(this);" /> 44 44 </td> 45 45 <td>${fieldValue(bean: sampleInstance, field: "name")}</td> -
trunk/grails-app/views/advancedQuery/studyresults.gsp
r1689 r1798 44 44 also http://datatables.net/examples/api/form.html and advancedQueryResults.js 45 45 */ %> 46 <g:checkBox name=" id" value="${studyInstance.id}" checked="${false}" onClick="updateCheckAll(this);" />46 <g:checkBox name="uuid" value="${studyInstance.giveUUID()}" checked="${false}" onClick="updateCheckAll(this);" /> 47 47 </td> 48 48 <td> -
trunk/src/groovy/dbnp/query/Search.groovy
r1717 r1798 795 795 * @return A list with only those results for which the id is in the selectedIds 796 796 */ 797 public List filterResults( List selected Ids ) {798 if( !selected Ids || !results )797 public List filterResults( List selectedTokens ) { 798 if( !selectedTokens || !results ) 799 799 return results 800 800 801 801 return results.findAll { 802 selected Ids.contains( it.id)802 selectedTokens.contains( it.giveUUID() ) 803 803 } 804 804 } -
trunk/web-app/js/advancedQueryResults.js
r1668 r1798 58 58 } 59 59 60 function performAction( form, action, module ) {60 function performAction( form, action, module, url ) { 61 61 // Make sure the data from the paginated table is submitted 62 62 // This is performed with javascript, because otherwise 63 63 // checkboxes of hidden rows won't be taken into account 64 64 // See also http://datatables.net/examples/api/form.html 65 66 if( url == undefined ) 67 url = '/advancedQuery/performAction'; 65 68 66 69 // First remove all previously created inputs, in order to avoid any collissions … … 74 77 $('input', oTable.fnGetNodes()).each(function(idx,el) { 75 78 var $el = $(el); 76 if( $el.attr( 'name' ) == " id" && $(el).attr( 'checked' ) ) {79 if( $el.attr( 'name' ) == "uuid" && $(el).attr( 'checked' ) ) { 77 80 checked = true; 78 form.append( $( '<input type="hidden" name=" id" value="' + $el.attr( 'value' ) + '" class="created" />' ) );81 form.append( $( '<input type="hidden" name="tokens" value="' + $el.attr( 'value' ) + '" class="created" />' ) ); 79 82 } 80 83 }) … … 88 91 $( '[name=actionName]', form ).val( action ); 89 92 $( '[name=moduleName]', form ).val( module ); 90 submitForm( form, '/advancedQuery/performAction' ); 93 94 form.attr( 'action', url ); 95 form.submit(); 91 96 }
Note: See TracChangeset
for help on using the changeset viewer.