Changeset 1908
- Timestamp:
- Jun 1, 2011, 4:05:21 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/query/AdvancedQueryController.groovy
r1800 r1908 3 3 import dbnp.modules.* 4 4 import org.dbnp.gdt.* 5 6 // TODO: Make use of the searchable-plugin or Lucene possibilities instead of querying the database directly 5 import dbnp.studycapturing.*; 7 6 8 7 /** … … 26 25 criteria = parseCriteria( params.criteria, false ) 27 26 } 28 [searchModes: SearchMode.values(), entitiesToSearchFor: entitiesToSearchFor, searchableFields: getSearchableFields(), criteria: criteria ]27 [searchModes: SearchMode.values(), entitiesToSearchFor: entitiesToSearchFor, searchableFields: getSearchableFields(), criteria: criteria, previousSearches: session.queries ] 29 28 } 30 29 … … 234 233 def queryId = saveSearch( combined ); 235 234 redirect( action: "show", id: queryId ); 235 } 236 237 /** 238 * Registers a search from a module with GSCF, in order to be able to refine the searches 239 */ 240 def refineExternal = { 241 // Determine parameters and retrieve objects based on the tokens 242 def name = params.name 243 def url = params.url 244 def entity = params.entity 245 def tokens = params.list( 'tokens' ); 246 def results 247 248 switch( entity ) { 249 case "Study": 250 results = Study.findAll( "from Study s where s.studyUUID IN (:tokens)", [ 'tokens': tokens ] ) 251 break; 252 case "Assay": 253 results = Assay.findAll( "from Assay a where a.assayUUID IN (:tokens)", [ 'tokens': tokens ] ) 254 break; 255 case "Sample": 256 results = Sample.findAll( "from Sample s where s.sampleUUID IN (:tokens)", [ 'tokens': tokens ] ) 257 break; 258 default: 259 response.sendError( 400 ); 260 render "The given entity is not supported. Choose one of Study, Assay or Sample" 261 return; 262 } 263 264 // Register and save search 265 Search s = Search.register( name, url, entity, results ); 266 int searchId = saveSearch( s ); 267 268 println "Params: " + params.url 269 println "Search: " + s.url 270 271 // Redirect to the search screen 272 def params = [ 273 "criteria.0.entityfield": s.entity, 274 "criteria.0.operator": "in", 275 "criteria.0.value": searchId 276 ]; 277 278 redirect( action: "index", params: params) 236 279 } 237 280 … … 449 492 450 493 s.id = id; 494 495 if( !s.url ) 496 s.url = g.createLink( controller: "advancedQuery", action: "show", id: id ); 497 451 498 session.queries[ id ] = s; 452 499 … … 547 594 module: "gscf", 548 595 name:"simpletox", 596 type: "export", 549 597 description: "Export as SimpleTox", 550 598 url: createLink( controller: "exporter", action: "export", params: [ 'format': 'list', 'ids' : ids ] ), … … 554 602 module: "gscf", 555 603 name:"excel", 604 type: "export", 556 605 description: "Export as CSV", 557 606 url: createLink( controller: "study", action: "exportToExcel", params: [ 'format': 'list', 'ids' : ids ] ), … … 570 619 module: "gscf", 571 620 name:"excel", 621 type: "export", 572 622 description: "Export as CSV", 573 623 url: createLink( controller: "assay", action: "exportToExcel", params: [ 'format': 'list', 'ids' : ids ] ), … … 618 668 module: moduleName, 619 669 name: action.name, 670 type: action.type ?: 'default', 620 671 description: action.description + " (" + moduleName + ")", 621 672 url: url + "&" + paramString, -
trunk/grails-app/views/advancedQuery/_criteria.gsp
r1717 r1908 9 9 <span class="value"> 10 10 <g:if test="${criterion.value != null && criterion.value instanceof Search}"> 11 <g:link action="show" id="${criterion.value.id}">${criterion.value}</g:link>11 <g:link url="${criterion.value.url}">${criterion.value.toString()}</g:link> 12 12 </g:if> 13 13 <g:else> -
trunk/grails-app/views/advancedQuery/_resultbuttons.gsp
r1798 r1908 1 <% 2 def refineActions = actions.findAll { it.type == "refine" }; 3 def otherActions = actions.findAll { it.type != "refine" }; 4 %> 1 5 <p class="options multiple"> 2 6 <g:if test="${search.getNumResults() == 0}"> … … 8 12 <br /> 9 13 14 <g:each in="${refineActions}" var="action"> 15 <g:if test="${search.getNumResults() == 0}"> 16 <a href="#" onClick="return false;" class="refineSearch ${action.name} disabled">${action.description}</a> 17 </g:if> 18 <g:else> 19 <a class="refineSearch ${action.name}" href="${action.url}" onClick="performAction( $('form#results'), '${action.name.encodeAsJavaScript()}', '${action.module.encodeAsJavaScript()}', '${action.submitUrl.encodeAsJavaScript()}', true ); return false;">${action.description}</a> 20 </g:else> 21 <br /> 22 </g:each> 23 10 24 <g:link class="search" action="index">Search again</g:link><br /> 11 25 <g:link class="discard" action="discard" id="${queryId}">Discard results</g:link><br /> … … 13 27 </p> 14 28 <p class="options multiple"> 15 <g:each in="${ actions}" var="action">29 <g:each in="${otherActions}" var="action"> 16 30 <g:if test="${search.getNumResults() == 0}"> 17 31 <a href="#" onClick="return false;" class="performAction ${action.name} disabled">${action.description}</a> 18 32 </g:if> 19 33 <g:else> 20 <a class="performAction ${action.name}" href="${action.url}" onClick="performAction( $('form#results'), '${action.name }', '${action.module}', '${action.submitUrl}' ); return false;">${action.description}</a>34 <a class="performAction ${action.name}" href="${action.url}" onClick="performAction( $('form#results'), '${action.name.encodeAsJavaScript()}', '${action.module.encodeAsJavaScript()}', '${action.submitUrl.encodeAsJavaScript()}' ); return false;">${action.description}</a> 21 35 </g:else> 22 36 <br /> -
trunk/grails-app/views/advancedQuery/_resultsform.gsp
r1581 r1908 2 2 <input type="hidden" name="actionName" value="" /> 3 3 <input type="hidden" name="moduleName" value="" /> 4 <input type="hidden" name="entity" value="${search.entity}" /> 5 <input type="hidden" name="name" value="${search.toString()}" /> 6 <input type="hidden" name="url" value="${search.url}" /> 4 7 <input type="hidden" name="queryId" value="${search.id}" /> 5 8 </form> -
trunk/grails-app/views/advancedQuery/assayresults.gsp
r1875 r1908 12 12 <body> 13 13 14 <h1>Search results </h1>14 <h1>Search results: ${search.toString()}</h1> 15 15 16 16 <div class="searchoptions"> -
trunk/grails-app/views/advancedQuery/index.gsp
r1879 r1908 1 <%@ page import="dbnp.query.Operator" %> 1 2 <html> 2 3 <head> … … 46 47 $(function() { 47 48 <g:each in="${criteria}" var="criterion"> 48 showCriterium("${criterion.entityField().encodeAsJavaScript()}", "${criterion.value.toString().encodeAsJavaScript()}", "${criterion.operator.toString().encodeAsJavaScript()}"); 49 <g:if test="${criterion.operator == Operator.insearch}"> 50 /* ${previousSearches?.getAt( criterion.value )?.url} */ 51 showCriterium( 52 "${criterion.entityField().encodeAsJavaScript()}", 53 { 54 'id': ${criterion.value}, 55 'description': "<g:if test="${previousSearches?.getAt( criterion.value )}">${previousSearches[ criterion.value ].toString().encodeAsJavaScript()}</g:if><g:else>Search ${criterion.value}</g:else>", 56 'url': "<g:if test="${previousSearches?.getAt( criterion.value )?.url}">${previousSearches[ criterion.value ].url.encodeAsJavaScript()}</g:if><g:else><g:createLink controller='advancedQuery' action='show' id="${criterion.value}" /></g:else>" 57 }, 58 "${criterion.operator.toString().encodeAsJavaScript()}" 59 ); 60 </g:if> 61 <g:else> 62 showCriterium("${criterion.entityField().encodeAsJavaScript()}", "${criterion.value.toString().encodeAsJavaScript()}", "${criterion.operator.toString().encodeAsJavaScript()}"); 63 </g:else> 49 64 </g:each> 50 65 -
trunk/grails-app/views/advancedQuery/list.gsp
r1581 r1908 63 63 <span class="value"> 64 64 <g:if test="${criterion.value instanceof Search}"> 65 < g:link action="show" id="${criterion.value.id}">${criterion.value}</g:link>65 <a href="${criterion.value.url}">${criterion.value?.toString()}</a> 66 66 </g:if> 67 67 <g:else> -
trunk/grails-app/views/advancedQuery/sampleresults.gsp
r1875 r1908 12 12 <body> 13 13 14 <h1>Query results </h1>14 <h1>Query results: ${search.toString()}</h1> 15 15 16 16 <div class="searchoptions"> -
trunk/grails-app/views/advancedQuery/studyresults.gsp
r1875 r1908 12 12 <body> 13 13 14 <h1>Query results </h1>14 <h1>Query results: ${search.toString()}</h1> 15 15 16 16 <div class="searchoptions"> -
trunk/src/groovy/dbnp/query/Search.groovy
r1904 r1908 52 52 */ 53 53 public int id; 54 55 /** 56 * Description of this search. Defaults to 'Search <id>' 57 */ 58 public String description; 59 60 /** 61 * URL to view the results of this search 62 */ 63 public String url; 54 64 55 65 /** … … 948 958 949 959 public String toString() { 950 return ( this.entity ? this.entity + " search" : "Search" ) + " " + this.id 960 if( this.description ) { 961 return this.description 962 } else if( this.entity ) { 963 return this.entity + " search " + this.id; 964 } else { 965 return "Search " + this.id 966 } 951 967 } 952 968 … … 960 976 Search s = (Search) o; 961 977 978 // Determine criteria equality 979 def criteriaEqual = false; 980 if( !criteria && !s.criteria ) { 981 criteriaEqual = true; 982 } else if( criteria && s.criteria ) { 983 criteriaEqual = criteria.size()== s.criteria.size() && 984 s.criteria.containsAll( criteria ) && 985 criteria.containsAll( s.criteria ) 986 } 987 962 988 return ( searchMode == s.searchMode && 963 entity == s.entity && 964 criteria.size() == s.criteria.size() && 965 s.criteria.containsAll( criteria ) && 966 criteria.containsAll( s.criteria ) ); 989 entity == s.entity && 990 criteriaEqual 991 ); 967 992 } 968 993 … … 982 1007 } 983 1008 1009 /** 1010 * Registers a query that has been performed somewhere else, but used in GSCF (e.g. refined) 1011 * 1012 * @param description Description of the search 1013 * @param url Url to view the search results 1014 * @param entity Entity that has been sought 1015 * @param results List of 1016 * @return 1017 */ 1018 public static Search register( String description, String url, String entity, def results ) { 1019 Search s; 1020 1021 // Determine entity 1022 switch( entity ) { 1023 case "Study": 1024 s = new StudySearch(); 1025 break; 1026 case "Assay": 1027 s = new AssaySearch(); 1028 break; 1029 case "Sample": 1030 s = new SampleSearch(); 1031 break; 1032 default: 1033 return null; 1034 } 1035 1036 // Set properties 1037 s.description = description; 1038 s.url = url 1039 s.results = results 1040 1041 return s; 1042 } 984 1043 } -
trunk/web-app/css/buttons.css
r1686 r1908 49 49 background-image: url(../plugins/famfamfam-1.0.1/images/icons/brick_go.png); 50 50 } 51 .options a.refineSearch { 52 background-image: url(../plugins/famfamfam-1.0.1/images/icons/magnifier.png); 53 } 51 54 .options a.excel { 52 55 background-image: url(../plugins/famfamfam-1.0.1/images/icons/page_excel.png); -
trunk/web-app/js/advancedQuery.js
r1879 r1908 154 154 } 155 155 156 157 156 /** 158 157 * Shows a criterium on the screen … … 204 203 205 204 function createInSearchElement( fieldname, fieldvalue ) { 206 var a = $( '<a class="' + fieldname + '" href="' + baseUrl + '/advancedQuery/show/' + fieldvalue+ '"></a>')207 a.text( "Search " + fieldvalue);205 var a = $( '<a class="' + fieldname + '" href="' + fieldvalue.url + '"></a>') 206 a.text( fieldvalue.description ); 208 207 209 208 var inputField = $( '<input type="hidden" name="criteria.' + criteriumId + '.' + fieldname + '" />' ); 210 inputField.val( fieldvalue );209 inputField.val( fieldvalue.id ); 211 210 212 211 a.append( inputField ); -
trunk/web-app/js/advancedQueryResults.js
r1798 r1908 58 58 } 59 59 60 function performAction( form, action, module, url ) { 60 /** 61 * Submits the form with selected elements to a given URL 62 * 63 * @param form JQuery object representing the form to be submitted 64 * @param action Name of the action to perform 65 * @param module Name of the module to perform the action on 66 * @param url Url to post the form to 67 * @param allIfNothingSelected If set to true, the action will be performed on all elements if none is selected 68 */ 69 function performAction( form, action, module, url, allIfNothingSelected ) { 61 70 // Make sure the data from the paginated table is submitted 62 71 // This is performed with javascript, because otherwise … … 66 75 if( url == undefined ) 67 76 url = '/advancedQuery/performAction'; 77 78 if( allIfNothingSelected == undefined ) 79 allIfNothingSelected = false; 68 80 69 81 // First remove all previously created inputs, in order to avoid any collissions … … 84 96 85 97 if( !checked ) { 86 alert( "Please pick at least one result to perform this action on." ); 87 return; 98 if( allIfNothingSelected ) { 99 // Submit all search results, instead of nothing 100 $('input', oTable.fnGetNodes()).each(function(idx,el) { 101 var $el = $(el); 102 if( $el.attr( 'name' ) == "uuid" ) { 103 checked = true; 104 form.append( $( '<input type="hidden" name="tokens" value="' + $el.attr( 'value' ) + '" class="created" />' ) ); 105 } 106 }) 107 } else { 108 alert( "Please pick at least one result to perform this action on." ); 109 return; 110 } 88 111 } 89 112
Note: See TracChangeset
for help on using the changeset viewer.