Skip to content

Commit

Permalink
feat(matrix ui): add links to all resources referenced in matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jan 28, 2018
1 parent 611ab7e commit 2958ae8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
20 changes: 20 additions & 0 deletions lib/pact_broker/api/pact_broker_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module PactBroker
module Api
module PactBrokerUrls

# TODO make base_url the last and optional argument for all methods, defaulting to ''

extend self

def pacticipants_url base_url
Expand All @@ -14,6 +16,14 @@ def pacticipant_url base_url, pacticipant
"#{pacticipants_url(base_url)}/#{url_encode(pacticipant.name)}"
end

def pacticipant_url_from_params params, base_url = ''
[
base_url,
'pacticipants',
url_encode(params.fetch(:pacticipant_name))
].join("/")
end

def latest_version_url base_url, pacticipant
"#{pacticipant_url(base_url, pacticipant)}/versions/latest"
end
Expand All @@ -26,6 +36,16 @@ def version_url base_url, version
"#{pacticipant_url(base_url, version.pacticipant)}/versions/#{version.number}"
end

def version_url_from_params params, base_url = ''
[
base_url,
'pacticipants',
url_encode(params.fetch(:pacticipant_name)),
'versions',
url_encode(params.fetch(:version_number)),
].join("/")
end

def pact_url base_url, pact
"#{pactigration_base_url(base_url, pact)}/version/#{pact.consumer_version_number}"
end
Expand Down
26 changes: 22 additions & 4 deletions lib/pact_broker/ui/view_models/matrix_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,25 @@ def provider_name
@line[:provider_name]
end

def provider_name_url
hal_browser_url(pacticipant_url_from_params(pacticipant_name: provider_name))
end

def consumer_name
@line[:consumer_name]
end

def consumer_name_url
hal_browser_url(pacticipant_url_from_params(pacticipant_name: consumer_name))
end

def pact_version_sha
@line[:pact_version_sha]
end

# verification number
# verification number, used in verification_url method
def number
@line[:number]
@line[:verification_number]
end

def consumer_name
Expand All @@ -40,7 +48,8 @@ def consumer_version_number
end

def consumer_version_number_url
pact_url_from_params('', @line)
params = { pacticipant_name: consumer_name, version_number: consumer_version_number }
hal_browser_url(version_url_from_params(params))
end

def consumer_version_order
Expand All @@ -60,7 +69,8 @@ def provider_version_order
end

def provider_version_number_url
hal_browser_url(verification_url(self))
params = { pacticipant_name: provider_name, version_number: provider_version_number }
hal_browser_url(version_url_from_params(params))
end

def provider_version_order
Expand Down Expand Up @@ -116,10 +126,18 @@ def verification_status
# end
end

def verification_status_url
hal_browser_url(verification_url(self))
end

def pact_publication_date
relative_date(@line[:pact_created_at])
end

def pact_publication_date_url
pact_url_from_params('', @line)
end

def relative_date date
DateHelper.distance_of_time_in_words(date, DateTime.now) + " ago"
end
Expand Down
12 changes: 8 additions & 4 deletions lib/pact_broker/ui/views/matrix/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@
- lines.each do | line |
%tr
%td.consumer{'data-sort-value' => line.consumer_name}
= line.consumer_name
%a{href: line.consumer_name_url}
= line.consumer_name
%td.consumer-version{'data-sort-value' => line.consumer_version_order}
%div
%a{href: line.consumer_version_number_url}
Expand All @@ -113,9 +114,11 @@
.tag.label.label-default
= tag.name
%td.pact-published{'data-sort-value' => line.pact_published_order}
= line.pact_publication_date
%a{href: line.pact_publication_date_url}
= line.pact_publication_date
%td.provider{'data-sort-value' => line.provider_name}
= line.provider_name
%a{href: line.provider_name_url}
= line.provider_name
%td.provider-version{'data-sort-value' => line.provider_version_order}
%div
%a{href: line.provider_version_number_url}
Expand All @@ -131,4 +134,5 @@
.tag.label.label-default
= tag.name
%td.verification-result{class: line.verification_status_class}
= line.verification_status
%a{href: line.verification_status_url}
= line.verification_status

0 comments on commit 2958ae8

Please sign in to comment.