Skip to content

Commit 99a72f4

Browse files
Merge pull request #1167 from NASA-IMPACT/1156-update-exclude-checkmark-action-to-change-behavior-based-on-inclusion-status
Update exclude checkmark action to change behavior based on inclusion status
2 parents 4083d7d + 456c763 commit 99a72f4

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

sde_collections/serializers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class DeltaURLSerializer(serializers.ModelSerializer):
7373
match_pattern_type = serializers.SerializerMethodField(read_only=True)
7474
delta_urls_count = serializers.SerializerMethodField(read_only=True)
7575
tdamm_tag = serializers.SerializerMethodField()
76+
exclude_pattern_type = serializers.IntegerField(read_only=True)
77+
include_pattern_id = serializers.IntegerField(read_only=True)
7678

7779
def get_tdamm_tag(self, obj):
7880
tags = obj.tdamm_tag
@@ -108,6 +110,8 @@ class Meta:
108110
"division_display",
109111
"visited",
110112
"tdamm_tag",
113+
"exclude_pattern_type",
114+
"include_pattern_id",
111115
)
112116

113117

sde_collections/views.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,30 @@ def _filter_by_is_excluded(self, queryset, is_excluded):
279279
def get_queryset(self):
280280
queryset = super().get_queryset()
281281
if self.request.method == "GET":
282+
collection_id = self.request.GET.get("collection_id")
282283
# Filter based on exclusion status
283284
is_excluded = self.request.GET.get("is_excluded")
284285
if is_excluded:
285286
queryset = self._filter_by_is_excluded(queryset, is_excluded)
287+
288+
# Annotate queryset with two pieces of information:
289+
# 1. exclude_pattern_type: Type of exclude pattern (1=Individual URL, 2=Multi-URL Pattern)
290+
# Ordered by -match_pattern_type to prioritize multi-url patterns (type 2)
291+
# 2. include_pattern_id: ID of any include pattern affecting this URL
292+
# Used when we need to delete the include pattern during re-exclusion
293+
queryset = queryset.annotate(
294+
exclude_pattern_type=models.Subquery(
295+
DeltaExcludePattern.objects.filter(delta_urls=models.OuterRef("pk"), collection_id=collection_id)
296+
.order_by("-match_pattern_type")
297+
.values("match_pattern_type")[:1]
298+
),
299+
include_pattern_id=models.Subquery(
300+
DeltaIncludePattern.objects.filter(
301+
delta_urls=models.OuterRef("pk"), collection_id=collection_id
302+
).values("id")[:1]
303+
),
304+
)
305+
286306
return queryset.order_by("url")
287307

288308
def update_division(self, request, pk=None):

sde_indexing_helper/static/js/delta_url_list.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ function initializeDataTable() {
259259
getDocumentTypeColumn(),
260260
getDivisionColumn(),
261261
{ data: "id", visible: false, searchable: false },
262+
{ data: "exclude_pattern_type", visible: false, searchable: false },
263+
{ data: "include_pattern_id", visible: false, searchable: false },
262264
{ data: "generated_title_id", visible: false, searchable: false },
263265
{ data: "match_pattern_type", visible: false, searchable: false },
264266
{ data: "delta_urls_count", visible: false, searchable: false },
@@ -1483,11 +1485,54 @@ function handleUrlPartButton() {
14831485

14841486
function handleExcludeIndividualUrlClick() {
14851487
$("body").on("click", ".exclude_individual_url", function () {
1486-
postExcludePatterns(
1487-
(match_pattern = $(this).attr("value")),
1488-
(match_pattern_type = 1),
1489-
true
1490-
);
1488+
const url = $(this).attr("value");
1489+
// "check" for excluded, "close" for not excluded
1490+
const isExcluded = $(this).children("i").text() === "check";
1491+
const row = $(this).closest("tr");
1492+
const table = $("#delta_urls_table").DataTable();
1493+
const rowData = table.row(row).data();
1494+
const isAffectedByMultiPattern = rowData.exclude_pattern_type === MULTI_URL_PATTERN;
1495+
const patternId = rowData.include_pattern_id;
1496+
1497+
if (isAffectedByMultiPattern) {
1498+
// For URLs affected by multi-URL exclude patterns:
1499+
// - If excluded: Create individual include pattern to override
1500+
// - If not excluded: Delete the override include pattern
1501+
if (isExcluded) {
1502+
postIncludePatterns((match_pattern = url), (match_pattern_type = 1));
1503+
} else {
1504+
deletePatternWithoutPrompt(`/api/include-patterns/${patternId}/`);
1505+
}
1506+
} else {
1507+
// For URLs not affected by multi-URL patterns:
1508+
// Toggle individual exclude pattern
1509+
postExcludePatterns(
1510+
(match_pattern = url),
1511+
(match_pattern_type = 1),
1512+
true
1513+
);
1514+
}
1515+
});
1516+
}
1517+
1518+
function deletePatternWithoutPrompt(url) {
1519+
$.ajax({
1520+
url: url,
1521+
type: "DELETE",
1522+
data: {
1523+
csrfmiddlewaretoken: csrftoken,
1524+
},
1525+
headers: {
1526+
"X-CSRFToken": csrftoken,
1527+
},
1528+
success: function (data) {
1529+
$("#delta_urls_table").DataTable().ajax.reload(null, false);
1530+
$("#exclude_patterns_table").DataTable().ajax.reload(null, false);
1531+
$("#include_patterns_table").DataTable().ajax.reload(null, false);
1532+
$("#title_patterns_table").DataTable().ajax.reload(null, false);
1533+
$("#document_type_patterns_table").DataTable().ajax.reload(null, false);
1534+
$("#division_patterns_table").DataTable().ajax.reload(null, false);
1535+
},
14911536
});
14921537
}
14931538

0 commit comments

Comments
 (0)