Skip to content

Commit b5d15d5

Browse files
committed
feat(index): add button to delete all pact versions
1 parent dc55729 commit b5d15d5

File tree

10 files changed

+482
-5
lines changed

10 files changed

+482
-5
lines changed

lib/pact_broker/api/pact_broker_urls.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def latest_pacts_url base_url
7373
"#{base_url}/pacts/latest"
7474
end
7575

76-
def pact_versions_url consumer_name, provider_name, base_url
76+
def pact_versions_url consumer_name, provider_name, base_url = ""
7777
"#{base_url}/pacts/provider/#{url_encode(provider_name)}/consumer/#{url_encode(consumer_name)}/versions"
7878
end
7979

lib/pact_broker/ui/view_models/index_item.rb

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'pact_broker/ui/helpers/url_helper'
33
require 'pact_broker/date_helper'
44
require 'pact_broker/versions/abbreviate_number'
5+
require 'pact_broker/configuration'
56

67
module PactBroker
78
module UI
@@ -66,6 +67,10 @@ def any_webhooks?
6667
@relationship.any_webhooks?
6768
end
6869

70+
def pact_versions_url
71+
PactBroker::Api::PactBrokerUrls.pact_versions_url(consumer_name, provider_name, PactBroker.configuration.base_url)
72+
end
73+
6974
def webhook_label
7075
return "" unless show_webhook_status?
7176
case @relationship.webhook_status
@@ -90,6 +95,10 @@ def show_webhook_status?
9095
@relationship.latest?
9196
end
9297

98+
def show_settings?
99+
@relationship.latest?
100+
end
101+
93102
def webhook_last_execution_date
94103
PactBroker::DateHelper.distance_of_time_in_words(@relationship.last_webhook_execution_date, DateTime.now) + " ago"
95104
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
%link{rel: 'stylesheet', href: '/stylesheets/index.css'}
2+
%link{rel: 'stylesheet', href: '/stylesheets/material-menu.css'}
3+
%link{rel: 'stylesheet', href: '/stylesheets/material-icon.css'}
4+
%script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
5+
%script{type: 'text/javascript', src:'/javascripts/material-menu.js'}
6+
%script{type: 'text/javascript', src:'/javascripts/index.js'}

lib/pact_broker/ui/views/index/show-with-tags.haml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
%body
2-
%link{rel: 'stylesheet', href: '/stylesheets/index.css'}
3-
%script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
2+
= render :haml, :'index/_css_and_js', :layout => false
43
.container
54
= render :haml, :'index/_navbar', :layout => false, locals: {tag_toggle: false}
65
- if index_items.empty?
@@ -31,6 +30,7 @@
3130
%th
3231
Last<br>verified
3332
%span.glyphicon.glyphicon-sort.relationships-sort
33+
%th
3434
%tbody
3535

3636
- index_items.each do | index_item |
@@ -73,6 +73,9 @@
7373
= index_item.last_verified_date.gsub("about ", "")
7474
- if index_item.warning?
7575
%span.glyphicon.glyphicon-warning-sign{ 'aria-hidden': true }
76+
%td
77+
- if index_item.show_settings?
78+
%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}
7679
%div.relationships-size
7780
= index_items.size_label
7881

lib/pact_broker/ui/views/index/show.haml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
%body
2-
%link{rel: 'stylesheet', href: '/stylesheets/index.css'}
3-
%script{type: 'text/javascript', src:'/javascripts/jquery.tablesorter.min.js'}
2+
= render :haml, :'index/_css_and_js', :layout => false
43
.container
54
= render :haml, :'index/_navbar', :layout => false, locals: {tag_toggle: true}
65
- if index_items.empty?
@@ -26,6 +25,7 @@
2625
Webhook<br>status
2726
%th
2827
Last<br>verified
28+
%th
2929
%tbody
3030

3131
- index_items.each do | index_item |
@@ -54,6 +54,8 @@
5454
= index_item.last_verified_date
5555
- if index_item.warning?
5656
%span.glyphicon.glyphicon-warning-sign{ 'aria-hidden': true }
57+
%td
58+
%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}
5759
%div.relationships-size
5860
= index_items.size_label
5961
Binary file not shown.

public/javascripts/index.js

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
$(document).ready(function() {
2+
$(".integration-settings")
3+
.materialMenu("init", {
4+
position: "overlay",
5+
animationSpeed: 1,
6+
items: [
7+
{
8+
type: "normal",
9+
text: "Delete all pact versions...",
10+
click: function(e) {
11+
promptToDeletePactVersions($(e).data(), $(e).closest("tr"));
12+
}
13+
}
14+
]
15+
})
16+
.click(function() {
17+
$(this).materialMenu("open");
18+
});
19+
});
20+
21+
function promptToDeletePactVersions(rowData, row) {
22+
const agree = confirm(
23+
`This will delete all versions of the pact between ${
24+
rowData.consumerName
25+
} and ${rowData.providerName}. It will keep ${rowData.consumerName} and ${
26+
rowData.providerName
27+
}, and all other data related to them (webhooks, application versions, and tags). Do you wish to continue?`
28+
);
29+
if (agree) {
30+
deletePactVersions(
31+
rowData.pactVersionsUrl,
32+
function() {
33+
handleDeletionSuccess(row);
34+
},
35+
handleDeletionFailure
36+
);
37+
}
38+
}
39+
40+
function handleDeletionSuccess(row) {
41+
row
42+
.children("td, th")
43+
.animate({ padding: 0 })
44+
.wrapInner("<div />")
45+
.children()
46+
.slideUp(function() {
47+
$(this)
48+
.closest("tr")
49+
.remove();
50+
});
51+
}
52+
53+
function handleDeletionFailure(response) {
54+
let errorMessage = null;
55+
56+
if (response.error && response.error.message && response.error.reference) {
57+
errorMessage =
58+
"Could not delete resources due to error: " +
59+
response.error.message +
60+
"\nError reference: " +
61+
response.error.reference;
62+
} else {
63+
errorMessage =
64+
"Could not delete resources due to error: " + JSON.stringify(response);
65+
}
66+
67+
alert(errorMessage);
68+
}
69+
70+
function deletePactVersions(url, successCallback, errorCallback) {
71+
$.ajax({
72+
url: url,
73+
dataType: "json",
74+
type: "delete",
75+
accepts: {
76+
text: "application/hal+json"
77+
},
78+
success: function(data, textStatus, jQxhr) {
79+
successCallback();
80+
},
81+
error: function(jqXhr, textStatus, errorThrown) {
82+
errorCallback(jqXhr.responseJSON);
83+
}
84+
});
85+
}

0 commit comments

Comments
 (0)