Skip to content

Commit

Permalink
Filter by repeated member_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkadel committed Apr 20, 2023
1 parent ea08fe3 commit f32d821
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
31 changes: 30 additions & 1 deletion app/javascript/orangelight/figgy_manifest_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,41 @@ class FiggyViewerSet {
return resources
}

getMemberIds(resources) {
const ids = resources.map((resource) => {
return resource.members.map((member) => {
return member.id
})
})

return ids.flat()
}

getManifestUrls(resources) {
if (!resources) {
return []
}

return resources.map((resource) => {
// If there is a resource whose ID is included as a member_id of another resource,
// filter it out
const filterDuplicatedResources = resources.filter((resource) => {
if (!resource['members'])
return true
const member_ids = this.getMemberIds(resources)
const resource_is_unique = member_ids.map((member_id) => {
if (member_ids.includes(resource.id))
return false
})

return !resource_is_unique.includes(false)
})

if (resources.length > 0 && filterDuplicatedResources.length < 1)
return resources.map((resource) => {
return resource.manifestUrl
})

return filterDuplicatedResources.map((resource) => {
return resource.manifestUrl
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ async function loadResourcesByOrangelightId(id) {
},
label,
url,
members {
id
},
embed {
type,
content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ async function loadResourcesByOrangelightIds(ids) {
thumbnailUrl
},
url,
members {
id
},
... on ScannedResource {
manifestUrl,
orangelightId
Expand Down
45 changes: 43 additions & 2 deletions spec/javascript/orangelight/figgy_manifest_manager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ describe('RelatedRecords', function() {
},
"label": "Pennsylvania: Troy Quadrangle.",
"url": "https://figgy.princeton.edu/catalog/26b01ff3-eb40-40b0-821c-42fade1cf349",
"members": [
{
"id": "85773d63-8a3a-4cea-b1c3-d9d0196bac3f",
"__typename": "FileSet"
}
],
"embed": {
"type": "html",
"content": "\u003ciframe allowfullscreen=\"true\" id=\"uv_iframe\" src=\"https://figgy.princeton.edu/viewer#?manifest=https://figgy.princeton.edu/concern/scanned_maps/26b01ff3-eb40-40b0-821c-42fade1cf349/manifest\"\u003e\u003c/iframe\u003e",
Expand All @@ -45,6 +51,16 @@ describe('RelatedRecords', function() {
},
"label": "Pennsylvania: (Lycoming) Trout Run Quadrangle",
"url": "https://figgy.princeton.edu/catalog/a65bd135-5356-4613-8089-d90fc445cfda",
"members": [
{
"id": "595ee476-d247-4339-83e2-bddb90a7d069",
"__typename": "ScannedMap"
},
{
"id": "26b01ff3-eb40-40b0-821c-42fade1cf349",
"__typename": "ScannedMap"
}
],
"embed": {
"type": "html",
"content": "\u003ciframe allowfullscreen=\"true\" id=\"uv_iframe\" src=\"https://figgy.princeton.edu/viewer#?manifest=https://figgy.princeton.edu/concern/scanned_maps/a65bd135-5356-4613-8089-d90fc445cfda/manifest\"\u003e\u003c/iframe\u003e",
Expand All @@ -64,6 +80,12 @@ describe('RelatedRecords', function() {
},
"label": "Pennsylvania: (Lycoming) Trout Run Quadrangle (Lycoming)",
"url": "https://figgy.princeton.edu/catalog/595ee476-d247-4339-83e2-bddb90a7d069",
"members": [
{
"id": "8fa8bc9b-b0e9-456c-a1ee-a913b2499054",
"__typename": "FileSet"
}
],
"embed": {
"type": "html",
"content": "\u003ciframe allowfullscreen=\"true\" id=\"uv_iframe\" src=\"https://figgy.princeton.edu/viewer#?manifest=https://figgy.princeton.edu/concern/scanned_maps/595ee476-d247-4339-83e2-bddb90a7d069/manifest\"\u003e\u003c/iframe\u003e",
Expand All @@ -87,8 +109,7 @@ describe('RelatedRecords', function() {

const viewerSet = new FiggyViewerSet(viewerWrapperElement, queryFunction, '9968683243506421', null)
await viewerSet.render()
// We eventually want the length to be 1
expect(viewerWrapperElement.getElementsByTagName('iframe')).toHaveLength(3);
expect(viewerWrapperElement.getElementsByTagName('iframe')).toHaveLength(1);
})

test('displays two viewers for objects with multi-spectral imaging', async() => {
Expand All @@ -103,6 +124,16 @@ describe('RelatedRecords', function() {
},
"label": "At a Council held at Boston March 8. 1679,80. : The governour and Council, upon mature consideration of the many loud calls of Providence ... Do therefore appoint and order, that the fifteenth day of April next, be set apart for a day of humiliation and prayer ...",
"url": "https://figgy.princeton.edu/catalog/bbc6f6c4-3b92-4ae9-8461-1a14c113af8c",
"members": [
{
"id": "8ecd795b-cd1b-4efc-9f1b-1411574d948c",
"__typename": "FileSet"
},
{
"id": "2e6c63af-7e2d-4191-a1b6-b4113394ce33",
"__typename": "FileSet"
}
],
"embed": {
"type": "html",
"content": "\u003ciframe allowfullscreen=\"true\" id=\"uv_iframe\" src=\"https://figgy.princeton.edu/viewer#?manifest=https://figgy.princeton.edu/concern/scanned_resources/bbc6f6c4-3b92-4ae9-8461-1a14c113af8c/manifest\"\u003e\u003c/iframe\u003e",
Expand All @@ -122,6 +153,16 @@ describe('RelatedRecords', function() {
},
"label": "At a Council held at Boston March 8. 1679,80. : The governour and Council, upon mature consideration of the many loud calls of Providence ... Do therefore appoint and order, that the fifteenth day of April next, be set apart for a day of humiliation and prayer ...",
"url": "https://figgy.princeton.edu/catalog/54b399c7-f28c-46f6-a7b4-c835a60516c4",
"members": [
{
"id": "b9ce8d56-2ab7-48e0-8e97-d510b904f920",
"__typename": "ScannedResource"
},
{
"id": "e3e5ba6b-e7c6-4016-8c62-fe6656c020ca",
"__typename": "ScannedResource"
}
],
"embed": {
"type": "html",
"content": "\u003ciframe allowfullscreen=\"true\" id=\"uv_iframe\" src=\"https://figgy.princeton.edu/viewer#?manifest=https://figgy.princeton.edu/concern/scanned_resources/54b399c7-f28c-46f6-a7b4-c835a60516c4/manifest\"\u003e\u003c/iframe\u003e",
Expand Down

0 comments on commit f32d821

Please sign in to comment.