diff --git a/assets/src/bundles/admin/deposit.js b/assets/src/bundles/admin/deposit.js index c3839ae9466667ed67cd092a9180b4b2b7fa1a8e..ef7f773c830a2d1f64647d9ae2fec66e15a96000 100644 --- a/assets/src/bundles/admin/deposit.js +++ b/assets/src/bundles/admin/deposit.js @@ -7,19 +7,29 @@ import {getHumanReadableDate} from 'utils/functions'; -function genSwhLink(data, type) { +function genSwhLink(data, type, linkText = '') { if (type === 'display' && data && data.startsWith('swh')) { const browseUrl = Urls.browse_swhid(data); const formattedSWHID = data.replace(/;/g, ';<br/>'); - return `<a href="${browseUrl}">${formattedSWHID}</a>`; + if (!linkText) { + linkText = formattedSWHID; + } + return `<a href="${browseUrl}">${linkText}</a>`; } return data; } -function genLink(data, type) { +function genLink(data, type, openInNewTab = false, linkText = '') { if (type === 'display' && data) { const sData = encodeURI(data); - return `<a href="${sData}">${sData}</a>`; + if (!linkText) { + linkText = sData; + } + let attrs = ''; + if (openInNewTab) { + attrs = 'target="_blank" rel="noopener noreferrer"'; + } + return `<a href="${sData}" ${attrs}>${linkText}</a>`; } return data; } @@ -70,7 +80,19 @@ export function initDepositAdmin(username, isStaff) { data: 'uri', name: 'uri', render: (data, type, row) => { - return genLink(data, type); + const sanitizedURL = $.fn.dataTable.render.text().display(data); + let swhLink = ''; + let originLink = ''; + if (row.swhid_context && data) { + swhLink = genSwhLink(row.swhid_context, type, sanitizedURL); + } else if (data) { + swhLink = sanitizedURL; + } + if (data) { + originLink = genLink(sanitizedURL, type, true, + '<i class="mdi mdi-open-in-new" aria-hidden="true"></i>'); + } + return swhLink + ' ' + originLink; } }, { @@ -88,7 +110,7 @@ export function initDepositAdmin(username, isStaff) { render: (data, type, row) => { if (type === 'display') { if (row.raw_metadata) { - return `<button class="btn btn-default metadata">metadata</button>`; + return `<button class="btn btn-default metadata">display</button>`; } } return data; diff --git a/cypress/integration/deposit-admin.spec.js b/cypress/integration/deposit-admin.spec.js index f3e18a499af41f0f1dc917efa46a1a241a0ffdcb..a79daa4ee96bcad5e7eff22890ed69ba0a6e53c0 100644 --- a/cypress/integration/deposit-admin.spec.js +++ b/cypress/integration/deposit-admin.spec.js @@ -11,6 +11,8 @@ let expectedOrigins; let depositModerationUrl; let depositListUrl; +const $ = Cypress.$; + describe('Test moderation deposit Login/logout', function() { before(function() { depositModerationUrl = this.Urls.admin_deposit(); @@ -135,6 +137,7 @@ describe('Test admin deposit page', function() { // only 2 entries cy.get('@rows').each((row, idx, collection) => { + const cells = row[0].cells; const deposit = deposits[idx]; const responseDeposit = testDeposits[idx]; assert.isNotNull(deposit); @@ -156,6 +159,15 @@ describe('Test admin deposit page', function() { cy.contains(expectedOrigin).should('be.visible'); } + if (deposit.uri && deposit.swhid_context) { + let html = `<a href="${this.Urls.browse_swhid(deposit.swhid_context)}">${deposit.uri}</a>`; + html += ` <a href="${deposit.uri}" target="_blank" rel="noopener noreferrer">`; + html += '<i class="mdi mdi-open-in-new" aria-hidden="true"></i></a>'; + expect($(cells[2]).html()).to.contain(html); + } else if (!deposit.uri) { + expect($(cells[2]).text().trim()).to.equal(''); + } + cy.contains(deposit.status).should('be.visible'); // those are hidden by default, so now visible if (deposit.status_detail !== null) { @@ -171,6 +183,7 @@ describe('Test admin deposit page', function() { if (deposit.raw_metadata !== null) { cy.get('button.metadata', {withinSubject: row}) .should('exist') + .should('have.text', 'display') .click({force: true}); cy.get('#swh-web-modal-html code.xml').should('be.visible');