From 735ea2945b9e382c859456155c873ff370ac9222 Mon Sep 17 00:00:00 2001 From: jon Date: Tue, 8 Oct 2024 10:50:23 +1300 Subject: [PATCH] - Clicking a visit should always select+display the first recording in the visit with a track matching the visit classification. --- .../src/components/VisitsDailyBreakdown.vue | 2 +- .../cptv-decoder/decoder.worker.ts | 1 + browse-next/src/views/ActivitySearchView.vue | 32 +++++++++++-- browse-next/src/views/DashboardView.vue | 45 ++++++++++++++++--- 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/browse-next/src/components/VisitsDailyBreakdown.vue b/browse-next/src/components/VisitsDailyBreakdown.vue index a3ef0b38..efeab6e9 100644 --- a/browse-next/src/components/VisitsDailyBreakdown.vue +++ b/browse-next/src/components/VisitsDailyBreakdown.vue @@ -359,7 +359,7 @@ const isStillProcessing = computed(() => { {{ diff --git a/browse-next/src/components/cptv-player/cptv-decoder/decoder.worker.ts b/browse-next/src/components/cptv-player/cptv-decoder/decoder.worker.ts index 03019508..05766b6c 100644 --- a/browse-next/src/components/cptv-player/cptv-decoder/decoder.worker.ts +++ b/browse-next/src/components/cptv-player/cptv-decoder/decoder.worker.ts @@ -127,6 +127,7 @@ class CptvDecoderInterface { }; this.response = await fetch( `${apiRoot}/api/v1/recordings/raw/${id}`, + // eslint-disable-next-line no-undef request as RequestInit ); if (this.response.status === 200) { diff --git a/browse-next/src/views/ActivitySearchView.vue b/browse-next/src/views/ActivitySearchView.vue index 28f9300a..c5fcb5ce 100644 --- a/browse-next/src/views/ActivitySearchView.vue +++ b/browse-next/src/views/ActivitySearchView.vue @@ -1688,12 +1688,36 @@ watch( recId, tracks, })); + const visitClassification = visit.classification || ""; + let firstRec = visit.recordings[0]; + let firstTrack = + (firstRec.tracks && + firstRec.tracks.length !== 0 && + firstRec.tracks[0]) || + undefined; + if (visitClassification !== "") { + // Make sure we set the first recording as one that contains the visit classification. + const firstRecordingWithVisitClassification = visit.recordings.find( + (rec) => + rec.tracks.some( + (track) => + track.tag === visit.classification || + (!track.tag && track.aiTag === visit.classification) + ) + ); + if (firstRecordingWithVisitClassification) { + firstRec = firstRecordingWithVisitClassification; + firstTrack = firstRec.tracks.find( + (track) => + track.tag === visit.classification || + (!track.tag && track.aiTag === visit.classification) + ); + } + } const params: Record = { visitLabel: visit.classification || "", - currentRecordingId: recordingIds[0].recId.toString(), - trackId: (recordingIds[0].tracks && - recordingIds[0].tracks.length && - recordingIds[0].tracks[0].id.toString()) as string, + currentRecordingId: firstRec.recId.toString(), + trackId: (firstTrack && firstTrack.id.toString()) as string, }; if (recordingIds.length) { params.recordingIds = recordingIds.map(({ recId }) => recId).join(","); diff --git a/browse-next/src/views/DashboardView.vue b/browse-next/src/views/DashboardView.vue index 355bd36f..2a9a7619 100644 --- a/browse-next/src/views/DashboardView.vue +++ b/browse-next/src/views/DashboardView.vue @@ -165,18 +165,49 @@ watch( (visit: ApiVisitResponse | null, prevVisit: ApiVisitResponse | null) => { if (visit && !prevVisit) { // Set route so that modal shows up - const recordingIds = visit.recordings.map(({ recId }) => recId); - const params = { - visitLabel: visit.classification, - currentRecordingId: recordingIds[0].toString(), + + const recordingIds = visit.recordings.map(({ recId, tracks }) => ({ + recId, + tracks, + })); + const visitClassification = visit.classification || ""; + let firstRec = visit.recordings[0]; + let firstTrack = + (firstRec.tracks && + firstRec.tracks.length !== 0 && + firstRec.tracks[0]) || + undefined; + if (visitClassification !== "") { + // Make sure we set the first recording as one that contains the visit classification. + const firstRecordingWithVisitClassification = visit.recordings.find( + (rec) => + rec.tracks.some( + (track) => + track.tag === visit.classification || + (!track.tag && track.aiTag === visit.classification) + ) + ); + if (firstRecordingWithVisitClassification) { + firstRec = firstRecordingWithVisitClassification; + firstTrack = firstRec.tracks.find( + (track) => + track.tag === visit.classification || + (!track.tag && track.aiTag === visit.classification) + ); + } + } + const params: Record = { + visitLabel: visit.classification || "", + currentRecordingId: firstRec.recId.toString(), + trackId: (firstTrack && firstTrack.id.toString()) as string, }; - if (recordingIds.length > 1) { - (params as Record).recordingIds = - recordingIds.join(","); + if (recordingIds.length) { + params.recordingIds = recordingIds.map(({ recId }) => recId).join(","); } router.push({ name: "dashboard-visit", params, + query: route.query, }); } else if (!visit && prevVisit) { // We've stopped having a selected visit modal