diff --git a/lib/pact_broker/ui/controllers/matrix.rb b/lib/pact_broker/ui/controllers/matrix.rb index ad5eeb8f9..1448ba7f0 100644 --- a/lib/pact_broker/ui/controllers/matrix.rb +++ b/lib/pact_broker/ui/controllers/matrix.rb @@ -1,5 +1,5 @@ require 'pact_broker/ui/controllers/base_controller' -require 'pact_broker/ui/view_models/matrix_line' +require 'pact_broker/ui/view_models/matrix_lines' require 'pact_broker/matrix/parse_query' require 'pact_broker/logging' require 'haml' @@ -29,7 +29,7 @@ class Matrix < Base errors = matrix_service.validate_selectors(selectors) if errors.empty? lines = matrix_service.find(selectors, options) - locals[:lines] = lines.collect{ |line| PactBroker::UI::ViewDomain::MatrixLine.new(line) } + locals[:lines] = PactBroker::UI::ViewDomain::MatrixLines.new(lines) else locals[:errors] = errors end @@ -45,7 +45,7 @@ class Matrix < Base selectors = [{ pacticipant_name: params[:consumer_name] }, { pacticipant_name: params[:provider_name] } ] options = {latestby: 'cvpv', limit: 100} lines = matrix_service.find(selectors, options) - lines = lines.collect{ |line| PactBroker::UI::ViewDomain::MatrixLine.new(line) }.sort + lines = PactBroker::UI::ViewDomain::MatrixLines.new(lines) locals = { lines: lines, title: "The Matrix", diff --git a/lib/pact_broker/ui/view_models/matrix_line.rb b/lib/pact_broker/ui/view_models/matrix_line.rb index 56ef3b303..fe6ad4411 100644 --- a/lib/pact_broker/ui/view_models/matrix_line.rb +++ b/lib/pact_broker/ui/view_models/matrix_line.rb @@ -12,6 +12,7 @@ class MatrixLine def initialize line @line = line + @overwritten = false # true if the pact was revised and this revision is no longer the latest end def provider_name @@ -153,6 +154,14 @@ def verification_status_class else '' end end + + def overwritten? + @overwritten + end + + def overwritten= overwritten + @overwritten = overwritten + end end end end diff --git a/lib/pact_broker/ui/view_models/matrix_lines.rb b/lib/pact_broker/ui/view_models/matrix_lines.rb new file mode 100644 index 000000000..df1b9ee0b --- /dev/null +++ b/lib/pact_broker/ui/view_models/matrix_lines.rb @@ -0,0 +1,29 @@ +require 'pact_broker/ui/view_models/matrix_line' + +module PactBroker + module UI + module ViewDomain + class MatrixLines < Array + + def initialize rows + lines = rows.collect do | row | + PactBroker::UI::ViewDomain::MatrixLine.new(row) + end + + super(lines.sort) + + # Don't have a URL to view ovewritten pact revisions, so don't show a link for them until we do + line_group_ids = [] + each do | line | + line_group_id = [line.consumer_name, line.consumer_version_number, line.provider_name, line.provider_version_number] + if line_group_ids.include?(line_group_id) + line.overwritten = true + else + line_group_ids << line_group_id + end + end + end + 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 8178facc2..584e6bd61 100644 --- a/lib/pact_broker/ui/views/matrix/show.haml +++ b/lib/pact_broker/ui/views/matrix/show.haml @@ -114,8 +114,11 @@ .tag.label.label-default = tag.name %td.pact-published{'data-sort-value' => line.pact_published_order} - %a{href: line.pact_publication_date_url} - = line.pact_publication_date + - if !line.overwritten? + %a{href: line.pact_publication_date_url} + = line.pact_publication_date + - else + = "#{line.pact_publication_date} (overwritten)" %td.provider{'data-sort-value' => line.provider_name} %a{href: line.provider_name_url} = line.provider_name