diff --git a/assets/src/bundles/admin/deposit.js b/assets/src/bundles/admin/deposit.js --- a/assets/src/bundles/admin/deposit.js +++ b/assets/src/bundles/admin/deposit.js @@ -87,7 +87,13 @@ }, { data: 'status', - name: 'status' + name: 'status', + render: (data, type, row) => { + if (type === 'display') { + return `${data} `; + } + return data; + } }, { data: 'status_detail', @@ -144,10 +150,25 @@ `); + + // Show a modal when the "metadata" button is clicked + $('#swh-admin-deposit-list tbody').on('click', 'tr button.metadata', function() { + var data = depositsTable.row(this).data(); + console.log(this); + console.log(depositsTable.row(this)); + console.log(data); + + var row = depositsTable.row(this.parentNode.parentNode).data(); + var metadata = row.raw_metadata; + var escapedMetadata = $('
').text(metadata).html(); + swh.webapp.showModalHtml(`Metadata of deposit ${row.id}`, `
${escapedMetadata}
`, '90%'); + }); + // Adding exclusion pattern update behavior, when typing, update search $('#swh-admin-deposit-list-exclude-filter').keyup(function() { depositsTable.draw(); }); + // at last draw the table depositsTable.draw(); }); diff --git a/swh/web/admin/deposit.py b/swh/web/admin/deposit.py --- a/swh/web/admin/deposit.py +++ b/swh/web/admin/deposit.py @@ -13,7 +13,7 @@ from swh.web.admin.adminurls import admin_route from swh.web.auth.utils import ADMIN_LIST_DEPOSIT_PERMISSION -from swh.web.common.utils import get_deposits_list +from swh.web.common.utils import get_deposit_raw_metadata, get_deposits_list def _can_list_deposits(user): @@ -79,14 +79,15 @@ "status_detail": d["status_detail"], "swhid": d["swhid"], "swhid_context": d["swhid_context"], + "raw_metadata": get_deposit_raw_metadata(d["id"])[-1], } for d in data ] except Exception as exc: sentry_sdk.capture_exception(exc) - table_data["error"] = ( - "An error occurred while retrieving " "the list of deposits !" - ) + table_data[ + "error" + ] = "An error occurred while retrieving the list of deposits !" return JsonResponse(table_data) diff --git a/swh/web/common/utils.py b/swh/web/common/utils.py --- a/swh/web/common/utils.py +++ b/swh/web/common/utils.py @@ -394,7 +394,8 @@ deposits_list_url, auth=deposits_list_auth, timeout=30 ).json()["count"] - deposits_data = cache.get(f"swh-deposit-list-{username}") + cache_key = f"swh-deposit-list-{username}" + deposits_data = cache.get(cache_key) if not deposits_data or deposits_data["count"] != nb_deposits: deposits_list_url = _deposits_list_url( deposits_list_base_url, page_size=nb_deposits, username=username @@ -402,11 +403,24 @@ deposits_data = requests.get( deposits_list_url, auth=deposits_list_auth, timeout=30, ).json() - cache.set(f"swh-deposit-list-{username}", deposits_data) + cache.set(cache_key, deposits_data) return deposits_data["results"] +def get_deposit_raw_metadata(deposit_id: int) -> Optional[str]: + cache_key = f"swh-deposit-raw-metadata-{deposit_id}" + metadata = cache.get(cache_key) + if metadata is not None: + config = get_config()["deposit"] + + url = f"{config['private_api_url']}/{deposit_id}/meta" + metadata = requests.get(url).json()["metadata_raw"] + cache.set(cache_key, metadata) + + return metadata + + def origin_visit_types() -> List[str]: """Return the exhaustive list of visit types for origins ingested into the archive.