|
From: <jt...@hy...> - 2007-03-24 20:05:37
|
Author: jtravis Date: 2007-03-24 12:05:34 -0800 (Sat, 24 Mar 2007) New Revision: 3861 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=3861 Added: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/HQHelper.groovy Modified: trunk/ui_plugins/hqu_livedata/showResource.gsp trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy Log: Add the HQHelper, easy ability to link to a resource Modified: trunk/ui_plugins/hqu_livedata/showResource.gsp =================================================================== --- trunk/ui_plugins/hqu_livedata/showResource.gsp 2007-03-24 17:39:11 UTC (rev 3860) +++ trunk/ui_plugins/hqu_livedata/showResource.gsp 2007-03-24 20:05:34 UTC (rev 3861) @@ -1,6 +1,6 @@ <html> <body> - <h1>LiveData commands for <%= resource.name %> + <h1>LiveData commands for <%= link_to resource.name, [resource:resource] %> (<%= resource.appdefResourceTypeValue.name %>)</h1> <p> Modified: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy =================================================================== --- trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy 2007-03-24 17:39:11 UTC (rev 3860) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/BaseController.groovy 2007-03-24 20:05:34 UTC (rev 3861) @@ -7,12 +7,14 @@ import org.apache.commons.logging.Log import org.apache.commons.logging.LogFactory +import org.hyperic.hq.appdef.shared.AppdefEntityID import org.hyperic.hq.authz.server.session.AuthzSubject import org.hyperic.hq.ui.util.ContextUtils import org.hyperic.hq.ui.util.RequestUtils import org.hyperic.hq.ui.rendit.helpers.LiveDataHelper import org.hyperic.hq.ui.rendit.helpers.ResourceHelper +import org.hyperic.hq.ui.rendit.helpers.HQHelper import groovy.text.SimpleTemplateEngine import java.io.File @@ -41,6 +43,7 @@ def getResourceHelper() { return new ResourceHelper(getUser()) } def getLiveDataHelper() { return new LiveDataHelper(getUser()) } + def getHQHelper() { return new HQHelper(getUser()) } /** * Retreives the currently logged-in user @@ -58,15 +61,20 @@ public String h(str) { StringEscapeUtils.escapeHtml(str) } - + + // TODO: These need to be moved to a separate class public RENDER_BUILTINS = [ link_to : { text, Object[] args -> def url = "" def opts = (args.length > 0) ? args[0] : [:] def htmlOpts = (args.length > 1) ? args[1] : [:] - if (opts.containsKey('action')) + if (opts.containsKey('action')) { url += h(opts['action']) + } else if (opts.containsKey('resource')) { + def entId = opts['resource'].entityId.appdefKey + url = getHQHelper().serverURL + "Resource.do?eid=$entId" + } url += '?' for (o in htmlOpts) { @@ -74,6 +82,8 @@ URLEncoder.encode("" + o.value, "UTF-8") + "&" } + if (url[-1] == '?' || url[-1] == '&') + url = url[0..-2] return "<a href=\"$url\">$text</a>" }, Added: trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/HQHelper.groovy =================================================================== --- trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/HQHelper.groovy (rev 0) +++ trunk/ui_plugins/rendit_sys/org/hyperic/hq/ui/rendit/helpers/HQHelper.groovy 2007-03-24 20:05:34 UTC (rev 3861) @@ -0,0 +1,22 @@ +package org.hyperic.hq.ui.rendit.helpers + +import org.hyperic.hq.common.shared.HQConstants +import org.hyperic.hq.common.server.session.ServerConfigManagerEJBImpl + +class HQHelper + extends BaseHelper +{ + HQHelper(user) { + super(user) + } + + private getServerMan() { ServerConfigManagerEJBImpl.one } + + String getServerURL() { + def res = serverMan.config.getProperty(HQConstants.BaseURL) + if (!res.endsWith('/')) { + res += '/' + } + res + } +} |