HTML Properties

From Mea Wiki
Revision as of 12:28, 12 April 2018 by TeeHiet (talk | contribs) (307302)
Jump to navigation Jump to search

The HTML presentation object is used to display custom written HTML content inside QPR UI views. HTML presentation objects are able to interact with context variables. Main differences to External Content presentation object are follows:

  • External content is basically a link to an external web page that resides outside QPR UI. HTML presentation object settings contains the needed HTML code, and thus the content is stored to QPR UI and transfered when exporting and importing views. Still, the HTML code may refer to external resources in web, but that should be avoided so that views are easily deployable.
  • External content presentation object is not able to draw outside its area in the view. This is because External content presentation object is tecnically an iframe, and browsers don't allow iframes to draw to its parent window area. HTML presentation object is able to draw outside its content area.
  • The HTML code in the HTML presentation object is not an entire web page but an HTML block, such as a DIV tag. External content presentation object needs to link to full web page (starting with HTML tag).

Security note: HTML presentation objects can embed JavaScript code into the dashboards, which may cause information security issues, because the embedded code is executed when users open the dashboard. Thus the dashboard designer persons need to be trusted. Viewer users are not able to change dashboards and embed JavaScript code into dashboards.

Properties Tab

The following properties can be set on the Properties tab:

  • Name: Name of the HTML presentation object. The name is not visible in the dashboard.
  • Description: Description for the HTML presentation object. The description is not visible in the dashboard.

Datasets Tab

Presentation Tab

The following settings can be set on the Presentation tab:

  • HTML code contains the HTML that will make up the displayed HTML content. Also CSS and JavaScript blocks can be used. You can also use context variables in the HTML code. If the used context variable values change, the HTML presentation object is initialized and possible stored state in JavaScript variables in the code are lost.
  • Horizontal / Vertical scrollbar defines how the horizontal or vertical scrollbar is shown for the HTML presentation object. Options are:
    • Auto: Scrollbar is visible if the content is scrollable (i.e. HTML presentation object height is greater than the available area for the presentation object in the view). Scrollbar is hidden, if the content is not scrollable. Setting widths of the HTML content programmatically may be more difficult as the available width depends whether the vertical scrollbar is shown.
    • Visible: Scrollbar is always visible. If the content is not scrollable, the scrollbar is grayed.
    • Hidden: Scrollbars is never shown. This setting can be used when the HTML presentation object should not contain scrollbars to prevent the scrollbars appearing in any case. If the height of the HTML presentation object is greater than the available area in the view, rest of the content is not accessible.

Callback Functions in HTML Code

In the HTML code the following callback functions may be defined:

  • function <#contextChangeFunction>(changedContextVariables): This function is automatically called by QPR UI when the effective context of the HTML presentation objects changes. The changed context variables are available in the changedContextVariables parameter as key-value pairs. This function is also called once when the HTML presentation object is initialized (the view is loaded). Use this function to write custom logic that should occur in the HTML presentation object when context variables change.
  • function <#resizeFunction>(newWidth, newHeight): This function is automatically called by QPR UI when the HTML presentation object size changes, for example as a result of changing browser window size. The function is needed, if the resize logic needs to be written using JavaScript. This function is called also once when the HTML presentation object is initialized (the view is loaded).
  • function <#datasetChangeFunction>(datasetIdentifier, datasetChangeCallbackFunction): This function is called when any dataset changes that is visible to this HTML presentation object. Changed dataset identifier is provided as a first parameter. The second parameter is a callback function, which can be called if the HTML presentation object needs to access the changed dataset data. As a parameter for this callback function, you need to provide the function that is then called back by QPR UI with the actual dataset data. See the example in the following chapter.

Notes:

  • These functions need to be defined inside script block.
  • The actual function names are not known in view design time and that's why the tag syntax is used. QPR UI will replace the tags with the actual function names during HTML presentation object is rendered. This is also to guarantee that the function names are unique when there are same HTML code used multiple times in the view.
  • These functions are not called when the HTML presentation object is hidden (using the Show in view setting).

Setting Context Variables in HTML code

Context variables can be set in the HTML code using following JavaScript function:

  • setSessionVariable(variableName, variableValue, presentationObjectRuntimeId, noNewHistoryEntry) where following parameters are available:
    • variableName is the name of the variable to be set. This parameter is mandatory.
    • variableValue is variable value to be set (the value must be a string). This parameter is mandatory.
    • presentationObjectRuntimeId: Defines the scope where the variable is set. null means session scope.
    • (currently not supported) noNewHistoryEntry is a boolean value defining whether to create a new browser history entry of the context variable change. true defines that no new browser history entry is created. This means that when user click the Back button, it reverts both that context variable change and the latest history entry that existed before the context variable change. The parameter is optional and by default it's false.
  • (currently not supported) setSessionVariables(variables) where the following parameter is available:
    • variables: Changed variables as an object (key-value pairs)
  • (currently not supported) deleteSessionVariable where following parameters are available:
    • variableName is the name of the variable to be set. This parameter is mandatory.

Following code example shows how the context variables can be set through the window.parent object:

window.parent.setSessionVariable("variable1", "value1");

Accessing Datasets in HTML Code

In the HTML code, it is possible to define a JavaScript function that is called when a dataset changes or the data in the dataset changes. This change function is also called for all available datasets, when the HTML presentation object is drawn. In addition, it is possible to define a JavaScript callback function that is called when the dataset data is available. The dataset itself is available as a table. For example:

<div id="content_<#uniqueId>"></div>

<script>
function <#datasetChangeFunction>(datasetIdentifier, datasetChangeCallbackFunction) {
  if (datasetIdentifier == "myDataset") {
    datasetChangeCallbackFunction(myDatasetAvailable<#uniqueId>);
  }
}

function myDatasetAvailable<#uniqueId>(datasetData) {
  if (datasetData == null || datasetData.sheets == null || datasetData.sheets.length == 0 || datasetData.sheets[0] == null || datasetData.sheets[0].values == null || datasetData.sheets[0].values.length == 0) return;
  var convertedData = [];
  for (var row = 1; row < datasetData.sheets[0].values[0].length; row++) {
    var rowObject = {};
    for (var column = 0; column < datasetData.sheets[0].values.length; column++) {
      rowObject[datasetData.sheets[0].values[column][0].attribute] = datasetData.sheets[0].values[column][row].value;
    }
    convertedData.push(rowObject);
  }
  $("#content_<#uniqueId>").ejGrid({dataSource: convertedData});
}
</script>

See the Pivot Grid, Bubble Chart, Gantt Chart, and Multiselect Dropdown List links below for more examples.

Querying Datasources in HTML Code

It's possible to query the QPR Suite Web Service, QPR ProcessAnalyzer, and QPR Reporting Expression by using the qpr.runQuery(datasourceType, parameters, dataAvailable, errorOccurred, identifier) javascript function.

Parameters for the qpr.runQuery function:

  • datasourceType: The used datasource type. Possible values are "QprSuite", "ProcessAnalyzer", and "ReportingExpression".
  • parameters: Query parameters as an object:
    • query: The actual query. Used with all datasource types.
    • criteria: Used with the "QprSuite" datasource type. See QPR Suite Web Service for the description.
    • sortby: Used with the "QprSuite" datasource type. See QPR Suite Web Service for the description.
    • attributes: Used with the "QprSuite" datasource type. See QPR Suite Web Service for the description.
    • options: Used with the "QprSuite" datasource type. See QPR Suite Web Service for the description.
  • dataAvailable: The callback function to execute when the query is successful.
  • errorOccurred: The callback function to execute when the query fails.
  • identifier: An optional javascript object that is returned fo the success and fail callbacks.

For example, the following HTML code will query the names and descriptions of all the QPR Metrics models available in the QPR Suite Web Service Datasource and display the queried data in a data grid:

<div id="griddiv_1"></div>

<script>
var datasourceType = "QprSuite";
var identifier = "id123";
var parameters = {
  "query": "[SC].Models",
  "attributes": "name, description",
  "criteria":"",
  "sortby":"name",
  "options":""
};

function dataAvailable(data, identifier) {  
  if (data == null || data.sheets == null || data.sheets.length == 0 || data.sheets[0] == null || data.sheets[0].values == null || data.sheets[0].values.length == 0) return;
  var convertedData = [];
  for (var row = 1; row < data.sheets[0].values[0].length; row++) {
    var rowObject = {};
    for (var column = 0; column < data.sheets[0].values.length; column++) {
      rowObject[data.sheets[0].values[column][0].attribute] = data.sheets[0].values[column][row].value;
    }
    convertedData.push(rowObject);
  }
  $("#griddiv_1").ejGrid({dataSource: convertedData});
}

function errorOccurred(errormessage, identifier) {
  alert("failure, message: " + errormessage +  ", identifier: " + identifier);
}

qpr.runQuery(datasourceType, parameters, dataAvailable, errorOccurred, identifier);
</script>

UniqueId tag

<#uniqueId> tag can be used in the HTML code. It provides a unique number in the entire view (also inside Repeater). The unique number is useful to be able to generate unique HTML id's. See the example below for a usecase. Unique id's are needed because all HTML presentation objects' code belong to the same HTML page, and there should be a way to differentiate between HTML presentation objects. This way exactly the same HTML code can be used in different HTML presentation objects in the same view.

How to Add an HTML Presentation Object

HTML presentation object is added to a view like adding the SVG presentation object, but instead of SVG presentation object select the HTML presentation object in the toolbar. You can use the example HTML code defined above. Note that HTML presentation objects don't contain actions like SVG presentation objects.

Examples