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,15 @@ } }); + 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 testsData) { + assert.isTrue(swhIdsContext.hasOwnProperty(testData.objectType)); + assert.equal(swhIdsContext[testData.objectType].swh_id, + testData.objectPids.slice(-1)[0]); + } + }); + }); + }); 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 %}