Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more options for dashboard view #824

Merged
merged 1 commit into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ dashboardView('example') {
buildButton()
}
topPortlets {
jenkinsJobsList {
displayName('acme jobs')
}
}
leftPortlets {
testStatisticsChart()
}
rightPortlets {
testTrendChart()
}
bottomPortlets {
iframe {
effectiveUrl('http://example.com')
}
testStatisticsGrid()
buildStatistics()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ class DashboardView extends ListView {
}
}
}

static enum DisplayStatus {
ALL, SUCCESS, FAILED, SKIPPED
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package javaposse.jobdsl.dsl.views.portlets

import javaposse.jobdsl.dsl.Context

class BuildStatisticsContext implements Context {

String displayName = 'Build statistics'

/**
* Sets the display name for the portlet. Defaults to {@code 'Build statistics'}.
*/
void displayName(String displayName) {
this.displayName = displayName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,55 @@ class DashboardPortletContext implements Context {

protected final List<Node> portletNodes = []

/**
* Add a build statistics.
*
* @since 1.46
*/
void buildStatistics(@DslContext(BuildStatisticsContext) Closure closure = null) {
BuildStatisticsContext context = new BuildStatisticsContext()
ContextHelper.executeInContext(closure, context)

portletNodes << new NodeBuilder().'hudson.plugins.view.dashboard.stats.StatBuilds' {
id(generatePortletId())
name(context.displayName ?: '')
}
}

/**
* Add a iframe portlet.
*
* @since 1.46
*/
void iframe(@DslContext(IframeContext) Closure closure = null) {
IframeContext context = new IframeContext()
ContextHelper.executeInContext(closure, context)

portletNodes << new NodeBuilder().'hudson.plugins.view.dashboard.core.IframePortlet' {
id(generatePortletId())
name(context.displayName ?: '')
iframeSource(context.iframeSource ?: '')
effectiveSource(context.effectiveSource ?: '')
effectiveUrl(context.effectiveUrl ?: '')
divStyle(context.divStyle ?: '')
}
}

/**
* Add a jenkins jobs list.
*
* @since 1.46
*/
void jenkinsJobsList(@DslContext(JenkinsJobsListContext) Closure closure = null) {
JenkinsJobsListContext context = new JenkinsJobsListContext()
ContextHelper.executeInContext(closure, context)

portletNodes << new NodeBuilder().'hudson.plugins.view.dashboard.core.HudsonStdJobsPortlet' {
id(generatePortletId())
name(context.displayName ?: '')
}
}

/**
* Adds a test statistics chart.
*/
Expand Down Expand Up @@ -41,6 +90,26 @@ class DashboardPortletContext implements Context {
}
}

/**
* Adds a trend chart.
*
* @since 1.46
*/
void testTrendChart(@DslContext(TestTrendChartContext) Closure closure = null) {
TestTrendChartContext context = new TestTrendChartContext()
ContextHelper.executeInContext(closure, context)

portletNodes << new NodeBuilder().'hudson.plugins.view.dashboard.test.TestTrendChart' {
id(generatePortletId())
name(context.displayName ?: '')
graphWidth(context.graphWidth ?: 200)
graphHeight(context.graphHeight ?: 300)
dateRange(context.dateRange ?: 30)
dateShift(context.dateShift ?: 0)
displayStatus(context.displayStatus)
}
}

private static String generatePortletId() {
"dashboard_portlet_${RANDOM.nextInt(32000)}"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package javaposse.jobdsl.dsl.views.portlets

import javaposse.jobdsl.dsl.Context

class IframeContext implements Context {

String displayName = 'Iframe Portlet'
String iframeSource = ''
String effectiveSource = ''
String effectiveUrl = ''
String divStyle = 'width:100%;height:1000px;'

/**
* Sets the display name for the portlet. Defaults to {@code 'Iframe Portlet'}.
*/
void displayName(String displayName) {
this.displayName = displayName
}

/**
* Sets the iframe source for portlet. Defaults is empty.
*/
void iframeSource(String iframeSource) {
this.iframeSource = iframeSource
}

/**
* Sets the effective source for portlet. Defaults is empty.
*/
void effectiveSource(String effectiveSource) {
this.effectiveSource = effectiveSource
}

/**
* Sets the effective url for portlet. Defaults is empty.
*/
void effectiveUrl(String effectiveUrl) {
this.effectiveUrl = effectiveUrl
}

/**
* Sets the div style for portlet. Defaults to {@code 'width:100%;height:1000px;'}.
*/
void divStyle(String divStyle) {
this.divStyle = divStyle
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package javaposse.jobdsl.dsl.views.portlets

import javaposse.jobdsl.dsl.Context

class JenkinsJobsListContext implements Context {
String displayName = 'Jenkins Jobs List'

/**
* Sets the display name for the portlet. Defaults to {@code 'Jenkins Jobs List'}.
*/
void displayName(String displayName) {
this.displayName = displayName
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package javaposse.jobdsl.dsl.views.portlets

import javaposse.jobdsl.dsl.Context
import javaposse.jobdsl.dsl.views.DashboardView.DisplayStatus

class TestTrendChartContext implements Context {

String displayName = 'Test Trend Chart'
Integer graphWidth = 300
Integer graphHeight = 200
Integer dateRange = 30
Integer dateShift = 0
DisplayStatus displayStatus = DisplayStatus.ALL

/**
* Sets the display name for the portlet. Defaults to {@code 'Test Trend Chart'}.
*/
void displayName(String displayName) {
this.displayName = displayName
}

/**
* Sets the graph width for the this portlet. Defaults to {@code '300'}.
*/
void graphWidth(Integer graphWidth) {
this.graphWidth = graphWidth
}

/**
* Sets the graph height for this portlet. Defaults to {@code '200'}
*/
void graphHeight(Integer graphHeight) {
this.graphHeight = graphHeight
}

/**
* Sets the date range for thies portlet. Defaults to {@code '0'}
*/
void dateRange(Integer dateRange) {
this.dateRange = dateRange
}

/**
* Sets the date shift for this portlet. Defaults to {@code '0'}
*/
void dateShift(Integer dateShift) {
this.dateShift = dateShift
}

/**
* Sets the display status for this portlet. Defaults to {@code DisplayStatus.ALL}.
*/
void displayStatus(DisplayStatus displayStatus) {
this.displayStatus = displayStatus
}
}
Loading