Book a Demo

Author Topic: External includes in Ea Javascript engine?  (Read 6384 times)

timoc

  • EA User
  • **
  • Posts: 201
  • Karma: +14/-0
    • View Profile
External includes in Ea Javascript engine?
« on: June 05, 2019, 04:30:33 pm »
Hi,

Is there a way to include scripts from the file-system in the (new?) Javascript engine? or do they have to be imported?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: External includes in Ea Javascript engine?
« Reply #1 on: June 05, 2019, 04:50:53 pm »
I think you'll need to import them and use !Include

Geert

PS. If you have a lot of scripts to import, I wrote an script importer function in VBScript, see here: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/tree/master/Framework/Tools/Script%20Management

timoc

  • EA User
  • **
  • Posts: 201
  • Karma: +14/-0
    • View Profile
Re: External includes in Ea Javascript engine?
« Reply #2 on: June 05, 2019, 06:28:00 pm »
I think you'll need to import them and use !Include

Geert

PS. If you have a lot of scripts to import, I wrote an script importer function in VBScript, see here: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/tree/master/Framework/Tools/Script%20Management

Thanks i will look at it. Its not a matter of import as such, its a matter of the development cycle overheads of having to repeatedly import external dependencies.
Out of curiosity, is there a HTML DOM/view attached to the JS engine somewhere inside EA?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: External includes in Ea Javascript engine?
« Reply #3 on: June 05, 2019, 06:58:50 pm »
Out of curiosity, is there a HTML DOM/view attached to the JS engine somewhere inside EA?
Not sure what you mean by that. Can you explain?

Geert

timoc

  • EA User
  • **
  • Posts: 201
  • Karma: +14/-0
    • View Profile
Re: External includes in Ea Javascript engine?
« Reply #4 on: June 05, 2019, 08:23:57 pm »
Out of curiosity, is there a HTML DOM/view attached to the JS engine somewhere inside EA?
Not sure what you mean by that. Can you explain?

Geert

I am trying to instrument the script with some logging output using console.log(). This does not work because it seems to be tied to a HTML DOM , so i wondered if EA is able to render HTML in a "popup" window from a script.

Also, In the script engine description it can be "called from report document templates to populate reports".
I want to develop in Javascript and render HTML, as it is easier to test with outside of EA, and there is alot of off the shelf scripts for HTML dom manipulation.

Third,

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: External includes in Ea Javascript engine?
« Reply #5 on: June 05, 2019, 08:52:24 pm »
the "called from report generator" probably point to the script fragments in RTF templates.

if you want logging you can use either Session.Output (for debugging) or Repository.WriteOutput (for status information)
You can definitely create HTML from a script, and then show that html file using your favorite browser, but your script isn't executed in a browser context.

Pretty much anything you can do outside of EA as a standalone script is possible from inside EA.

Geert

timoc

  • EA User
  • **
  • Posts: 201
  • Karma: +14/-0
    • View Profile
Re: External includes in Ea Javascript engine?
« Reply #6 on: June 06, 2019, 05:59:59 pm »
the "called from report generator" probably point to the script fragments in RTF templates.

if you want logging you can use either Session.Output (for debugging) or Repository.WriteOutput (for status information)
You can definitely create HTML from a script, and then show that html file using your favorite browser, but your script isn't executed in a browser context.

Pretty much anything you can do outside of EA as a standalone script is possible from inside EA.

Geert

For anyone else interested, this is how i extended the logging function to implement a browser console.log():

Code: [Select]
!INC EAScriptLib.JScript-Logging

var console = new Object();
console.log = function( message ){ Session.Output( _LOGGetDisplayDate() + " [JS Console]: " + message ); };