grails elfinder plugin: use placeholder in rootDir - grails

in my Grails project I'm using elfinder plugin to manage files and directories. I want to have a dynamic root directory, because I use the plugin for different folders.
The path of directory is like the following:
grails.plugin.elfinder.rootDir = "${userHome}/docm_patients_doc/{patientcf}/"
where patientcf is the id of an entity in my application. When I enter into the show.gsp page of that entity, I need to replace the patientcf with the related value.
How can I do it?
EDIT:
I've tried to modify the placeholder before the script and div that shows elfinder in gsp page, but I notice that the path is not modified. Maybe the gsp is not the place in which the placeholder can be modified...

I am author of elfinder plugin, though plugins isn't developed with multiple roots in mind.
You can try this. Plugin registers a spring bean with name elfinderFileManager which has a property with name ‘root’ which is path to your root directory. Try setting the root property at runtime. The bean can be injected in your controller/service and you can try changing the root property.

Related

Aurelia compose viewmodel paths

I have components that has dynamic parts with compose. The dynamic parts are in other modules i.e. node projects.
If I want to use a custom element in a page like:
<my-custom-element body.bind="someVariableContainingThePath"></my-custom-element>
I get an error saying that the viewmodel specified in someVariableContainingThePath cannot be found in ./my-custom-element/someVariableContainingThePath.
What is the recommended way to deal with paths when using compose element.
I'm using webpack.
Is there a way to alias a module.
So can set someVariableContainingThePath='moduleA' and then specify
that moduleA = /some/path/my-body-custom-element ?
For webpack bundling you have to give it a hint. Otherwise your view will not get bundled.
you can add your component to globalResourses when configuring aurelia
http://aurelia.io/docs/fundamentals/app-configuration-and-startup#making-resources-global
You have to decorate your module names with PLATFORM.modulename as in .globalResources(PLATFORM.modulename('my-module'))

Generate URL of resources that are handled by Grails AssetPipeline

I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.

GRAILS : include javascript file that contains grails code from within a plugin

I want to include a javascript file custom.js in my gsp from a plugin. My main app uses this plugin as a dependency. The custom.js javascript file contains a variable whose value is obtained by executing grails code within GString.
var root = "${request.contextPath}";
It has to be a separate file and if I try to include it inside my .gsp file using <script src="custom.js"></script> the grails code doesn't get executed. If I use <g:javascript src="custom.js" /> it tries to fetch the file from within the plugin and cannot find it. The file is actually in my main application. But the code that's trying to include it is in the plugin. Something like a way of providing custom Javascript implementation. How do I go about this?
Update
Taking this answer into consideration I have to specify the value of the variable in a separate scrip tag. No grails code is interpreted if it's in a non-.gsp file.
I solved it. All I had to do was: add contextPath="" into the g:javascript tag
According to the documentation of the tag g:javascript about the contextPath attribute:
contextPath (optional) - the context path to use (relative to the
application context path). Defaults to "" or path to the plugin for a
plugin view or template.
It defaults to the path to the plugin. So by setting it to empty string we tell it to avoid the plugin path from the source. Previously it modified the paths to the javascript to something like appname/plugins/pluginname/js/custom.js. Now with contextPath set to empty string it simply makes the path appname/js/cusomt.js

grails render tag: can't find file unless it's located in src/templates/scaffolding?

I tried to follow the example under "Shared Templates" here:
http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.2.3%20Views%20and%20Templates
But this just plain didn't work. The tag I used was:
<g:render template="/includes/mySearch"></g:render>
I created a directory under the views called "includes" and created a gsp file, with a very basic form in it, named mySearch.gsp.
However, grails reported being unable to find the file:
java.io.FileNotFoundException: C:\springsource\sts-2.8.1.RELEASE\grails-1.3.7\src\grails\templates\scaffolding_mySearch.gsp
According to the documentation: "In this case you can place them in the root views directory at grails-app/views or any subdirectory below that location and then with the template attribute use a / before the template name to indicate the relative template path."
It would appear that this is exactly what I did, but grails was not looking there? Any advice?
Many thanks,
Alexx
Template files need to be starting with an underscore. Therefore you need to rename your mySearch.gsp to _mySearch.gsp.

Grails application root path

Is there a variable where I can find out the root directory of my Grails application?
for example, I have a folder named chart under \%root%\web-app\images\ where I put my charts in. Once I deploy my Grails application on Jetty, I will get FileNotFoundException because the root path becomes /srv/www/vhosts/domain-name/jetty-version/
I would like to know if there is a variable that returns the root path (like /srv/www/vhosts/domain-name/jetty-version/webapps/myapp), and there should be because CSS uses relative path just fine.
solved.
request.getSession().getServletContext().getRealPath("/")
this actually gives me the path to where my application puts the images, css, WEB-INF, etc. folders.
System.properties['base.dir']
I know it is an old question, but this could work if you are not in an http request:
ServletContextHolder.servletContext.getRealPath('/')
If you want to establish this is GSPs try this:
${createLink(uri: '/')}

Resources