Data Sharing Between Apps
Activities
JavaScript
Activity Participants
Each activity instance has a single owner window and can optionally have one or more helper windows. The owner window controls the lifetime of the activity - if the owner is closed, the activity and all other windows are closed as well. The activity is running as long as the owner is running. Helper windows support the owner of the activity and may be defined in the activity type configuration or joined to the activity at runtime.
Configuring an Activity
Activity applications are defined in the same manner as regular applications. You can configure an activity by creating an activity configuration .json
file and place it in the %LocalAppData%\Tick42\UserData\<ENV-REG>\apps
folder, where <ENV-REG>
should be replaced by the environment and region of your Glue42 Enterprise copy (e.g., T42-DEMO
).
[
{
"title": "Clients",
"type": "activity",
"name": "clients",
"icon": "http://localhost:22080/resources/icons/client-list.ico",
"hidden": false,
"details": {
"initialContext": {
"context": "someContext"
},
"layout": {
"mode": "pixels"
},
"owner": {
"type": "clientlist",
"name": "ClientList",
"left": 20,
"top": 20,
"width": 400,
"height": 400
},
"windows": [
{
"type": "clientportfolio",
"name": "ClientPortfolio",
"left": 420,
"top": 20,
"width": 400,
"height": 400
}
]
}
},
{
"title": "Client List",
"type": "window",
"name": "ClientList",
"hidden": true,
"details": {
"url": "http://localhost:22080/client-list-portfolio-contact/dist/#/clientlist",
"mode": "html"
},
"activityTarget": {
"enabled": true,
"windowType": "clientlist"
}
},
{
"title": "Client Portfolio",
"type": "window",
"name": "ClientPortfolio",
"hidden": true,
"details": {
"url": "http://localhost:22080/client-list-portfolio-contact/dist/#/clientportfolio/",
"mode": "html"
},
"activityTarget": {
"enabled": true,
"windowType": "clientportfolio"
}
}
]
owner
- the owner window of the activity;windows
- array of helper windows;windowType
- unique identifier within the Activities API (defaults to the application name);
Only the owner
property is required. It is useful to specify the activityTarget
property in order to describe how your application will look when it is an activity window. The same is valid for the layout
property, which specifies whether the window dimensions are in pixels
(default) or relative to the screen (percents
). For more details, you can see the application configuration schema.
Detecting Activities
The Activities API can be accessed through glue.activities
.
A window is not necessarily aware whether it was instantiated as part of an activity or as a standalone window, so the best practice is to design windows to be able to either pick context from the activity, or by registering Interop methods.
If glue.activities.aware
is false
, your window is standalone. Otherwise, glue.activities.my.window
will hold a valid activity window reference on which you can expect the isOwner
property (if false
, the window is a helper window).
You can check whether a window has joined an activity with glue.activities.inActivity
and you can then track when a window joins or leaves an activity using the onActivityJoined()
or onActivityLeft()
callbacks.
Managing Activity Context
Reading Current Context
To get the current context, use:
const context = glue.activities.my.context;
The context is a simple JSON-serializable object:
// a client is looking at the market depth of an instrument
const context = {
// client information
party: {
pId: "12345",
gId: "56789"
},
// instrument information
instrument: {
ric: "VOD.L",
bpod: "VOD.LN",
bbgTerminal: "VOD LN Equity"
}
};
Subscribing for Context Updates
You can subscribe for context updates with onContextChanged()
:
glue.activities.my.onContextChanged(
(context, delta, removed) => {
// react to context updates
});
context
is the current context object of the activity;delta
is an object containing only the changes between the previous and the latest contexts;removed
is an array containing the names of the properties which were removed from the context;
Updating a Context
You can update a context object:
glue.activities.my.updateContext(
{
newProperty: "value", // adds a property
existingOne: "updated", // updates a property
oneToRemove: null // setting a property to null will remove the property
});
For example, if we select another party
and remove the selected instrument
:
glue.activities.my.updateContext(
{
party: { pId: "34567", gId: "01234" },
instrument: null
});
...then onContextChanged()
will fire with the following arguments:
const context = { // new context
party: {
pId: "34567", // note the change
gId: "01234" // note this one as well
}
// note the removal of the instrument
};
const delta = { //object, containing the changes between the new and the old context
party: {
pId: "34567",
gId: "01234"
},
instrument: null
};
const removed = [ "instrument" ]; // the properties removed from the context
Replacing a Context
To replace a context, use:
glue.activities.my.setContext(
{
newProperty: "value",
anotherProperty: "new"
});
Managing Activity Windows
You can query and manipulate activity windows by obtaining a reference to the current activity:
const currentActivity = glue.activities.my.activity;
Querying Activity Windows
Finding the owner window:
const owner = currentActivity.owner;
Finding all windows within the activity instance:
const windows = currentActivity.windows;
Finding windows of a specific window type:
const clientListWindows = currentActivity.getWindowsByType("clientlist");
Creating and Destroying Activity Windows
Creating a window of a specific type:
currentActivity.createWindow("clientlist").then(
(window) => {
window.activate(); // you can use the Window Management API here
});
The createWindow()
method accepts either a string
or a WindowDefinition
, so when creating a window, you can pass an initial context, window position and/or style to it, just like in the Window Management API windows.open()
call:
currentActivity.createWindow({
type: "clientportfolio",
relativeTo: "clientlist",
relativeDirection: "bottom",
height: 300
});
Removing a window from an activity (cannot be the owner window):
currentActivity.leave("clientportfolio");
Note: Once you get hold of a window, you can use the Window Management API to manipulate the window.
Activity Layouts
Activities have special layouts (arrangement of windows/apps) that can be saved and later restored.
For more information on how to do that, see the Activity Layouts section of the Layouts documentation.
Using the Window Management API
Activity windows can be manipulated using the Window Management API:
glue.activities.my.window.underlyingWindow.moveResize({ left: 100 });