Skip to content

Commit

Permalink
Add include pattern displays
Browse files Browse the repository at this point in the history
  • Loading branch information
code-geek committed Nov 30, 2023
1 parent 32b1810 commit 706841b
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 5 deletions.
86 changes: 81 additions & 5 deletions sde_indexing_helper/static/js/candidate_url_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ function initializeDataTable() {
]
});

var include_patterns_table = $('#include_patterns_table').DataTable({
"scrollY": true,
"serverSide": true,
"ajax": `/api/include-patterns/?format=datatables&collection_id=${collection_id}`,
"columns": [
{ "data": "match_pattern" },
{ "data": "match_pattern_type_display", "class": "text-center", "sortable": false },
{ "data": "candidate_urls_count", "class": "text-center", "sortable": false },
{
"data": null,
"sortable": false,
"class": "text-center",
"render": function (data, type, row) {
return `<button class="btn btn-danger btn-sm delete-include-pattern-button" data-row-id="${row['id']}"><i class="material-icons">delete</i></button >`;
}
},
{ "data": "id", "visible": false, "searchable": false },
]
});

var title_patterns_table = $('#title_patterns_table').DataTable({
"scrollY": true,
"serverSide": true,
Expand Down Expand Up @@ -130,10 +150,12 @@ function setupClickHandlers() {

handleCreateDocumentTypePatternButton();
handleCreateExcludePatternButton();
handleCreateIncludePatternButton();
handleCreateTitlePatternButton();

handleDeleteDocumentTypeButtonClick();
handleDeleteExcludePatternButtonClick();
handleDeleteIncludePatternButtonClick();
handleDeleteTitlePatternButtonClick();

handleDocumentTypeSelect()
Expand Down Expand Up @@ -195,15 +217,15 @@ function getVisitedColumn(true_icon, false_icon) {
}
}

function getIsPresentOnTestColumn(true_icon, false_icon){
function getIsPresentOnTestColumn(true_icon, false_icon) {
return {
"data": "present_on_test", "class": "col-1 text-center", "render": function (data, type, row) {
return (data === true) ? true_icon : false_icon
}
}
}

function getIsPresentInProductionColumn(true_icon, false_icon){
function getIsPresentInProductionColumn(true_icon, false_icon) {
return {
"data": "present_on_prod", "class": "col-1 text-center", "render": function (data, type, row) {
return (data === true) ? true_icon : false_icon
Expand Down Expand Up @@ -254,6 +276,12 @@ function handleCreateExcludePatternButton() {
});
}

function handleCreateIncludePatternButton() {
$("body").on("click", ".create_include_pattern_button", function () {
$modal = $('#includePatternModal').modal();
});
}

function handleCreateTitlePatternButton() {
$("body").on("click", ".create_title_pattern_button", function () {
$modal = $('#titlePatternModal').modal();
Expand Down Expand Up @@ -286,6 +314,13 @@ function handleDeleteExcludePatternButtonClick() {
});
}

function handleDeleteIncludePatternButtonClick() {
$("body").on("click", ".delete-include-pattern-button", function () {
row_id = $(this).data('row-id');
deletePattern(`/api/include-patterns/${row_id}/`, data_type = 'Include Pattern');
});
}

function handleDeleteTitlePatternButtonClick() {
$("body").on("click", ".delete-title-pattern-button", function () {
row_id = $(this).data('row-id');
Expand Down Expand Up @@ -315,8 +350,8 @@ function handleNewTitleChange() {
var match_pattern_type = $(this).data('match-pattern-type');
var candidate_urls_count = $(this).data('candidate-urls-count');
if (!title_pattern) {
deletePattern(`/api/title-patterns/${generated_title_id}/`, data_type = 'Title Pattern', url_type = match_pattern_type, candidate_urls_count= candidate_urls_count);
}else{
deletePattern(`/api/title-patterns/${generated_title_id}/`, data_type = 'Title Pattern', url_type = match_pattern_type, candidate_urls_count = candidate_urls_count);
} else {
postTitlePatterns(match_pattern, title_pattern, match_pattern_type = 1, title_pattern_type = 1);
}
});
Expand Down Expand Up @@ -384,6 +419,32 @@ function postExcludePatterns(match_pattern, match_pattern_type = 0) {
});
}

function postIncludePatterns(match_pattern, match_pattern_type = 0) {
if (!match_pattern) {
toastr.error('Please highlight a pattern to include.');
return;
}

$.ajax({
url: '/api/include-patterns/',
type: "POST",
data: {
collection: collection_id,
match_pattern: match_pattern,
match_pattern_type: match_pattern_type,
csrfmiddlewaretoken: csrftoken
},
success: function (data) {
$('#candidate_urls_table').DataTable().ajax.reload();
$('#include_patterns_table').DataTable().ajax.reload();
},
error: function (xhr, status, error) {
var errorMessage = xhr.responseText;
toastr.error(errorMessage);
}
});
}

function postTitlePatterns(match_pattern, title_pattern, match_pattern_type = 1) {
if (!match_pattern) {
toastr.error('Please highlight a pattern to change the title.');
Expand Down Expand Up @@ -427,7 +488,7 @@ function postVisited(url) {
});
}

function deletePattern(url, data_type, url_type=null, candidate_urls_count=null) {
function deletePattern(url, data_type, url_type = null, candidate_urls_count = null) {
if (url_type === MULTI_URL_PATTERN) {
var confirmDelete = confirm(`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 {
Expand All @@ -448,6 +509,7 @@ function deletePattern(url, data_type, url_type=null, candidate_urls_count=null)
success: function (data) {
$('#candidate_urls_table').DataTable().ajax.reload();
$('#exclude_patterns_table').DataTable().ajax.reload();
$('#include_patterns_table').DataTable().ajax.reload();
$('#title_patterns_table').DataTable().ajax.reload();
$('#document_type_patterns_table').DataTable().ajax.reload();
}
Expand Down Expand Up @@ -571,6 +633,20 @@ $('#exclude_pattern_form').on('submit', function (e) {
$('#excludePatternModal').modal('hide');
});

$('#include_pattern_form').on('submit', function (e) {
e.preventDefault();
inputs = {};
input_serialized = $(this).serializeArray();
input_serialized.forEach(field => {
inputs[field.name] = field.value;
});

postIncludePatterns(match_pattern = inputs.match_pattern, match_pattern_type = 2);

// close the modal if it is open
$('#includePatternModal').modal('hide');
});

$('#title_pattern_form').on('submit', function (e) {
e.preventDefault();
inputs = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ <h3>
</thead>
</table>
<hr>
<h3>
Include Patterns
<button class="btn btn-primary btn-sm create_include_pattern_button">
<i class="material-icons">add</i>
</button>
</h3>
<table class="table" id="include_patterns_table">
<thead>
<tr>
<th scope="col" class="text-center col-1">
<strong>Match Pattern</strong>
</th>
<th scope="col" class="text-center col-1">
<strong>Match Pattern Type</strong>
</th>
<th scope="col" class="text-center col-1">
<strong>Affected URLs</strong>
</th>
<th scope="col" class="text-center col-1">
<strong>Actions</strong>
</th>
<th scope="col" class="text-center col-1">
<strong>ID</strong>
</th>
</tr>
</thead>
</table>
<hr>
<h3>
Title Patterns
<button class="btn btn-primary btn-sm create_title_pattern_button">
Expand Down Expand Up @@ -146,6 +174,7 @@ <h3>
</table>
<ul class="custom-menu list-group">
<li data-action="exclude-pattern" class="list-group-item">Create Exclude Pattern</li>
<li data-action="include-pattern" class="list-group-item">Create Include Pattern</li>
<li data-action="title-pattern" class="list-group-item">Create Title Pattern</li>
<li data-action="document-type-pattern" class="list-group-item">Create Document Type Pattern</li>
</ul>
Expand Down Expand Up @@ -182,6 +211,40 @@ <h5 class="modal-title" id="excludePatternModalLabel">Exclude Pattern Form</h5>
</form>
</div>
</div>
</div>
<div class="modal fade"
id="includePatternModal"
data-backdrop="static"
data-keyboard="false"
tabindex="-1"
aria-labelledby="includePatternModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="includePatternModalLabel">Include Pattern Form</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<form id="include_pattern_form">
<div class="modal-body">
<div class="form-group">
<label for="match_pattern_input">Match Pattern*</label>
<input type="text"
class="form-control"
id="match_pattern_input"
required
name="match_pattern">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div>
</div>
<div class="modal fade"
id="titlePatternModal"
Expand Down

0 comments on commit 706841b

Please sign in to comment.