diff --git a/types/.sqlx/query-c9c0c39118f06319b1617f8ae8020985ed41a9eeafddbd84887555305ca49cb3.json b/types/.sqlx/query-306bae711df4c78f9ba98b7932596aeac8594ab5ee5e415fffb8bb2185bce714.json similarity index 55% rename from types/.sqlx/query-c9c0c39118f06319b1617f8ae8020985ed41a9eeafddbd84887555305ca49cb3.json rename to types/.sqlx/query-306bae711df4c78f9ba98b7932596aeac8594ab5ee5e415fffb8bb2185bce714.json index 26fbc004f..11dc57e76 100644 --- a/types/.sqlx/query-c9c0c39118f06319b1617f8ae8020985ed41a9eeafddbd84887555305ca49cb3.json +++ b/types/.sqlx/query-306bae711df4c78f9ba98b7932596aeac8594ab5ee5e415fffb8bb2185bce714.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "select\n d.id,\n d.short_name,\n d.title,\n d.is_reference,\n d.written_at,\n d.audio_slice_id,\n media_resource.url as \"audio_url?\",\n media_resource.recorded_at as \"recorded_at?\",\n dailp_user.id as \"recorded_by?\",\n dailp_user.display_name as \"recorded_by_name?\",\n media_slice.time_range as \"audio_slice?\",\n ubd.bookmarked_on as \"bookmarked_on?\",\n coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'name', contributor.full_name, 'role', attr.contribution_role\n )\n ) filter (where contributor is not null),\n '[]'\n )\n as contributors\nfrom document as d\n left join contributor_attribution as attr on attr.document_id = d.id\n left join contributor on contributor.id = attr.contributor_id\n left join media_slice on media_slice.id = d.audio_slice_id\n left join media_resource on media_resource.id = media_slice.resource_id\n left join dailp_user on dailp_user.id = media_resource.recorded_by\n left join user_bookmarked_document as ubd on ubd.document_id = d.id\nwhere d.short_name = any($1)\ngroup by d.id,\n media_slice.id,\n media_resource.id,\n dailp_user.id,\n ubd.bookmarked_on\n", + "query": "select\n d.id,\n d.short_name,\n d.title,\n d.is_reference,\n d.written_at,\n d.audio_slice_id,\n d.include_audio_in_edited_collection,\n media_resource.url as \"audio_url?\",\n media_resource.recorded_at as \"recorded_at?\",\n dailp_user.id as \"recorded_by?\",\n dailp_user.display_name as \"recorded_by_name?\",\n media_slice.time_range as \"audio_slice?\",\n ubd.bookmarked_on as \"bookmarked_on?\",\n coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'name', contributor.full_name, 'role', attr.contribution_role\n )\n ) filter (where contributor is not null),\n '[]'\n )\n as contributors\nfrom document as d\n left join contributor_attribution as attr on attr.document_id = d.id\n left join contributor on contributor.id = attr.contributor_id\n left join media_slice on media_slice.id = d.audio_slice_id\n left join media_resource on media_resource.id = media_slice.resource_id\n left join dailp_user on dailp_user.id = media_resource.recorded_by\n left join user_bookmarked_document as ubd on ubd.document_id = d.id\nwhere d.short_name = any($1)\ngroup by d.id,\n media_slice.id,\n media_resource.id,\n dailp_user.id,\n ubd.bookmarked_on\n", "describe": { "columns": [ { @@ -35,36 +35,41 @@ }, { "ordinal": 6, + "name": "include_audio_in_edited_collection", + "type_info": "Bool" + }, + { + "ordinal": 7, "name": "audio_url?", "type_info": "Text" }, { - "ordinal": 7, + "ordinal": 8, "name": "recorded_at?", "type_info": "Date" }, { - "ordinal": 8, + "ordinal": 9, "name": "recorded_by?", "type_info": "Uuid" }, { - "ordinal": 9, + "ordinal": 10, "name": "recorded_by_name?", "type_info": "Text" }, { - "ordinal": 10, + "ordinal": 11, "name": "audio_slice?", "type_info": "Int8Range" }, { - "ordinal": 11, + "ordinal": 12, "name": "bookmarked_on?", "type_info": "Date" }, { - "ordinal": 12, + "ordinal": 13, "name": "contributors", "type_info": "Jsonb" } @@ -82,6 +87,7 @@ true, true, false, + false, true, false, false, @@ -90,5 +96,5 @@ null ] }, - "hash": "c9c0c39118f06319b1617f8ae8020985ed41a9eeafddbd84887555305ca49cb3" + "hash": "306bae711df4c78f9ba98b7932596aeac8594ab5ee5e415fffb8bb2185bce714" } diff --git a/types/.sqlx/query-b65e199479fbd23d8bdc2169e90a581faf595b9b33d274b97c2a7e88bdc9458f.json b/types/.sqlx/query-b65e199479fbd23d8bdc2169e90a581faf595b9b33d274b97c2a7e88bdc9458f.json new file mode 100644 index 000000000..6318141e0 --- /dev/null +++ b/types/.sqlx/query-b65e199479fbd23d8bdc2169e90a581faf595b9b33d274b97c2a7e88bdc9458f.json @@ -0,0 +1,142 @@ +{ + "db_name": "PostgreSQL", + "query": "select\n d.id,\n d.short_name,\n d.title,\n d.is_reference,\n d.written_at,\n d.format_id,\n d.genre_id,\n d.audio_slice_id,\n d.include_audio_in_edited_collection,\n media_resource.url as \"audio_url?\",\n media_resource.recorded_at as \"recorded_at?\",\n dailp_user.id as \"recorded_by?\",\n dailp_user.display_name as \"recorded_by_name?\",\n media_slice.time_range as \"audio_slice?\",\n ubd.bookmarked_on as \"bookmarked_on?\",\n coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', contributor.id,\n 'name', contributor.full_name,\n 'role', attr.contribution_role\n )\n ) filter (where contributor is not null),\n '[]'\n ) as contributors,\n (\n select coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', k.id,\n 'name', k.name,\n 'status', k.status\n )\n ),\n '[]'\n )\n from document_keyword dk\n join keyword k on k.id = dk.keyword_id\n where dk.document_id = d.id\n ) as keywords,\n (\n select coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', l.id,\n 'name', l.name,\n 'status', l.status\n )\n ),\n '[]'\n )\n from document_language dl\n join language l on l.id = dl.language_id\n where dl.document_id = d.id\n ) as languages,\n ( -- Subject Headings\n select coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', sh.id,\n 'name', sh.name,\n 'status', sh.status\n )), '[]')\n from document_subject_heading dsh\n join subject_heading sh on sh.id = dsh.subject_heading_id\n where dsh.document_id = d.id\n ) as subject_headings,\n ( -- Spatial Coverage\n select coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', sc.id,\n 'name', sc.name,\n 'status', sc.status\n )\n ),\n '[]'\n )\n from document_spatial_coverage dsc\n join spatial_coverage sc on sc.id = dsc.spatial_coverage_id\n where dsc.document_id = d.id\n ) as spatial_coverage,\n (\n select coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', cr.id,\n 'name', cr.name\n )\n ),\n '[]'\n )\n from document_creator dcr\n join creator cr on cr.id = dcr.creator_id\n where dcr.document_id = d.id\n ) as creators\nfrom document as d\n left join contributor_attribution as attr on attr.document_id = d.id\n left join contributor on contributor.id = attr.contributor_id\n left join media_slice on media_slice.id = d.audio_slice_id\n left join media_resource on media_resource.id = media_slice.resource_id\n left join dailp_user on dailp_user.id = media_resource.recorded_by\n left join user_bookmarked_document as ubd on ubd.document_id = d.id\nwhere d.id = any($1)\ngroup by\n d.id,\n media_slice.id,\n media_resource.id,\n dailp_user.id,\n ubd.bookmarked_on;\n", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "id", + "type_info": "Uuid" + }, + { + "ordinal": 1, + "name": "short_name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "title", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "is_reference", + "type_info": "Bool" + }, + { + "ordinal": 4, + "name": "written_at", + "type_info": "Date" + }, + { + "ordinal": 5, + "name": "format_id", + "type_info": "Uuid" + }, + { + "ordinal": 6, + "name": "genre_id", + "type_info": "Uuid" + }, + { + "ordinal": 7, + "name": "audio_slice_id", + "type_info": "Uuid" + }, + { + "ordinal": 8, + "name": "include_audio_in_edited_collection", + "type_info": "Bool" + }, + { + "ordinal": 9, + "name": "audio_url?", + "type_info": "Text" + }, + { + "ordinal": 10, + "name": "recorded_at?", + "type_info": "Date" + }, + { + "ordinal": 11, + "name": "recorded_by?", + "type_info": "Uuid" + }, + { + "ordinal": 12, + "name": "recorded_by_name?", + "type_info": "Text" + }, + { + "ordinal": 13, + "name": "audio_slice?", + "type_info": "Int8Range" + }, + { + "ordinal": 14, + "name": "bookmarked_on?", + "type_info": "Date" + }, + { + "ordinal": 15, + "name": "contributors", + "type_info": "Jsonb" + }, + { + "ordinal": 16, + "name": "keywords", + "type_info": "Jsonb" + }, + { + "ordinal": 17, + "name": "languages", + "type_info": "Jsonb" + }, + { + "ordinal": 18, + "name": "subject_headings", + "type_info": "Jsonb" + }, + { + "ordinal": 19, + "name": "spatial_coverage", + "type_info": "Jsonb" + }, + { + "ordinal": 20, + "name": "creators", + "type_info": "Jsonb" + } + ], + "parameters": { + "Left": [ + "UuidArray" + ] + }, + "nullable": [ + false, + false, + false, + false, + true, + true, + true, + true, + false, + false, + true, + false, + false, + true, + false, + null, + null, + null, + null, + null, + null + ] + }, + "hash": "b65e199479fbd23d8bdc2169e90a581faf595b9b33d274b97c2a7e88bdc9458f" +} diff --git a/types/.sqlx/query-f2c4999389ca455e12e0349afcfab508671042d19332a39a3bad8d85b688f65b.json b/types/.sqlx/query-f2c4999389ca455e12e0349afcfab508671042d19332a39a3bad8d85b688f65b.json deleted file mode 100644 index a2d98efa4..000000000 --- a/types/.sqlx/query-f2c4999389ca455e12e0349afcfab508671042d19332a39a3bad8d85b688f65b.json +++ /dev/null @@ -1,136 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "select\n d.id,\n d.short_name,\n d.title,\n d.is_reference,\n d.written_at,\n d.format_id,\n d.genre_id,\n d.audio_slice_id,\n media_resource.url as \"audio_url?\",\n media_resource.recorded_at as \"recorded_at?\",\n dailp_user.id as \"recorded_by?\",\n dailp_user.display_name as \"recorded_by_name?\",\n media_slice.time_range as \"audio_slice?\",\n ubd.bookmarked_on as \"bookmarked_on?\",\n coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', contributor.id,\n 'name', contributor.full_name,\n 'role', attr.contribution_role\n )\n ) filter (where contributor is not null),\n '[]'\n ) as contributors,\n (\n select coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', k.id,\n 'name', k.name,\n 'status', k.status\n )\n ),\n '[]'\n )\n from document_keyword dk\n join keyword k on k.id = dk.keyword_id\n where dk.document_id = d.id\n ) as keywords,\n (\n select coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', l.id,\n 'name', l.name,\n 'status', l.status\n )\n ),\n '[]'\n )\n from document_language dl\n join language l on l.id = dl.language_id\n where dl.document_id = d.id\n ) as languages,\n ( -- Subject Headings\n select coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', sh.id,\n 'name', sh.name,\n 'status', sh.status\n )), '[]')\n from document_subject_heading dsh\n join subject_heading sh on sh.id = dsh.subject_heading_id\n where dsh.document_id = d.id\n ) as subject_headings,\n ( -- Spatial Coverage\n select coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', sc.id,\n 'name', sc.name,\n 'status', sc.status\n )\n ),\n '[]'\n )\n from document_spatial_coverage dsc\n join spatial_coverage sc on sc.id = dsc.spatial_coverage_id\n where dsc.document_id = d.id\n ) as spatial_coverage,\n (\n select coalesce(\n jsonb_agg(\n jsonb_build_object(\n 'id', cr.id,\n 'name', cr.name\n )\n ),\n '[]'\n )\n from document_creator dcr\n join creator cr on cr.id = dcr.creator_id\n where dcr.document_id = d.id\n ) as creators\nfrom document as d\n left join contributor_attribution as attr on attr.document_id = d.id\n left join contributor on contributor.id = attr.contributor_id\n left join media_slice on media_slice.id = d.audio_slice_id\n left join media_resource on media_resource.id = media_slice.resource_id\n left join dailp_user on dailp_user.id = media_resource.recorded_by\n left join user_bookmarked_document as ubd on ubd.document_id = d.id\nwhere d.id = any($1)\ngroup by\n d.id,\n media_slice.id,\n media_resource.id,\n dailp_user.id,\n ubd.bookmarked_on;\n", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Uuid" - }, - { - "ordinal": 1, - "name": "short_name", - "type_info": "Text" - }, - { - "ordinal": 2, - "name": "title", - "type_info": "Text" - }, - { - "ordinal": 3, - "name": "is_reference", - "type_info": "Bool" - }, - { - "ordinal": 4, - "name": "written_at", - "type_info": "Date" - }, - { - "ordinal": 5, - "name": "format_id", - "type_info": "Uuid" - }, - { - "ordinal": 6, - "name": "genre_id", - "type_info": "Uuid" - }, - { - "ordinal": 7, - "name": "audio_slice_id", - "type_info": "Uuid" - }, - { - "ordinal": 8, - "name": "audio_url?", - "type_info": "Text" - }, - { - "ordinal": 9, - "name": "recorded_at?", - "type_info": "Date" - }, - { - "ordinal": 10, - "name": "recorded_by?", - "type_info": "Uuid" - }, - { - "ordinal": 11, - "name": "recorded_by_name?", - "type_info": "Text" - }, - { - "ordinal": 12, - "name": "audio_slice?", - "type_info": "Int8Range" - }, - { - "ordinal": 13, - "name": "bookmarked_on?", - "type_info": "Date" - }, - { - "ordinal": 14, - "name": "contributors", - "type_info": "Jsonb" - }, - { - "ordinal": 15, - "name": "keywords", - "type_info": "Jsonb" - }, - { - "ordinal": 16, - "name": "languages", - "type_info": "Jsonb" - }, - { - "ordinal": 17, - "name": "subject_headings", - "type_info": "Jsonb" - }, - { - "ordinal": 18, - "name": "spatial_coverage", - "type_info": "Jsonb" - }, - { - "ordinal": 19, - "name": "creators", - "type_info": "Jsonb" - } - ], - "parameters": { - "Left": [ - "UuidArray" - ] - }, - "nullable": [ - false, - false, - false, - false, - true, - true, - true, - true, - false, - true, - false, - false, - true, - false, - null, - null, - null, - null, - null, - null - ] - }, - "hash": "f2c4999389ca455e12e0349afcfab508671042d19332a39a3bad8d85b688f65b" -} diff --git a/types/queries/many_documents.sql b/types/queries/many_documents.sql index bea5adcc2..24923a1b7 100644 --- a/types/queries/many_documents.sql +++ b/types/queries/many_documents.sql @@ -7,6 +7,7 @@ select d.format_id, d.genre_id, d.audio_slice_id, + d.include_audio_in_edited_collection, media_resource.url as "audio_url?", media_resource.recorded_at as "recorded_at?", dailp_user.id as "recorded_by?", diff --git a/types/queries/many_documents_by_name.sql b/types/queries/many_documents_by_name.sql index da3a939a5..7de0b2f0f 100644 --- a/types/queries/many_documents_by_name.sql +++ b/types/queries/many_documents_by_name.sql @@ -5,6 +5,7 @@ select d.is_reference, d.written_at, d.audio_slice_id, + d.include_audio_in_edited_collection, media_resource.url as "audio_url?", media_resource.recorded_at as "recorded_at?", dailp_user.id as "recorded_by?", diff --git a/types/src/database_sql.rs b/types/src/database_sql.rs index 1a4ee47b3..0ae5b1d8d 100644 --- a/types/src/database_sql.rs +++ b/types/src/database_sql.rs @@ -2744,7 +2744,7 @@ impl Loader for Database { parent_track: None, annotations: None, index: 0, - include_in_edited_collection: true, + include_in_edited_collection: item.include_audio_in_edited_collection, edited_by: None, recorded_at: item.recorded_at.map(Date::new), recorded_by: item.recorded_by.and_then(|user_id| { @@ -2821,8 +2821,7 @@ impl Loader for Database { parent_track: None, annotations: None, index: 0, - // TODO: is this a bad default? - include_in_edited_collection: true, + include_in_edited_collection: item.include_audio_in_edited_collection, edited_by: None, recorded_at: item.recorded_at.map(Date::new), recorded_by: item.recorded_by.and_then(|user_id| { diff --git a/website/src/pages/documents/document.page.tsx b/website/src/pages/documents/document.page.tsx index 8d53cd44f..b7385f34d 100644 --- a/website/src/pages/documents/document.page.tsx +++ b/website/src/pages/documents/document.page.tsx @@ -494,8 +494,10 @@ export const DocumentTitleHeader = (p: {
- {/* only show document audio to non-editors , editors can see which ones are shown from checkmark*/} - {p.doc.editedAudio.length > 0 && role !== UserRole.Editor && ( + {/* Each Role has their own view of the audio */} + {role === UserRole.Reader && p.doc.editedAudio.length > 0 && ( + // Published audio only - official DAILP track and + // user-contributed audio that has been published by an editor. <>

Document Audio:

{p.doc.editedAudio.map((audio, index) => ( @@ -526,15 +528,35 @@ export const DocumentTitleHeader = (p: { ))} )} - {role === UserRole.Contributor && ( - <> -

User-contributed Audio:

- {p.doc.userContributedAudio.map( - (audio, index) => - audio.recordedBy?.id === userId && ( + {role === UserRole.Contributor && + (() => { + // Includes the official DAILP track + published user-contributed audio + this user's own uploads + // No "show to readers" checkbox. + const ownUploads = p.doc.userContributedAudio.filter( + (a) => a.recordedBy?.id === userId + ) + const seen = new Set() + const contributorAudio = [ + ...p.doc.editedAudio, + ...ownUploads, + ].filter((a) => { + if (!a.sliceId) return true + if (seen.has(a.sliceId)) return false + seen.add(a.sliceId) + return true + }) + if (contributorAudio.length === 0) return null + return ( + <> +

Document Audio:

+ {contributorAudio.map((audio, index) => (
- ) - )} - - )} - {role === UserRole.Editor && ( - <> -

User-contributed Audio:

- {p.doc.userContributedAudio.map((audio, index) => ( -
- {role === UserRole.Editor && ( - <> + ))} + + ) + })()} + {role === UserRole.Editor && + (() => { + // All user-contributed audio + the official DAILP track + // All items get the "Publish to readers" checkbox. + const userContributedSliceIds = new Set( + p.doc.userContributedAudio + .map((a) => a.sliceId) + .filter((id): id is string => !!id) + ) + const ingestedOnly = p.doc.editedAudio.filter( + (a) => !a.sliceId || !userContributedSliceIds.has(a.sliceId) + ) + const editorAudio = [ + ...ingestedOnly, + ...p.doc.userContributedAudio, + ] + if (editorAudio.length === 0) return null + return ( + <> +

Document Audio:

+ {editorAudio.map((audio, index) => ( +
)} - - )} -
- ))} - - )} +
+ ))} + + ) + })()} {(role === UserRole.Editor || role === UserRole.Contributor) && ( )}