Versions Compared

Key

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

...

Code Examples

the following 2 examples can be found in the working sample logic Dashboard_Portlet_Dimensions

Code Block
languagegroovy
themeMidnight
titleExample of a Dashboard logic element, with ResultMatrix
linenumbersfalse
final Integer INITIAL_WIDTH = 600  // 600 pixels
final Integer INITIAL_HEIGHT = 200  // 200 pixels

ResultMatrix resultMatrix = createSampleResultMatrix()

// Sets initial width and height for the returned result matrix.
// Result matrix represents the portlet, so this becomes initial portlet dimensions
resultMatrix.withLayout(INITIAL_WIDTH, INITIAL_HEIGHT)  //❶

return resultMatrix


/**
 * Sample result matrix, representing a portlet with data formatted in table
 * @return
 */
ResultMatrix createSampleResultMatrix() {
    defResultMatrix resultMatrix = api.newMatrix("Customer Id", "Net Margin %")

    resultMatrix.addRow(["Customer Id": "C1", "Net Margin %": 0.104])
    resultMatrix.addRow(["Customer Id": "C2", "Net Margin %": 0.044])
    resultMatrix.addRow(["Customer Id": "C3", "Net Margin %": 0.014])

    return resultMatrix
}

❶ see withLayout() in Groovy API

Code Block
languagegroovy
themeMidnight
titleExample of Dashboard logic element, with DashboardController
linenumbersfalse
final Integer INITIAL_WIDTH = 300  // 300 pixels
final Integer INITIAL_HEIGHT = 500  // 500 pixels

def controller = createSampleDashboardController()

// Sets initial width and height for the returned controller.
// Dashboard Controller represents the portlet, so this becomes initial portlet dimensions.
controller.withLayout(INITIAL_WIDTH, INITIAL_HEIGHT)    //❶

return controller


/**
 * Sample dashboard controller, representing a portlet with html content
 * @return
 */
def createSampleDashboardController() {
    def controller = api.newController()
    controller.addButton("Show Products", AppPages.MD_PRODUCTS_PAGE)
    def lorem = "<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nullam sit amet magna in magna gravida vehicula. Aliquam id dolor. Cras elementum.</p>"
    (1..3).each { controller.addHTML(lorem) }
    return controller
}

❶ see withLayout() in Groovy API