-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
1155 add a column to track the reindexing curator #1180
base: dev
Are you sure you want to change the base?
Changes from 7 commits
1447d19
4ff58d7
11dfed8
0bb0ccb
cf7d1f8
6c3d9c8
ad4364b
8541c75
386ddaf
e0a9367
9ec2e45
150dfb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 4.2.9 on 2025-01-09 05:07 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("sde_collections", "0075_alter_collection_reindexing_status_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="collection", | ||
name="reindexing_curated_by", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="reindexing_curated_by", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Generated by Django 4.2.9 on 2025-01-09 05:12 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("sde_collections", "0076_collection_reindexing_curated_by"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="collection", | ||
name="reindexing_curated_by", | ||
field=models.ForeignKey( | ||
blank=True, | ||
default=None, | ||
null=True, | ||
on_delete=django.db.models.deletion.DO_NOTHING, | ||
related_name="reindexing_curated_by", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ class Meta: | |
"workflow_status_display", | ||
"reindexing_status_display", | ||
"curated_by", | ||
"reindexing_curated_by", | ||
"division", | ||
"document_type", | ||
"name", | ||
|
@@ -45,6 +46,13 @@ class Meta: | |
# "division": {"required": False}, | ||
# } | ||
|
||
def update(self, instance, validated_data): | ||
# If reindexing_status is REINDEXING_NOT_NEEDED, set Reindexing Curator field to None (reset to default) | ||
if validated_data.get("reindexing_status") == 1: | ||
validated_data["reindexing_curated_by"] = None | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we maintain the history of changes on this field? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. History is now maintained. |
||
return super().update(instance, validated_data) | ||
|
||
|
||
class CollectionReadSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,11 @@ const COLUMNS = { | |
CURATOR: 6, | ||
CONNECTOR_TYPE: 7, | ||
REINDEXING_STATUS: 8, | ||
WORKFLOW_STATUS_RAW: 9, | ||
CURATOR_ID: 10, | ||
REINDEXING_STATUS_RAW: 11 | ||
REINDEXING_CURATOR: 9, | ||
WORKFLOW_STATUS_RAW: 10, | ||
CURATOR_ID: 11, | ||
REINDEXING_STATUS_RAW: 12, | ||
REINDEXING_CURATOR_ID: 13 | ||
}; | ||
|
||
var uniqueId; //used for logic related to contents on column customization modal | ||
|
@@ -122,11 +124,25 @@ let table = $("#collection_table").DataTable({ | |
}, | ||
}, | ||
], | ||
searchPanes: { | ||
controls: true, | ||
// layout: 'columns-6', | ||
columns: [ | ||
COLUMNS.DIVISION, | ||
COLUMNS.DELTA_URLS, | ||
COLUMNS.CURATED_URLS, | ||
COLUMNS.WORKFLOW_STATUS, | ||
COLUMNS.CURATOR, | ||
COLUMNS.CONNECTOR_TYPE, | ||
COLUMNS.REINDEXING_STATUS | ||
] | ||
}, | ||
|
||
columnDefs: [ | ||
// hide the data columns | ||
{ | ||
targets: [COLUMNS.WORKFLOW_STATUS_RAW, COLUMNS.CURATOR_ID, COLUMNS.REINDEXING_STATUS_RAW], | ||
visible: false, | ||
targets: [COLUMNS.WORKFLOW_STATUS_RAW, COLUMNS.CURATOR_ID, COLUMNS.REINDEXING_STATUS_RAW, COLUMNS.REINDEXING_CURATOR_ID], | ||
visible: false, width: "0px", responsivePriority: -1 | ||
}, | ||
{ width: "200px", targets: COLUMNS.URL }, | ||
{ | ||
|
@@ -229,13 +245,6 @@ let table = $("#collection_table").DataTable({ | |
targets: [COLUMNS.CURATED_URLS], | ||
type: "num-fmt", | ||
}, | ||
// hide the data panes | ||
{ | ||
searchPanes: { | ||
show: false, | ||
}, | ||
targets: [COLUMNS.WORKFLOW_STATUS_RAW, COLUMNS.CURATOR_ID, COLUMNS.REINDEXING_STATUS_RAW], | ||
}, | ||
{ | ||
searchPanes: { | ||
dtOpts: { | ||
|
@@ -253,29 +262,37 @@ let table = $("#collection_table").DataTable({ | |
targets: [COLUMNS.CONNECTOR_TYPE], | ||
}, | ||
], | ||
autoWidth: false, | ||
}); | ||
|
||
$("#collection-dropdown-4").on("change", function () { | ||
$("#workflow-status-selector").on("change", function () { | ||
table | ||
.columns(COLUMNS.WORKFLOW_STATUS_RAW) | ||
.search(this.value ? "^" + this.value + "$" : "", true, false) | ||
.draw(); | ||
}); | ||
|
||
$("#collection-dropdown-5").on("change", function () { | ||
$("#curator-selector").on("change", function () { | ||
table | ||
.columns(COLUMNS.CURATOR_ID) | ||
.search(this.value ? "^" + this.value + "$" : "", true, false) | ||
.draw(); | ||
}); | ||
|
||
$("#collection-dropdown-6").on("change", function () { | ||
$("#reindexing-status-selector").on("change", function () { | ||
table | ||
.columns(COLUMNS.REINDEXING_STATUS_RAW) | ||
.search(this.value ? "^" + this.value + "$" : "", true, false) | ||
.draw(); | ||
}); | ||
|
||
$("#reindexing-curator-selector").on("change", function () { | ||
table | ||
.columns(COLUMNS.REINDEXING_CURATOR_ID) | ||
.search(this.value ? "^" + this.value + "$" : "", true, false) | ||
.draw(); | ||
}); | ||
|
||
$("#nameFilter").on("keyup", function () { | ||
table.columns(COLUMNS.NAME).search(this.value).draw(); | ||
}); | ||
|
@@ -426,6 +443,37 @@ function handleCuratorSelect() { | |
}); | ||
} | ||
|
||
function handleReindexingCuratorSelect() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this code dry and reuse code that we already have for CuratorSelect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tried to modularize the handleReindexingCuratorSelect() and handleCuratorSelect() functions into one, but ended up with too much if-else statements. So leaving as it is for better understandability. |
||
$("body").on("click", ".reindexing_curator_select", function () { | ||
const collection_id = $(this).data("collection-id"); | ||
const reindexing_curator_id = $(this).attr("value"); | ||
const reindexing_curator_text = $(this).text(); | ||
|
||
// Update button text and style | ||
const $button = $(`#reindexing-curator-button-${collection_id}`).last(); | ||
$button | ||
.text(reindexing_curator_text) | ||
.removeClass("btn-light btn-danger btn-warning btn-info btn-success btn-primary btn-dark") | ||
.addClass("btn-success"); | ||
|
||
// Update DataTable | ||
const rowIndex = table.row("#" + collection_id).index(); | ||
table.data()[rowIndex][COLUMNS.REINDEXING_CURATOR] = createReindexingCuratorButton(reindexing_curator_text); | ||
// table.searchPanes.rebuildPane(COLUMNS.REINDEXING_CURATOR); | ||
|
||
// Send update to server | ||
postReindexingCurator(collection_id, reindexing_curator_id); | ||
}); | ||
} | ||
|
||
// Helper function to create reindexing curator button HTML | ||
function createReindexingCuratorButton(reindexing_curator_text) { | ||
const buttonClass = reindexing_curator_text === "None" ? "btn-dark" : "btn-success"; | ||
return `<div class="dropdown reindexing_curator_dropdown"> | ||
<button class="btn ${buttonClass} btn-sm dropdown-toggle">${reindexing_curator_text}</button> | ||
</div>`; | ||
} | ||
|
||
function postReindexingStatus(collection_id, reindexing_status) { | ||
var url = `/api/collections/${collection_id}/`; | ||
$.ajax({ | ||
|
@@ -440,6 +488,16 @@ function postReindexingStatus(collection_id, reindexing_status) { | |
}, | ||
success: function (data) { | ||
toastr.success("Reindexing Status Updated!"); | ||
|
||
// If reindexing_status is REINDEXING_NOT_NEEDED, set Reindexing Curator field to None (reset to default) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take a look at the post_save method in collection.py and refactor it based on standards. |
||
if (reindexing_status == 1) { | ||
const $button = $(`#reindexing-curator-button-${collection_id}`).last(); | ||
$button.text("None").removeClass("btn-success").addClass("btn-dark"); | ||
// Update DataTable | ||
const rowIndex = table.row("#" + collection_id).index(); | ||
table.data()[rowIndex][COLUMNS.REINDEXING_CURATOR] = createReindexingCuratorButton("None"); | ||
// table.searchPanes.rebuildPane(COLUMNS.REINDEXING_CURATOR); | ||
} | ||
}, | ||
}); | ||
} | ||
|
@@ -481,6 +539,24 @@ function postCurator(collection_id, curator_id) { | |
}); | ||
} | ||
|
||
function postReindexingCurator(collection_id, reindexing_curator_id) { | ||
var url = `/api/collections/${collection_id}/`; | ||
$.ajax({ | ||
url: url, | ||
type: "PUT", | ||
data: { | ||
reindexing_curated_by: reindexing_curator_id, | ||
csrfmiddlewaretoken: csrftoken, | ||
}, | ||
headers: { | ||
"X-CSRFToken": csrftoken, | ||
}, | ||
success: function (data) { | ||
toastr.success("Reindexing Curator Updated!"); | ||
}, | ||
}); | ||
} | ||
|
||
$(document).ready(function () { | ||
setupClickHandlers(); | ||
|
||
|
@@ -489,8 +565,6 @@ $(document).ready(function () { | |
|
||
// Remove the search input and add custom titles | ||
var paneTitles = [ | ||
null, | ||
null, | ||
"Division", | ||
"Delta URLs", | ||
"Curated URLs", | ||
|
@@ -545,6 +619,7 @@ function setupClickHandlers() { | |
handleWorkflowStatusSelect(); | ||
handleReindexingStatusSelect(); | ||
handleCuratorSelect(); | ||
handleReindexingCuratorSelect(); | ||
} | ||
|
||
function clearSearchValues() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write tests as well.