Display global context in the edit dialog of a custom node

Hello, i'm stuck on something.

When editing a node in the edit dialog, i want the "user" to be able to select an item from a list stored in the global context.

I already create an http endpoint, then when we open the edit dialog tab, it requests the runtime for values.

html file

oneditprepare : function(){
            $.getJSON('listStored',function(data) {
                $("#node-input-list").typedInput({
                    types: [
                        {
                            value: "list",
                            options: [
                                { value: "", label: "--Select an item--"},
                                ...data
                            ]
                        }
                    ]
                })
            });
        }

js file

RED.httpAdmin.get("/listStored", RED.auth.needsPermission('node.read'), function(req,res) {
        let listFromGlobal = //How to access global context from here

        res.json(listFromGlobal);
});

But from here how to access the global context ?
I looked at the documentation on RED module butunderstand how to use it

In general you shouldn't be exposing global context in this way.

How does that list get into global context to begin with?

The runtime already provides an endpoint for querying context - as used by the context sidebar. I don't have the specific details to hand, but if you use the browser tools to examine the network requests the editor makes when you have the context sidebar open and click the 'refresh' button, you should be able to identify the endpoint.

Following @knolleary advice I got: http://127.0.0.1:1880/context/global

You can also get specifics:

http://red.localhost:1880/red/context/node/a440f5977ec34da8/uib_cache?store=default

Notes:

  • My admin root is set to /red/ - use a relative URL to avoid having to worry about locations.
  • That gets a node's context variable with a specific name and a given store.

You can also update context this way:

http://red.localhost:1880/red/inject/a4f2bd730664b927

Notes:

  • Use POST rather than GET

Doh! It hadn't occurred to me to try that method when I put together uibuilder's caching node. I did it via an API call. Though in my case, not sure that this method helps that much since I need the same functions in the js file of the node anyway - all it saves is an API endpoint and they use pretty much all standard code.

There is no api for updating context from the editor. The url you shared there is the one to trigger an inject node - that has nothing to do with context.

Ah. OK. That makes sense.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.