jsreport / jsreport-core

The minimalist jsreport rendering core
GNU Lesser General Public License v3.0
85 stars 24 forks source link

How to add another script as allowedModule task in the jsreport server as well as jsreportonline? #8

Closed snehilmodani closed 8 years ago

snehilmodani commented 8 years ago

I can use "moment" in the helper functions but also need "moment-timezone" for a few other functionalities. I found this piece of code which i think can help me around it, but I am not able to figure out how and where to use it:

var jsreport = require('jsreport-core')( 
   { tasks: { allowedModules: ['moment'] } })

//or unblock everything

var jsreport = require('jsreport-core')( 
   { tasks: { allowedModules: '*' } })

I am keen to know how it works too.

Note: We are using jsreport server for development and jsreportonline for our production environments.

On a side note if you add moment-timezone too in the default loading of the allowed modules as it would help all developers manage data across timezones without much hassle.

pofider commented 8 years ago

In the on premise installation you normally do:

 { "tasks": { "allowedModules": '*' } })
var moment = require('moment-timezone');
moment().tz("America/Los_Angeles").format();

In the jsreportonline, you don't have control over configuration. We may add moment timezone in future releases, but until then you can workaround it by adding the timezone code at the bottom of the helpers. See it here https://playground.jsreport.net/studio/workspace/HkqFhP6c/3 (Note on jsreportonline, you should add just timezone code, because moment is already there) It is not so pretty, I know. I've in mind a new extension that allows to upload any kind of file and reference it form helpers/html. It should come in couple of months.

snehilmodani commented 8 years ago

The workaround works fine! Looking forward to this new extension.