diff --git a/sde_collections/migrations/0074_alter_collection_reindexing_status_and_more.py b/sde_collections/migrations/0074_alter_collection_reindexing_status_and_more.py new file mode 100644 index 00000000..06963e83 --- /dev/null +++ b/sde_collections/migrations/0074_alter_collection_reindexing_status_and_more.py @@ -0,0 +1,59 @@ +# Generated by Django 4.2.9 on 2024-12-11 02:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("sde_collections", "0073_alter_collection_workflow_status_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="collection", + name="reindexing_status", + field=models.IntegerField( + choices=[ + (1, "Re-Indexing Not Needed"), + (2, "Re-Indexing Needed"), + (3, "Re-Indexing Finished"), + (4, "Ready for Re-Curation"), + (5, "Re-Curation Finished"), + (6, "Re-Indexed on Prod"), + ], + default=1, + verbose_name="Reindexing Status", + ), + ), + migrations.AlterField( + model_name="reindexinghistory", + name="old_status", + field=models.IntegerField( + choices=[ + (1, "Re-Indexing Not Needed"), + (2, "Re-Indexing Needed"), + (3, "Re-Indexing Finished"), + (4, "Ready for Re-Curation"), + (5, "Re-Curation Finished"), + (6, "Re-Indexed on Prod"), + ], + null=True, + ), + ), + migrations.AlterField( + model_name="reindexinghistory", + name="reindexing_status", + field=models.IntegerField( + choices=[ + (1, "Re-Indexing Not Needed"), + (2, "Re-Indexing Needed"), + (3, "Re-Indexing Finished"), + (4, "Ready for Re-Curation"), + (5, "Re-Curation Finished"), + (6, "Re-Indexed on Prod"), + ], + default=1, + ), + ), + ] diff --git a/sde_collections/models/collection_choice_fields.py b/sde_collections/models/collection_choice_fields.py index f5e0bb9f..6bba7846 100644 --- a/sde_collections/models/collection_choice_fields.py +++ b/sde_collections/models/collection_choice_fields.py @@ -108,12 +108,12 @@ class ReindexingStatusChoices(models.IntegerChoices): REINDEXING_CURATED = 5, "Re-Curation Finished" REINDEXING_INDEXED_ON_PROD = 6, "Re-Indexed on Prod" - @classmethod - def get_status_string(cls, value): - for choice in cls.choices: - if choice[0] == value: - return choice[1] - return "N/A" + # @classmethod + # def get_status_string(cls, value): + # for choice in cls.choices: + # if choice[0] == value: + # return choice[1] + # return "N/A" class TDAMMTags(models.TextChoices): diff --git a/sde_collections/serializers.py b/sde_collections/serializers.py index a27482c0..1a4ac099 100644 --- a/sde_collections/serializers.py +++ b/sde_collections/serializers.py @@ -1,6 +1,6 @@ from rest_framework import serializers -from .models.collection import Collection, WorkflowHistory +from .models.collection import Collection, ReindexingHistory, WorkflowHistory from .models.collection_choice_fields import Divisions, DocumentTypes from .models.delta_patterns import ( DeltaDivisionPattern, @@ -36,7 +36,7 @@ class Meta: "division": {"required": False}, "document_type": {"required": False}, "name": {"required": False}, - "reindexing_status": {"required": False}, + # "reindexing_status": {"required": False}, } # extra_kwargs = { @@ -58,6 +58,12 @@ class Meta: fields = "__all__" +class ReindexingHistorySerializer(serializers.ModelSerializer): + class Meta: + model = ReindexingHistory + fields = "__all__" + + class DeltaURLSerializer(serializers.ModelSerializer): excluded = serializers.BooleanField(required=False) document_type_display = serializers.CharField(source="get_document_type_display", read_only=True) diff --git a/sde_collections/views.py b/sde_collections/views.py index 215a7353..8b3f1727 100644 --- a/sde_collections/views.py +++ b/sde_collections/views.py @@ -179,6 +179,7 @@ def get_context_data(self, **kwargs): "-created_at" ) context["workflow_status_choices"] = WorkflowStatusChoices + context["reindexing_status_choices"] = ReindexingStatusChoices return context diff --git a/sde_indexing_helper/static/js/delta_url_list.js b/sde_indexing_helper/static/js/delta_url_list.js index c6cac7dd..aff3e86a 100644 --- a/sde_indexing_helper/static/js/delta_url_list.js +++ b/sde_indexing_helper/static/js/delta_url_list.js @@ -2107,6 +2107,42 @@ function postWorkflowStatus(collection_id, workflow_status) { }); } +function postReindexingStatus(collection_id, reindexing_status) { + var url = `/api/collections/${collection_id}/`; + $.ajax({ + url: url, + type: "PUT", + data: { + reindexing_status: reindexing_status, + csrfmiddlewaretoken: csrftoken, + }, + headers: { + "X-CSRFToken": csrftoken, + }, + success: function (data) { + $('#reindexingStatusChangeModal button').blur(); + $("#reindexingStatusChangeModal") + .removeClass('show') + .removeAttr('aria-hidden') + .modal('hide'); + $('.modal-backdrop').remove(); + $('body').removeClass('modal-open'); + toastr.success("Reindexing Status Updated!"); + + // Refresh page after modal closes and success message shows + setTimeout(function () { + window.location = window.location.href; + }, 1500); + }, + error: function (xhr, status, error) { + $('#reindexingStatusChangeModal button').blur(); + $("#reindexingStatusChangeModal").modal('hide'); + $('.modal-backdrop').remove(); + toastr.error("Error updating reindexing status: " + error); + } + }); +} + function handleWorkflowStatusSelect() { $("body").on("click", ".workflow_status_select", function () { $("#workflowStatusChangeModal").modal(); @@ -2161,42 +2197,6 @@ function handleWorkflowStatusSelect() { }); } -function postReindexingStatus(collection_id, reindexing_status) { - var url = `/api/collections/${collection_id}/`; - $.ajax({ - url: url, - type: "PUT", - data: { - reindexing_status: reindexing_status, - csrfmiddlewaretoken: csrftoken, - }, - headers: { - "X-CSRFToken": csrftoken, - }, - success: function (data) { - $('#reindexingStatusChangeModal button').blur(); - $("#reindexingStatusChangeModal") - .removeClass('show') - .removeAttr('aria-hidden') - .modal('hide'); - $('.modal-backdrop').remove(); - $('body').removeClass('modal-open'); - toastr.success("Reindexing Status Updated!"); - - // Refresh page after modal closes and success message shows - setTimeout(function () { - window.location = window.location.href; - }, 1500); - }, - error: function (xhr, status, error) { - $('#reindexingStatusChangeModal button').blur(); - $("#reindexingStatusChangeModal").modal('hide'); - $('.modal-backdrop').remove(); - toastr.error("Error updating reindexing status: " + error); - } - }); -} - function handleReindexingStatusSelect() { $("body").on("click", ".reindexing_status_select", function () { $("#reindexingStatusChangeModal").modal(); @@ -2208,7 +2208,6 @@ function handleReindexingStatusSelect() { $(".reindexing-status-change-caption").html( `
Reindexing status for ${collectionName} will change to ${new_reindexing_status}
` ); - $("#reindexingStatusChangeModalForm").on("click", "button", function (event) { event.preventDefault(); var buttonId = $(this).attr("id"); @@ -2228,8 +2227,11 @@ function handleReindexingStatusSelect() { }; $button = $(`#reindexing-status-button-${collection_id}`); + $button.text(new_reindexing_status); - $button.removeClass("btn-light btn-danger btn-warning btn-info btn-success btn-primary btn-secondary"); + $button.removeClass( + "btn-light btn-danger btn-warning btn-info btn-success btn-primary btn-secondary" + ); $button.addClass(color_choices[parseInt(reindexing_status)]); postReindexingStatus(collection_id, reindexing_status); $("#reindexingStatusChangeModal").modal("hide"); diff --git a/sde_indexing_helper/templates/sde_collections/delta_urls_list.html b/sde_indexing_helper/templates/sde_collections/delta_urls_list.html index c041dde4..fb0555fa 100644 --- a/sde_indexing_helper/templates/sde_collections/delta_urls_list.html +++ b/sde_indexing_helper/templates/sde_collections/delta_urls_list.html @@ -39,28 +39,27 @@

URLs

-
-
- +
@@ -640,20 +639,21 @@
- - + - - + {% endblock content %}