Skip to content

Commit 7a279fc

Browse files
committed
finalise the affected urls page for all the pattern types
1 parent b15410e commit 7a279fc

File tree

4 files changed

+25
-95
lines changed

4 files changed

+25
-95
lines changed

sde_collections/models/candidate_url.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@
1111

1212
class CandidateURLQuerySet(models.QuerySet):
1313
def with_exclusion_status(self):
14-
# currently this is only handling the exclude_patterns
15-
# need to add functionality of including include_patterns
16-
# exclude=false
17-
# if some_include_pattern exists which matches this url:
18-
# then exclude = false
19-
# else
20-
# if some_exclude_pattern exists which matches this url:
21-
# exclude = true
2214
return self.annotate(
2315
excluded=models.Exists(
2416
ExcludePattern.candidate_urls.through.objects.filter(candidateurl=models.OuterRef("pk"))

sde_collections/views.py

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -239,73 +239,32 @@ class AffectedURLsListView(LoginRequiredMixin, ListView):
239239
def get_queryset(self):
240240

241241
if 'exclude-pattern' in self.request.path:
242-
print("Going with exclude patterns......")
243-
# Get the exclude pattern based on the ID from the URL kwargs
244242
self.pattern = ExcludePattern.objects.get(id=self.kwargs["id"])
245-
246-
# Get excluded URLs
247-
excluded_urls = self.pattern.matched_urls().annotate(is_included=Value(False, output_field=BooleanField()))
248-
249-
# Get included URLs for the same collection
250-
include_patterns = IncludePattern.objects.filter(collection=self.pattern.collection)
251-
included_urls = CandidateURL.objects.filter(
252-
collection=self.pattern.collection,
253-
id__in=include_patterns.values_list('candidate_urls__id', flat=True)
254-
).distinct()
255-
256-
# Annotate excluded URLs with is_included if they are also in included_urls
257-
queryset = excluded_urls.annotate(
258-
is_included=Case(
259-
When(id__in=included_urls.values('id'), then=Value(True)),
260-
default=Value(False),
261-
output_field=BooleanField()
262-
)
263-
)
264-
243+
self.pattern_type = "Exclude"
265244
elif 'include-pattern' in self.request.path:
266-
print("Going with include patterns......")
267-
# Get the include pattern based on the ID from the URL kwargs
268245
self.pattern = IncludePattern.objects.get(id=self.kwargs["id"])
269-
270-
# Get included URLs for the pattern
271-
included_urls = self.pattern.matched_urls().annotate(is_excluded=Value(False, output_field=BooleanField()))
272-
273-
# Get excluded URLs for the same collection
274-
exclude_patterns = ExcludePattern.objects.filter(collection=self.pattern.collection)
275-
excluded_urls = CandidateURL.objects.filter(
276-
collection=self.pattern.collection,
277-
id__in=exclude_patterns.values_list('candidate_urls__id', flat=True)
278-
).distinct()
279-
280-
# Annotate included URLs with is_excluded if they are also in excluded_urls
281-
queryset = included_urls.annotate(
282-
is_excluded=Case(
283-
When(id__in=excluded_urls.values('id'), then=Value(True)),
284-
default=Value(False),
285-
output_field=BooleanField()
286-
)
287-
)
288-
246+
self.pattern_type = "Include"
247+
elif 'title-pattern' in self.request.path:
248+
self.pattern = TitlePattern.objects.get(id=self.kwargs["id"])
249+
self.pattern_type = "Title"
250+
elif 'document-type-pattern' in self.request.path:
251+
self.pattern = DocumentTypePattern.objects.get(id=self.kwargs["id"])
252+
self.pattern_type = "Document Type"
253+
else:
254+
return super().get_queryset()
255+
256+
queryset = self.pattern.matched_urls()
289257
return queryset
290258

291259
def get_context_data(self, **kwargs):
292260
context = super().get_context_data(**kwargs)
293261
context["pattern"] = self.pattern
294262
context["url_count"] = self.pattern.matched_urls().count()
295263
context["collection"] = self.pattern.collection
296-
context["pattern_type"] = "Exclude" if 'exclude-pattern' in self.request.path else "Include"
297-
298-
299-
# print(self.pattern.collection.id)
300-
301-
# affected_urls = self.pattern.matched_urls()
302-
# for url in affected_urls:
303-
# print(url.collection)
304-
# Your affected_urls is a list of CandidateURL model objects.
264+
context["pattern_type"] = self.pattern_type
305265

306266
return context
307267

308-
309268
class SdeDashboardView(LoginRequiredMixin, ListView):
310269
model = Collection
311270
template_name = "sde_collections/sde_dashboard.html"

sde_indexing_helper/static/js/affected_urls.js

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var MULTI_URL_PATTERN = 2;
44
collection_id = getCollectionId();
55

66
$(document).ready(function () {
7-
// handleAjaxStartAndStop();
87
initializeDataTable();
98
setupClickHandlers();
109
});
@@ -14,7 +13,6 @@ function initializeDataTable() {
1413
pageLength: 100,
1514
colReorder: true,
1615
stateSave: true,
17-
searching: true,
1816
layout: {
1917
bottomEnd: "inputPaging",
2018
topEnd: null,
@@ -32,16 +30,6 @@ function initializeDataTable() {
3230
pagingType: "input",
3331
rowId: "url"
3432
},
35-
// createdRow: function (row, data, dataIndex) {
36-
// // Assuming the 'Include URL' column is at index 3
37-
// let includeUrlCell = $(row).find('td').eq(2);
38-
39-
// // Check if the cell has the cross-mark
40-
// if (includeUrlCell.find('i.cross-mark').length > 0) {
41-
// // Highlight the row if it contains a cross-mark
42-
// $(row).css('background-color', 'rgba(255, 61, 87, 0.36)'); // Light red background
43-
// }
44-
// }
4533

4634
})
4735

@@ -85,7 +73,6 @@ function handleIncludeIndividualUrlClick() {
8573

8674

8775
} else {
88-
// Handle the functionality of excluding that URL again (maybe delete that include pattern which was just created)
8976
var url = $(this).attr("value");
9077
console.log("url", url);
9178
getCorrespondingIncludePattern(url).then(function(patternId) {
@@ -240,21 +227,6 @@ function postExcludePatterns(match_pattern, match_pattern_type = 0, force) {
240227
});
241228
}
242229

243-
function deleteRowById(rowId) {
244-
// Find the DataTable instance
245-
var affected_urls_table = $("#affectedURLsTable").DataTable();
246-
247-
// Find the row with ID 1
248-
var rowToDelete = affected_urls_table.row(rowId); // Adjust based on 0-indexing
249-
250-
if (rowToDelete.length) {
251-
rowToDelete.remove(); // Remove the row
252-
affected_urls_table.draw(); // Redraw the table
253-
} else {
254-
console.log("Row not found.");
255-
}
256-
}
257-
258230
function deletePattern(
259231
url,
260232
data_type,
@@ -273,6 +245,10 @@ function deletePattern(
273245
success: function (data) {
274246
console.log("Successfully deleted.")
275247
},
248+
error: function (xhr, status, error) {
249+
var errorMessage = xhr.responseText;
250+
toastr.error(errorMessage);
251+
},
276252
});
277253
}
278254

sde_indexing_helper/templates/sde_collections/affected_urls.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
{% load static i18n %}
33
{% load humanize %}
44
{% block title %}
5-
Affected URLs
5+
Affected URLs for {{pattern_type}} Pattern
66
{% endblock title %}
77

88
{% block stylesheets %}
99
{{ block.super }}
1010
<link href="//cdn.datatables.net/v/bs4/jszip-3.10.1/dt-2.0.5/af-2.7.0/b-3.0.2/b-colvis-3.0.2/b-html5-3.0.2/b-print-3.0.2/cr-2.0.1/fc-5.0.0/fh-4.0.1/kt-2.12.0/r-3.0.2/rg-1.5.0/rr-1.5.0/sc-2.4.1/sp-2.3.1/sl-2.0.1/datatables.min.css" rel="stylesheet">
1111
<link href="https://cdn.datatables.net/plug-ins/2.0.8/features/inputPaging/dist/dataTables.inputPaging.min.css" rel="stylesheet" />
12-
<link href="{% static 'css/project.css' %}" rel="stylesheet">
1312
<link rel="stylesheet" href="{% static 'css/affected_urls.css' %}" />
13+
<link href="{% static 'css/project.css' %}" rel="stylesheet">
1414
{% endblock stylesheets %}
1515

1616
{% block content %}
@@ -19,14 +19,16 @@
1919
<h1 class="pageTitle">Affected URLs</h1>
2020
</div>
2121

22+
<div class="candidateUrlContainer">
23+
2224
<h3 class="whiteText candidateTitle">
2325
{{ url_count|intcomma }} affected URLs for {{ pattern_type | lower }} pattern:
2426
<span style="color: #65B1EF;">{{ pattern.match_pattern }}</span>
2527
</h3>
2628

2729
<div class="container mt-4">
2830
<!-- Table to display the URLs -->
29-
<table id="affectedURLsTable" class="table table-striped table-bordered" style="width:100%">
31+
<table id="affectedURLsTable" class="table" style="width:100%">
3032
<thead class="tableHeader">
3133
<tr>
3234
<th scope="col" class="text-center col-1">#</th>
@@ -39,7 +41,7 @@ <h3 class="whiteText candidateTitle">
3941
{% endif %}
4042
</th> -->
4143
</tr>
42-
<tr>
44+
<tr class="filter-row">
4345
<td> </td>
4446
<td ><input type="text" class="table_filter_row_input textBoxStyling" id="affectedURLsFilter" placeholder="URL" /></td>
4547
</tr>
@@ -79,7 +81,8 @@ <h3 class="whiteText candidateTitle">
7981
{% endfor %}
8082
</tbody>
8183
</table>
82-
84+
</div>
85+
</div>
8386
{% endblock content %}
8487

8588
{% block javascripts %}

0 commit comments

Comments
 (0)