Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Div
idProductTOC

On this page

Table of Contents
maxLevel1
excludeOn this page
typeflat
separator |

...

Table plus
border0
heading0
multiplefalse
enableHeadingAttributesfalse
columnAttributesstyle="border:0;width=5%;",style="border:0;width=65%;",style="border:0;width=30%;max-width=30% !important;"
enableSortingfalse
classingredients_table
enableHighlightingfalse

Ingredients

...

Table plus
border0
heading0
multiplefalse
enableHeadingAttributesfalse
columnAttributesstyle="border:0;width=5%;",style="border:0;width=65%;",style="border:0;width=30%;max-width=30% !important;"
idsteps_table
enableSortingfalse
enableHighlightingfalse

Create Confluence page

Div
classtime

Estimated Time: 2 min

Create a Confluence page that will eventually contain the macros needed to produce the chart.

  1. Create a page named Monthly Sales By Product in a space accessible to the desired audience.
  2. Click the Unrestricted button to open the Page Restrictions screen.
  3. Click the Restrict editing radio button.
  4. Start typing confluence-administrators in the text box and select that group name from the list of suggestions to apply an edit restriction to that group. (info) This restriction is being added so that Macro Security managed macros can be used. You will be configuring Macro Security in a later step.
  5. Click Save to close the Page Restrictions screen.
  6. Click Save to save the new page.

 

 

Anchor
step1
step1
Adding page restrictions:



Configure the Run macro

Div
classtime

 Estimated Time: 3 min 

Edit the Monthly Sales By Product page and do the following:

  1. Insert the Run with a user form and parameters macro.
  2. Click the Run with a user form and parameters macro container and click Edit so you can adjust its parameters as shown on the right.
    1. The Replace field list parameter indicates to display the following 2 fields as selection criteria:
      1. The first field is a single select list that allows the user to select the Product. Each string within this field is delimited with a colon (:) except for the final one, which ends with a comma (,) to signify the end of the field.

        Field 1:

        Div
        stylemax-width: 600px;
        StringDescription
        product:This is the key, which is "product." In a later step, you will refer to this field as ""$product" so its value can be substituted.
        Samplesoft product:This is the value, which Indicates the initial value for the product field.
        Select a Product:This is the description, which indicates how the product field will be labelled when shown on-screen.
        select:This is the field type, indicating it should be a single select list.
        1:This is the number of rows that should be visible in the select list before the user clicks the dropdown arrow.
        Demoware:Demoware product:"Demoware" defines the replacement value of the first entry in the Product select list. "Demoware product" defines the text that is displayed to the user for this first entry in the select list.
        Samplesoft:Samplesoft product"Samplesoft" defines the replacement value of the second entry in the Product select list. "Samplesoft product" defines the text that is displayed to the user for this second entry in the select list.
        Usecaser:Usercaser product"Usecaser" defines the replacement value of the third entry in the Product select list. "Usecaser product" defines the text that is displayed to the user for this third entry in the select list.
      2. The second field is a single select list that allows the user to select the year for which sales data should be selected. As with the first field, each string within this field is delimited with a colon (:) except for the final one, which needs nothing following it since it is the last field.

        Field 2:

        Div
        stylemax-width: 600px;
        StringDescription
        year:This is the key, which is "year." In a later step, you will refer to this field as ""$year" so its value can be substituted.
        2014:This is the value, which Indicates the initial value for the year field.
        Select a YearThis is the description, which indicates how the year field will be labelled when shown on-screen.
        integer-selectThis is the field type, indicating it should be a select list of integers.
        2012:This indicates the lower bound of the Year select list.
        2015"2012" indicates the upper bound of the Year select list. Along with the lower bound, this means that the Year select list will list 2012, 2013, 2014 and 2015.
    2. The Automatically render body on display parameter indicates to automatically run the report when the Confluence page is rendered.
    3. The Field name to receive focus parameter indicates the field in which the cursor will be positioned when the Confluence page is initially displayed. This is set to the first field (Select a Product) to facilitate the user's selection for this field.
  3. Click Save to save your changes to the Run macro's parameters.

Anchor
step2
step2
Run macro parameters:

Div
stylemax-width: 600px;
Replace field list
product:Samplesoft product:Select a Product:select:1:Demoware:Demoware product:Samplesoft:Samplesoft product:Usecaser:Usercase product,year:2014:Select a Year:integer-select:2012:2015
Automatically render body on display
trueselected
Field name to receive focus
Select a Product

 

Form generated by Run macro:



 

Configure the Chart macro

Div
classtime

Estimated Time: 2-3 min 

Edit the Monthly Sales By Product page and do the following:

  1. With the cursor positioned within the Run macro, insert the Chart macro.
  2. Click the Chart macro container and click Edit so you can adjust its parameters as shown on the right.
    • The Type parameter indicates to display a bar chart.
    • The Width parameter indicates the width of the chart in pixels.
    • The Height parameter indicates the height of the chart in pixels.
    • The Display rendered data parameter indicates that a data table should be displayed after (below) the chart.
    • The Chart Title parameter provides a title for the chart with the user-selected values substituted for $year and $product.
    • The Columns parameter indicates to use the first two columns of the SQL data as the data for the bar chart. You will be defining the data in the next step when you configure the SQL Query macro.
  3. Click Save to save your changes to the Chart macro's parameters.

Anchor
step3
step3
Chart macro parameters:

Typebar
Width (pixel value only)700
Height (pixel value only)500
Display rendered dataafter
Chart Title$year Monthly Sales for $product
Columns1,2


Monthly Sales By Product page, in Edit mode:



Configure the SQL Query macro

Div
classtime

Estimated Time: 2 min 

This step uses the SQL Query macro, which is part of the SQL for Confluence (Pro Edition) and SQL for Confluence (Express Edition) add-ons, to retrieve the data that will be displayed in the bar chart. To configure the SQL Query macro, do the following:

  1. With the cursor positioned inside the Chart macro container, insert the SQL Query macro.
  2. Adjust its parameters as shown on the right.
    • The Data source name parameter indicates to use the examplegeardb data source profile that you set up when installing the Examplegear database.
    • The Show error if there are no rows parameter indicates to show an error if no rows are returned in the resultset of the SQL query.
    • The Text to display when there are no rows parameter indicates the text of the error message to be displayed when no rows are returned in the resultset of the SQL query.
  3. Click Save to save your changes to the SQL Query macro's parameters.
  4. With the cursor positioned inside the SQL Query macro container, paste in these SQL statements:

    Code Block
    languagesql
    themeDJango
    linenumberstrue
    SELECT DATE_FORMAT(S.OrderDate, '%b') AS Month, ROUND(SUM(S.SubTotal)) As Revenue
    FROM Sales S
    INNER JOIN LineItems LI ON S.SalesID = LI.SalesID
    INNER JOIN Products P ON LI.ProductID = P.ProductID
    WHERE YEAR(S.OrderDate) = $year AND P.BaseProductName = '$product'
    GROUP BY DATE_FORMAT(S.OrderDate, '%m/%Y')
    ORDER BY DATE_FORMAT(S.OrderDate, '%m/%Y'); 

 

Info

In the SQL statements, the DATE_FORMAT(S.OrderDate, '%b') indicates to show the month name (e.g., Jan, Feb, Mar, etc.), but the GROUP BY and ORDER BY clauses must use DATE_FORMAT(S.OrderDate, '%m/%Y') in order to ensure the months are shown in ascending order numerically.

Anchor
step4
step4
SQL Query macro parameters:

Data source nameexamplegeardb
Show error if there are no rowstrueselected
Text to display when there are no rowsNo rows selected


Monthly Sales by Product page, in Edit mode


Configure Macro Security

Div
classtime

 Estimated Time: 2-3 min

Before you save the Monthly Sales By Product page, you should install the Macro Security for Confluence add-on and configure it with a property file that identifies who can run each security-enabled macro. Each macro security enabled macro accepts specific parameters to controls its use. This safeguards your Confluence instance and data from misuse or performance issues caused by inexperienced users or inappropriate use.

Follow these steps to configure it:

  1. Download the sample macro-security.properties file that is configured for moderate restrictions. This restricts most security-enabled macros so that only Administrators can execute them, but allows some others to be used by any user.
  2. Review the file and ensure that the lines beginning with "sql-query.datasource.*", "run" and "run-now" are restricted to the confluence-administrators group as shown in the example configuration file to the right.

  3. Save the file.
  4. Create a Confluence page entitled Macro Security Configuration in a space accessible only to Administrators (or apply page-level restrictions so the page is accessible only to Administrators) and attach the file to it. Take note of the space key of the space. The space key appears in the URL of the page after you've saved, immediately after "display/". For instance, in the URL http://wiki.examplegear.com/display/admin/Macro Security Configuration, the space key is admin.
  5. Go to Manage Add-ons administration screen, locate the Macro Security add-on and click its Configure button. This will take you to the Macro Security configuration screen.
  6. In the Load Security Configuration section, supply the location of your macro-security.properties file, in the form of spacekey:pagetitle^filename such as admin:Macro Security Configuration^macro-security.properties and click Load.
  7. Select the Enable button and click Save.

Anchor
step5
step5
Example configuration file:

Code Block
languagetext
themeDJango
titlemacro-security.properties file
linenumberstrue
# See the documentation space - https://bobswiftappfire.atlassian.net/wiki/display/CMSP
# More specifically:
# - managed macros: https://bobswiftappfire.atlassian.net/wiki/display/CMSP/Macro+Security+Managed+Macros
#
# Macro security is enabled/disabled from the UPM configure link for Macro Security for Confluence
# Property setting are loaded from the same configuration screen.
#
# Property settings here can restrict use of some powerful macro capabilities to trusted users
#   while still allowing non-trusted users to view content created by using these macros
# - this is accomplished by requiring those pages using the restricted macros
#   are controlled by trusted users
#   - a page is controlled by having edit capabilities restricted to a group
#     that is identified as being trusted in the properties file
#   - a page is also considered to be controlled if it is in a permitted space
#
# Property file
# - The property file can be loaded from any file location on the Confluence server or from an attachment
#
# No specific configuration
# - Add-ons can implement their own rules if there is no specific configuration found
#   depending on what they are restricting
# - Standard/default is
#   - Configuration entry must be specified if the macro is restricted
#     - *ANY can be used to allow all use (run is an example where *ANY is a likely use)
#   - Some macros have additional, finer grained (parameter level) restrictions
#     - these MUST also have something specified, otherwise macro use is not authorized
#   - Some macros only restrict a specific parameter
#     - these generally do not have to be specifically configured for use
#
# Property keys and values are case sensitive
#
# Property values are a comma separated list of groups or space names
# - the page edit restriction must match one of the groups listed
# - no other users or groups can be permitted to edit the page
# - use *ANY to indicate no restriction
#
 
# SQL - https://bobswiftappfire.atlassian.net/wiki/display/SQL
sql = confluence-administrators
sql.datasource.* = confluence-administrators
sql.datasource.testDS = *ANY
sql.limit = confluence-administrators
sql.disableAntiXss = confluence-administrators
sql.querytimeout = confluence-administrators
 
sql-query = confluence-administrators
sql-query.datasource.* = confluence-administrators
sql-query.datasource.testDS = *ANY
sql-query.limit = confluence-administrators
sql-query.disableAntiXss = confluence-administrators
sql-query.querytimeout = confluence-administrators
 
# Live template support - https://bobswiftappfire.atlassian.net/wiki/display/CMSP/Live+Template+Support
sql-query&live-template.datasource.* = *global
 
# Script - https://bobswiftappfire.atlassian.net/wiki/display/SCRP
beanshell = confluence-administrators
groovy = confluence-administrators
gant = confluence-administrators
jython = confluence-administrators
 
# HTML - https://bobswiftappfire.atlassian.net/wiki/display/HTML
html = confluence-administrators
xslt = confluence-administrators
 
# Run CLI Actions - https://bobswiftappfire.atlassian.net/wiki/display/CCLI
cli = confluence-administrators
cli.profile.* = confluence-administrators
cli.product.* = confluence-administrators
cli.directory.* = confluence-administrators
cli.datasource.* = confluence-administrators
 
include-remote = confluence-administrators
include-remote.profile.* = confluence-administrators
 
# Cache - https://bobswiftappfire.atlassian.net/wiki/display/CACHE
cache = *ANY
future = *ANY
future.timeout = confluence-administrators
 
# Run - https://bobswiftappfire.atlassian.net/wiki/display/RUN
run = confluence-administrators
run-now = confluence-administrators
run.disableAntiXss = confluence-administrators
 
# Advanced Tables - https://bobswiftappfire.atlassian.net/wiki/display/TBL
csv.url.* = *ANY
csv.disableAntiXss = confluence-administrators
json-table.url.* = *ANY
json-table.disableAntiXss = confluence-administrators
 
# Excel - https://bobswiftappfire.atlassian.net/wiki/display/XL
excel.url.* = *ANY
excel.disableAntiXss = confluence-administrators
 
# Flash - https://bobswiftappfire.atlassian.net/wiki/display/FLASH
flash.url.* = confluence-administrators
 
# Markdown - https://bobswiftappfire.atlassian.net/wiki/display/MARKDOWN
markdown.allowHtml = confluence-administrators
markdown-attachment.allowHtml = confluence-administrators
markdown-url.allowHtml = confluence-administrators
 
# Code Pro - https://bobswiftappfire.atlassian.net/wiki/display/CODE
code-pro.url = *ANY
code-pro.profile.* = confluence-administrators

 

Macro Security Configuration page, after loading the macro-security.properties file:


Save and test the page

Div
classtime

  Estimated Time: 2-3 min 

Now, go back to the Monthly Sales by Product page and click Save to save it. You should now see a page that appears as shown on the right. The bar chart is shown, with the data table appearing after it.

To run the report with different selection criteria, just select a different Product and/or Year and click the Run button.

If you see an error such as "Error rendering macro 'sql-query' : com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException", then check the syntax of the SELECT statement within the SQL Query macro container.

If you see an error such as "Error rendering macro 'sql-query' : Unable to connect to database", then verify that the SQL Query macro's Data source name parameter is set to the correct value and that the examplegeardb data source profile was set up per the installation instructions.

 

 

Anchor
step6
step6
Monthly Sales by Product page, in View mode:

...