Changeset 1424 for trunk/grails-app
- Timestamp:
- Jan 21, 2011, 4:30:04 PM (10 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/query/AdvancedQueryController.groovy
r1415 r1424 36 36 // Create a search object and let it do the searching 37 37 Search search; 38 String view; 38 39 switch( params.entity ) { 39 case "Study": search = new StudySearch(); break;40 case "Sample": search = new SampleSearch(); break;40 case "Study": search = new StudySearch(); view = "studyresults"; break; 41 case "Sample": search = new SampleSearch(); view = "sampleresults"; break; 41 42 42 43 // This exception will only be thrown if the entitiesToSearchFor contains more entities than … … 47 48 search.execute( parseCriteria( params.criteria ) ); 48 49 49 render( view: search.getView(), model: [search: search] );50 render( view: view, model: [search: search] ); 50 51 } 51 52 … … 64 65 def templateFields = TemplateField.findAllByEntity( entity ) 65 66 66 fields[ it ] = ( domainFields + templateFields ).collect { it.name }.unique().sort { a, b -> a[0].toUpperCase() + a[1..-1] <=> b[0].toUpperCase() + b[1..-1] }; 67 def fieldNames = ( domainFields + templateFields ).collect { it.name }.unique() + 'Template' 68 69 fields[ it ] = fieldNames.sort { a, b -> a[0].toUpperCase() + a[1..-1] <=> b[0].toUpperCase() + b[1..-1] }; 67 70 } 68 71 } … … 86 89 * ] 87 90 * 88 * @return List with [entity: ..., field: ..., entityfield: ..., operator: ..., value: ...] tuples.91 * @return List with Criterion objects 89 92 */ 90 93 protected List parseCriteria( def c ) { … … 94 97 c.each { 95 98 if( it.key ==~ /[0-9]+/ ) { 96 def criterium = it.value; 99 def formCriterion = it.value; 100 Criterion criterion = new Criterion(); 97 101 98 def field = criterium.entityfield?.split( /\./ ); 102 // Split entity and field 103 def field = formCriterion.entityfield?.split( /\./ ); 99 104 100 105 if( field.size() > 1 ) { 101 criteri um.entity = field[0].toString();102 criteri um.field = field[1].toString();106 criterion.entity = field[0].toString(); 107 criterion.field = field[1].toString(); 103 108 } else { 104 criteri um.entity = null;105 criteri um.field = field;109 criterion.entity = null; 110 criterion.field = field; 106 111 } 107 112 108 list << criterium; 113 // Convert operator string to Operator-enum field 114 switch( formCriterion.operator ) { 115 case ">=": criterion.operator = Operator.gte; break; 116 case ">": criterion.operator = Operator.gt; break; 117 case "<": criterion.operator = Operator.lte; break; 118 case "<=": criterion.operator = Operator.lt; break; 119 case "contains": criterion.operator = Operator.contains; break; 120 case "equals": criterion.operator = Operator.equals; break; 121 } 122 123 // Copy value 124 criterion.value = formCriterion.value; 125 126 list << criterion; 109 127 } 110 128 } -
trunk/grails-app/domain/dbnp/studycapturing/RelTime.groovy
r959 r1424 21 21 package dbnp.studycapturing 22 22 23 class RelTime {23 class RelTime implements Comparable { 24 24 final static long s = 1L; 25 25 final static long m = 60L * s; … … 285 285 286 286 public void computeDifference(Date start, Date end) { 287 println([start, end]);288 println([start.getTime(), end.getTime()]);289 290 287 if (start && end) { 291 288 long seconds = (end.getTime() - start.getTime()) / 1000L; … … 301 298 return reltime; 302 299 } 300 301 public boolean equals( Object o ) { 302 if( o == null ) 303 return false 304 if( !( o instanceof RelTime ) ) 305 return false 306 307 RelTime rt = (RelTime) o; 308 309 return rt.reltimeValue == this.reltimeValue; 310 } 311 312 public int compareTo( Object o ) throws ClassCastException { 313 if( o == null || !( o instanceof RelTime ) ) 314 throw new ClassCastException( "Can't cast object " + o + " of class " + o.class.getName() + " to RelTime for comparison.") 315 316 RelTime rt = (RelTime) o; 317 318 return rt.reltimeValue <=> this.reltimeValue; 319 } 303 320 } -
trunk/grails-app/views/advancedQuery/index.gsp
r1415 r1424 13 13 <form id="input_criteria"> 14 14 <h2>Add criterium</h2> 15 <p> 16 N.B. Comparing numerical values is done without taking into 17 account the units. E.g. a weight of 1 kg equals 1 grams. 18 </p> 15 19 <label for="field">Field</label> 16 20 <select name="field"> … … 27 31 </select> 28 32 33 <label for="value">Comparison</label> 34 <select name="operator"> 35 <option value="equals">Equals</option> 36 <option value="contains">Contains</option> 37 <option value=">=">Greater than or equals</option> 38 <option value=">">Greater than</option> 39 <option value="<">Lower than</option> 40 <option value="<=">Lower than or equals</option> 41 </select> 42 29 43 <label for="value">Value</label> 30 44 <input class='text' type="text" name="value" /> -
trunk/grails-app/views/advancedQuery/results.gsp
r1415 r1424 15 15 </p> 16 16 <ul id="criteria"> 17 <g:each in="${search.getCriteria()}" var="criteri um">17 <g:each in="${search.getCriteria()}" var="criterion"> 18 18 <li> 19 <span class="entityfield">${criteri um.entityfield}</span>20 <span class="operator">${criteri um.operator}</span>21 <span class="value">${criteri um.value}</span>19 <span class="entityfield">${criterion.entity}.${criterion.field}</span> 20 <span class="operator">${criterion.operator}</span> 21 <span class="value">${criterion.value}</span> 22 22 </li> 23 23 </g:each> -
trunk/grails-app/views/advancedQuery/studyresults.gsp
r1415 r1424 15 15 </p> 16 16 <ul id="criteria"> 17 <g:each in="${search.getCriteria()}" var="criteri um">17 <g:each in="${search.getCriteria()}" var="criterion"> 18 18 <li> 19 <span class="entityfield">${criteri um.entityfield}</span>20 <span class="operator">${criteri um.operator}</span>21 <span class="value">${criteri um.value}</span>19 <span class="entityfield">${criterion.entity}.${criterion.field}</span> 20 <span class="operator">${criterion.operator}</span> 21 <span class="value">${criterion.value}</span> 22 22 </li> 23 23 </g:each>
Note: See TracChangeset
for help on using the changeset viewer.