@@ -14,6 +14,7 @@ function initializeDataTable() {
14
14
pageLength : 100 ,
15
15
colReorder : true ,
16
16
stateSave : true ,
17
+ searching : true ,
17
18
layout : {
18
19
bottomEnd : "inputPaging" ,
19
20
topEnd : null ,
@@ -43,10 +44,18 @@ function initializeDataTable() {
43
44
// }
44
45
45
46
} )
47
+
48
+ $ ( "#affectedURLsFilter" ) . on (
49
+ "beforeinput" ,
50
+ DataTable . util . debounce ( function ( val ) {
51
+ affected_urls_table . columns ( 1 ) . search ( this . value ) . draw ( ) ;
52
+ } , 1000 )
53
+ ) ;
46
54
}
47
55
48
56
function setupClickHandlers ( ) {
49
57
handleIncludeIndividualUrlClick ( ) ;
58
+ handleExcludeIndividualUrlClick ( ) ;
50
59
}
51
60
52
61
function handleIncludeIndividualUrlClick ( ) {
@@ -65,10 +74,6 @@ function handleIncludeIndividualUrlClick() {
65
74
parentCol3 . setAttribute ( 'data-sort' , '1' ) ; // Set data-sort to '1' for the check-mark
66
75
}
67
76
68
- // // Change to tick mark
69
- // i.classList.remove('cross-mark');
70
- // i.innerHTML = '✔'; // Tick mark
71
- // then add that URL to the includeURLs list
72
77
match_pattern = remove_protocol ( $ ( this ) . attr ( "value" ) ) ;
73
78
match_pattern_type = INDIVIDUAL_URL ;
74
79
console . log ( match_pattern ) ;
@@ -77,20 +82,6 @@ function handleIncludeIndividualUrlClick() {
77
82
match_pattern_type = match_pattern_type ,
78
83
true
79
84
) ;
80
-
81
- // const row = $(this).closest('tr'); // Get the closest table row
82
- // const rowId = $("#affectedURLsTable").DataTable().row(row).index();
83
- // console.log(rowId);
84
- // deleteRowById(rowId);
85
-
86
- //Along with this, remove this pattern from the exclude_patterns
87
- // First, check if similar kind of pattern is available in the exclude_pattern table
88
- // If yes, this run this block of code.
89
- // postExcludePatterns(
90
- // match_pattern = match_pattern,
91
- // match_pattern_type = match_pattern_type,
92
- // true
93
- // );
94
85
95
86
96
87
} else {
@@ -133,26 +124,73 @@ function handleIncludeIndividualUrlClick() {
133
124
} ) ;
134
125
}
135
126
127
+
136
128
function handleExcludeIndividualUrlClick ( ) {
137
- // exclude that URL
138
- // check in the include patterns if similar URL is present
139
- // if yes then delete that URL in the
129
+ $ ( "body" ) . on ( "click" , ".exclude-url-btn" , function ( ) {
140
130
141
- }
131
+ const i = this . querySelector ( 'i' ) ;
132
+ if ( i . classList . contains ( 'cross-mark' ) ) {
133
+ // Change to tick mark
134
+ i . classList . remove ( 'cross-mark' ) ;
135
+ i . classList . add ( 'tick-mark' ) ; // Add the tick-mark class
136
+ i . style . color = 'green' ; // Change color to green
137
+ i . textContent = 'check' ; // Set the text to "check"
138
+ let parentCol3 = i . closest ( '.col-3' ) ;
139
+ // Change the data-sort attribute of the parent element
140
+ if ( parentCol3 ) {
141
+ parentCol3 . setAttribute ( 'data-sort' , '1' ) ; // Set data-sort to '1' for the check-mark
142
+ }
142
143
143
- function postIncludePatterns ( match_pattern , match_pattern_type = 0 ) {
144
- if ( ! match_pattern ) {
145
- toastr . error ( "Please highlight a pattern to include." ) ;
146
- return ;
144
+ match_pattern = remove_protocol ( $ ( this ) . attr ( "value" ) ) ;
145
+ match_pattern_type = INDIVIDUAL_URL ;
146
+ console . log ( match_pattern ) ;
147
+ postExcludePatterns (
148
+ match_pattern = match_pattern ,
149
+ match_pattern_type = match_pattern_type ,
150
+ true
151
+ ) ;
152
+
153
+
154
+ } else {
155
+ // Handle the functionality of including that URL again (maybe delete that exclude pattern which was just created)
156
+ var url = $ ( this ) . attr ( "value" ) ;
157
+ console . log ( "url" , url ) ;
158
+ getCorrespondingExcludePattern ( url ) . then ( function ( patternId ) {
159
+ if ( patternId !== null ) {
160
+ console . log ( 'Pattern ID:' , patternId ) ;
161
+ currentURLtoDelete = `/api/exclude-patterns/${ patternId } /` ;
162
+ deletePattern (
163
+ currentURLtoDelete ,
164
+ ( data_type = "Exclude Pattern" )
165
+ ) ;
166
+
167
+ // Change back to cross mark
168
+ i . classList . remove ( 'tick-mark' ) ;
169
+ i . classList . add ( 'cross-mark' ) ; // Add the cross-mark class
170
+ i . style . color = 'red' ; // Change color to red
171
+ i . textContent = 'close' ; // Set the text to "close"
172
+ let parentCol3 = i . closest ( '.col-3' ) ;
173
+ // Change the data-sort attribute of the parent element
174
+ if ( parentCol3 ) {
175
+ parentCol3 . setAttribute ( 'data-sort' , '0' ) ; // Set data-sort to '0' for the cross-mark
176
+ }
177
+
178
+ console . log ( "URL removed from the exclude pattern" )
179
+
180
+
181
+ } else {
182
+ console . log ( 'No matching pattern found.' ) ;
183
+ }
184
+ } ) . catch ( function ( error ) {
185
+ console . error ( "Error occurred:" , error ) ;
186
+ } ) ;
187
+
188
+ }
189
+
190
+ } ) ;
147
191
}
148
192
149
- // if pattern exists in table already
150
- // var table = $("#include_patterns_table").DataTable();
151
- // var itemIdColumnData = table.column(0).data().toArray();
152
- // if (itemIdColumnData.includes(match_pattern)) {
153
- // toastr.success("Pattern already exists");
154
- // return;
155
- // }
193
+ function postIncludePatterns ( match_pattern , match_pattern_type = 0 ) {
156
194
157
195
$ . ajax ( {
158
196
url : "/api/include-patterns/" ,
@@ -165,16 +203,6 @@ function postIncludePatterns(match_pattern, match_pattern_type = 0) {
165
203
} ,
166
204
success : function ( data ) {
167
205
console . log ( "Success on adding to the Included URLs" ) ;
168
- // $("#candidate_urls_table").DataTable().ajax.reload(null, false);
169
- // $("#include_patterns_table").DataTable().ajax.reload(null, false);
170
- // if(currentTab === ""){ //Only add a notification if we are on the first tab
171
- // newIncludePatternsCount = newIncludePatternsCount + 1;
172
- // $("#includePatternsTab").html(
173
- // `Include Patterns <span class="pill notifyBadge badge badge-pill badge-primary">` +
174
- // newIncludePatternsCount + " new" +
175
- // `</span>`
176
- // );
177
- // }
178
206
} ,
179
207
error : function ( xhr , status , error ) {
180
208
var errorMessage = xhr . responseText ;
@@ -193,21 +221,6 @@ function remove_protocol(url) {
193
221
194
222
195
223
function postExcludePatterns ( match_pattern , match_pattern_type = 0 , force ) {
196
- // if (!match_pattern) {
197
- // toastr.error("Please highlight a pattern to exclude.");
198
- // return;
199
- // }
200
- // if (!force) {
201
- // //If the user clicked the icon in the table, we make the change regardless
202
- // // if pattern exists in table already (unless another pattern overrules it)
203
- // var table = $("#exclude_patterns_table").DataTable();
204
- // var itemIdColumnData = table.column(0).data().toArray();
205
- // if (itemIdColumnData.includes(match_pattern)) {
206
- // toastr.success("Pattern already exists");
207
- // return;
208
- // }
209
- // }
210
-
211
224
$ . ajax ( {
212
225
url : "/api/exclude-patterns/" ,
213
226
type : "POST" ,
@@ -218,17 +231,7 @@ function postExcludePatterns(match_pattern, match_pattern_type = 0, force) {
218
231
csrfmiddlewaretoken : csrftoken ,
219
232
} ,
220
233
success : function ( data ) {
221
- console . log ( "Success on removing from Excluded URLs" ) ;
222
- // $("#candidate_urls_table").DataTable().ajax.reload(null, false);
223
- // $("#exclude_patterns_table").DataTable().ajax.reload(null, false);
224
- // if(currentTab === ""){ //Only add a notification if we are on the first tab
225
- // newExcludePatternsCount = newExcludePatternsCount + 1;
226
- // $("#excludePatternsTab").html(
227
- // `Exclude Patterns <span class="pill notifyBadge badge badge-pill badge-primary">` +
228
- // newExcludePatternsCount + " new" +
229
- // `</span>`
230
- // );
231
- // }
234
+ console . log ( "Success on adding to the Excluded URLs" ) ;
232
235
} ,
233
236
error : function ( xhr , status , error ) {
234
237
var errorMessage = xhr . responseText ;
@@ -291,4 +294,24 @@ function getCorrespondingIncludePattern(url) {
291
294
console . error ( "Error fetching include patterns:" , error ) ;
292
295
return null ;
293
296
} ) ;
297
+ }
298
+
299
+ function getCorrespondingExcludePattern ( url ) {
300
+ return $ . ajax ( {
301
+ url : `/api/exclude-patterns/?format=datatables&collection_id=${ collection_id } ` ,
302
+ method : 'GET' ,
303
+ dataType : 'json'
304
+ } ) . then ( function ( response ) {
305
+ // Iterate through the 'data' array to find a matching pattern
306
+ for ( let i = 0 ; i < response . data . length ; i ++ ) {
307
+ let pattern = response . data [ i ] . match_pattern ;
308
+ if ( pattern === remove_protocol ( url ) ) {
309
+ return response . data [ i ] . id ; // Return the first matching pattern id
310
+ }
311
+ }
312
+ return null ; // Return null if no pattern matches
313
+ } ) . catch ( function ( error ) {
314
+ console . error ( "Error fetching exclude patterns:" , error ) ;
315
+ return null ;
316
+ } ) ;
294
317
}
0 commit comments