Example
// Create an instance of the CognosApi
const api = new CognosApi({
cognosRootURL: 'http://localhost/bi/',
node: document.getElementById('containerDivId'),
sessionCode: 'CD1a2b34567b8c901234d5'
});
// initialize the CognosApi in order to obtain the service APIs
api.initialize().then(() => {
// obtain the dashboard API of a new dasboard instance
api.dashboard.createNew().then((dashboardApi) => {
...
});
});
Members
(static, readonly) DashboardAPI.EVENTS :string
Enumeration of dashboard events
Type:
- string
Properties:
Name | Type | Description |
---|---|---|
DIRTY |
string |
(static, readonly) DashboardAPI.MODES :string
Enumeration of Dashboard modes
Type:
- string
Properties:
Name | Type | Description |
---|---|---|
EDIT |
string | Edit (authoring) mode. Allows user to author the current dashboard. |
VIEW |
string | View (consumption) mode. Allows user to view and explore the current dashboard. |
EDIT_GROUP |
string | Event group edit mode. Allows user to edit the widget connections in the current dashboard. |
Methods
addSources()
Add sources that can used as data sources in the dashboard.
Once the source is successfully added, it will appear on the datasource list pane with the given name.
Once the source is successfully added, it will appear on the datasource list pane with the given name.
Parameters:
Name | Type | Description |
---|---|---|
sourceInfo.id |
String | Identifier for the source. Will be passed back for actions such as relink |
sourceInfo.name |
String | Name of the source |
sourceInfo.module |
String | The module definition |
Example
DashboardApi.addSources([{
id: 'myUniqueId',
name: 'Sample datasource',
module: {...}
}, {
id: 'myUniqueId2',
name: 'Sample datasource 2',
module: {...}
}]);
clearDirty()
Clears the dashboard dirty state
Example
DashboardApi.clearDirty();
getMode() → {DashboardApi.MODES}
Get the current dashboard mode.
Returns:
Dashboard mode enumeration value
- Type
- DashboardApi.MODES
Example
DashboardApi.getMode().then(function(mode) {
console.log(mode);
});
getSpec() → {Object}
Get the dashboard instance specification
Returns:
dashboard spec
- Type
- Object
Example
DashboardApi.getSpec().then(function(spec) {
console.log(spec);
});
off(eventName, handler)
Unregister an event handler that was registered with DashboardApi.on
Parameters:
Name | Type | Description |
---|---|---|
eventName |
string | Name of the dashboard event |
handler |
function | Event handler to be called when the event occurrs |
Example
// handle the event when the dashboard is modified
function onModified(event) {
console.log('dashboard has been modified');
}
// Register the event handler
DashboardApi.on(DashboardApi.EVENTS.DIRTY, onModified);
...
// Unregister the event handler
DashboardApi.off(DashboardApi.EVENTS.DIRTY, onModified);
on(eventName, handler)
Register an event handler for dashboard events
Parameters:
Name | Type | Description |
---|---|---|
eventName |
string | Name of the dashboard event |
handler |
function | Event handler to be called when the event occurrs. Multiple handlers can be registered with the same eventName. Each handlers needs to be registered and unregistered individually. |
Example
// handle the event when the dashboard is modified
function onModified(event) {
console.log('dashboard has been modified');
}
// Register the event handler
DashboardApi.on(DashboardApi.EVENTS.DIRTY, onModified);
redo()
Redo the last DashboardApi.undo action performed on the dashboard
Example
// edit the dashboard
...
DashboardApi.undo();
DashboardApi.redo();
relink()
Relink an existing source to a new module.
Widgets that reference this source will reload after the relink is finished.
Widgets that reference this source will reload after the relink is finished.
Parameters:
Name | Type | Description |
---|---|---|
sourceInfo.id |
String | Id of the source to relink. This id is passed to the caller in the relink:clicked event |
sourceInfo.name |
String | Name of the source, only needed if you wish to change the name. |
sourceInfo.module |
String | The module definition |
Example
DashboardApi.relink({
id: '123456',
name: 'Sample datasource',
module: {...}
});
setMode(mode)
Change the dashboard mode between EDIT, VIEW and EDIT_GROUP.
Parameters:
Name | Type | Description |
---|---|---|
mode |
DashboardApi.MODES | Dashboard mode enumeration value |
Example
DashboardApi.setMode(DashboardApi.MODES.VIEW);
toggleProperties(toggleopt)
Toggle the properties pane
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
toggle |
boolean |
<optional> |
if true display the properties pane, otherwise hide the properties pane. The state is toggled from the current state when omitted. |
undo()
Undo the last action performed on the dashboard
Example
// edit the dashboard
...
DashboardApi.undo();