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,20 @@ export function getBrowsedSwhObjectMetadata() { return browsedSwhObjectMetadata; } + +// will contain a mapping between archived object type +// and related metadata (notably computed SWHIDs with and +// without contextual info) for each object reachable from +// the current browse view. +let swhIdsContext = {}; + +export function setSwhIdsContext(swhids) { + swhIdsContext = {}; + for (let swhid of swhids) { + 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 %}