Skip to content

Commit

Permalink
Add AIPs search (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcantelon committed Jul 3, 2024
1 parent 120878e commit 18ddf58
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
6 changes: 6 additions & 0 deletions AIPscan/Reporter/templates/aips.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

{% if storage_services %}

<div class="float-right">
<form action="{{ url_for('reporter.view_aips') }}" method="GET" class="pr-3" id="queryform">
<i class="fas fa-search"></i> Search <input name="query" id="query"/><input type="submit" hidden/>
</form>
</div>

<div class="report-opts" style="margin-bottom: 0.2em;">
<div>
<span class="fixed-width-menu-span-left">
Expand Down
29 changes: 22 additions & 7 deletions AIPscan/Reporter/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def storage_locations_with_aips(storage_locations):
return [loc for loc in storage_locations if loc.aips]


def get_aip_pager(page, per_page, storage_service, storage_location):
def get_aip_pager(page, per_page, storage_service, storage_location, query):
try:
page = int(page)
except ValueError:
Expand All @@ -96,14 +96,25 @@ def get_aip_pager(page, per_page, storage_service, storage_location):
if storage_service is not None:
storage_service_id = storage_service.id

pager = AIP.query.filter_by(storage_service_id=storage_service_id).paginate(
page=page, per_page=per_page, error_out=False
aips = AIP.query

if query is not None:
aips = aips.filter(
AIP.uuid.like("%" + query + "%") |
AIP.transfer_name.like("%" + query + "%") |
AIP.create_date.like("%" + query + "%")
)

aips = aips.filter_by(
storage_service_id=storage_service_id
)

if storage_location:
pager = pager.query.filter_by(storage_location_id=storage_location.id).paginate(
page=page, per_page=per_page, error_out=False
)
aips = aips.filter_by(storage_location_id=storage_location.id)

pager = aips.paginate(
page=page, per_page=per_page, error_out=False
)

return pager

Expand Down Expand Up @@ -131,8 +142,12 @@ def view_aips():
except Exception as e:
print(e)

query = request.args.get("query")
if query is None:
query = ""

page = request.args.get(request_params.PAGE, default="1")
pager = get_aip_pager(page, 10, storage_service, storage_location)
pager = get_aip_pager(page, 10, storage_service, storage_location, query)

first_item, last_item = calculate_paging_window(pager)

Expand Down
11 changes: 11 additions & 0 deletions AIPscan/static/js/reporter/aips.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $(document).ready(function () {
function reloadPage(ignoreLocation) {
var storageServiceId = $("#ss").val();
var storageLocationId = $("#sl").val();
var query = $("#query").val();

var url = new URL("reporter/aips", $("body").data("url-root"));
var params = {
Expand All @@ -15,6 +16,10 @@ $(document).ready(function () {
params["storage_location"] = storageLocationId;
}

if (query !== "") {
params["query"] = query;
}

url.search = new URLSearchParams(params).toString();
window.location.href = url.href;
}
Expand All @@ -26,4 +31,10 @@ $(document).ready(function () {
$("#sl").on("change", function () {
reloadPage(false);
});

$("#queryform").on("submit", function () {
reloadPage(false);

return false;
});
});

0 comments on commit 18ddf58

Please sign in to comment.