From c4136bd63b24944de3659aebee4d94124a33839b Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 18 Dec 2017 18:10:55 +1100 Subject: [PATCH] feat(matrix ui): add limit and latestby to form --- lib/pact_broker/matrix/parse_query.rb | 11 ++++------- lib/pact_broker/ui/controllers/matrix.rb | 19 ++++++++++++++++--- lib/pact_broker/ui/views/matrix/show.haml | 23 ++++++++++++++++++++++- public/stylesheets/matrix.css | 10 +++++++++- 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/lib/pact_broker/matrix/parse_query.rb b/lib/pact_broker/matrix/parse_query.rb index 651bcb3fa..f644d2388 100644 --- a/lib/pact_broker/matrix/parse_query.rb +++ b/lib/pact_broker/matrix/parse_query.rb @@ -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 diff --git a/lib/pact_broker/ui/controllers/matrix.rb b/lib/pact_broker/ui/controllers/matrix.rb index 2d068308f..de122ba3c 100644 --- a/lib/pact_broker/ui/controllers/matrix.rb +++ b/lib/pact_broker/ui/controllers/matrix.rb @@ -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) @@ -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 @@ -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 diff --git a/lib/pact_broker/ui/views/matrix/show.haml b/lib/pact_broker/ui/views/matrix/show.haml index 4a904e4d0..999cd4d4a 100644 --- a/lib/pact_broker/ui/views/matrix/show.haml +++ b/lib/pact_broker/ui/views/matrix/show.haml @@ -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 @@ -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} @@ -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'} diff --git a/public/stylesheets/matrix.css b/public/stylesheets/matrix.css index b287bb7ec..cc01caeac 100644 --- a/public/stylesheets/matrix.css +++ b/public/stylesheets/matrix.css @@ -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; }