Skip to content

Commit

Permalink
feat(matrix ui): add tags
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 25, 2018
1 parent 73e55e7 commit 869d49d
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 8 deletions.
13 changes: 11 additions & 2 deletions lib/pact_broker/matrix/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 30 additions & 1 deletion lib/pact_broker/ui/view_models/matrix_line.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
42 changes: 42 additions & 0 deletions lib/pact_broker/ui/view_models/matrix_tag.rb
Original file line number Diff line number Diff line change
@@ -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
32 changes: 27 additions & 5 deletions lib/pact_broker/ui/views/matrix/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions public/javascripts/matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)});
});
});
9 changes: 9 additions & 0 deletions public/stylesheets/matrix.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions spec/lib/pact_broker/matrix/repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 869d49d

Please sign in to comment.