diff --git a/swh/web/admin/origin_save.py b/swh/web/admin/origin_save.py --- a/swh/web/admin/origin_save.py +++ b/swh/web/admin/origin_save.py @@ -20,7 +20,7 @@ ) from swh.web.common.origin_save import ( - create_save_origin_request, + create_save_origin_request, get_save_origin_task_info, SAVE_REQUEST_PENDING, SAVE_REQUEST_REJECTED ) @@ -192,3 +192,15 @@ entry.delete() status_code = 200 return HttpResponse(status=status_code) + + +@admin_route(r'origin/save/task/info/(?P.+)/', + view_name='admin-origin-save-task-info') +@staff_member_required(login_url=settings.LOGIN_URL) +def _save_origin_task_info(request, save_request_id): + request_info = get_save_origin_task_info(save_request_id) + for date_field in ('scheduled', 'started', 'ended'): + if date_field in request_info and request_info[date_field] is not None: + request_info[date_field] = request_info[date_field].isoformat() + return HttpResponse(json.dumps(request_info), + content_type='application/json') diff --git a/swh/web/assets/src/bundles/admin/origin-save.js b/swh/web/assets/src/bundles/admin/origin-save.js --- a/swh/web/assets/src/bundles/admin/origin-save.js +++ b/swh/web/assets/src/bundles/admin/origin-save.js @@ -41,6 +41,7 @@ info: false }); enableRowSelection('#swh-authorized-origin-urls'); + swh.webapp.addJumpToPagePopoverToDataTable(authorizedOriginTable); unauthorizedOriginTable = $('#swh-unauthorized-origin-urls').DataTable({ serverSide: true, @@ -51,6 +52,7 @@ info: false }); enableRowSelection('#swh-unauthorized-origin-urls'); + swh.webapp.addJumpToPagePopoverToDataTable(unauthorizedOriginTable); let columnsData = [ { @@ -106,6 +108,7 @@ } }); enableRowSelection('#swh-origin-save-pending-requests'); + swh.webapp.addJumpToPagePopoverToDataTable(pendingSaveRequestsTable); rejectedSaveRequestsTable = $('#swh-origin-save-rejected-requests').DataTable({ serverSide: true, @@ -126,6 +129,7 @@ } }); enableRowSelection('#swh-origin-save-rejected-requests'); + swh.webapp.addJumpToPagePopoverToDataTable(rejectedSaveRequestsTable); columnsData.push({ data: 'save_task_status', @@ -139,6 +143,18 @@ } }); + columnsData.push({ + name: 'info', + render: (data, type, row) => { + if (row.save_task_status === 'succeed' || row.save_task_status === 'failed') { + return '`; + } else { + return ''; + } + } + }); + acceptedSaveRequestsTable = $('#swh-origin-save-accepted-requests').DataTable({ serverSide: true, processing: true, @@ -158,6 +174,7 @@ } }); enableRowSelection('#swh-origin-save-accepted-requests'); + swh.webapp.addJumpToPagePopoverToDataTable(acceptedSaveRequestsTable); $('#swh-origin-save-requests-nav-item').on('shown.bs.tab', () => { pendingSaveRequestsTable.draw(); @@ -199,6 +216,14 @@ rejectedSaveRequestsTable.ajax.reload(null, false); }); + $('body').on('click', e => { + if ($(e.target).parents('.popover').length > 0) { + event.stopPropagation(); + } else if ($(e.target).parents('.swh-save-request-info').length === 0) { + $('.swh-save-request-info').popover('dispose'); + } + }); + }); } @@ -332,3 +357,93 @@ export function removeRejectedOriginSaveRequest() { removeOriginSaveRequest(rejectedSaveRequestsTable); } + +export function displaySaveRequestInfo(event, saveRequestId) { + event.stopPropagation(); + const saveRequestTaskInfoUrl = Urls.admin_origin_save_task_info(saveRequestId); + $('.swh-save-request-info').popover('dispose'); + $(event.target).popover({ + 'title': 'Save request task information', + 'content': `
+
+ +

Fetching task information ...

+
+
`, + 'html': true, + 'placement': 'left', + 'sanitizeFn': swh.webapp.filterXSS + }); + $(event.target).popover('show'); + fetch(saveRequestTaskInfoUrl) + .then(response => response.json()) + .then(saveRequestTaskInfo => { + let content; + if ($.isEmptyObject(saveRequestTaskInfo)) { + content = 'Not available'; + } else { + let saveRequestInfo = []; + saveRequestInfo.push({ + key: 'Task type', + value: saveRequestTaskInfo.type + }); + if (saveRequestTaskInfo.hasOwnProperty('task_name')) { + saveRequestInfo.push({ + key: 'Task name', + value: saveRequestTaskInfo.name + }); + } + saveRequestInfo.push({ + key: 'Task arguments', + value: JSON.stringify(saveRequestTaskInfo.arguments, null, 2) + }); + saveRequestInfo.push({ + key: 'Task id', + value: saveRequestTaskInfo.id + }); + saveRequestInfo.push({ + key: 'Task backend id', + value: saveRequestTaskInfo.backend_id + }); + saveRequestInfo.push({ + key: 'Task scheduling date', + value: new Date(saveRequestTaskInfo.scheduled).toLocaleString() + }); + saveRequestInfo.push({ + key: 'Task termination date', + value: new Date(saveRequestTaskInfo.ended).toLocaleString() + }); + if (saveRequestTaskInfo.hasOwnProperty('duration')) { + saveRequestInfo.push({ + key: 'Task duration', + value: saveRequestTaskInfo.duration + ' s' + }); + } + if (saveRequestTaskInfo.hasOwnProperty('worker')) { + saveRequestInfo.push({ + key: 'Task executor', + value: saveRequestTaskInfo.worker + }); + } + if (saveRequestTaskInfo.hasOwnProperty('message')) { + saveRequestInfo.push({ + key: 'Task log', + value: saveRequestTaskInfo.message + }); + } + content = ''; + for (let info of saveRequestInfo) { + content += + ` + + + `; + } + content += '
'; + } + $('.swh-popover').html(content); + $(event.target).popover('update'); + }); +} diff --git a/swh/web/assets/src/bundles/browse/browse.css b/swh/web/assets/src/bundles/browse/browse.css --- a/swh/web/assets/src/bundles/browse/browse.css +++ b/swh/web/assets/src/bundles/browse/browse.css @@ -40,20 +40,6 @@ display: block; } -.swh-metadata-table-row { - border-top: 1px solid #ddd !important; -} - -.swh-metadata-table-key { - min-width: 200px; - max-width: 200px; - width: 200px; -} - -.swh-metadata-table-value pre { - white-space: pre-wrap; -} - .swh-table-cell-text-overflow { white-space: nowrap; overflow: hidden; @@ -78,20 +64,6 @@ width: 440px; } -.swh-popover { - max-height: 50vh; - overflow-y: auto; - overflow-x: auto; - padding: 0; - padding-right: 1.4em; -} - -@media screen and (min-width: 768px) { - .swh-popover { - max-width: 80vh; - } -} - .swh-search-pagination { margin-top: 5px; } diff --git a/swh/web/assets/src/bundles/webapp/webapp.css b/swh/web/assets/src/bundles/webapp/webapp.css --- a/swh/web/assets/src/bundles/webapp/webapp.css +++ b/swh/web/assets/src/bundles/webapp/webapp.css @@ -506,3 +506,31 @@ .admonition.warning .first { font-size: 1.5rem; } + +.swh-popover { + max-height: 50vh; + overflow-y: auto; + overflow-x: auto; + padding: 0; + padding-right: 1.4em; +} + +@media screen and (min-width: 768px) { + .swh-popover { + max-width: 50vw; + } +} + +.swh-metadata-table-row { + border-top: 1px solid #ddd !important; +} + +.swh-metadata-table-key { + min-width: 200px; + max-width: 200px; + width: 200px; +} + +.swh-metadata-table-value pre { + white-space: pre-wrap; +} diff --git a/swh/web/templates/admin/origin-save.html b/swh/web/templates/admin/origin-save.html --- a/swh/web/templates/admin/origin-save.html +++ b/swh/web/templates/admin/origin-save.html @@ -77,6 +77,7 @@ Type Url Status + Info