Skip to content

Commit c4136bd

Browse files
committed
feat(matrix ui): add limit and latestby to form
1 parent 00d7da1 commit c4136bd

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

lib/pact_broker/matrix/parse_query.rb

+4-7
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,16 @@ def self.call query
2222
if params.key?('success') && params['success'].is_a?(String)
2323
options[:success] = [params['success'] == '' ? nil : params['success'] == 'true']
2424
end
25-
if params.key?('scope')
26-
options[:scope] = params['scope']
27-
end
28-
if params.key?('latestby')
25+
if params.key?('latestby') && params['latestby'] != ''
2926
options[:latestby] = params['latestby']
3027
end
31-
if params.key?('limit')
28+
if params.key?('limit') && params['limit'] != ''
3229
options[:limit] = params['limit']
3330
end
34-
if params.key?('latest')
31+
if params.key?('latest') && params['latest'] != ''
3532
options[:latest] = params['latest']
3633
end
37-
if params.key?('tag')
34+
if params.key?('tag') && params['tag'] != ''
3835
options[:tag] = params['tag']
3936
end
4037
return selectors, options

lib/pact_broker/ui/controllers/matrix.rb

+16-3
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@ class Matrix < Base
1414

1515
get "/" do
1616
selectors = [OpenStruct.new, OpenStruct.new]
17+
options = { limit: 100, latestby: 'cvpv' }
1718
locals = {
1819
lines: [],
1920
title: "The Matrix",
20-
selectors: create_selector_objects(selectors)
21+
selectors: create_selector_objects(selectors),
22+
options: create_options_model(options)
2123
}
2224
begin
2325
if params[:q]
2426
selectors, options = PactBroker::Matrix::ParseQuery.call(request.env['QUERY_STRING'])
2527
locals[:selectors] = create_selector_objects(selectors)
28+
locals[:options] = create_options_model(options)
2629
errors = matrix_service.validate_selectors(selectors)
2730
if errors.empty?
2831
lines = matrix_service.find(selectors, options)
@@ -40,14 +43,16 @@ class Matrix < Base
4043

4144
get "/provider/:provider_name/consumer/:consumer_name" do
4245
selectors = [{ pacticipant_name: params[:consumer_name] }, { pacticipant_name: params[:provider_name] } ]
43-
lines = matrix_service.find(selectors, {latestby: 'cvpv', limit: 1000})
46+
options = {latestby: 'cvpv', limit: 100}
47+
lines = matrix_service.find(selectors, options)
4448
lines = lines.collect{ |line| PactBroker::UI::ViewDomain::MatrixLine.new(line) }.sort
4549
locals = {
4650
lines: lines,
4751
title: "The Matrix",
4852
consumer_name: params[:consumer_name],
4953
provider_name: params[:provider_name],
50-
selectors: create_selector_objects(selectors)
54+
selectors: create_selector_objects(selectors),
55+
options: create_options_model(options)
5156
}
5257
haml :'matrix/show', {locals: locals, layout: :'layouts/main'}
5358
end
@@ -63,6 +68,14 @@ def create_selector_objects(selector_hashes)
6368
o
6469
end
6570
end
71+
72+
def create_options_model(options)
73+
o = OpenStruct.new(options)
74+
o.cvpv_checked = o.latestby == 'cvpv' ? 'checked' : nil
75+
o.cvp_checked = o.latestby == 'cvp' ? 'checked' : nil
76+
o.all_rows_checked = o.latestby.nil? ? 'checked' : nil
77+
o
78+
end
6679
end
6780
end
6881
end

lib/pact_broker/ui/views/matrix/show.haml

+22-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
%script{type: 'text/javascript', src:'/javascripts/matrix.js'}
88
%script{type: 'text/javascript', src:'/js/bootstrap.min.js'}
99

10+
-# This code is an embarassment. Sorry. Just trying to get as much stuff done in the little time I have.
11+
1012
.container
1113
%h1.page-header
1214
= title
@@ -21,7 +23,7 @@
2123
.selector
2224
%label{for: "pacticipant#{index}"}
2325
Pacticipant name
24-
%input{name: 'q[]pacticipant', id: "pacticipant1#{index}", value: selector.pacticipant_name}
26+
%input{name: 'q[]pacticipant', id: "pacticipant1#{index}", value: selector.pacticipant_name}
2527

2628
.input-group
2729
%input{type: 'radio', name: "ignorethis#{index}", class: 'specify-all-versions version-selectorizor', value: 'all_versions', id: "pacticipant#{index}_all_versions", checked: selector.specify_all_versions_checked}
@@ -41,7 +43,26 @@
4143
%input{name: 'q[]tag', type: 'text', id: "pacticipant#{index}_tag", class: "by-latest-tag", value: selector.tag}
4244
%input{name: 'q[]latest', value: 'true', hidden: true, class: 'latest-flag'}
4345

46+
%div.top-of-group
47+
.input-group
48+
%input{type: 'radio', name: "latestby", class: '', value: 'cvpv', id: 'cvpv', checked: options.cvpv_checked}
49+
%label{for: 'cvpv'}
50+
Show latest row for each consumer version/provider version
51+
%div
52+
.input-group
53+
%input{type: 'radio', name: "latestby", class: '', value: 'cvp', id: 'cvp', checked: options.cvp_checked}
54+
%label{for: 'cvp'}
55+
Show latest row for each consumer version/provider
4456
%div
57+
.input-group
58+
%input{type: 'radio', name: "latestby", class: '', value: '', id: 'all_rows', checked: options.all_rows_checked}
59+
%label{for: 'all_rows'}
60+
Show all rows
61+
%div.top-of-group
62+
%label{for: "limit"}
63+
Limit
64+
%input{name: 'limit', id: "limit", value: options.limit}
65+
%div.top-of-group
4566
%input{type: 'submit'}
4667

4768

public/stylesheets/matrix.css

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
.input-group {
22
display: inline-block;
3-
padding-left: 20px
3+
padding-right: 20px
4+
}
5+
6+
input[type="radio"] {
7+
/*margin-right: 4px;*/
8+
}
9+
10+
div.top-of-group {
11+
margin-top: 10px;
412
}

0 commit comments

Comments
 (0)