Skip to content

Commit

Permalink
feat(matrix ui): add limit and latestby to form
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Dec 18, 2017
1 parent 00d7da1 commit c4136bd
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
11 changes: 4 additions & 7 deletions lib/pact_broker/matrix/parse_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,16 @@ def self.call query
if params.key?('success') && params['success'].is_a?(String)
options[:success] = [params['success'] == '' ? nil : params['success'] == 'true']
end
if params.key?('scope')
options[:scope] = params['scope']
end
if params.key?('latestby')
if params.key?('latestby') && params['latestby'] != ''
options[:latestby] = params['latestby']
end
if params.key?('limit')
if params.key?('limit') && params['limit'] != ''
options[:limit] = params['limit']
end
if params.key?('latest')
if params.key?('latest') && params['latest'] != ''
options[:latest] = params['latest']
end
if params.key?('tag')
if params.key?('tag') && params['tag'] != ''
options[:tag] = params['tag']
end
return selectors, options
Expand Down
19 changes: 16 additions & 3 deletions lib/pact_broker/ui/controllers/matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ class Matrix < Base

get "/" do
selectors = [OpenStruct.new, OpenStruct.new]
options = { limit: 100, latestby: 'cvpv' }
locals = {
lines: [],
title: "The Matrix",
selectors: create_selector_objects(selectors)
selectors: create_selector_objects(selectors),
options: create_options_model(options)
}
begin
if params[:q]
selectors, options = PactBroker::Matrix::ParseQuery.call(request.env['QUERY_STRING'])
locals[:selectors] = create_selector_objects(selectors)
locals[:options] = create_options_model(options)
errors = matrix_service.validate_selectors(selectors)
if errors.empty?
lines = matrix_service.find(selectors, options)
Expand All @@ -40,14 +43,16 @@ class Matrix < Base

get "/provider/:provider_name/consumer/:consumer_name" do
selectors = [{ pacticipant_name: params[:consumer_name] }, { pacticipant_name: params[:provider_name] } ]
lines = matrix_service.find(selectors, {latestby: 'cvpv', limit: 1000})
options = {latestby: 'cvpv', limit: 100}
lines = matrix_service.find(selectors, options)
lines = lines.collect{ |line| PactBroker::UI::ViewDomain::MatrixLine.new(line) }.sort
locals = {
lines: lines,
title: "The Matrix",
consumer_name: params[:consumer_name],
provider_name: params[:provider_name],
selectors: create_selector_objects(selectors)
selectors: create_selector_objects(selectors),
options: create_options_model(options)
}
haml :'matrix/show', {locals: locals, layout: :'layouts/main'}
end
Expand All @@ -63,6 +68,14 @@ def create_selector_objects(selector_hashes)
o
end
end

def create_options_model(options)
o = OpenStruct.new(options)
o.cvpv_checked = o.latestby == 'cvpv' ? 'checked' : nil
o.cvp_checked = o.latestby == 'cvp' ? 'checked' : nil
o.all_rows_checked = o.latestby.nil? ? 'checked' : nil
o
end
end
end
end
Expand Down
23 changes: 22 additions & 1 deletion lib/pact_broker/ui/views/matrix/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
%script{type: 'text/javascript', src:'/javascripts/matrix.js'}
%script{type: 'text/javascript', src:'/js/bootstrap.min.js'}

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

.input-group
%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}
Expand All @@ -41,7 +43,26 @@
%input{name: 'q[]tag', type: 'text', id: "pacticipant#{index}_tag", class: "by-latest-tag", value: selector.tag}
%input{name: 'q[]latest', value: 'true', hidden: true, class: 'latest-flag'}

%div.top-of-group
.input-group
%input{type: 'radio', name: "latestby", class: '', value: 'cvpv', id: 'cvpv', checked: options.cvpv_checked}
%label{for: 'cvpv'}
Show latest row for each consumer version/provider version
%div
.input-group
%input{type: 'radio', name: "latestby", class: '', value: 'cvp', id: 'cvp', checked: options.cvp_checked}
%label{for: 'cvp'}
Show latest row for each consumer version/provider
%div
.input-group
%input{type: 'radio', name: "latestby", class: '', value: '', id: 'all_rows', checked: options.all_rows_checked}
%label{for: 'all_rows'}
Show all rows
%div.top-of-group
%label{for: "limit"}
Limit
%input{name: 'limit', id: "limit", value: options.limit}
%div.top-of-group
%input{type: 'submit'}


Expand Down
10 changes: 9 additions & 1 deletion public/stylesheets/matrix.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
.input-group {
display: inline-block;
padding-left: 20px
padding-right: 20px
}

input[type="radio"] {
/*margin-right: 4px;*/
}

div.top-of-group {
margin-top: 10px;
}

0 comments on commit c4136bd

Please sign in to comment.