Skip to content

Commit 1f70b32

Browse files
committed
add initial frontend fixes
1 parent ad82236 commit 1f70b32

File tree

4 files changed

+121
-13
lines changed

4 files changed

+121
-13
lines changed

sde_collections/serializers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@
1515
class CollectionSerializer(serializers.ModelSerializer):
1616
curation_status_display = serializers.CharField(source="get_curation_status_display", read_only=True)
1717
workflow_status_display = serializers.CharField(source="get_workflow_status_display", read_only=True)
18+
reindexing_status_display = serializers.CharField(source="get_reindexing_status_display", read_only=True)
1819

1920
class Meta:
2021
model = Collection
2122
fields = (
2223
"id",
2324
"curation_status",
2425
"workflow_status",
26+
"reindexing_status",
2527
"curation_status_display",
2628
"workflow_status_display",
29+
"reindexing_status_display",
2730
"curated_by",
2831
"division",
2932
"document_type",
@@ -33,6 +36,7 @@ class Meta:
3336
"division": {"required": False},
3437
"document_type": {"required": False},
3538
"name": {"required": False},
39+
"reindexing_status": {"required": False},
3640
}
3741

3842
# extra_kwargs = {

sde_collections/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
CurationStatusChoices,
2525
Divisions,
2626
DocumentTypes,
27+
ReindexingStatusChoices,
2728
WorkflowStatusChoices,
2829
)
2930
from .models.delta_patterns import (
@@ -80,6 +81,7 @@ def get_context_data(self, **kwargs):
8081
context["curators"] = User.objects.filter(groups__name="Curators")
8182
context["curation_status_choices"] = CurationStatusChoices
8283
context["workflow_status_choices"] = WorkflowStatusChoices
84+
context["reindexing_status_choices"] = ReindexingStatusChoices
8385

8486
return context
8587

sde_indexing_helper/static/js/collection_list.js

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ let table = $("#collection_table").DataTable({
108108
],
109109
columnDefs: [
110110
{
111-
targets: 8,
111+
targets: [8, 9], // Added 9 for reindexing status ID
112112
visible: false,
113113
},
114114
{ width: "200px", targets: 1 },
@@ -170,7 +170,7 @@ let table = $("#collection_table").DataTable({
170170
searchPanes: {
171171
show: false,
172172
},
173-
targets: [7, 8],
173+
targets: [7, 8, 9], // Added 9 for reindexing status ID
174174
},
175175
{
176176
searchPanes: {
@@ -180,6 +180,14 @@ let table = $("#collection_table").DataTable({
180180
},
181181
targets: [5],
182182
},
183+
{
184+
searchPanes: {
185+
dtOpts: {
186+
scrollY: "100%",
187+
},
188+
},
189+
targets: [6], // Add searchPane for reindexing status column
190+
},
183191
],
184192
});
185193

@@ -302,6 +310,51 @@ function handleWorkflowStatusSelect() {
302310
postWorkflowStatus(collection_id, workflow_status);
303311
});
304312
}
313+
function handleReindexingStatusSelect() {
314+
$("body").on("click", ".reindexing_status_select", function () {
315+
var collection_id = $(this).data("collection-id");
316+
var reindexing_status = $(this).attr("value");
317+
var reindexing_status_text = $(this).text();
318+
var color_choices = {
319+
1: "btn-light", // REINDEXING_NOT_NEEDED
320+
2: "btn-warning", // REINDEXING_NEEDED_ON_DEV
321+
3: "btn-secondary", // REINDEXING_FINISHED_ON_DEV
322+
4: "btn-info", // REINDEXING_READY_FOR_CURATION
323+
5: "btn-primary", // REINDEXING_CURATED
324+
6: "btn-success", // REINDEXING_INDEXED_ON_PROD
325+
};
326+
327+
$possible_buttons = $("body").find(
328+
`[id="reindexing-status-button-${collection_id}"]`
329+
);
330+
if ($possible_buttons.length > 1) {
331+
$button = $possible_buttons[1];
332+
$button = $($button);
333+
} else {
334+
$button = $(`#reindexing-status-button-${collection_id}`);
335+
}
336+
$button.text(reindexing_status_text);
337+
$button.removeClass(
338+
"btn-light btn-danger btn-warning btn-info btn-success btn-primary btn-secondary"
339+
);
340+
$button.addClass(color_choices[parseInt(reindexing_status)]);
341+
var row = table.row("#" + collection_id);
342+
let index = row.index();
343+
var $html = $("<div />", { html: table.data()[index][9] }); // Assuming this is column index 9
344+
$html.find("button").html(reindexing_status_text);
345+
$html
346+
.find("button")
347+
.removeClass(
348+
"btn-light btn-danger btn-warning btn-info btn-success btn-primary btn-secondary"
349+
);
350+
$html.find("button").addClass(color_choices[parseInt(reindexing_status)]);
351+
table.data()[index][9] = $html.html();
352+
$("#collection_table").DataTable().searchPanes.rebuildPane(9);
353+
354+
postReindexingStatus(collection_id, reindexing_status);
355+
});
356+
}
357+
305358

306359
function handleCuratorSelect() {
307360
$("body").on("click", ".curator_select", function () {
@@ -334,6 +387,24 @@ function handleCuratorSelect() {
334387
});
335388
}
336389

390+
function postReindexingStatus(collection_id, reindexing_status) {
391+
var url = `/api/collections/${collection_id}/`;
392+
$.ajax({
393+
url: url,
394+
type: "PUT",
395+
data: {
396+
reindexing_status: reindexing_status,
397+
csrfmiddlewaretoken: csrftoken,
398+
},
399+
headers: {
400+
"X-CSRFToken": csrftoken,
401+
},
402+
success: function (data) {
403+
toastr.success("Reindexing Status Updated!");
404+
},
405+
});
406+
}
407+
337408
function postCurationStatus(collection_id, curation_status) {
338409
var url = `/api/collections/${collection_id}/`;
339410
$.ajax({
@@ -403,6 +474,7 @@ $(document).ready(function () {
403474
"Workflow Status",
404475
"Curator",
405476
"Connector Type",
477+
"Reindexing Status",
406478
];
407479

408480
// Event listener for the collection search input
@@ -415,16 +487,16 @@ $(document).ready(function () {
415487

416488
// Filter the table based on the query in the collection name and config folder data attribute
417489
table.rows().every(function () {
418-
let row = $(this.node());
419-
let name = row.find('td').first().text().toLowerCase();
420-
let configFolder = row.data('config-folder').toLowerCase();
421-
let url = row.find('td').eq(1).text().toLowerCase();
422-
423-
if (name.includes(query) || configFolder.includes(query) || url.includes(query)) {
424-
row.show();
425-
} else {
426-
row.hide();
427-
}
490+
let row = $(this.node());
491+
let name = row.find('td').first().text().toLowerCase();
492+
let configFolder = row.data('config-folder').toLowerCase();
493+
let url = row.find('td').eq(1).text().toLowerCase();
494+
495+
if (name.includes(query) || configFolder.includes(query) || url.includes(query)) {
496+
row.show();
497+
} else {
498+
row.hide();
499+
}
428500
});
429501
});
430502

@@ -448,6 +520,7 @@ $(document).ready(function () {
448520
function setupClickHandlers() {
449521
// handleCurationStatusSelect();
450522
handleWorkflowStatusSelect();
523+
handleReindexingStatusSelect();
451524
handleCuratorSelect();
452525
}
453526

sde_indexing_helper/templates/sde_collections/collection_list.html

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ <h2 class="title">Welcome back!</h2>
2222
<th class="text-center noBorder" style="padding-right:25px !important">Workflow Status</th>
2323
<th class="text-center noBorder" style="padding-right:25px !important">Curator</th>
2424
<th class="text-center noBorder" style="padding-right:25px !important">Connector Type</th>
25-
25+
<th class="text-center noBorder" style="padding-right:25px !important">Reindexing Status</th>
26+
<th class="hideDisplay"></th>
2627
<th class="hideDisplay"></th>
2728
<th class="hideDisplay"></th>
2829
</tr>
@@ -44,8 +45,15 @@ <h2 class="title">Welcome back!</h2>
4445
{% endfor %}
4546
</select></td>
4647
<td class="filterRowBottom"><input class="table_filter_row_input textBoxStyling" type="text" id="connectorTypeFilter" placeholder="Connector Type" /></td>
48+
<td class="filterRowBottom"><select id="collection-dropdown-6" class="select-dropdown selectStyling">
49+
<option value="">SELECT</option>
50+
{% for choice in reindexing_status_choices %}
51+
<option value="{{ choice }}" data-collection-id={{ collection.id }}>{{ choice.label }}</option>
52+
{% endfor %}
53+
</select></td>
4754
<td class="hideDisplay"></td>
4855
<td class="hideDisplay"></td>
56+
<th class="hideDisplay"></th>
4957
</tr>
5058
</thead>
5159

@@ -114,8 +122,29 @@ <h2 class="title">Welcome back!</h2>
114122
</div>
115123
</td>
116124
<td class="whiteText noBorder">{{ collection.get_connector_display }}</td>
125+
<td class="noBorder">
126+
<div class="dropdown reindexing_status_dropdown"
127+
data-match-pattern
128+
remove_protocol
129+
row
130+
url>
131+
<button class="btn {{ collection.reindexing_status_button_color }} btn-sm dropdown-toggle"
132+
type="button"
133+
id="reindexing-status-button-{{ collection.id }}"
134+
data-toggle="dropdown"
135+
aria-haspopup="true"
136+
aria-expanded="false">{{ collection.get_reindexing_status_display }}</button>
137+
<div class="dropdown-menu"
138+
aria-labelledby="reindexing-status-button-{{ collection.id }}">
139+
{% for choice in reindexing_status_choices %}
140+
<a class="dropdown-item reindexing_status_select" value="{{ choice }}" data-collection-id={{ collection.id }} >{{ choice.label }}</a>
141+
{% endfor %}
142+
</div>
143+
</div>
144+
</td>
117145
<td class="hideDisplay">{{ collection.workflow_status }}</td>
118146
<td class="hideDisplay">{{ collection.curated_by_id }}</td>
147+
<td class="hideDisplay">{{ collection.reindexing_status }}</td>
119148
</tr>
120149
{% endfor %}
121150
</tbody>

0 commit comments

Comments
 (0)