From dc4a9dfe7c42dd99f68487659d580bee50486525 Mon Sep 17 00:00:00 2001 From: Michelle <88682822+emshahh@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:52:17 -0400 Subject: [PATCH 1/9] modal popping up for confirming deletion of any pattern on candidate url page and successfully deletes or closes modal depending on what user chooses --- .../static/js/candidate_url_list.js | 93 ++++++++++++++----- .../sde_collections/candidate_urls_list.html | 27 ++++++ 2 files changed, 96 insertions(+), 24 deletions(-) diff --git a/sde_indexing_helper/static/js/candidate_url_list.js b/sde_indexing_helper/static/js/candidate_url_list.js index c283f55d..97ebec37 100644 --- a/sde_indexing_helper/static/js/candidate_url_list.js +++ b/sde_indexing_helper/static/js/candidate_url_list.js @@ -13,6 +13,7 @@ var matchPatternTypeMap = { "Individual URL Pattern": 1, "Multi-URL Pattern": 2, }; + var uniqueId; //used for logic related to contents on column customization modal const dict = { 1: "Images", @@ -44,14 +45,14 @@ function modalContents(tableName) { if (checkboxCount > 0 && tableName === uniqueId) { $modal = $("#hideShowColumnsModal").modal({ - backdrop: 'static', + backdrop: "static", keyboard: true, }); return; } $modal = $("#hideShowColumnsModal").modal({ - backdrop: 'static', + backdrop: "static", keyboard: true, }); var table = $(tableName).DataTable(); @@ -101,13 +102,16 @@ function initializeDataTable() { colReorder: true, stateSave: true, layout: { - bottomEnd: 'inputPaging', + bottomEnd: "inputPaging", topEnd: null, topStart: { - info:true, + info: true, pageLength: { - menu: [[25, 50, 100, 500],["Show 25", "Show 50", "Show 100", "Show 500"]] - }, + menu: [ + [25, 50, 100, 500], + ["Show 25", "Show 50", "Show 100", "Show 500"], + ], + }, buttons: [ "spacer", "csv", @@ -120,8 +124,8 @@ function initializeDataTable() { }, }, ], - } - }, + }, + }, serverSide: true, orderCellsTop: true, pagingType: "input", @@ -166,9 +170,9 @@ function initializeDataTable() { let alteredLines = []; lines.forEach((line) => { let newLine = ""; - newLine = line.replace("open_in_new",""); + newLine = line.replace("open_in_new", ""); alteredLines.push(newLine); - }) + }); return alteredLines.join("\n") + appliedFiltersInfo; }, }, @@ -254,7 +258,10 @@ function initializeDataTable() { ], createdRow: function (row, data, dataIndex) { if (data["excluded"]) { - $(row).attr("style", "background-color: rgba(255, 61, 87, 0.36) !important"); + $(row).attr( + "style", + "background-color: rgba(255, 61, 87, 0.36) !important" + ); } }, }); @@ -340,7 +347,7 @@ function initializeDataTable() { data: "candidate_urls_count", class: "text-center whiteText", sortable: true, - }, + }, { data: null, sortable: false, @@ -784,7 +791,7 @@ function handleHideorShowKeypress() { $("#hideShowColumnsModal").modal("hide"); } //Confirm modal selections via enter - if(event.key == "Enter" && $("#hideShowColumnsModal").is(":visible")) { + if (event.key == "Enter" && $("#hideShowColumnsModal").is(":visible")) { var table = $(uniqueId).DataTable(); $("[id^='checkbox_']").each(function () { var checkboxValue = $(this).val(); @@ -796,7 +803,7 @@ function handleHideorShowKeypress() { $("#hideShowColumnsModal").modal("hide"); } }); - + $("body").on("click", ".modal-backdrop", function () { $("#hideShowColumnsModal").modal("hide"); }); @@ -819,7 +826,9 @@ function handleHideorShowSubmitButton() { function handleDocumentTypeSelect() { $("body").on("click", ".document_type_select", function () { - $match_pattern = $(this).parents(".document_type_dropdown").data("match-pattern"); + $match_pattern = $(this) + .parents(".document_type_dropdown") + .data("match-pattern"); postDocumentTypePatterns( $match_pattern, (match_pattern_type = 1), @@ -846,9 +855,9 @@ function handleExcludeIndividualUrlClick() { function handleDeleteExcludePatternButtonClick() { $("body").on("click", ".delete-exclude-pattern-button", function () { - row_id = $(this).data("row-id"); + var patternRowId = $(this).data("row-id"); deletePattern( - `/api/exclude-patterns/${row_id}/`, + `/api/exclude-patterns/${patternRowId}/`, (data_type = "Exclude Pattern") ); }); @@ -856,9 +865,9 @@ function handleDeleteExcludePatternButtonClick() { function handleDeleteIncludePatternButtonClick() { $("body").on("click", ".delete-include-pattern-button", function () { - row_id = $(this).data("row-id"); + var patternRowId = $(this).data("row-id"); deletePattern( - `/api/include-patterns/${row_id}/`, + `/api/include-patterns/${patternRowId}/`, (data_type = "Include Pattern") ); }); @@ -866,9 +875,9 @@ function handleDeleteIncludePatternButtonClick() { function handleDeleteTitlePatternButtonClick() { $("body").on("click", ".delete-title-pattern-button", function () { - row_id = $(this).data("row-id"); + patternRowId = $(this).data("row-id"); deletePattern( - `/api/title-patterns/${row_id}/`, + `/api/title-patterns/${patternRowId}/`, (data_type = "Title Pattern") ); }); @@ -876,9 +885,9 @@ function handleDeleteTitlePatternButtonClick() { function handleDeleteDocumentTypeButtonClick() { $("body").on("click", ".delete-document-type-pattern-button", function () { - row_id = $(this).data("row-id"); + patternRowId = $(this).data("row-id"); deletePattern( - `/api/document-type-patterns/${row_id}/`, + `/api/document-type-patterns/${patternRowId}/`, (data_type = "Document Type Pattern") ); }); @@ -1143,10 +1152,46 @@ function deletePattern( `YOU ARE ATTEMPTING TO DELETE A MULTI-URL PATTERN. THIS WILL AFFECT ${candidate_urls_count} URLs. \n\nAre you sure you want to do this? Currently there is no way to delete a single URL from a Multi-URL pattern` ); } else { - var confirmDelete = confirm( + console.log("data_type", data_type); + $modal = $("#deletePatternModal").modal({ + backdrop: "static", + keyboard: true, + }); + + $(".delete-pattern-caption").text( `Are you sure you want to delete this ${data_type}?` ); } + + $("#deletePatternModalForm").on("click", "button", function (event) { + event.preventDefault(); + var buttonId = $(this).attr("id"); + if (buttonId === "dontDeletePattern") { + $modal = $("#deletePatternModal").modal("hide"); + return; + } else if (buttonId === "deletePattern") { + $.ajax({ + url: url, + type: "DELETE", + data: { + csrfmiddlewaretoken: csrftoken, + }, + headers: { + "X-CSRFToken": csrftoken, + }, + success: function (data) { + $("#candidate_urls_table").DataTable().ajax.reload(null, false); + $("#exclude_patterns_table").DataTable().ajax.reload(null, false); + $("#include_patterns_table").DataTable().ajax.reload(null, false); + $("#title_patterns_table").DataTable().ajax.reload(null, false); + $("#document_type_patterns_table") + .DataTable() + .ajax.reload(null, false); + }, + }); + } + }); + if (!confirmDelete) { return; } diff --git a/sde_indexing_helper/templates/sde_collections/candidate_urls_list.html b/sde_indexing_helper/templates/sde_collections/candidate_urls_list.html index cef56211..f5d31fd7 100644 --- a/sde_indexing_helper/templates/sde_collections/candidate_urls_list.html +++ b/sde_indexing_helper/templates/sde_collections/candidate_urls_list.html @@ -418,5 +418,32 @@
Customize Column + + + + {% endblock content %} \ No newline at end of file From 39063c40beed2417046c10be5467eec3b63e372c Mon Sep 17 00:00:00 2001 From: Michelle <88682822+emshahh@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:56:47 -0400 Subject: [PATCH 2/9] remove console logs --- sde_indexing_helper/static/js/candidate_url_list.js | 1 - 1 file changed, 1 deletion(-) diff --git a/sde_indexing_helper/static/js/candidate_url_list.js b/sde_indexing_helper/static/js/candidate_url_list.js index 97ebec37..bc316bcf 100644 --- a/sde_indexing_helper/static/js/candidate_url_list.js +++ b/sde_indexing_helper/static/js/candidate_url_list.js @@ -1152,7 +1152,6 @@ function deletePattern( `YOU ARE ATTEMPTING TO DELETE A MULTI-URL PATTERN. THIS WILL AFFECT ${candidate_urls_count} URLs. \n\nAre you sure you want to do this? Currently there is no way to delete a single URL from a Multi-URL pattern` ); } else { - console.log("data_type", data_type); $modal = $("#deletePatternModal").modal({ backdrop: "static", keyboard: true, From 0224d8af488281e2cae4959585114925cb00c927 Mon Sep 17 00:00:00 2001 From: Michelle <88682822+emshahh@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:50:32 -0400 Subject: [PATCH 3/9] modal popping up for delete url button --- .../static/js/collection_detail.js | 27 ++++++++++++++++++ .../sde_collections/collection_detail.html | 28 ++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/sde_indexing_helper/static/js/collection_detail.js b/sde_indexing_helper/static/js/collection_detail.js index 892b0fb1..43f9b906 100644 --- a/sde_indexing_helper/static/js/collection_detail.js +++ b/sde_indexing_helper/static/js/collection_detail.js @@ -53,6 +53,33 @@ function postDocTypeChange(collection_id, docType) { }); } +////////////////////////////// +///// DELETE URL CHANGE ////// +////////////////////////////// + +function handleDeleteURLButtonClick(dataId) { + $modal = $("#deleteURLModal").modal(); + $("#deleteURLModalForm").on("click", "button", function (event) { + event.preventDefault(); + var buttonId = $(this).attr("id"); + + if (buttonId === "cancelURLDeletion") { + $modal = $("#deleteURLModal").modal("hide"); + return; + } else if (buttonId === "deleteURL") { + // url delete req here + } + }); +} + +$(document).ready(function () { + $("body").on("click", ".urlDeleteButton", function (e) { + e.preventDefault(); + var dataId = $(this).data("id"); + handleDeleteURLButtonClick(dataId); + }); +}); + ////////////////////////////// ///// DIVISION CHANGE //////// ////////////////////////////// diff --git a/sde_indexing_helper/templates/sde_collections/collection_detail.html b/sde_indexing_helper/templates/sde_collections/collection_detail.html index c119e6f6..db2b4170 100644 --- a/sde_indexing_helper/templates/sde_collections/collection_detail.html +++ b/sde_indexing_helper/templates/sde_collections/collection_detail.html @@ -160,7 +160,7 @@

{{ colle {% for required_url in required_urls %}
-
+ {% csrf_token %}
+ + + {% endblock content %} {% block javascripts %} From 223eb596f13bc3046219c13f031bd17c75e79007 Mon Sep 17 00:00:00 2001 From: Michelle <88682822+emshahh@users.noreply.github.com> Date: Mon, 10 Jun 2024 12:04:14 -0400 Subject: [PATCH 4/9] wip --- .../static/js/collection_detail.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sde_indexing_helper/static/js/collection_detail.js b/sde_indexing_helper/static/js/collection_detail.js index 43f9b906..b501916b 100644 --- a/sde_indexing_helper/static/js/collection_detail.js +++ b/sde_indexing_helper/static/js/collection_detail.js @@ -68,6 +68,26 @@ function handleDeleteURLButtonClick(dataId) { return; } else if (buttonId === "deleteURL") { // url delete req here + $.ajax({ + url: "/delete-required-url/" + dataId, + type: "PUT", + data: { + name: inputValue, + csrfmiddlewaretoken: csrftoken, + }, + headers: { + "X-CSRFToken": csrftoken, + }, + success: function (data) { + // console.log("Success:", data); + $(".collectionName").text(`${data.name}`); + toastr.success("Name Updated!"); + }, + error: function (xhr, textStatus, errorThrown) { + // console.log("Error:", errorThrown); + toastr.error("Error updating name."); + }, + }); } }); } From 7b482a8e225058638bdc66bd85ebffaeb8a08b10 Mon Sep 17 00:00:00 2001 From: Michelle <88682822+emshahh@users.noreply.github.com> Date: Mon, 10 Jun 2024 12:29:26 -0400 Subject: [PATCH 5/9] delete modal for url delete successfully popping up, delete url when clicking delete, closing when user changes mind --- .../static/js/collection_detail.js | 20 +++++++------------ .../sde_collections/collection_detail.html | 4 ++-- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/sde_indexing_helper/static/js/collection_detail.js b/sde_indexing_helper/static/js/collection_detail.js index b501916b..548b14c5 100644 --- a/sde_indexing_helper/static/js/collection_detail.js +++ b/sde_indexing_helper/static/js/collection_detail.js @@ -57,8 +57,9 @@ function postDocTypeChange(collection_id, docType) { ///// DELETE URL CHANGE ////// ////////////////////////////// -function handleDeleteURLButtonClick(dataId) { +function handleDeleteURLButtonClick(dataId, dataURL) { $modal = $("#deleteURLModal").modal(); + $(".delete-URL-caption").text(`Are you sure you want to delete ${dataURL}?`); $("#deleteURLModalForm").on("click", "button", function (event) { event.preventDefault(); var buttonId = $(this).attr("id"); @@ -67,25 +68,18 @@ function handleDeleteURLButtonClick(dataId) { $modal = $("#deleteURLModal").modal("hide"); return; } else if (buttonId === "deleteURL") { - // url delete req here $.ajax({ url: "/delete-required-url/" + dataId, - type: "PUT", - data: { - name: inputValue, - csrfmiddlewaretoken: csrftoken, - }, + type: "POST", headers: { "X-CSRFToken": csrftoken, }, success: function (data) { - // console.log("Success:", data); - $(".collectionName").text(`${data.name}`); - toastr.success("Name Updated!"); + window.location.reload(); }, error: function (xhr, textStatus, errorThrown) { - // console.log("Error:", errorThrown); - toastr.error("Error updating name."); + console.log("Error:", errorThrown); + toastr.error("Error deleting URL."); }, }); } @@ -96,7 +90,7 @@ $(document).ready(function () { $("body").on("click", ".urlDeleteButton", function (e) { e.preventDefault(); var dataId = $(this).data("id"); - handleDeleteURLButtonClick(dataId); + handleDeleteURLButtonClick(dataId.id, dataId.url); }); }); diff --git a/sde_indexing_helper/templates/sde_collections/collection_detail.html b/sde_indexing_helper/templates/sde_collections/collection_detail.html index db2b4170..858327aa 100644 --- a/sde_indexing_helper/templates/sde_collections/collection_detail.html +++ b/sde_indexing_helper/templates/sde_collections/collection_detail.html @@ -163,7 +163,7 @@

{{ colle
{% csrf_token %}
@@ -308,7 +308,7 @@