diff --git a/lib/pact_broker/ui/view_models/index_item.rb b/lib/pact_broker/ui/view_models/index_item.rb index fbe735c73..35da6c731 100644 --- a/lib/pact_broker/ui/view_models/index_item.rb +++ b/lib/pact_broker/ui/view_models/index_item.rb @@ -30,7 +30,11 @@ def provider_name end def consumer_version_number - PactBroker::Versions::AbbreviateNumber.call(@relationship.consumer_version_number) + @relationship.consumer_version_number + end + + def display_consumer_version_number + PactBroker::Versions::AbbreviateNumber.call(consumer_version_number) end def consumer_version_order @@ -38,7 +42,11 @@ def consumer_version_order end def provider_version_number - PactBroker::Versions::AbbreviateNumber.call(@relationship.provider_version_number) + @relationship.provider_version_number + end + + def display_provider_version_number + PactBroker::Versions::AbbreviateNumber.call(provider_version_number) end def latest? diff --git a/lib/pact_broker/ui/views/index/show-with-tags.haml b/lib/pact_broker/ui/views/index/show-with-tags.haml index 5c8c0c615..8be708681 100644 --- a/lib/pact_broker/ui/views/index/show-with-tags.haml +++ b/lib/pact_broker/ui/views/index/show-with-tags.haml @@ -39,9 +39,9 @@ %a{:href => index_item.consumer_group_url } = index_item.consumer_name %td.consumer-version-number{"data-text": index_item.consumer_version_order} - %div.clippable - = index_item.consumer_version_number - - if index_item.consumer_version_number + %div.clippable{"data-clippable": index_item.consumer_version_number} + = index_item.display_consumer_version_number + - if index_item.display_consumer_version_number %button.clippy.invisible{ title: "Copy to clipboard" } %span.copy-icon - if index_item.latest? @@ -63,9 +63,9 @@ %a{ href: index_item.provider_group_url } = index_item.provider_name %td.provider-version-number - %div.clippable - = index_item.provider_version_number - - if index_item.provider_version_number + %div.clippable{"data-clippable": index_item.provider_version_number} + = index_item.display_provider_version_number + - if index_item.display_provider_version_number %button.clippy.invisible{ title: "Copy to clipboard" } %span.copy-icon - if index_item.provider_version_branch diff --git a/lib/pact_broker/ui/views/matrix/show.haml b/lib/pact_broker/ui/views/matrix/show.haml index 2cb77c2c6..451147cad 100644 --- a/lib/pact_broker/ui/views/matrix/show.haml +++ b/lib/pact_broker/ui/views/matrix/show.haml @@ -112,7 +112,7 @@ %a{href: line.consumer_name_url} = line.consumer_name %td.consumer-version{'data-sort-value' => line.consumer_version_order, 'data-consumer-version-id' => line.consumer_version_id} - %div.clippable + %div.clippable{'data-clippable': line.consumer_version_number} %a{href: line.consumer_version_number_url} = line.display_consumer_version_number - if line.display_consumer_version_number @@ -144,7 +144,7 @@ %a{href: line.provider_name_url} = line.provider_name %td.provider-version{'data-sort-value' => line.provider_version_order, 'data-provider-version-id' => line.provider_version_id } - %div.clippable + %div.clippable{'data-clippable': line.provider_version_number} %a{href: line.provider_version_number_url} = line.display_provider_version_number - if line.display_provider_version_number diff --git a/public/javascripts/clipboard.js b/public/javascripts/clipboard.js index e1fb27d6b..ce9affbf1 100644 --- a/public/javascripts/clipboard.js +++ b/public/javascripts/clipboard.js @@ -24,9 +24,15 @@ function initializeClipper(selector) { .children(".clippy") .click(function() { const clippyButton = $(this); - const text = $.trim(clippyButton.closest(selector).text()); + const clipTarget = clippyButton.closest(selector); + let text = null; + if(clipTarget.data('clippable')) { + text = clipTarget.data('clippable'); + } else { + text = clippyButton.closest(selector).text(); + } + copyToClipboard($.trim(text)); - copyToClipboard(text); flashClipped(clippyButton); }); }