diff --git a/lib/pact_broker/matrix/repository.rb b/lib/pact_broker/matrix/repository.rb index c6b3296fb..438fde278 100644 --- a/lib/pact_broker/matrix/repository.rb +++ b/lib/pact_broker/matrix/repository.rb @@ -29,7 +29,12 @@ def find selectors, options = {} lines = lines.select{ |l| options[:success].include?(l.success) } end - lines.sort.collect(&:values) + lines.sort.collect do | line | + values = line.values + values[:consumer_version_tags] = line.consumer_version_tags.collect(&:values) + values[:provider_version_tags] = line.provider_version_tags.collect(&:values) + values + end end def apply_latestby options, selectors, lines @@ -59,7 +64,11 @@ def find_compatible_pacticipant_versions selectors def query_matrix selectors, options query = view_for(options).select_all.matching_selectors(selectors) query = query.limit(options[:limit]) if options[:limit] - query.order_by_names_ascending_most_recent_first.all + query + .order_by_names_ascending_most_recent_first + .eager(:consumer_version_tags) + .eager(:provider_version_tags) + .all end def view_for(options) diff --git a/lib/pact_broker/ui/view_models/matrix_line.rb b/lib/pact_broker/ui/view_models/matrix_line.rb index f6148a488..0d4f43fb4 100644 --- a/lib/pact_broker/ui/view_models/matrix_line.rb +++ b/lib/pact_broker/ui/view_models/matrix_line.rb @@ -1,6 +1,7 @@ require 'pact_broker/api/pact_broker_urls' require 'pact_broker/ui/helpers/url_helper' require 'pact_broker/date_helper' +require 'pact_broker/ui/view_models/matrix_tag' module PactBroker module UI @@ -70,6 +71,30 @@ def provider_version_order end end + def latest_consumer_version_tags + @line[:consumer_version_tags] + .select{ | tag | tag[:latest] } + .collect{ | tag | MatrixTag.new(tag.merge(pacticipant_name: consumer_name, version_number: consumer_version_number)) } + end + + def other_consumer_version_tags + @line[:consumer_version_tags] + .select{ | tag | !tag[:latest] } + .collect{ | tag | MatrixTag.new(tag.merge(pacticipant_name: consumer_name, version_number: consumer_version_number)) } + end + + def latest_provider_version_tags + @line[:provider_version_tags] + .select{ | tag | tag[:latest] } + .collect{ | tag | MatrixTag.new(tag.merge(pacticipant_name: provider_name, version_number: provider_version_number)) } + end + + def other_provider_version_tags + @line[:provider_version_tags] + .select{ | tag | !tag[:latest] } + .collect{ | tag | MatrixTag.new(tag.merge(pacticipant_name: provider_name, version_number: provider_version_number)) } + end + def orderable_fields [consumer_name, consumer_version_order, @line[:pact_revision_number], provider_name, @line[:verification_id]] end @@ -92,7 +117,11 @@ def verification_status end def pact_publication_date - DateHelper.distance_of_time_in_words(@line[:pact_created_at], DateTime.now) + " ago" + relative_date(@line[:pact_created_at]) + end + + def relative_date date + DateHelper.distance_of_time_in_words(date, DateTime.now) + " ago" end def pact_published_order diff --git a/lib/pact_broker/ui/view_models/matrix_tag.rb b/lib/pact_broker/ui/view_models/matrix_tag.rb new file mode 100644 index 000000000..77c75264d --- /dev/null +++ b/lib/pact_broker/ui/view_models/matrix_tag.rb @@ -0,0 +1,42 @@ +require 'pact_broker/api/pact_broker_urls' +require 'pact_broker/ui/helpers/url_helper' +require 'pact_broker/date_helper' + +module PactBroker + module UI + module ViewDomain + class MatrixTag + + include PactBroker::Api::PactBrokerUrls + + def initialize params + @params = params + @name = params[:name] + @version_number = params[:version_number] + @created_at = params[:created_at] + @latest = !!params[:latest] + end + + def name + @params[:name] + end + + def tooltip + if @latest + "LATEST. Tag created #{relative_date(@created_at)}." + else + "Tag created #{relative_date(@created_at)}." + end + end + + def url + hal_browser_url("/pacticipants/#{ERB::Util.url_encode(@params[:pacticipant_name])}/versions/#{@params[:version_number]}/tags/#{@params[:name]}") + end + + def relative_date date + DateHelper.distance_of_time_in_words(date, DateTime.now) + " ago" + 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 10bc4c785..ee31cdc1d 100644 --- a/lib/pact_broker/ui/views/matrix/show.haml +++ b/lib/pact_broker/ui/views/matrix/show.haml @@ -99,14 +99,36 @@ %td.consumer{'data-sort-value' => line.consumer_name} = line.consumer_name %td.consumer-version{'data-sort-value' => line.consumer_version_order} - %a{href: line.consumer_version_number_url} - = line.consumer_version_number + %div + %a{href: line.consumer_version_number_url} + = line.consumer_version_number + - line.latest_consumer_version_tags.each do | tag | + .tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"} + %a{href: tag.url} + .tag.label.label-primary + = tag.name + - line.other_consumer_version_tags.each do | tag | + .tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"} + %a{href: tag.url} + .tag.label.label-default + = tag.name %td.pact-published{'data-sort-value' => line.pact_published_order} = line.pact_publication_date - %td.provider{'data-sort-value' => line.provider_version_order} + %td.provider{'data-sort-value' => line.provider_name} = line.provider_name %td.provider-version{'data-sort-value' => line.provider_version_order} - %a{href: line.provider_version_number_url} - = line.provider_version_number + %div + %a{href: line.provider_version_number_url} + = line.provider_version_number + - line.latest_provider_version_tags.each do | tag | + .tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"} + %a{href: tag.url} + .tag.label.label-primary + = tag.name + - line.other_provider_version_tags.each do | tag | + .tag-parent{"title": tag.tooltip, "data-toggle": "tooltip", "data-placement": "right"} + %a{href: tag.url} + .tag.label.label-default + = tag.name %td.verification-result{class: line.verification_status_class} = line.verification_status diff --git a/public/javascripts/matrix.js b/public/javascripts/matrix.js index d7c8deb72..48338f8f1 100644 --- a/public/javascripts/matrix.js +++ b/public/javascripts/matrix.js @@ -57,4 +57,9 @@ $(document).ready(function(){ return n.attr('data-sort-value') || n.text(); } }); + + + $('[data-toggle="tooltip"]').each(function(index, el){ + $(el).tooltip({container: $(el)}); + }); }); diff --git a/public/stylesheets/matrix.css b/public/stylesheets/matrix.css index cc01caeac..7f8a05480 100644 --- a/public/stylesheets/matrix.css +++ b/public/stylesheets/matrix.css @@ -10,3 +10,12 @@ input[type="radio"] { div.top-of-group { margin-top: 10px; } + +div.tag-parent { + margin-top: 5px; + margin-bottom: 1px; +} + +div.tag { + display: inline-block; +} \ No newline at end of file diff --git a/spec/lib/pact_broker/matrix/repository_spec.rb b/spec/lib/pact_broker/matrix/repository_spec.rb index a315bcfdc..c2be8fa7f 100644 --- a/spec/lib/pact_broker/matrix/repository_spec.rb +++ b/spec/lib/pact_broker/matrix/repository_spec.rb @@ -510,6 +510,10 @@ def shorten_rows rows expect(subject).to include_hash_matching provider_version_number: "2.0.0" expect(subject.size).to eq 1 end + + it "returns the tag information" do + expect(subject.first[:provider_version_tags]).to include_hash_matching name: 'prod', latest: 1 + end end context "when the latest version is specified for a provider without a tag" do