Skip to content

Commit

Permalink
feat(index): add button to delete all pact versions
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Apr 12, 2019
1 parent dc55729 commit b5d15d5
Show file tree
Hide file tree
Showing 10 changed files with 482 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/api/pact_broker_urls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def latest_pacts_url base_url
"#{base_url}/pacts/latest"
end

def pact_versions_url consumer_name, provider_name, base_url
def pact_versions_url consumer_name, provider_name, base_url = ""
"#{base_url}/pacts/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}/versions"
end

Expand Down
9 changes: 9 additions & 0 deletions lib/pact_broker/ui/view_models/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'pact_broker/ui/helpers/url_helper'
require 'pact_broker/date_helper'
require 'pact_broker/versions/abbreviate_number'
require 'pact_broker/configuration'

module PactBroker
module UI
Expand Down Expand Up @@ -66,6 +67,10 @@ def any_webhooks?
@relationship.any_webhooks?
end

def pact_versions_url
PactBroker::Api::PactBrokerUrls.pact_versions_url(consumer_name, provider_name, PactBroker.configuration.base_url)
end

def webhook_label
return "" unless show_webhook_status?
case @relationship.webhook_status
Expand All @@ -90,6 +95,10 @@ def show_webhook_status?
@relationship.latest?
end

def show_settings?
@relationship.latest?
end

def webhook_last_execution_date
PactBroker::DateHelper.distance_of_time_in_words(@relationship.last_webhook_execution_date, DateTime.now) + " ago"
end
Expand Down
6 changes: 6 additions & 0 deletions lib/pact_broker/ui/views/index/_css_and_js.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%link{rel: 'stylesheet', href: '/stylesheets/index.css'}
%link{rel: 'stylesheet', href: '/stylesheets/material-menu.css'}
%link{rel: 'stylesheet', href: '/stylesheets/material-icon.css'}
%script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
%script{type: 'text/javascript', src:'/javascripts/material-menu.js'}
%script{type: 'text/javascript', src:'/javascripts/index.js'}
7 changes: 5 additions & 2 deletions lib/pact_broker/ui/views/index/show-with-tags.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
%body
%link{rel: 'stylesheet', href: '/stylesheets/index.css'}
%script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
= render :haml, :'index/_css_and_js', :layout => false
.container
= render :haml, :'index/_navbar', :layout => false, locals: {tag_toggle: false}
- if index_items.empty?
Expand Down Expand Up @@ -31,6 +30,7 @@
%th
Last<br>verified
%span.glyphicon.glyphicon-sort.relationships-sort
%th
%tbody

- index_items.each do | index_item |
Expand Down Expand Up @@ -73,6 +73,9 @@
= index_item.last_verified_date.gsub("about ", "")
- if index_item.warning?
%span.glyphicon.glyphicon-warning-sign{ 'aria-hidden': true }
%td
- if index_item.show_settings?
%span.integration-settings.glyphicon.glyphicon-cog{ 'aria-hidden': true, 'data-pact-versions-url': index_item.pact_versions_url, 'data-consumer-name': index_item.consumer_name, 'data-provider-name': index_item.provider_name}
%div.relationships-size
= index_items.size_label
Expand Down
6 changes: 4 additions & 2 deletions lib/pact_broker/ui/views/index/show.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
%body
%link{rel: 'stylesheet', href: '/stylesheets/index.css'}
%script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
= render :haml, :'index/_css_and_js', :layout => false
.container
= render :haml, :'index/_navbar', :layout => false, locals: {tag_toggle: true}
- if index_items.empty?
Expand All @@ -26,6 +25,7 @@
Webhook<br>status
%th
Last<br>verified
%th
%tbody

- index_items.each do | index_item |
Expand Down Expand Up @@ -54,6 +54,8 @@
= index_item.last_verified_date
- if index_item.warning?
%span.glyphicon.glyphicon-warning-sign{ 'aria-hidden': true }
%td
%span.integration-settings.glyphicon.glyphicon-cog{ 'aria-hidden': true, 'data-pact-versions-url': index_item.pact_versions_url, 'data-consumer-name': index_item.consumer_name, 'data-provider-name': index_item.provider_name}
%div.relationships-size
= index_items.size_label
Expand Down
Binary file not shown.
85 changes: 85 additions & 0 deletions public/javascripts/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
$(document).ready(function() {
$(".integration-settings")
.materialMenu("init", {
position: "overlay",
animationSpeed: 1,
items: [
{
type: "normal",
text: "Delete all pact versions...",
click: function(e) {
promptToDeletePactVersions($(e).data(), $(e).closest("tr"));
}
}
]
})
.click(function() {
$(this).materialMenu("open");
});
});

function promptToDeletePactVersions(rowData, row) {
const agree = confirm(
`This will delete all versions of the pact between ${
rowData.consumerName
} and ${rowData.providerName}. It will keep ${rowData.consumerName} and ${
rowData.providerName
}, and all other data related to them (webhooks, application versions, and tags). Do you wish to continue?`
);
if (agree) {
deletePactVersions(
rowData.pactVersionsUrl,
function() {
handleDeletionSuccess(row);
},
handleDeletionFailure
);
}
}

function handleDeletionSuccess(row) {
row
.children("td, th")
.animate({ padding: 0 })
.wrapInner("<div />")
.children()
.slideUp(function() {
$(this)
.closest("tr")
.remove();
});
}

function handleDeletionFailure(response) {
let errorMessage = null;

if (response.error && response.error.message && response.error.reference) {
errorMessage =
"Could not delete resources due to error: " +
response.error.message +
"\nError reference: " +
response.error.reference;
} else {
errorMessage =
"Could not delete resources due to error: " + JSON.stringify(response);
}

alert(errorMessage);
}

function deletePactVersions(url, successCallback, errorCallback) {
$.ajax({
url: url,
dataType: "json",
type: "delete",
accepts: {
text: "application/hal+json"
},
success: function(data, textStatus, jQxhr) {
successCallback();
},
error: function(jqXhr, textStatus, errorThrown) {
errorCallback(jqXhr.responseJSON);
}
});
}
Loading

0 comments on commit b5d15d5

Please sign in to comment.