Skip to content

Commit

Permalink
fix modal bug and add workflow status
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonDavis committed Dec 11, 2024
1 parent 5ca98a4 commit b5c1c42
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
12 changes: 6 additions & 6 deletions sde_collections/models/collection_choice_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions sde_collections/serializers.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions sde_collections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def get_context_data(self, **kwargs):
"-created_at"
)
context["workflow_status_choices"] = WorkflowStatusChoices
context["reindexing_status_choices"] = ReindexingStatusChoices

return context

Expand Down
78 changes: 40 additions & 38 deletions sde_indexing_helper/static/js/delta_url_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -2208,7 +2208,6 @@ function handleReindexingStatusSelect() {
$(".reindexing-status-change-caption").html(
`<div>Reindexing status for <b class="bold">${collectionName}</b> will change to <b class="bold">${new_reindexing_status}</b></div>`

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
DOM text
is reinterpreted as HTML without escaping meta-characters.
);

$("#reindexingStatusChangeModalForm").on("click", "button", function (event) {
event.preventDefault();
var buttonId = $(this).attr("id");
Expand All @@ -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");
Expand Down
44 changes: 22 additions & 22 deletions sde_indexing_helper/templates/sde_collections/delta_urls_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,27 @@ <h1 class="pageTitle mb-0">URLs</h1>
</div>
</div>

<div class="btn-group">
<button type="button"
class="btn {{ collection.reindexing_status_button_color }} dropdown-toggle btn-sm"
id="reindexing-status-button-{{ collection.id }}"
<div class="btn-group mr-2">
<button class="btn badge {{ collection.reindexing_status_button_color }} dropdown-toggle title-dropdown btn-sm"
type="button"
data-toggle="dropdown"
aria-haspopup="true"
id="reindexing-status-button-{{ collection.id }}"
aria-expanded="false">
{{ collection.get_reindexing_status_display }}
</button>
<div class="dropdown-menu" aria-labelledby="reindexing-status-button-{{ collection.id }}">
{% for choice in reindexing_status_choices.choices %}
{% for choice in reindexing_status_choices %}
<a class="dropdown-item reindexing_status_select"
href="#"
value="{{ choice.0 }}"
value="{{ choice }}"
data-collection-id="{{ collection.id }}">
{{ choice.1 }}
{{ choice.label }}
</a>
{% endfor %}
</div>
</div>
</div>
</div>
</div>


<div class="deltaUrlContainer">
Expand Down Expand Up @@ -640,20 +639,21 @@ <h5 class="modal-title">Are you sure?</h5>
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" id="modal-body">
<h5 class="modal-title">Are you sure?</h5>
<p class="workflow-status-change-caption" id="caption"></p>
</div>
<div class="modal-footer">
<form id="workflowStatusChangeModalForm">
<div class="button-wrapper">
<div class="modal-body" id="workflow-modal-body">
<h5 class="modal-title">Are you sure?</h5>
<p class="workflow-status-change-caption" id="workflow-caption"></p>
</div>
<div class="modal-footer">
<form id="workflowStatusChangeModalForm">
<div class="button-wrapper">
<button type="submit" class="btn btn-secondary modal-button-1" id="cancelworkflowStatusChange">No</button>
<button type="submit" class="btn btn-primary modal-button-2" data-dismiss="modal" id="changeWorkflowStatus">Yes</button>
</div>
</form>
</div>
</div>
</form>
</div>
</div>
</div>
</div>

<div class="modal" id="reindexingStatusChangeModal" tabindex="-1"
aria-labelledby="reindexingStatusChangeModal" aria-hidden="true">
Expand All @@ -664,9 +664,9 @@ <h5 class="modal-title">Are you sure?</h5>
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body" id="modal-body">
<div class="modal-body" id="reindexing-modal-body">
<h5 class="modal-title">Are you sure?</h5>
<p class="reindexing-status-change-caption" id="caption"></p>
<p class="reindexing-status-change-caption" id="reindexing-caption"></p>
</div>
<div class="modal-footer">
<form id="reindexingStatusChangeModalForm">
Expand All @@ -678,7 +678,7 @@ <h5 class="modal-title">Are you sure?</h5>
</div>
</div>
</div>

</div>

{% endblock content %}

Expand Down

0 comments on commit b5c1c42

Please sign in to comment.