Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Ignore Intellij IDEA files
.idea
*.iml

# Ignore build artifacts
target

# Ignore packaged plugins
*.zip

stacktrace.log
plugin.xml

.DS_Store
4 changes: 2 additions & 2 deletions NavigationGrailsPlugin.groovy
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class NavigationGrailsPlugin {
def version = '1.3.2'
def version = '1.4.0-SNAPSHOT'

// the version or versions of Grails the plugin is designed for
def grailsVersion = "1.2 > *"
def grailsVersion = "2.4 > *"

def dependsOn = [controllers:"1.0 > *"]
def observe = ['controllers']
Expand Down
4 changes: 1 addition & 3 deletions application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#Grails Metadata file
#Fri Jul 29 12:57:45 BST 2011
app.grails.version=1.3.7
app.grails.version=2.4.4
app.name=Navigation
plugins.hibernate=1.3.7
plugins.tomcat=1.3.7
29 changes: 29 additions & 0 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6

grails.project.fork = false

grails.project.dependency.resolver = "maven"
grails.project.dependency.resolution = {

inherits("global")

repositories {
grailsCentral()
mavenLocal()
mavenCentral()
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

// runtime 'mysql:mysql-connector-java:5.1.5'
}

plugins {
build ':release:3.0.1', {
export = false
}
}
}
63 changes: 37 additions & 26 deletions grails-app/conf/DataSource.groovy
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
dataSource {
pooled = true
driverClassName = "org.hsqldb.jdbcDriver"
username = "sa"
password = ""
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "jdbc:hsqldb:mem:devDB"
}
}
test {
dataSource {
dbCreate = "create-drop"
url = "jdbc:hsqldb:mem:testDb"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:hsqldb:file:prodDb;shutdown=true"
}
}
}
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}
45 changes: 23 additions & 22 deletions grails-app/services/NavigationService.groovy
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import org.codehaus.groovy.grails.commons.GrailsControllerClass
import org.codehaus.groovy.grails.commons.ConfigurationHolder
import org.codehaus.groovy.grails.commons.GrailsClassUtils

// @todo subItem sorting
class NavigationService {

static transactional = false


def grailsApplication

def manuallyRegistered = []
def byGroup = ['*':[]]
def hidden = new HashSet()
def activePathByRequestArgs = [:]

def reset() {
byGroup = ['*':[]]
// re-add the manually defined items
ConfigurationHolder.config.navigation?.each { k, v ->
grailsApplication.config.navigation?.each { k, v ->
doRegisterItem(k, v)
}
manuallyRegistered.each { item ->
Expand Down Expand Up @@ -52,7 +53,7 @@ class NavigationService {
}
return k.toString()
}

def reverseMapActivePathFor(controller, action, params) {
// Try first with params
def kWithParams = makeReverseMapKey(controller, action, params)
Expand All @@ -63,7 +64,7 @@ class NavigationService {
}
return path ?: kWithParams.tokenize('/')
}

void calculatePath(pathValue, item) {
if (pathValue) {
item.path = pathValue instanceof List ? pathValue : pathValue.tokenize('/')
Expand All @@ -76,7 +77,7 @@ class NavigationService {
}
}
}

def populateItem(src, item, controllerGrailsClass) {
item.action = src.action ?: (controllerGrailsClass ? controllerGrailsClass.defaultAction : 'index')
item.order = src.order
Expand All @@ -100,15 +101,15 @@ class NavigationService {
* Register a navigation item by convention
*/
def registerItem(GrailsControllerClass controllerGrailsClass) {
def p = [
def p = [
controller:controllerGrailsClass.logicalPropertyName
]
def grp
def grp
def navInfo = '*'
if (controllerGrailsClass.clazz.metaClass.hasProperty(controllerGrailsClass.clazz, 'navigation')) {
navInfo = controllerGrailsClass.clazz.navigation
if (navInfo == false) {
return
if (navInfo == false) {
return
}
if (navInfo == true) {
navInfo = '*'
Expand All @@ -119,7 +120,7 @@ class NavigationService {

grp = navInfo.group
} else if (navInfo instanceof List) {
// Handle lists of info
// Handle lists of info
navInfo.each { info ->
def params = [:]
params.controller = p.controller
Expand All @@ -141,32 +142,32 @@ class NavigationService {
}
doRegisterItem(grp, p)
}

/**
* Manually register a navigation item
*/
def registerItem(String group, params) {
def item = doRegisterItem(group, params)
manuallyRegistered << [group:group, info:item]
}

protected doRegisterItem(String group, Collection v) {
v.eachWithIndex { item, n -> doRegisterItem(group, item, n) }
}

protected doRegisterItem(String group, Map params, defaultOrderValue = null) {
params.action = params.action ?: 'index' // @todo should be default action of controller

def item = [:]
item.controller = params.controller
if (!params.order) {
params.order = defaultOrderValue
}
populateItem(params, item, null)

def k = makeReverseMapKey(item.controller, item.action, item.params)
activePathByRequestArgs[ k ] = item.path

if (!group) group = '*'

def catInfo = byGroup[group]
Expand All @@ -177,21 +178,21 @@ class NavigationService {
if (group != '*') {
byGroup['*'] << item
}

return item
}

def hide(String controller) {
hidden << controller
}

/**
* Must be called after you have registered your items, to enforce ordering
*/
def updated() {
byGroup.keySet().each { k ->
byGroup[k] = byGroup[k].findAll { info -> !hidden.contains(info.controller) }
byGroup[k] = byGroup[k]?.sort { a, b ->
byGroup[k] = byGroup[k]?.sort { a, b ->
if (b.order) {
return a.order?.compareTo(b.order) ?: 0
} else return +1 // items with no ordering come last
Expand Down