Skip to content

Commit b5c1c42

Browse files
committed
fix modal bug and add workflow status
1 parent 5ca98a4 commit b5c1c42

File tree

6 files changed

+136
-68
lines changed

6 files changed

+136
-68
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Generated by Django 4.2.9 on 2024-12-11 02:41
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("sde_collections", "0073_alter_collection_workflow_status_and_more"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="collection",
15+
name="reindexing_status",
16+
field=models.IntegerField(
17+
choices=[
18+
(1, "Re-Indexing Not Needed"),
19+
(2, "Re-Indexing Needed"),
20+
(3, "Re-Indexing Finished"),
21+
(4, "Ready for Re-Curation"),
22+
(5, "Re-Curation Finished"),
23+
(6, "Re-Indexed on Prod"),
24+
],
25+
default=1,
26+
verbose_name="Reindexing Status",
27+
),
28+
),
29+
migrations.AlterField(
30+
model_name="reindexinghistory",
31+
name="old_status",
32+
field=models.IntegerField(
33+
choices=[
34+
(1, "Re-Indexing Not Needed"),
35+
(2, "Re-Indexing Needed"),
36+
(3, "Re-Indexing Finished"),
37+
(4, "Ready for Re-Curation"),
38+
(5, "Re-Curation Finished"),
39+
(6, "Re-Indexed on Prod"),
40+
],
41+
null=True,
42+
),
43+
),
44+
migrations.AlterField(
45+
model_name="reindexinghistory",
46+
name="reindexing_status",
47+
field=models.IntegerField(
48+
choices=[
49+
(1, "Re-Indexing Not Needed"),
50+
(2, "Re-Indexing Needed"),
51+
(3, "Re-Indexing Finished"),
52+
(4, "Ready for Re-Curation"),
53+
(5, "Re-Curation Finished"),
54+
(6, "Re-Indexed on Prod"),
55+
],
56+
default=1,
57+
),
58+
),
59+
]

sde_collections/models/collection_choice_fields.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ class ReindexingStatusChoices(models.IntegerChoices):
108108
REINDEXING_CURATED = 5, "Re-Curation Finished"
109109
REINDEXING_INDEXED_ON_PROD = 6, "Re-Indexed on Prod"
110110

111-
@classmethod
112-
def get_status_string(cls, value):
113-
for choice in cls.choices:
114-
if choice[0] == value:
115-
return choice[1]
116-
return "N/A"
111+
# @classmethod
112+
# def get_status_string(cls, value):
113+
# for choice in cls.choices:
114+
# if choice[0] == value:
115+
# return choice[1]
116+
# return "N/A"
117117

118118

119119
class TDAMMTags(models.TextChoices):

sde_collections/serializers.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from rest_framework import serializers
22

3-
from .models.collection import Collection, WorkflowHistory
3+
from .models.collection import Collection, ReindexingHistory, WorkflowHistory
44
from .models.collection_choice_fields import Divisions, DocumentTypes
55
from .models.delta_patterns import (
66
DeltaDivisionPattern,
@@ -36,7 +36,7 @@ class Meta:
3636
"division": {"required": False},
3737
"document_type": {"required": False},
3838
"name": {"required": False},
39-
"reindexing_status": {"required": False},
39+
# "reindexing_status": {"required": False},
4040
}
4141

4242
# extra_kwargs = {
@@ -58,6 +58,12 @@ class Meta:
5858
fields = "__all__"
5959

6060

61+
class ReindexingHistorySerializer(serializers.ModelSerializer):
62+
class Meta:
63+
model = ReindexingHistory
64+
fields = "__all__"
65+
66+
6167
class DeltaURLSerializer(serializers.ModelSerializer):
6268
excluded = serializers.BooleanField(required=False)
6369
document_type_display = serializers.CharField(source="get_document_type_display", read_only=True)

sde_collections/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ def get_context_data(self, **kwargs):
179179
"-created_at"
180180
)
181181
context["workflow_status_choices"] = WorkflowStatusChoices
182+
context["reindexing_status_choices"] = ReindexingStatusChoices
182183

183184
return context
184185

sde_indexing_helper/static/js/delta_url_list.js

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,42 @@ function postWorkflowStatus(collection_id, workflow_status) {
21072107
});
21082108
}
21092109

2110+
function postReindexingStatus(collection_id, reindexing_status) {
2111+
var url = `/api/collections/${collection_id}/`;
2112+
$.ajax({
2113+
url: url,
2114+
type: "PUT",
2115+
data: {
2116+
reindexing_status: reindexing_status,
2117+
csrfmiddlewaretoken: csrftoken,
2118+
},
2119+
headers: {
2120+
"X-CSRFToken": csrftoken,
2121+
},
2122+
success: function (data) {
2123+
$('#reindexingStatusChangeModal button').blur();
2124+
$("#reindexingStatusChangeModal")
2125+
.removeClass('show')
2126+
.removeAttr('aria-hidden')
2127+
.modal('hide');
2128+
$('.modal-backdrop').remove();
2129+
$('body').removeClass('modal-open');
2130+
toastr.success("Reindexing Status Updated!");
2131+
2132+
// Refresh page after modal closes and success message shows
2133+
setTimeout(function () {
2134+
window.location = window.location.href;
2135+
}, 1500);
2136+
},
2137+
error: function (xhr, status, error) {
2138+
$('#reindexingStatusChangeModal button').blur();
2139+
$("#reindexingStatusChangeModal").modal('hide');
2140+
$('.modal-backdrop').remove();
2141+
toastr.error("Error updating reindexing status: " + error);
2142+
}
2143+
});
2144+
}
2145+
21102146
function handleWorkflowStatusSelect() {
21112147
$("body").on("click", ".workflow_status_select", function () {
21122148
$("#workflowStatusChangeModal").modal();
@@ -2161,42 +2197,6 @@ function handleWorkflowStatusSelect() {
21612197
});
21622198
}
21632199

2164-
function postReindexingStatus(collection_id, reindexing_status) {
2165-
var url = `/api/collections/${collection_id}/`;
2166-
$.ajax({
2167-
url: url,
2168-
type: "PUT",
2169-
data: {
2170-
reindexing_status: reindexing_status,
2171-
csrfmiddlewaretoken: csrftoken,
2172-
},
2173-
headers: {
2174-
"X-CSRFToken": csrftoken,
2175-
},
2176-
success: function (data) {
2177-
$('#reindexingStatusChangeModal button').blur();
2178-
$("#reindexingStatusChangeModal")
2179-
.removeClass('show')
2180-
.removeAttr('aria-hidden')
2181-
.modal('hide');
2182-
$('.modal-backdrop').remove();
2183-
$('body').removeClass('modal-open');
2184-
toastr.success("Reindexing Status Updated!");
2185-
2186-
// Refresh page after modal closes and success message shows
2187-
setTimeout(function () {
2188-
window.location = window.location.href;
2189-
}, 1500);
2190-
},
2191-
error: function (xhr, status, error) {
2192-
$('#reindexingStatusChangeModal button').blur();
2193-
$("#reindexingStatusChangeModal").modal('hide');
2194-
$('.modal-backdrop').remove();
2195-
toastr.error("Error updating reindexing status: " + error);
2196-
}
2197-
});
2198-
}
2199-
22002200
function handleReindexingStatusSelect() {
22012201
$("body").on("click", ".reindexing_status_select", function () {
22022202
$("#reindexingStatusChangeModal").modal();
@@ -2208,7 +2208,6 @@ function handleReindexingStatusSelect() {
22082208
$(".reindexing-status-change-caption").html(
22092209
`<div>Reindexing status for <b class="bold">${collectionName}</b> will change to <b class="bold">${new_reindexing_status}</b></div>`
22102210
);
2211-
22122211
$("#reindexingStatusChangeModalForm").on("click", "button", function (event) {
22132212
event.preventDefault();
22142213
var buttonId = $(this).attr("id");
@@ -2228,8 +2227,11 @@ function handleReindexingStatusSelect() {
22282227
};
22292228

22302229
$button = $(`#reindexing-status-button-${collection_id}`);
2230+
22312231
$button.text(new_reindexing_status);
2232-
$button.removeClass("btn-light btn-danger btn-warning btn-info btn-success btn-primary btn-secondary");
2232+
$button.removeClass(
2233+
"btn-light btn-danger btn-warning btn-info btn-success btn-primary btn-secondary"
2234+
);
22332235
$button.addClass(color_choices[parseInt(reindexing_status)]);
22342236
postReindexingStatus(collection_id, reindexing_status);
22352237
$("#reindexingStatusChangeModal").modal("hide");

sde_indexing_helper/templates/sde_collections/delta_urls_list.html

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,27 @@ <h1 class="pageTitle mb-0">URLs</h1>
3939
</div>
4040
</div>
4141

42-
<div class="btn-group">
43-
<button type="button"
44-
class="btn {{ collection.reindexing_status_button_color }} dropdown-toggle btn-sm"
45-
id="reindexing-status-button-{{ collection.id }}"
42+
<div class="btn-group mr-2">
43+
<button class="btn badge {{ collection.reindexing_status_button_color }} dropdown-toggle title-dropdown btn-sm"
44+
type="button"
4645
data-toggle="dropdown"
4746
aria-haspopup="true"
47+
id="reindexing-status-button-{{ collection.id }}"
4848
aria-expanded="false">
4949
{{ collection.get_reindexing_status_display }}
5050
</button>
5151
<div class="dropdown-menu" aria-labelledby="reindexing-status-button-{{ collection.id }}">
52-
{% for choice in reindexing_status_choices.choices %}
52+
{% for choice in reindexing_status_choices %}
5353
<a class="dropdown-item reindexing_status_select"
54-
href="#"
55-
value="{{ choice.0 }}"
54+
value="{{ choice }}"
5655
data-collection-id="{{ collection.id }}">
57-
{{ choice.1 }}
56+
{{ choice.label }}
5857
</a>
5958
{% endfor %}
6059
</div>
6160
</div>
6261
</div>
63-
</div>
62+
</div>
6463

6564

6665
<div class="deltaUrlContainer">
@@ -640,20 +639,21 @@ <h5 class="modal-title">Are you sure?</h5>
640639
<span aria-hidden="true">&times;</span>
641640
</button>
642641
</div>
643-
<div class="modal-body" id="modal-body">
644-
<h5 class="modal-title">Are you sure?</h5>
645-
<p class="workflow-status-change-caption" id="caption"></p>
646-
</div>
647-
<div class="modal-footer">
648-
<form id="workflowStatusChangeModalForm">
649-
<div class="button-wrapper">
642+
<div class="modal-body" id="workflow-modal-body">
643+
<h5 class="modal-title">Are you sure?</h5>
644+
<p class="workflow-status-change-caption" id="workflow-caption"></p>
645+
</div>
646+
<div class="modal-footer">
647+
<form id="workflowStatusChangeModalForm">
648+
<div class="button-wrapper">
650649
<button type="submit" class="btn btn-secondary modal-button-1" id="cancelworkflowStatusChange">No</button>
651650
<button type="submit" class="btn btn-primary modal-button-2" data-dismiss="modal" id="changeWorkflowStatus">Yes</button>
652-
</div>
653-
</form>
654-
</div>
651+
</div>
652+
</form>
653+
</div>
655654
</div>
656655
</div>
656+
</div>
657657

658658
<div class="modal" id="reindexingStatusChangeModal" tabindex="-1"
659659
aria-labelledby="reindexingStatusChangeModal" aria-hidden="true">
@@ -664,9 +664,9 @@ <h5 class="modal-title">Are you sure?</h5>
664664
<span aria-hidden="true">&times;</span>
665665
</button>
666666
</div>
667-
<div class="modal-body" id="modal-body">
667+
<div class="modal-body" id="reindexing-modal-body">
668668
<h5 class="modal-title">Are you sure?</h5>
669-
<p class="reindexing-status-change-caption" id="caption"></p>
669+
<p class="reindexing-status-change-caption" id="reindexing-caption"></p>
670670
</div>
671671
<div class="modal-footer">
672672
<form id="reindexingStatusChangeModalForm">
@@ -678,7 +678,7 @@ <h5 class="modal-title">Are you sure?</h5>
678678
</div>
679679
</div>
680680
</div>
681-
681+
</div>
682682

683683
{% endblock content %}
684684

0 commit comments

Comments
 (0)