Portals Extension Module
The Portals Extension Module has been created to allow 3rd party content and applications to be integrated inside Portals. This documentation is split into several parts and each relevant section also includes a list of API functions.
Topics:
Including Portals API in your application
The Extension module allows integration of your application into portals by providing an iFrame for your content and an API for communication with Portals. The module accepts an url and allows dynamic GET parameters to be passed to your application through that url. Just select the participant variables and master data you want to pass to your application and provide names for the GET keys.
A portals page can have several Extension modules on a single page and all modules can communicate with each other through the provided message bus in the Portals API.
For enhanced data exchange with EFS, we recommend that your application uses the EFS ServiceLayer in the backend to query and update data in EFS.
Import
In your application, you have to import the PortalsAPI JavaScript file in order to be able to use the message bus or other Portals API functions.
<script src="https://{yourEFSInstallation}/public/modules/portals/dist/portalsApi/portalsApi-1.0.js"></script>
Initialization
After your document has finished loading you need to initialize the api. This registers your document with Portals for messaging.
<script>
Questback.portalsApi.initialize()
.then(function() {
...
}
.catch(function(error) {
...
});
</script>
Ā
Checking initialization status
You can check the initialization status by calling isInitialized, though it is generally recommended to do your api operations in the then-handler of the initialize method as shown above.
Questback.portalsApi.isInitialized();
Unregister
You can completely revert the registration of the iFrame and unregister all its handlers by calling unregister.
Ā
Using the Portals message bus
The message bus is intended for communication between extension module iFrames. You can send and listen to your own events and transfer any data you want.
Listening for messages
After the initialization has been completed you can start to register handlers for events from other iFrames. The example code registers a handler for an event called "myEvent". This is an event name that you expect other iFrames to send messages for.
Sending messages
Sending a message to other iFrames is just as simple. You just call the send method with an eventname that you chose and a data object as second parameter.
Just note that you do not get a result back from this call, as it works like a broadcast. Also note that by default the sending iFrame will not receive its own event back, even if it has registered a handler for it. You can supply a third parameter to send with a value of true to force sending the event to the sender iFrame, too.
Stop listening for messages
You can remove handlers for events by an eventname.
Note that this removes all handlers for the given eventname for this iFrame at once.
Querying data from Portals
The api supplies a set of methods to request specific data from Portals.
query.portalInfo
Get information about the portal.
query.user
Get the user object of the currently logged in user. Returns null if there is no logged in user.
query.language
Get the language object of the currently used language.
query.token
Returns the Portals Api token, which can be used in external software to additionally validate the user via EFS web service.
If the user is logged in, the token field will contain the users api token, which you can validate by calling the following EFS web service. Otherwise, token will be an empty string.
If the token is valid the userId and portalId is returned. Otherwise an exception is thrown. Please refer to the web services documentation for more details on this service call.
query.deviceInfo
Get information about the client device.
query.ajax (reserved for future use)
Makes an ajax call to the internal portals server API and returns the result. Since Portals itself does not provide a public portals server API, this function is reserved for future use.
Trigger actions in Portals
The api supplies a set of methods to trigger specific actions in Portals.
trigger.height
Set the iFrames height to a specified value, given as a string including the unit.
trigger.autoHeight
Set the iFrames height to the height of its content. This is done once per call, not repeatedly. So you have to react to resize events yourself.
trigger.logout
Log out the current user from Portals and thus redirect to the configured landing page. The iFrame will be removed from the DOM by this opreation.
trigger.route
Redirect to the given page slug. The iFrame will be removed from the DOM by this opreation.
Accessing MySight instances in Portals
There are a number of methods to interact with Tableau in a MySight module. For all of these you need the pageModuleIdentifier of a MySight module to target your requests. This identifier is set in the Portals CMS in the settings for the MySight page module and can be reused on other pages for the same or even different Tableau instances.
mySight.vizGetIsReady
Gets whether the onFirstInteractive event has been fired yet.
mySight.vizGetAreTabsHidden
Gets whether the tabs are hidden or not.
mySight.vizGetIsToolbarHidden
Gets whether the tabs are hidden or not.
mySight.vizGetUrl
Gets the url of the viz.
mySight.vizGetCurrentUrl
Gets the current url of the viz.
mySight.vizGetIsHidden
Gets whether the viz is hidden or not.
mySight.vizShow
Shows the viz.
mySight.vizHide
Hides the viz.
mySight.vizDispose
Disposes the viz.
mySight.vizGetAreAutomaticUpdatesPaused
Gets the status of automatic updates.
mySight.vizPauseAutomaticUpdates
Pauses automatic updates.
mySight.vizResumeAutomaticUpdates
Resumes automatic updates.
mySight.vizToggleAutomaticUpdates
Toggles automatic updates.
mySight.vizRevertAll
Restores the initial state. Note that url parameters will be ignored in this operation and as such the restored state may differ from the real initial state.
mySight.vizRefreshData
Refreshes data from the server.
mySight.vizShowDownloadWorkbookDialog
Shows the download workbook dialog.
mySight.vizShowExportImageDialog
Shows the export image dialog.
mySight.vizShowExportPDFDialog
Shows the export PDF dialog.
mySight.vizShowExportDataDialog
Shows the export data dialog for the current or a specific sheet.
mySight.vizShowExportCrossTabDialog
Shows the export cross tab dialog for the current or a specific sheet.
mySight.vizShowShareDialog
Shows the share dialog for the current or a specific sheet.
mySight.vizSetFrameSize
Sets the vizs frame size. Note that the min-width might be set to 100% by Portals, taking precedence over any width that is set here.
mySight.workbookGetName
Gets the name of the workbook.
mySight.workbookGetSheetsInfo
Gets information about all sheets.
mySight.workbookGetActiveSheetName
Gets the name of the active sheet.
mySight.workbookGetActiveSheetIndex
Gets the index of the active sheet.
mySight.workbookActivateSheet
Actives a sheet by its name or index.
mySight.workbookRevertAll
Restores the initial state of the workbook. Note that url parameters will be ignored in this operation and as such the restored state may differ from the real initial state.
mySight.workbookGetParameterNames
Gets a list of the parameter names.
mySight.workbookGetParameterCurrentValue
Gets the current value of a parameter.
mySight.workbookGetParameterDataType
Gets the data type of a parameter.
mySight.workbookGetParameterAllowableValuesType
Gets the type of allowable values of a parameter.
mySight.workbookGetParameterAllowableValues
Gets a list of allowable values of a parameter.
mySight.workbookGetParameterMinValue
Gets the min value of a parameter.
mySight.workbookGetParameterMaxValue
Gets the max value of a parameter.
mySight.workbookGetParameterStepSize
Gets the step size of a parameter.
mySight.workbookGetParameterDateStepPeriod
Gets the date step period of a parameter.
mySight.workbookChangeParameterValue
Sets a parameter to a given value.
mySight.sheetGetName
Gets the name of a sheet by its index.
mySight.sheetGetIndex
Gets the index of a sheet by its name.
mySight.sheetGetIsActive
Gets whether a sheet is active or not.
mySight.sheetGetIsHidden
Gets whether a sheet is hidden or not.
mySight.sheetGetType
Gets the type of the currently active or a specific sheet.
mySight.sheetGetUrl
Gets the url of the currently active or a specific sheet.
mySight.sheetGetSize
Gets the size of the currently active or a specific sheet.
mySight.sheetChangeSize
Sets the size of the active sheet.
mySight.sheetGetFilters
Gets the filters of a sheet specified by its name.
mySight.sheetApplyFilter
Applies the filter for a sheet specified by its name.
mySight.sheetApplyRangeFilter
Applies the range filter for a sheet specified by its name.
mySight.sheetApplyRelativeDateFilter
Applies the relative date filter for a sheet specified by its name.
mySight.sheetApplyHierarchicalFilter
Applies the hierarchical filter for a sheet specified by its name.
mySight.sheetClearFilter
Clears the filter for a sheet specified by its name.
Listening to MySight Tableau events
The api supports registering for a number of Tableau events. The supported events are:
FIRST_INTERACTIVE
VIZ_RESIZE
TAB_SWITCH
FILTER_CHANGE
PARAMETER_VALUE_CHANGE
MARKS_SELECTION
To register a listener for an event use the apis bus methods together with the apis tableau event constants:
Note that you will receive events coming from any MySight Tableau instance on the page, so upon receiving an event you might have to make sure that you are only handling events coming from a specific instance by checking the pageModuleIdentifier in the event object.
Use Portals styles
You can use Portals CSS styles by importing its stylesheets into your iframe. The following examples will guide you through the setup process.
Retrieve file paths
First you need to get the paths of the stylesheet files and font definitions:
The result parameter will contain the necessary information in its layout field:
These paths do not change for a given portal (besides the value of the cachebuster parameter called v), so it is possible to retrieve them once, store them and hardcode them into your code, to save postMessage requests and improve startup times a little.
Importing the extension stylesheet
After retrieving the stylesheet urls you need to import the files by adding link tags into your documents head:
You should note that it takes some time to retrieve the file from the server, so there is a short time in which your application is rendered without the styles in the file. You might want to prevent your application from beeing shown to the user before the above code has been executed.
The extension.css is a subset of the portals stylesheet and contains the necessary styles for the most common use cases. If you want to include the complete portals stylesheet you can import result.layout.portalsCss instead of result.layout.extensionCss. But be aware that this might introduce conflicts with existing styles in your application.
Importing the custom stylesheet
If you have added custom css in the Look & Feel section of the CMS, that contains styles which you want to apply to you application, then you should import the custom.css file, too.
Importing the portals default font
To use the same font as your portal use the following code:
Using the styles
The extension.css contains classes for the most common use cases.
Color variables
Type color classes
Classes exist for the most common type and property combinations:
Profile background classes
The profile background classes exist, too:
Other classes
Buttons
You can style your buttons by using the portals button classes:
The button size can be set by adding one of the following classes:
The type can be set by adding one the following classes:
To enable hover effects, add the following class:
To display a button as disabled, add the following class:
If the button has the "disabled" attribute, the styles of "btn--disabled" are applied automatically.
Input fields
You can use styles for input fields as well. Write your markup as follows:
Please pay attention to the order of the elements and their classes. The oninput event handler is required to add or remove the input-filled class according to the inputs value. If your input receives an initial value you have to add the input-filled class manually.
Selectboxes
You can use native html selectboxes and they will be styled as close as possible to the original portals selectboxes. As those are generated by JavaScript, an exact replication is not possible.
As native html selectboxes always have a value selected, the input-filled class is always set on the select element.
Opening a dialog in Portals
The portalsApi has four methods that give you the ability to open a dialog outside of the scope of your iframe.
Dialog buttons
The methods openDialog and openIframeDialog open a dialog with a single "Close" button. The corresponding methods openConfirmDialog and openIframeConfirmDialog open a dialog with a "Cancel" and an "Ok" button.
Text dialogs
The methods openDialog and openConfirmDialog take a string as first parameter, which is the text shown in the main area of the dialog. The title is optional.
Iframe dialogs
The methods openIframeDialog and openIframeConfirmDialog render an iframe in the main area of the dialog with the url given at the first parameter. The title, height and heightUnit are optional. The paramters height and heightUnit define the height of the iframe in the dialog.
Simple call
The simplest way to open a dialog is by calling one of the dialog methods, give a text/url and not worry about any events:
Handle dialog close
The dialog can either be closed or canceled/accepted and this event can be handled by implementing Promise methods, like this:
The confirm dialogs make use of the then and catch methods:
The catch method does not indicate that an error happened, it just tells you about the way the dialog was closed. Both methods do not get any parameters. This means that no data from the dialogs iframe is transported back to the calling iframe.
If you want to transport data between the iframes or trigger actions in the other iframe make use of the PortalsApi's message bus functionality, documented under Using the Portals message bus
.
Ā
Ā© 2024 Tivian XI GmbH