diff --git a/cypress/integration/persistent-identifiers.spec.js b/cypress/integration/persistent-identifiers.spec.js --- a/cypress/integration/persistent-identifiers.spec.js +++ b/cypress/integration/persistent-identifiers.spec.js @@ -256,4 +256,18 @@ } }); + it('should be possible to retrieve SWHIDs context from JavaScript', function() { + cy.window().then(win => { + const swhIdsContext = win.swh.webapp.getSwhIdsContext(); + for (let testData of [{'object_type': 'content', 'swh_id': cntPid}, + {'object_type': 'directory', 'swh_id': dirPid}, + {'object_type': 'revision', 'swh_id': revPid}, + {'object_type': 'release', 'swh_id': relPid}, + {'object_type': 'snapshot', 'swh_id': snpPid}]) { + assert.isTrue(swhIdsContext.hasOwnProperty(testData.object_type)); + assert.equal(swhIdsContext[testData.object_type].swh_id, testData.swh_id); + } + }); + }); + }); diff --git a/swh/web/assets/src/bundles/webapp/webapp-utils.js b/swh/web/assets/src/bundles/webapp/webapp-utils.js --- a/swh/web/assets/src/bundles/webapp/webapp-utils.js +++ b/swh/web/assets/src/bundles/webapp/webapp-utils.js @@ -289,3 +289,16 @@ export function getBrowsedSwhObjectMetadata() { return browsedSwhObjectMetadata; } + +let swhIdsContext = {}; + +export function setSwhIdsContext(context) { + swhIdsContext = {}; + for (let swhid of context) { + swhIdsContext[swhid.object_type] = swhid; + } +} + +export function getSwhIdsContext() { + return swhIdsContext; +} diff --git a/swh/web/templates/includes/show-swh-ids.html b/swh/web/templates/includes/show-swh-ids.html --- a/swh/web/templates/includes/show-swh-ids.html +++ b/swh/web/templates/includes/show-swh-ids.html @@ -100,4 +100,7 @@ + {% endif %}