Page MenuHomeSoftware Heritage

D3088.id11030.diff
No OneTemporary

D3088.id11030.diff

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,24 @@
export function getBrowsedSwhObjectMetadata() {
return browsedSwhObjectMetadata;
}
+
+// This will contain a mapping between an archived object type
+// and its related SWHID metadata for each object reachable from
+// the current browse view.
+// SWHID metadata contain the following keys:
+// * object_type: type of archived object
+// * object_id: sha1 object identifier
+// * swh_id: SWH persistent identifier without contextual info
+// * swh_id_url: URL to resolve SWH persistent identifier without contextual info
+let swhidsContext_ = {};
+
+export function setSwhIdsContext(swhidsContext) {
+ swhidsContext_ = {};
+ for (let swhidContext of swhidsContext) {
+ swhidsContext_[swhidContext.object_type] = swhidContext;
+ }
+}
+
+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 @@
</div>
</div>
</div>
+ <script>
+ swh.webapp.setSwhIdsContext({{ swh_ids|jsonify }});
+ </script>
{% endif %}

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 30, 3:58 PM (6 d, 22 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3220697

Event Timeline