Jump to content
pconkie

How do I.....in Frog Code

Recommended Posts

Hello everyone.

I've got a couple of ideas but not sure about the best way to proceed...

1. If i upload an asset to a Frog Code app/widget (e.g. an image) what is the best way to refer to that asset in Frog Code?  

if I've uploaded my image to Projects --> Widget --> My Widget --> Assets --> picture.png

Can i refer to this asset in code whilst retaining this relative path and file name?  

 <img src="externalapps/icon/widget_ID" /> works for the widget icon but  <img src="externalapps/assets/picture/widget_ID" /> (and other permutations) does not work for other assets.

Yes, i can find the assets ID and use that, but what will happen if the widget is ever moved from one frog box to another?

 

2. Let's say i create App A and Widget A.

Would it be possible for different instances of Widget A to open App A and pass to it an object to help it initialise?

I've had a look at the App widget preference but got a bit lost.  Is this even possible and if so what's the best way to test if App A is already open?

 

3. The feedback app converts various files into images.  Is there an api to tap into this?

 

Thanks

Paul

Link to comment
Share on other sites

7 hours ago, Graham Quince said:

Worryingly - he's still off sick, poor chap.  I've dropped him a line or two, but haven't wanted to bother him too much.

Chris - if you're reading this - stop it!  and get well soon

That's what married life does to you..... ;)

Link to comment
Share on other sites

@pconkie, @Graham Quince, @ADT,

I have arisen... 

@pconkie - Lets answer these questions:

  1. The correct url for your assets is '//package/{type}/{uuid}/assets/picture.png'
    You may get problems previewing your image as this is served from a different address. You can change 'package' to 'staging', just don't forget it change it back. This won't be the case after the October release.
  2. If you haven't already, checkout the documentation (https://froglearn.backwellschool.net/app/lib/packaging/docs/Preferences.App.html) for the app preference. The App preference returns the Apps UUID. You can then use the App Lib Model to get a the rest of the info you need.
    if (this.prefs.app.value) {
      	this.showLoader();
    	Lib.Models.Applications.findOne(this.prefs.app.value)
      	  .always(this.hideLoader.bind(this))
          .fail(this.handleError.bind(this))
      	  .done(
          	  function(app) {
                  this.app = app;
              	  this.render();
              }.bind(this)
          );
    }

    I'm guessing you'll then want to use the CodeEditor pref to store the object you want to send to the app. That in itself is a nice little widget.

    With regards to testing if an app is already open, you can use this code:

    // Inside your Widget/App controller
    var apps = {};
    this.trigger('os.app.getRunning', function(running_apps) {
    	// this code is synchronous!
    	// data structure is {"app_name": num_instances}
    	apps = running_apps;
    });
    // FC apps use their uuid's to open!
    if (this.app.getUuid() in apps) {
    	// Your app is already open
    }

     

  3. Our Document conversion service does not have an API unfortunately. It is driven independently from within the Server.

@ADT - ¬¬

 

~ Chris

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Amazing, thank you.

4 hours ago, Chris.Smith said:

Im guessing you'll then want to use the CodeEditor pref to store the object you want to send to the app. That in itself is a nice little widget.

Exactly. How would this be passed to the app we are opening? Inside app.render()? What would be required to read and use the object inside the app?

thanks. 

Link to comment
Share on other sites

On 17/08/2017 at 18:57, pconkie said:

Amazing, thank you.

Exactly. How would this be passed to the app we are opening? Inside app.render()? What would be required to read and use the object inside the app?

thanks. 

Hi @pconkie,

When an app is opened with some data - or options - it is available from instantiation as it may be required to tell the app how to set up, where to deeplink to, etc. This is done in the form of an object that is assigned to the prototype scope - this.options

Consider the following example:

// package/widget/48F1...AB73/widget.js

FrogOS.openApp('7C974713200486AFDC475F8BD94B0000FD3A143C6506D1A6', {
	foo: 'bar'
});

// package/application/7C97...D1A6/production.js

Com.Frog.Controllers.Application.extend('7C974713200486AFDC475F8BD94B0000FD3A143C6506D1A6.Controllers.Core', {
    defaults: {
    	foo: 'baz'
    }
}, {
    packageID: '7C974713200486AFDC475F8BD94B0000FD3A143C6506D1A6',

    init: function() {
        this.main();
    },

    update: function(options) {
        this._super(options);
        this.main();
    },

    main: function() {
        this.render();
    },

    render: function() {
        this.element.html(
            this.view('main.ejs', { title: this.options.foo }) // renders out <h1>Bar</h1>
        );
    }
});

You open your app by passing the package id into FrogOS.openApp as the first param, your data is the second param. Your app will then open/focus and FrogOS will set the apps options to match/include the data passed in. When opening the app, this.options is set to the contents of the defaults object in the static object; which is then overridden by the data passed in. When focusing the application (calling openApp when there is already one open) your entry point is the update method. this._super(options) merges the any new data with the existing this.options.

In this example:

  • we started with a default of this.options.foo = 'baz'.
  • We initialised with a value of 'bar' so this replaced 'baz' as this.options.foo = 'bar'.
  • If we tried to open the application again, this time with a different value, 'bar' would be overwritten by that value.

There are some complications that you may experience depending how complex this setup gets, but usually you should be fine.

 

~ Chris

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...