Chapter 13. Environment Variables, Stylesheets, and Crosstabs

This chapter is dedicated to environment variables, stylesheets, and crosstabs. We will treat each of them in detail, defining what they are about and how to implement them in Pentaho Report Designer (PRD).

Using Environment Variables allows us to interact with the BA Server that is executing our reports. That is, we can obtain the username of the user who is currently logged in and his or her roles, among other information.

With Style Sheets, we can configure our report so that its look and feel varies according to certain CSS Rules . These CSS Rules are easy to configure, save, and import.

Finally, we will take a look at one of PRD's new jewels, Crosstabs . Using Crosstabs, we can show OLAP-style analytic information in our reports.

In this chapter we will do the following:

  • See examples of environment variables and use them to configure our objects in order to create CSS Rules for them
  • Create a new stylesheet and add our own rules to format objects' look and feel according to the user currently logged in
  • Save the stylesheet and assign it to our report
  • Create our own crosstab and configure it to show a crosstab analysis of year-month and ratings
  • Finally, we propose that you modify a previous report and configure the visibility of a graphic according to the user who is currently logged in

Learning about environment variables

Environment variables are basically variables whose values depend on the environment in which they are being used. For example, an environment variable can return to the application using it as a description of the current operating system or the complete path where the application is being executed.

In Pentaho Report Designer (PRD) there exists a series of predefined environment variables that will help us interact with the BA Server that is executing them. Making use of these variables, we can modify the behavior and content of our reports.

Environment variables in PRD

The environment variables that we can use in PRD are found in the Data tab, under the Environment node as shown in the following screenshot:

Environment variables in PRD

In the following list, we describe each of these:

  • env::hostColonPort: This environment variable specifies the IP address and port where Pentaho BA Server is being executed, separated by a colon. For example: localhost:8080.
  • env:serverBaseURL: This environment variable specifies the protocol, IP address, and port where Pentaho BA Server is being executed. For example: http://localhost:8080.
  • env::pentahoBaseURL: This environment variable specifies the protocol, IP address, port, and base URL where Pentaho User Console (PUC) is being executed. For example: http://localhost:8080/pentaho/.
  • env::username: This environment variable specifies the username of the user who is currently logged in. For example: Admin.
  • env::roles: This environment variable specifies the roles of the user who is currently logged in, separated by commas. For example: Administrator, Authenticated.
  • env::roles-array: This environment variable is the same as the previous variable, but with the difference that here we obtain an array. For example: {"Administrator"}, {"Authenticated"}.
  • env::solutionRoot: This environment variable specifies the complete path where the pentaho-solutions folder is physically located. For example: [BISERVER_HOME]/pentaho-solutions/.

Using the environment variables

Using the environment variables is simple and similar to what we have already seen. We can drag-and-drop environment variables in our reports and/or use them as part of a formula or expression, as a filter condition in a SQL query, and so on.

That is, we now have the capacity to vary the content of our report accordingly; for example, according to the user who runs it. We can, for example, show or hide charts, establish dynamic filters in our data sets, configure the look and feel (colors, images, and so on), hide the selector section, and so on.

We can take a wide variety of actions depending on the specific need of each case.

On practice

As we mentioned earlier, there are many examples that can be given for environment variables, from something as simple as displaying them to really complex actions such as varying the look and feel of our report. What we will do in this chapter with environment variables is configure the look and feel of our report in a simple and pleasant exercise that, although it is simple, still shows the capacities we want to analyze.

Before we formally begin the exercise, we need to talk about one of the new and impressive characteristics of PRD, stylesheets!

Learning CSS

Cascading Stylesheets (CSS) is a language used to describe the visual presentation of a tag-structured document; for example, HTML, XHTML, XML, SVG, and XUL.

CSS is based on a group of Rules through which we can configure the color, position, visibility, size, borders, and so on of the content of any tag in our document. CSS lets us reference these tags in different ways; for example, through their name, class, ID, and so on.

Basically, a CSS Rule consists of two parts: the tag selector and the style to be applied.

Stylesheets in PRD

PRD uses CSS3 to implement stylesheets, which allows, among other things, correct integration with the most popular web browsers.

The stylesheets' code in PRD is stored in an XML file with the extension .prptstyle. This file can be created, exported, and modified from the PRD UI using the Style Definition Editor. Also, this file can be embedded in our report or simply linked to it.

Using stylesheets in PRD will make the design of the final presentation of our reports easier and will save us a lot of manual configuration time, in addition to separating the presentation logic from the report logic. That is, we can create our stylesheets just once and then apply them to all of our reports. If, for example, our company changes its logo, colors, font face, and so on, we don't have to modify each and every report. We just modify the CSS assigned to the reports.

The Style Definition Editor

To open the Style Definition Editor, navigate to the main menu and then to the option Extras | Style Definition Editor.

The Style Definition Editor

To open a .prptstyle file, navigate to the option File | Open....

To add a new CSS Rule, click on the Add Style-Rule option as shown in the following screenshot:

The Style Definition Editor

This will create an empty CSS Rule as shown in the following screenshot:

The Style Definition Editor

Type the tag selector in the upper field and use the options below it to describe the style.

To save the changes, navigate to File | Save or File | Save As..., whichever is appropriate.

To delete a CSS Rule, click on the Remove Style-Rule option.

Applying CSS

In order for our report to use a .prptstyle file's CSS Rules, we select the Master Report node in the Structure tab and configure the value of Attributes.style-sheet-reference.

When creating tag selectors in our CSS Rules, we can reference any node in our report's structure; that is, a complete section or an object. Also, by using the options Attributes.style-class and Attributes.id, we can reference any node by its class or ID, respectively.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset