@@ -6,10 +6,13 @@ $(document).ready(function() {
6
6
items : [
7
7
{
8
8
type : "normal" ,
9
- text : "Delete all pact versions..." ,
10
- click : function ( e ) {
11
- promptToDeletePactVersions ( $ ( e ) . data ( ) , $ ( e ) . closest ( "tr" ) ) ;
12
- }
9
+ text : "Delete pacts ..." ,
10
+ click : handleDeletePactsSelected
11
+ } ,
12
+ {
13
+ type : "normal" ,
14
+ text : "Delete integration..." ,
15
+ click : handleDeleteIntegrationsSelected
13
16
}
14
17
]
15
18
} )
@@ -18,23 +21,117 @@ $(document).ready(function() {
18
21
} ) ;
19
22
} ) ;
20
23
21
- function promptToDeletePactVersions ( rowData , row ) {
24
+ function handleDeletePactsSelected ( clickedElement ) {
25
+ const tr = $ ( clickedElement ) . closest ( "tr" ) ;
26
+ const confirmationText = createPactVersionsDeletionConfirmationText ( tr . data ( ) ) ;
27
+ promptToDeleteResources (
28
+ tr ,
29
+ tr . data ( ) . pactVersionsUrl ,
30
+ confirmationText
31
+ ) ;
32
+ }
33
+
34
+ function handleDeleteIntegrationsSelected ( clickedElement ) {
35
+ const tr = $ ( clickedElement ) . closest ( "tr" ) ;
36
+ const confirmationText = createIntegrationDeletionConfirmationText (
37
+ tr . data ( )
38
+ ) ;
39
+ promptToDeleteResources (
40
+ tr ,
41
+ tr . data ( ) . integrationUrl ,
42
+ confirmationText
43
+ ) ;
44
+ }
45
+
46
+ function createIntegrationDeletionConfirmationText ( rowData ) {
47
+ return `This will delete ${ rowData . consumerName } and ${
48
+ rowData . providerName
49
+ } , and all associated data (pacts, verifications, application versions, tags and webhooks) that are not associated with other integrations. Do you wish to continue?`;
50
+ }
51
+
52
+ function promptToDeleteIntegration ( rowData , row ) {
22
53
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 ${
54
+ `This will delete ${ rowData . consumerName } and ${
26
55
rowData . providerName
27
- } , and all other data related to them (webhooks, application versions, and tags ). Do you wish to continue?`
56
+ } , and all associated data (pacts, verifications, application versions, tags and webhooks ). Do you wish to continue?`
28
57
) ;
29
- if ( agree ) {
58
+ }
59
+
60
+ function highlightRowsToBeDeleted ( table , consumerName , providerName ) {
61
+ table
62
+ . children ( "tbody" )
63
+ . find ( `[data-consumer-name="${ consumerName } "]` )
64
+ . children ( "td" )
65
+ . addClass ( "to-be-deleted" ) ;
66
+ table
67
+ . children ( "tbody" )
68
+ . find ( `[data-provider-name="${ providerName } "]` )
69
+ . children ( "td" )
70
+ . addClass ( "to-be-deleted" ) ;
71
+ }
72
+
73
+ function highlightRowToBeDeleted ( row ) {
74
+ row . children ( "td" ) . addClass ( "to-be-deleted" ) ;
75
+ }
76
+
77
+ function unHighlightRows ( table ) {
78
+ table . find ( ".to-be-deleted" ) . removeClass ( "to-be-deleted" ) ;
79
+ }
80
+
81
+ function createPactVersionsDeletionConfirmationText ( rowData ) {
82
+ return `This will delete all versions of the pact between ${
83
+ rowData . consumerName
84
+ } and ${ rowData . providerName } . It will keep ${ rowData . consumerName } and ${
85
+ rowData . providerName
86
+ } , and all other data related to them (webhooks, verifications, application versions, and tags). Do you wish to continue?`;
87
+ }
88
+
89
+ function confirmDeletePactVersions (
90
+ rowData ,
91
+ confirmationText ,
92
+ confirmCallbak ,
93
+ cancelCallback
94
+ ) {
95
+ $ . confirm ( {
96
+ title : "Confirm!" ,
97
+ content : confirmationText ,
98
+ buttons : {
99
+ delete : {
100
+ text : "DELETE" ,
101
+ btnClass : "alert alert-danger" ,
102
+ keys : [ "enter" , "shift" ] ,
103
+ action : confirmCallbak
104
+ } ,
105
+ cancel : cancelCallback
106
+ }
107
+ } ) ;
108
+ }
109
+
110
+ function promptToDeleteResources ( row , deletionUrl , confirmationText ) {
111
+ const rowData = row . data ( ) ;
112
+ const table = row . closest ( "table" ) ;
113
+ const cancel = function ( ) {
114
+ unHighlightRows ( table ) ;
115
+ } ;
116
+ const confirm = function ( ) {
30
117
deletePactVersions (
31
- rowData . pactVersionsUrl ,
118
+ deletionUrl ,
32
119
function ( ) {
33
120
handleDeletionSuccess ( row ) ;
34
121
} ,
35
- handleDeletionFailure
122
+ function ( response ) {
123
+ handleDeletionFailure ( table , response ) ;
124
+ }
36
125
) ;
37
- }
126
+ } ;
127
+
128
+ highlightRowToBeDeleted ( row ) ;
129
+ confirmDeletePactVersions (
130
+ rowData ,
131
+ confirmationText ,
132
+ confirm ,
133
+ cancel
134
+ ) ;
38
135
}
39
136
40
137
function handleDeletionSuccess ( row ) {
@@ -50,21 +147,25 @@ function handleDeletionSuccess(row) {
50
147
} ) ;
51
148
}
52
149
53
- function handleDeletionFailure ( response ) {
150
+ function handleDeletionFailure ( table , response ) {
151
+ unHighlightRows ( table ) ;
54
152
let errorMessage = null ;
55
153
56
154
if ( response . error && response . error . message && response . error . reference ) {
57
155
errorMessage =
58
- "Could not delete resources due to error: " +
156
+ "<p> Could not delete resources due to error: " +
59
157
response . error . message +
60
- "\nError reference: " +
61
- response . error . reference ;
158
+ "</p><p>Error reference: " +
159
+ response . error . reference + "</p>" ;
62
160
} else {
63
161
errorMessage =
64
162
"Could not delete resources due to error: " + JSON . stringify ( response ) ;
65
163
}
66
164
67
- alert ( errorMessage ) ;
165
+ $ . alert ( {
166
+ title : 'Error' ,
167
+ content : errorMessage ,
168
+ } ) ;
68
169
}
69
170
70
171
function deletePactVersions ( url , successCallback , errorCallback ) {
0 commit comments