Skip to content

Commit

Permalink
Merge pull request #561 from codeconsole/7.0.x-bootstrap
Browse files Browse the repository at this point in the history
Pagination support for Bootstrap 5
  • Loading branch information
codeconsole authored Jan 12, 2025
2 parents 4732664 + 179bf93 commit 8af339d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .sdkmanrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
java=17.0.13-librca
gradle=8.11.1
gradle=8.12

6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title=Groovy Server Pages (GSP)
authors=Puneet Behl
projectVersion=7.0.0-M1
projectVersion=7.0.0-SNAPSHOT
projectDesc=GSP (Groovy Server Pages) - A server-side view rendering technology based on Groovy
projectUrl=https://github.com/grails/grails-gsp
githubSlug=grails/grails-gsp
Expand All @@ -10,12 +10,12 @@ developers=Puneet Behl, Graeme Rocher
commonsTextVersion=1.13.0
elApiVersion=6.0.1
grailsGradlePluginVersion=7.0.0-SNAPSHOT
grailsVersion=7.0.0-M1
grailsVersion=7.0.0-SNAPSHOT
groovyVersion=4.0.24
jspApiVersion=4.0.0
jstlVersion=3.0.1
servletApiVersion=6.0.0
sitemeshVersion=7.0.0-M1
sitemeshVersion=7.0.0-SNAPSHOT
controllersRef=https://docs.grails.org/latest/ref/Controllers
commandLineRef=https://docs.grails.org/latest/ref/Command%20Line
grailsDocsVersion=7.0.0-SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
* @attr disabled Makes the resulting inputs and selects to be disabled. Is treated as a Groovy Truth.
* @attr readonly Makes the resulting inputs and selects to be made read only. Is treated as a Groovy Truth.
* @attr locale The locale to use for display formatting. Defaults to the current request locale and then the system default locale if not specified.
* @attr selectDateClass css class added to each select tag
*/
Closure datePicker = { attrs ->
def out = out // let x = x ?
Expand Down Expand Up @@ -797,6 +798,9 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
if (attrs.readonly) {
out << ' readonly="readonly"'
}
if (attrs.selectDateClass) {
out << ' class="'+attrs.selectDateClass+'"'
}
out << '>'

if (noSelection) {
Expand All @@ -821,6 +825,9 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
if (attrs.readonly) {
out << ' readonly="readonly"'
}
if (attrs.selectDateClass) {
out << ' class="'+attrs.selectDateClass+'"'
}
out << '>'

if (noSelection) {
Expand All @@ -847,6 +854,9 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
if (attrs.readonly) {
out << ' readonly="readonly"'
}
if (attrs.selectDateClass) {
out << ' class="'+attrs.selectDateClass+'"'
}
out << '>'

if (noSelection) {
Expand All @@ -871,6 +881,9 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
if (attrs.readonly) {
out << ' readonly="readonly"'
}
if (attrs.selectDateClass) {
out << ' class="'+attrs.selectDateClass+'"'
}
out << '>'

if (noSelection) {
Expand Down Expand Up @@ -902,6 +915,9 @@ class FormTagLib implements ApplicationContextAware, InitializingBean, TagLibrar
if (attrs.readonly) {
out << 'readonly="readonly"'
}
if (attrs.selectDateClass) {
out << ' class="'+attrs.selectDateClass+'"'
}
out << '>'

if (noSelection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ class UrlMappingTagLib implements TagLibrary{
}
}

Map appendClass(Map attrs, String cssClass) {
attrs['class'] = [attrs['class'] ?: '', cssClass].join(' ').trim()
attrs
}

/**
* Creates next/previous links to support pagination for the current controller.<br/>
*
Expand Down Expand Up @@ -139,6 +144,11 @@ class UrlMappingTagLib implements TagLibrary{
if (attrs.id != null) {
linkTagAttrs.id = attrs.id
}
if (attrs.containsKey('class')) {
linkTagAttrs.put('class', attrs.get('class'))
}
String activeClass = attrs.activeClass?:'currentStep'

if (attrs.fragment != null) {
linkTagAttrs.fragment = attrs.fragment
}
Expand All @@ -152,16 +162,15 @@ class UrlMappingTagLib implements TagLibrary{

// display previous link when not on firststep unless omitPrev is true
if (currentstep > firststep && !attrs.boolean('omitPrev')) {
linkTagAttrs.put('class', 'prevLink')
linkParams.offset = offset - max
writer << callLink((Map)linkTagAttrs.clone()) {
writer << callLink(appendClass((Map) linkTagAttrs.clone(), 'prevLink')) {
(attrs.prev ?: messageSource.getMessage('paginate.prev', null, messageSource.getMessage('default.paginate.prev', null, 'Previous', locale), locale))
}
}

// display steps when steps are enabled and laststep is not firststep
if (steps && laststep > firststep) {
linkTagAttrs.put('class', 'step')
Map stepAttrs = appendClass((Map) linkTagAttrs.clone(), 'step')

// determine begin and endstep paging variables
int beginstep = currentstep - (Math.round(maxsteps / 2.0d) as int) + (maxsteps % 2)
Expand All @@ -182,7 +191,7 @@ class UrlMappingTagLib implements TagLibrary{
// display firststep link when beginstep is not firststep
if (beginstep > firststep && !attrs.boolean('omitFirst')) {
linkParams.offset = 0
writer << callLink((Map)linkTagAttrs.clone()) {firststep.toString()}
writer << callLink((Map)stepAttrs.clone()) {firststep.toString()}
}
//show a gap if beginstep isn't immediately after firststep, and if were not omitting first or rev
if (beginstep > firststep+1 && (!attrs.boolean('omitFirst') || !attrs.boolean('omitPrev')) ) {
Expand All @@ -192,11 +201,11 @@ class UrlMappingTagLib implements TagLibrary{
// display paginate steps
(beginstep..endstep).each { int i ->
if (currentstep == i) {
writer << "<span class=\"currentStep\">${i}</span>"
writer << "<span class=\"${[attrs.get('class')?:'',activeClass].join(' ').trim()}\">${i}</span>"
}
else {
linkParams.offset = (i - 1) * max
writer << callLink((Map)linkTagAttrs.clone()) {i.toString()}
writer << callLink((Map)stepAttrs.clone()) {i.toString()}
}
}

Expand All @@ -207,15 +216,14 @@ class UrlMappingTagLib implements TagLibrary{
// display laststep link when endstep is not laststep
if (endstep < laststep && !attrs.boolean('omitLast')) {
linkParams.offset = (laststep - 1) * max
writer << callLink((Map)linkTagAttrs.clone()) { laststep.toString() }
writer << callLink((Map)stepAttrs.clone()) { laststep.toString() }
}
}

// display next link when not on laststep unless omitNext is true
if (currentstep < laststep && !attrs.boolean('omitNext')) {
linkTagAttrs.put('class', 'nextLink')
linkParams.offset = offset + max
writer << callLink((Map)linkTagAttrs.clone()) {
writer << callLink(appendClass((Map) linkTagAttrs.clone(), 'nextLink')) {
(attrs.next ? attrs.next : messageSource.getMessage('paginate.next', null, messageSource.getMessage('default.paginate.next', null, 'Next', locale), locale))
}
}
Expand Down

0 comments on commit 8af339d

Please sign in to comment.