Skip to content

Commit cc69476

Browse files
Mdevlin4zabil
authored andcommitted
Filter for pipeline history view (#2391)
This feature filters the pipeline history using wild card search for revision.
1 parent d269692 commit cc69476

File tree

5 files changed

+108
-12
lines changed

5 files changed

+108
-12
lines changed

server/src/com/thoughtworks/go/server/controller/PipelineHistoryController.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
import com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels;
2525
import com.thoughtworks.go.server.presentation.models.PipelineHistoryJsonPresentationModel;
2626
import com.thoughtworks.go.server.service.*;
27+
import com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult;
2728
import com.thoughtworks.go.server.service.result.ServerHealthStateOperationResult;
2829
import com.thoughtworks.go.server.util.Pagination;
2930
import com.thoughtworks.go.server.util.UserHelper;
31+
import com.thoughtworks.go.util.StringUtil;
3032
import org.springframework.beans.factory.annotation.Autowired;
3133
import org.springframework.stereotype.Controller;
3234
import org.springframework.web.bind.annotation.RequestMapping;
@@ -91,6 +93,7 @@ public ModelAndView list(@RequestParam("pipelineName") String pipelineName) thro
9193
public ModelAndView list(@RequestParam("pipelineName")String pipelineName,
9294
@RequestParam(value = "perPage", required = false)Integer perPageParam,
9395
@RequestParam(value = "start", required = false)Integer startParam,
96+
@RequestParam(value = "labelFilter", required = false) String labelFilter,
9497
HttpServletResponse response, HttpServletRequest request) throws NamingException {
9598
PipelineConfig pipelineConfig = goConfigService.pipelineConfigNamed(new CaseInsensitiveString(pipelineName));
9699
String username = CaseInsensitiveString.str(UserHelper.getUserName().getUsername());
@@ -106,7 +109,10 @@ public ModelAndView list(@RequestParam("pipelineName")String pipelineName,
106109

107110
PipelinePauseInfo pauseInfo = pipelinePauseService.pipelinePauseInfo(pipelineName);
108111
boolean hasBuildCauseInBuffer = pipelineScheduleQueue.hasBuildCause(CaseInsensitiveString.str(pipelineConfig.name()));
109-
PipelineInstanceModels pipelineHistory = pipelineHistoryService.load(pipelineName, pagination, username, true);
112+
PipelineInstanceModels pipelineHistory = StringUtil.isBlank(labelFilter) ?
113+
pipelineHistoryService.load(pipelineName, pagination, username, true) :
114+
pipelineHistoryService.findMatchingPipelineInstances(pipelineName, labelFilter, perPageParam, UserHelper.getUserName(), new HttpLocalizedOperationResult());
115+
110116

111117
boolean hasForcedBuildCause = pipelineScheduleQueue.hasForcedBuildCause(pipelineName);
112118

server/test/integration/com/thoughtworks/go/server/service/PipelineHistoryControllerIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private String getItemInJson(Map jsonMap, String key) {
172172
}
173173

174174
private Map requestPipelineHistoryPage() throws Exception {
175-
ModelAndView modelAndView = controller.list(fixture.pipelineName, 10, 0, response, request);
175+
ModelAndView modelAndView = controller.list(fixture.pipelineName, 10, 0, null, response, request);
176176
return (Map) modelAndView.getModel().get("json");
177177
}
178178

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!-- Code for searching through labels on pipeline history page -->
2+
function applyLabelFilter() {
3+
var inputVal = jQuery("#labelFilterField").val().trim();
4+
if (inputVal.length == 0) {
5+
removeLabelFilter();
6+
return;
7+
}
8+
jQuery('#search-message').text("");
9+
jQuery('#labelFilterClear').show();
10+
jQuery.get("/go/pipelineHistory.json?pipelineName="+pipelineName+"&start=0&perPage=25&labelFilter="+inputVal, function (data) {
11+
filterHistories(data, inputVal);
12+
});
13+
}
14+
15+
// Filters histories that match the search text. Rerenders the view with histories that match the text
16+
function filterHistories(pipelineHistory, filter) {
17+
//Need to stop periodic executor to show only the pipelines matching the filter
18+
dashboard_periodical_executer.stop();
19+
$('page_links').innerHTML = "";
20+
21+
var histories = pipelineHistory.groups[0].history;
22+
var count = histories.length;
23+
if(count == 0) {
24+
jQuery('.pipeline-history-group').html("");
25+
jQuery('#search-message').text("No instances found matching \"" + filter + "\"");
26+
return;
27+
}
28+
29+
pipelineHistory.showForceBuildButton = false;
30+
$('pipeline-history').innerHTML = pipelineHistoryObserver.getTemplate().process(
31+
{ data : pipelineHistory, _MODIFIERS: {
32+
escapeQuotes: function(str) {
33+
return str.replace(/"/g, '&quot;');
34+
},
35+
}});
36+
37+
}
38+
39+
// Removes the applied filter (if there is one) and resumes the periodic executer
40+
function removeLabelFilter() {
41+
jQuery("#labelFilterField").val("");
42+
jQuery('#search-message').text("");
43+
jQuery('#labelFilterClear').hide();
44+
45+
if(!dashboard_periodical_executer.is_execution_start)
46+
dashboard_periodical_executer.start();
47+
}
48+
49+
jQuery( document ).ready(function() {
50+
//Trigger filter when the input field changes
51+
jQuery('#labelFilterField').on('input', function () {
52+
applyLabelFilter();
53+
});
54+
jQuery('#labelFilterClear').hide();
55+
jQuery('#labelFilterClear').click(function(){
56+
removeLabelFilter();
57+
});
58+
});

server/webapp/WEB-INF/rails.new/app/assets/stylesheets/css/pipeline-history.scss

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,32 @@ a.unpause-build-link-disabled {
461461
background-image: image_url('pause-icon.png');
462462
}
463463

464+
#labelFilterField {
465+
width: 250px;
466+
font-size: 1.2em;
467+
}
464468

469+
.label-filter-group {
470+
padding: 5px;
471+
position: fixed;
472+
top: 50px;
473+
z-index: 1200;
474+
right: 10px;
475+
}
465476

477+
#search-message {
478+
font-size: 2em;
479+
padding-left: 10px;
480+
}
466481

467-
468-
469-
482+
.filter-clear-icon {
483+
background: image_url('andare/nav-sprites-pipeline.png') no-repeat 1px 1px;
484+
height: 14px;
485+
width: 14px;
486+
position: absolute;
487+
right: 10px;
488+
padding: 2px;
489+
top: 11px;
490+
opacity: 0.4;
491+
}
470492

server/webapp/WEB-INF/vm/pipeline/pipeline_history.vm

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,25 @@
2626
#parse("shared/_header.vm")
2727

2828
<style type="text/css">
29-
.pipeline-history-group .wrapper .onHover .detail,
30-
.pipeline-history-group .wrapper .onHover .rerun,
31-
.pipeline-history-group .wrapper .onHover .disabled-rerun
32-
{
33-
display:block;
34-
zoom: 1;
35-
}
29+
.pipeline-history-group .wrapper .onHover .detail,
30+
.pipeline-history-group .wrapper .onHover .rerun,
31+
.pipeline-history-group .wrapper .onHover .disabled-rerun {
32+
display: block;
33+
zoom: 1;
34+
}
3635
</style>
3736
<![endif]-->
3837
<textarea rows="0" cols="0" id='pipeline-history-list-template' style="display: none;">
3938
#parse('pipeline/_pipeline_history_list_jstemplate.vm')
4039
</textarea>
4140
<div id="yui-main">
41+
42+
<!-- Pipeline Label Filter -->
43+
<div class="label-filter-group">
44+
<button title="Clear" class="filter-clear-icon" style="display: block;" id="labelFilterClear"></button>
45+
<input type="text" id="labelFilterField" placeholder='Filter history...'>
46+
</div>
47+
4248
<div class="yui-b">
4349
<!-- breadcrumbs -->
4450
#set($current_page="pipeline_history")
@@ -58,6 +64,8 @@
5864
<img src="$req.getContextPath()/$concatenatedSpinnerIconFilePath" alt="loading..."/>
5965
</div>
6066

67+
<p id="search-message"></p>
68+
6169
#set($previousPage = "pipelineHistoryPage.switchToPage('$pipelineName', paginator.currentPage - 1)")
6270
#set($nextPage = "pipelineHistoryPage.switchToPage('$pipelineName', paginator.currentPage + 1)")
6371
#set($page = "pipelineHistoryPage.switchToPage('$pipelineName', ${% page.pageNumber %})")
@@ -85,6 +93,8 @@
8593
#if($pipeline_comment_feature_toggle_key)
8694
var PipelineHistoryComment = initPipelineHistoryComment(jQuery, Modalbox, dashboard_periodical_executer);
8795
#end
96+
97+
var pipelineName = "$pipelineName";
8898
</script>
8999

90100
#parse("shared/_footer.vm")

0 commit comments

Comments
 (0)