Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 992eaf8

Browse files
committed
Force button does not work when using the new categories in farmreport (Bug #215)
1 parent 531e859 commit 992eaf8

File tree

2 files changed

+206
-92
lines changed

2 files changed

+206
-92
lines changed

project/WebDashboard/Plugins/FarmReport/CategorizedFarmReportFarmPlugin.cs

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
using ThoughtWorks.CruiseControl.WebDashboard.Resources;
1313
using ThoughtWorks.CruiseControl.WebDashboard.ServerConnection;
1414

15+
using ThoughtWorks.CruiseControl.Core.Reporting.Dashboard.Navigation;
16+
using System;
17+
using ThoughtWorks.CruiseControl.Core;
18+
using System.Web;
19+
20+
1521
[ReflectorType("categorizedFarmReportFarmPlugin")]
1622
public class CategorizedFarmReportFarmPlugin : IPlugin, ICruiseAction
1723
{
@@ -41,7 +47,7 @@ public CategorizedFarmReportFarmPlugin(IFarmService farmService,
4147
public INamedAction[] NamedActions
4248
{
4349
get
44-
{
50+
{
4551
return new INamedAction[] { this.baseAction };
4652
}
4753
}
@@ -62,26 +68,38 @@ public IResponse Execute(ICruiseRequest request)
6268
var urlBuilder = request.UrlBuilder;
6369
var category = request.Request.GetText("Category");
6470

65-
var gridRows = this.projectGrid.GenerateProjectGridRows(projectStatus.StatusAndServerList, BaseActionName,
66-
ProjectGridSortColumn.Category, true,
67-
category, urlBuilder,this.translations);
71+
var sessionToken = request.RetrieveSessionToken();
72+
velocityContext["forceBuildMessage"] = ForceBuildIfNecessary(request.Request, sessionToken);
73+
74+
var gridRows = this.projectGrid.GenerateProjectGridRows(projectStatus.StatusAndServerList, BaseActionName,
75+
ProjectGridSortColumn.Category, true,
76+
category, urlBuilder, this.translations);
6877

6978
var categories = new SortedDictionary<string, CategoryInformation>();
70-
79+
7180
foreach (var row in gridRows)
7281
{
7382
var rowCategory = row.Category;
7483
CategoryInformation categoryRows;
7584
if (!categories.TryGetValue(rowCategory, out categoryRows))
7685
{
7786
categoryRows = new CategoryInformation(rowCategory);
78-
categories.Add(rowCategory, categoryRows);
87+
categories.Add(rowCategory, categoryRows);
7988
}
8089

81-
categoryRows.AddRow(row);
90+
categoryRows.AddRow(row);
8291
}
8392

84-
velocityContext["categories"] = categories.Values;
93+
// there is a category specified via a link, so expand that category by default
94+
// it's annoying to specify a category and still have to press the show link
95+
if (!string.IsNullOrEmpty(category))
96+
{
97+
categories[category].Display = true;
98+
}
99+
100+
101+
102+
velocityContext["categories"] = categories.Values;
85103

86104
return viewGenerator.GenerateView("CategorizedFarmReport.vm", velocityContext);
87105
}
@@ -116,5 +134,53 @@ public void AddRow(ProjectGridRow row)
116134
}
117135
}
118136
}
137+
138+
private string ForceBuildIfNecessary(IRequest request, string sessionToken)
139+
{
140+
Dictionary<string, string> parameters = new Dictionary<string, string>();
141+
foreach (string parameterName in HttpContext.Current.Request.Form.AllKeys)
142+
{
143+
if (parameterName.StartsWith("param_"))
144+
{
145+
parameters.Add(parameterName.Substring(6), HttpContext.Current.Request.Form[parameterName]);
146+
}
147+
}
148+
// Make the actual call
149+
if (request.FindParameterStartingWith("StopBuild") != string.Empty)
150+
{
151+
farmService.Stop(ProjectSpecifier(request), sessionToken);
152+
return this.translations.Translate("Stopping project {0}", SelectedProject(request));
153+
}
154+
else if (request.FindParameterStartingWith("StartBuild") != string.Empty)
155+
{
156+
farmService.Start(ProjectSpecifier(request), sessionToken);
157+
return this.translations.Translate("Starting project {0}", SelectedProject(request));
158+
}
159+
else if (request.FindParameterStartingWith("ForceBuild") != string.Empty)
160+
{
161+
farmService.ForceBuild(ProjectSpecifier(request), sessionToken, parameters);
162+
return this.translations.Translate("Build successfully forced for {0}", SelectedProject(request));
163+
}
164+
else if (request.FindParameterStartingWith("AbortBuild") != string.Empty)
165+
{
166+
farmService.AbortBuild(ProjectSpecifier(request), sessionToken);
167+
return this.translations.Translate("Abort successfully forced for {0}", SelectedProject(request));
168+
}
169+
else
170+
{
171+
return string.Empty;
172+
}
173+
}
174+
private DefaultProjectSpecifier ProjectSpecifier(IRequest request)
175+
{
176+
return new DefaultProjectSpecifier(
177+
farmService.GetServerConfiguration(request.GetText("serverName")), SelectedProject(request));
178+
}
179+
private static string SelectedProject(IRequest request)
180+
{
181+
return request.GetText("projectName");
182+
}
183+
119184
}
185+
120186
}
Lines changed: 132 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,140 @@
1-
<span>
1+
<script type="text/javascript">
2+
$(function(){
3+
$('#parameterCheck').dialog({
4+
autoOpen:false,
5+
modal:true,
6+
title:'$translations.Translate("Project Parameters")',
7+
width:400,
8+
height:300,
9+
overlay:{
10+
opacity:0.5,
11+
background:'black'
12+
}
13+
});
14+
#if ($wholeFarm)
15+
var sortList = [[0,0],[1,0]];
16+
#else
17+
var sortList = [[0,0]];
18+
#end
19+
$('#StatusGrid').initialiseProjectGrid({
20+
sortList:sortList
21+
});
22+
});
23+
</script>
24+
<div id="parameterCheck" style="display:none;">
25+
<div id="parameterEditor">$translations.Translate("Loading parameters, please wait...")</div>
26+
</div>
27+
<form id="RefreshForm"
28+
method="post">
29+
<table width="100%">
30+
<tr>
31+
<td align="right">
32+
<input type="submit"
33+
align="right"
34+
name="Refresh"
35+
value="$translations.Translate("Refresh status")" />
36+
</td>
37+
</tr>
38+
</table>
39+
</form>
40+
41+
#if ($forceBuildMessage.Length > 0)
42+
<P>
43+
<span id="StatusLabel">
44+
<b>
45+
<font color="#4A3C8C">$translations.Translate($forceBuildMessage)</font>
46+
</b>
47+
</span>
48+
</P>
49+
#end
50+
51+
<span>
252
<div style="margin-bottom: 5px; text-align: right">
3-
<a id="showAll" style="cursor:pointer;color:blue; text-decoration:underline;" onclick="$('.showLink').hide(); $('.hideLink').show(); $('.statusTable').show()">$translations.Translate("Show All")</a>
4-
<a id="hideAll" style="margin-right:25px;cursor:pointer;color:blue; text-decoration:underline;" onclick="$('.showLink').show(); $('.hideLink').hide(); $('.statusTable').hide()">$translations.Translate("Hide All")</a>
53+
<a id="showAll" style="cursor:pointer;color:blue; text-decoration:underline;" onclick="$('.showLink').hide(); $('.hideLink').show(); $('.statusTable').show()">$translations.Translate("Show All")</a>
54+
<a id="hideAll" style="margin-right:25px;cursor:pointer;color:blue; text-decoration:underline;" onclick="$('.showLink').show(); $('.hideLink').hide(); $('.statusTable').hide()">$translations.Translate("Hide All")</a>
555
</div>
656
#set ($categoryId = 0)
757
#foreach ($category in $categories)
8-
#set ($categoryId = $categoryId + 1)
9-
<div style="padding: 1px; background: white;"></div>
10-
<div style="padding: 5px; margin-right: 0.5px; background: $category.CategoryColor; color: white;">
11-
<span style="font-size: 150%; font-weight: bold; font-family: verdana,helvetica,arial,san-serif;">$category.Name</span>
12-
<span>
13-
<a id="showGrid$categoryId" class="showLink"
14-
style="color: white; text-decoration: underline; cursor: pointer; #if( $category.Display) display: none; #end"
15-
onclick="$('#showGrid$categoryId').hide(); $('#hideGrid$categoryId').show(); $('#statusGrid$categoryId').show()">$translations.Translate("show")</a>
16-
<a id="hideGrid$categoryId" class="hideLink"
17-
style="color: white; text-decoration: underline; cursor: pointer; #if( !$category.Display) display: none; #end"
18-
onclick="$('#showGrid$categoryId').show(); $('#hideGrid$categoryId').hide(); $('#statusGrid$categoryId').hide()">$translations.Translate("hide")</a>
19-
</span>
20-
</div>
58+
#set ($categoryId = $categoryId + 1)
59+
<div style="padding: 1px; background: white;"></div>
60+
<div style="padding: 5px; margin-right: 0.5px; background: $category.CategoryColor; color: white;">
61+
<span style="font-size: 150%; font-weight: bold; font-family: verdana,helvetica,arial,san-serif;">$category.Name</span>
62+
<span>
63+
<a id="showGrid$categoryId" class="showLink"
64+
style="color: white; text-decoration: underline; cursor: pointer; #if( $category.Display) display: none; #end"
65+
onclick="$('#showGrid$categoryId').hide(); $('#hideGrid$categoryId').show(); $('#statusGrid$categoryId').show()">$translations.Translate("show")</a>
66+
<a id="hideGrid$categoryId" class="hideLink"
67+
style="color: white; text-decoration: underline; cursor: pointer; #if( !$category.Display) display: none; #end"
68+
onclick="$('#showGrid$categoryId').show(); $('#hideGrid$categoryId').hide(); $('#statusGrid$categoryId').hide()">$translations.Translate("hide")</a>
69+
</span>
70+
</div>
2171

22-
<table id="statusGrid$categoryId" class="SortableGrid statusTable"
72+
<table id="statusGrid$categoryId" class="SortableGrid statusTable"
2373
style="#if( !$category.Display) display: none; #end ">
24-
<thead>
25-
<tr class="ProjectGridHeader">
26-
<th class="left">$translations.Translate("Server")</th>
27-
<th class="left">$translations.Translate("Project Name")</th>
28-
<th>$translations.Translate("Last Build Status")</th>
29-
<th>$translations.Translate("Last Build Time")</th>
30-
<th>$translations.Translate("Next Build Time")</th>
31-
<th>$translations.Translate("Last Build Label")</th>
32-
<th>$translations.Translate("CCNet Status")</th>
33-
<th>$translations.Translate("Activity")</th>
34-
<th class="{sorter:false}">$translations.Translate("Messages")</th>
35-
<th class="{sorter:false}">$translations.Translate("Admin")</th>
36-
</tr>
37-
</thead>
38-
#foreach ($row in $category.Rows)
39-
<tr>
40-
<td>$row.ServerName</td>
41-
<td>
42-
<a href="$row.Url" title="$row.Description">$row.Name</a>
43-
</td>
44-
<td class="$row.BuildStatusHtmlColor">$translations.Translate($row.BuildStatus)</td>
45-
<td>$translations.Translate($row.LastBuildDate)</td>
46-
<td>$translations.Translate($row.NextBuildTime)</td>
47-
<td>$row.LastBuildLabel</td>
48-
<td class="status$row.Status">$translations.Translate($row.Status)</td>
49-
<td class="activity$row.Activity">$translations.Translate($row.Activity.ToString())</td>
50-
<td>
51-
<ul>
52-
#if ($row.Breakers.Length > 0)
53-
<li>$translations.Translate("Breakers : {0}", $row.Breakers)</li>
54-
#end
55-
#if ($row.Fixer.Length > 0)
56-
<li>$row.Fixer</li>
57-
#end
58-
#if ($row.FailingTasks.Length > 0)
59-
<li>$translations.Translate("Failing Tasks : {0}", $row.FailingTasks)</li>
60-
#end
61-
</ul>
62-
</td>
63-
<td>
64-
<form method="post" style="margin-bottom:0px;">
65-
<input type="hidden" name="projectName" value="$row.Name" />
66-
<input type="hidden" name="serverName" value="$row.ServerName" />
67-
<font color="Black">
68-
#if ($row.allowForceBuild)
69-
#if($row.ForceAbortBuildButtonValue == "Force")
70-
<input type="button"
71-
name="$row.ForceAbortBuildButtonName"
72-
value="$translations.Translate($row.ForceAbortBuildButtonValue)"
73-
onclick="checkForParams(this, '$row.ParametersUrl')"/>
74-
#else
75-
<input type="submit"
76-
name="$row.ForceAbortBuildButtonName"
77-
value="$translations.Translate($row.ForceAbortBuildButtonValue)"/>
78-
#end
79-
#end
80-
#if ($row.AllowStartStopBuild)
81-
<input type="submit"
82-
name="$row.StartStopButtonName"
83-
value="$translations.Translate($row.StartStopButtonValue)"/>
84-
#end
85-
</font>
86-
</form>
87-
</td>
88-
</tr>
89-
#end
74+
<thead>
75+
<tr class="ProjectGridHeader">
76+
<th class="left">$translations.Translate("Server")</th>
77+
<th class="left">$translations.Translate("Project Name")</th>
78+
<th>$translations.Translate("Last Build Status")</th>
79+
<th>$translations.Translate("Last Build Time")</th>
80+
<th>$translations.Translate("Next Build Time")</th>
81+
<th>$translations.Translate("Last Build Label")</th>
82+
<th>$translations.Translate("CCNet Status")</th>
83+
<th>$translations.Translate("Activity")</th>
84+
<th class="{sorter:false}">$translations.Translate("Messages")</th>
85+
<th class="{sorter:false}">$translations.Translate("Admin")</th>
86+
</tr>
87+
</thead>
88+
#foreach ($row in $category.Rows)
89+
<tr>
90+
<td>$row.ServerName</td>
91+
<td><a href="$row.Url" title="$row.Description">$row.Name</a></td>
92+
<td class="$row.BuildStatusHtmlColor">$translations.Translate($row.BuildStatus)</td>
93+
<td>$translations.Translate($row.LastBuildDate)</td>
94+
<td>$translations.Translate($row.NextBuildTime)</td>
95+
<td>$row.LastBuildLabel</td>
96+
<td class="status$row.Status">$translations.Translate($row.Status)</td>
97+
<td class="activity$row.Activity">$translations.Translate($row.Activity.ToString())</td>
98+
<td>
99+
<ul>
100+
#if ($row.Breakers.Length > 0)
101+
<li>$translations.Translate("Breakers : {0}", $row.Breakers)</li>
102+
#end
103+
#if ($row.Fixer.Length > 0)
104+
<li>$row.Fixer</li>
105+
#end
106+
#if ($row.FailingTasks.Length > 0)
107+
<li>$translations.Translate("Failing Tasks : {0}", $row.FailingTasks)</li>
108+
#end
109+
</ul>
110+
</td>
111+
<td>
112+
<form method="post" style="margin-bottom:0px;">
113+
<input type="hidden" name="projectName" value="$row.Name" />
114+
<input type="hidden" name="serverName" value="$row.ServerName" />
115+
<font color="Black">
116+
#if ($row.allowForceBuild)
117+
#if($row.ForceAbortBuildButtonValue == "Force")
118+
<input type="button"
119+
name="$row.ForceAbortBuildButtonName"
120+
value="$translations.Translate($row.ForceAbortBuildButtonValue)"
121+
onclick="checkForParams(this, '$row.ParametersUrl')"/>
122+
#else
123+
<input type="submit"
124+
name="$row.ForceAbortBuildButtonName"
125+
value="$translations.Translate($row.ForceAbortBuildButtonValue)"/>
126+
#end
127+
#end
128+
#if ($row.AllowStartStopBuild)
129+
<input type="submit"
130+
name="$row.StartStopButtonName"
131+
value="$translations.Translate($row.StartStopButtonValue)"/>
132+
#end
133+
</font>
134+
</form>
135+
</td>
136+
</tr>
137+
#end
90138
</table>
91-
#end
139+
#end
92140
</span>

0 commit comments

Comments
 (0)