Skip to content

Commit

Permalink
Merge pull request #1167 from NASA-IMPACT/1156-update-exclude-checkma…
Browse files Browse the repository at this point in the history
…rk-action-to-change-behavior-based-on-inclusion-status

Update exclude checkmark action to change behavior based on inclusion status
  • Loading branch information
bishwaspraveen authored Jan 8, 2025
2 parents 4083d7d + 456c763 commit 99a72f4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 5 deletions.
4 changes: 4 additions & 0 deletions sde_collections/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class DeltaURLSerializer(serializers.ModelSerializer):
match_pattern_type = serializers.SerializerMethodField(read_only=True)
delta_urls_count = serializers.SerializerMethodField(read_only=True)
tdamm_tag = serializers.SerializerMethodField()
exclude_pattern_type = serializers.IntegerField(read_only=True)
include_pattern_id = serializers.IntegerField(read_only=True)

def get_tdamm_tag(self, obj):
tags = obj.tdamm_tag
Expand Down Expand Up @@ -108,6 +110,8 @@ class Meta:
"division_display",
"visited",
"tdamm_tag",
"exclude_pattern_type",
"include_pattern_id",
)


Expand Down
20 changes: 20 additions & 0 deletions sde_collections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,30 @@ def _filter_by_is_excluded(self, queryset, is_excluded):
def get_queryset(self):
queryset = super().get_queryset()
if self.request.method == "GET":
collection_id = self.request.GET.get("collection_id")
# Filter based on exclusion status
is_excluded = self.request.GET.get("is_excluded")
if is_excluded:
queryset = self._filter_by_is_excluded(queryset, is_excluded)

# Annotate queryset with two pieces of information:
# 1. exclude_pattern_type: Type of exclude pattern (1=Individual URL, 2=Multi-URL Pattern)
# Ordered by -match_pattern_type to prioritize multi-url patterns (type 2)
# 2. include_pattern_id: ID of any include pattern affecting this URL
# Used when we need to delete the include pattern during re-exclusion
queryset = queryset.annotate(
exclude_pattern_type=models.Subquery(
DeltaExcludePattern.objects.filter(delta_urls=models.OuterRef("pk"), collection_id=collection_id)
.order_by("-match_pattern_type")
.values("match_pattern_type")[:1]
),
include_pattern_id=models.Subquery(
DeltaIncludePattern.objects.filter(
delta_urls=models.OuterRef("pk"), collection_id=collection_id
).values("id")[:1]
),
)

return queryset.order_by("url")

def update_division(self, request, pk=None):
Expand Down
55 changes: 50 additions & 5 deletions sde_indexing_helper/static/js/delta_url_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ function initializeDataTable() {
getDocumentTypeColumn(),
getDivisionColumn(),
{ data: "id", visible: false, searchable: false },
{ data: "exclude_pattern_type", visible: false, searchable: false },
{ data: "include_pattern_id", visible: false, searchable: false },
{ data: "generated_title_id", visible: false, searchable: false },
{ data: "match_pattern_type", visible: false, searchable: false },
{ data: "delta_urls_count", visible: false, searchable: false },
Expand Down Expand Up @@ -1483,11 +1485,54 @@ function handleUrlPartButton() {

function handleExcludeIndividualUrlClick() {
$("body").on("click", ".exclude_individual_url", function () {
postExcludePatterns(
(match_pattern = $(this).attr("value")),
(match_pattern_type = 1),
true
);
const url = $(this).attr("value");
// "check" for excluded, "close" for not excluded
const isExcluded = $(this).children("i").text() === "check";
const row = $(this).closest("tr");
const table = $("#delta_urls_table").DataTable();
const rowData = table.row(row).data();
const isAffectedByMultiPattern = rowData.exclude_pattern_type === MULTI_URL_PATTERN;
const patternId = rowData.include_pattern_id;

if (isAffectedByMultiPattern) {
// For URLs affected by multi-URL exclude patterns:
// - If excluded: Create individual include pattern to override
// - If not excluded: Delete the override include pattern
if (isExcluded) {
postIncludePatterns((match_pattern = url), (match_pattern_type = 1));
} else {
deletePatternWithoutPrompt(`/api/include-patterns/${patternId}/`);
}
} else {
// For URLs not affected by multi-URL patterns:
// Toggle individual exclude pattern
postExcludePatterns(
(match_pattern = url),
(match_pattern_type = 1),
true
);
}
});
}

function deletePatternWithoutPrompt(url) {
$.ajax({
url: url,
type: "DELETE",
data: {
csrfmiddlewaretoken: csrftoken,
},
headers: {
"X-CSRFToken": csrftoken,
},
success: function (data) {
$("#delta_urls_table").DataTable().ajax.reload(null, false);
$("#exclude_patterns_table").DataTable().ajax.reload(null, false);
$("#include_patterns_table").DataTable().ajax.reload(null, false);
$("#title_patterns_table").DataTable().ajax.reload(null, false);
$("#document_type_patterns_table").DataTable().ajax.reload(null, false);
$("#division_patterns_table").DataTable().ajax.reload(null, false);
},
});
}

Expand Down

0 comments on commit 99a72f4

Please sign in to comment.