Changeset 1494 for trunk/grails-app
- Timestamp:
- Feb 4, 2011, 12:04:10 PM (10 years ago)
- Location:
- trunk/grails-app
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/studycapturing/StudyController.groovy
r1456 r1494 26 26 def user = AuthenticationService.getLoggedInUser() 27 27 def max = Math.min(params.max ? params.int('max') : 10, 100) 28 29 def studies = Study.giveReadableStudies( user, max );30 31 [studyInstanceList: studies, studyInstanceTotal: studies.count(), loggedInUser: user]28 def offset = params.offset ? params.int( 'offset' ) : 0 29 def studies = Study.giveReadableStudies( user, max, offset ); 30 31 [studyInstanceList: studies, studyInstanceTotal: Study.countReadableStudies( user ), loggedInUser: user] 32 32 } 33 33 … … 39 39 def user = AuthenticationService.getLoggedInUser() 40 40 def max = Math.min(params.max ? params.int('max') : 10, 100) 41 42 def studies = Study.findAllByOwner(user); 43 render( view: "list", model: [studyInstanceList: studies, studyInstanceTotal: studies.count(), loggedInUser: user] ) 41 def offset = params.offset ? params.int( 'offset' ) : 0 42 43 def studies = Study.findAllByOwner(user, [max:max,offset: offset]); 44 render( view: "list", model: [studyInstanceList: studies, studyInstanceTotal: Study.countByOwner(user), loggedInUser: user] ) 44 45 } 45 46 -
trunk/grails-app/domain/dbnp/studycapturing/Study.groovy
r1488 r1494 14 14 class Study extends TemplateEntity { 15 15 static searchable = true 16 16 17 17 def moduleNotificationService 18 18 … … 34 34 35 35 /** 36 * UUID of this study37 */36 * UUID of this study 37 */ 38 38 String studyUUID 39 39 40 40 41 41 static hasMany = [ 42 42 subjects: Subject, … … 85 85 static final List<TemplateField> domainFields = [ 86 86 new TemplateField( 87 88 89 87 name: 'title', 88 type: TemplateFieldType.STRING, 89 required: true), 90 90 new TemplateField( 91 92 93 94 91 name: 'description', 92 type: TemplateFieldType.TEXT, 93 comment:'Give a brief synopsis of what your study is about', 94 required: true), 95 95 new TemplateField( 96 97 98 99 100 96 name: 'code', 97 type: TemplateFieldType.STRING, 98 preferredIdentifier: true, 99 comment: 'Fill out the code by which many people will recognize your study', 100 required: true), 101 101 new TemplateField( 102 103 104 105 102 name: 'startDate', 103 type: TemplateFieldType.DATE, 104 comment: 'Fill out the official start date or date of first action', 105 required: true), 106 106 new TemplateField( 107 108 109 110 107 name: 'published', 108 type: TemplateFieldType.BOOLEAN, 109 comment: 'Determines whether this study is published (accessible for the study readers and, if the study is public, for anonymous users). A study can only be published if it meets certain quality criteria, which will be checked upon save.', 110 required: false) 111 111 ] 112 112 … … 123 123 def List<Event> getOrphanEvents() { 124 124 def orphans = events.findAll { event -> !event.belongsToGroup(eventGroups) } + 125 125 samplingEvents.findAll { event -> !event.belongsToGroup(eventGroups) } 126 126 127 127 return orphans … … 349 349 this.samples.findAll { sample -> 350 350 ( 351 (eventGroup.subjects.findAll { 352 it.equals(sample.parentSubject) 353 }) 354 && 355 (eventGroup.samplingEvents.findAll { 356 ( 357 (it.id && sample.parentEvent.id && it.id == sample.parentEvent.id) 358 || 359 (it.getIdentifier() == sample.parentEvent.getIdentifier()) 360 || 361 it.equals(sample.parentEvent) 351 (eventGroup.subjects.findAll { 352 it.equals(sample.parentSubject) 353 }) 354 && 355 (eventGroup.samplingEvents.findAll { 356 ( 357 (it.id && sample.parentEvent.id && it.id == sample.parentEvent.id) 358 || 359 (it.getIdentifier() == sample.parentEvent.getIdentifier()) 360 || 361 it.equals(sample.parentEvent) 362 ) 363 }) 362 364 ) 363 })364 )365 365 }.each() { sample -> 366 366 // remove sample from study … … 458 458 return c.list { 459 459 maxResults(max) 460 order("title", "asc") 461 460 462 } 461 463 } … … 463 465 return c.list { 464 466 maxResults(max) 467 order("title", "asc") 465 468 or { 466 469 eq("owner", user) … … 475 478 * Returns a list of studies that are readable by the given user 476 479 */ 477 public static giveReadableStudies(SecUser user, int max ) {480 public static giveReadableStudies(SecUser user, int max, int offset = 0) { 478 481 def c = Study.createCriteria() 479 482 … … 482 485 return c.list { 483 486 maxResults(max) 487 firstResult(offset) 488 order("title", "asc") 484 489 and { 485 490 eq("published", true) … … 490 495 return c.list { 491 496 maxResults(max) 497 firstResult(offset) 498 order("title", "asc") 492 499 } 493 500 } else { 494 501 return c.list { 495 502 maxResults(max) 503 firstResult(offset) 504 order("title", "asc") 496 505 or { 497 506 eq("owner", user) … … 509 518 } 510 519 } 511 520 521 /** 522 * Returns the number of studies that are readable by the given user 523 */ 524 public static countReadableStudies(SecUser user) { 525 def c = Study.createCriteria() 526 527 // Administrators are allowed to read everything 528 if (user == null) { 529 return c.count { 530 and { 531 eq("published", true) 532 eq("publicstudy", true) 533 } 534 } 535 } else if (user.hasAdminRights()) { 536 return Study.count(); 537 } else { 538 return c.count { 539 or { 540 eq("owner", user) 541 writers { 542 eq("id", user.id) 543 } 544 and { 545 readers { 546 eq("id", user.id) 547 } 548 eq("published", true) 549 } 550 } 551 } 552 } 553 } 554 512 555 /** 513 556 * Returns the UUID of this study and generates one if needed … … 520 563 } 521 564 } 522 565 523 566 return this.studyUUID; 524 567 } 525 568 526 569 /** 527 570 * Basic equals method to check whether objects are equals, by comparing the ids … … 532 575 if( o == null ) 533 576 return false; 534 577 535 578 if( !( o instanceof Study ) ) 536 579 return false 537 580 538 581 Study s = (Study) o; 539 582 540 583 return this.id == s.id 541 584 } -
trunk/grails-app/views/study/list.gsp
r1430 r1494 9 9 <body> 10 10 11 <g:form action="list_extended" >11 <g:form action="list_extended" name="list_extended"> 12 12 <div class="body"> 13 13 <h1><g:message code="default.list.label" args="[entityName]"/></h1> … … 78 78 <sec:ifLoggedIn> 79 79 <span class="button"><g:link class="create" controller="studyWizard" params="[jump:'create']"><g:message code="default.new.label" args="[entityName]"/></g:link></span> 80 <span class="button"><a class="compare" href="#" onClick="$( 'form#list_extended' ).first().submit(); return false;">Compare selected studies</a></span> 80 81 </sec:ifLoggedIn> 82 81 83 </div> 82 84 <div class="paginateButtons"> 83 <g:paginate total="${studyInstanceTotal}" prev="« Previous" next="» Next"/> 84 <br> 85 <INPUT TYPE=submit name=submit Value="Compare selected studies"> 85 <g:paginate max="10" total="${studyInstanceTotal}" prev="« Previous" next="» Next"/> 86 86 </div> 87 87 </div>
Note: See TracChangeset
for help on using the changeset viewer.