Bug 17387: add sidebar date filtering for item/biblio restore

Signed-off-by: Michaela <michaela.sieber@kit.edu>
Sponsored-by: ByWater Solutions
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Jacob O'Mara 2025-10-30 12:50:46 +00:00 committed by Lucas Gass
parent 61909daa10
commit 356576f6db
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
1 changed files with 88 additions and 8 deletions

View File

@ -30,12 +30,9 @@
[% END #/ WRAPPER breadcrumbs %]
[% END #/ WRAPPER sub-header.inc %]
[% SET asides = [] %]
[% asides.push('cat-menu') %]
[% WRAPPER 'main-container.inc' %]
<div class="main container-fluid">
<div class="row">
<div class="col-md-10 col-md-push-2">
<div class="col-md-10 order-md-2 order-sm-1">
<main>
<h1>Restore deleted records</h1>
@ -74,8 +71,36 @@
</div>
</main>
</div>
<div class="col-md-2 order-sm-2 order-md-1">
<aside>
<div id="filters">
<fieldset class="brief">
<h4>Filter results</h4>
<ol>
<li>
<label for="from">Deleted from:</label>
<input type="text" size="10" id="from" name="from" class="flatpickr" data-date_to="to" />
<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
</li>
<li>
<label for="to">Deleted to:</label>
<input type="text" size="10" id="to" name="to" class="flatpickr" />
<div class="hint">[% INCLUDE 'date-format.inc' %]</div>
</li>
</ol>
<fieldset class="action">
<button type="button" id="filter_table" class="btn btn-primary btn-sm">Apply</button>
<button type="button" id="clear_filters" class="btn btn-default btn-sm">Clear</button>
</fieldset>
</fieldset>
</div>
[% INCLUDE 'cat-menu.inc' %]
</aside>
</div>
</div>
[% END #/ WRAPPER main-container.inc %]
</div>
<!-- Modal for deleted biblio warning -->
<div class="modal" id="deletedBiblioModal" tabindex="-1" role="dialog" aria-labelledby="deletedBiblioModalLabel">
@ -151,6 +176,7 @@
[% MACRO jsinclude BLOCK %]
[% Asset.js("js/tools-menu.js") | $raw %]
[% INCLUDE 'datatables.inc' %]
[% INCLUDE 'calendar.inc' %]
<script>
function showMessage(message, type) {
var alert = $('<div class="alert alert-' + type + '">' + message + "</div>");
@ -164,10 +190,52 @@
}
$(document).ready(function () {
var oneYearAgo = new Date();
oneYearAgo.setFullYear(oneYearAgo.getFullYear() - 1);
var today = new Date();
var fromDate = oneYearAgo.toISOString().split("T")[0];
var toDate = today.toISOString().split("T")[0];
setTimeout(function () {
if ($("#from")[0]._flatpickr) {
$("#from")[0]._flatpickr.setDate(fromDate);
}
if ($("#to")[0]._flatpickr) {
$("#to")[0]._flatpickr.setDate(toDate);
}
}, 100);
function buildApiUrl(baseUrl) {
var from = $("#from").val();
var to = $("#to").val();
if (!from && !to) {
return baseUrl;
}
var query = {};
if (from && to) {
query["me.timestamp"] = {
"-between": [from + "T00:00:00Z", to + "T23:59:59Z"],
};
} else if (from) {
query["me.timestamp"] = {
">=": from + "T00:00:00Z",
};
} else if (to) {
query["me.timestamp"] = {
"<=": to + "T23:59:59Z",
};
}
return baseUrl + "?q=" + encodeURIComponent(JSON.stringify(query));
}
// Deleted biblios DataTable
var biblios_table = $("#deleted_biblios_table").kohaTable({
ajax: {
url: "/api/v1/deleted/biblios",
url: buildApiUrl("/api/v1/deleted/biblios"),
},
embed: "items",
order: [[3, "desc"]],
@ -235,7 +303,7 @@
// Deleted items DataTable
var items_table = $("#deleted_items_table").kohaTable({
ajax: {
url: "/api/v1/deleted/items",
url: buildApiUrl("/api/v1/deleted/items"),
},
embed: "biblio",
order: [[5, "desc"]],
@ -581,6 +649,18 @@
},
});
});
$("#filter_table").on("click", function () {
biblios_table_api.ajax.url(buildApiUrl("/api/v1/deleted/biblios")).load();
items_table_api.ajax.url(buildApiUrl("/api/v1/deleted/items")).load();
});
$("#clear_filters").on("click", function () {
$("#from").val("");
$("#to").val("");
biblios_table_api.ajax.url("/api/v1/deleted/biblios").load();
items_table_api.ajax.url("/api/v1/deleted/items").load();
});
});
</script>
[% END %]