Skip to content

Commit 3cfdd25

Browse files
committed
Use GetAccessFile in file viewer components
Use the `GetAccessFile` method in various file viewer components. In particular: - The code that fetches the PDF url in the file-viewer component - The code that fetches the proper audio file - The code that fetches the proper video file - The code that fetches which image to use in OpenSeaDragon PER-9873: Update clients to favor Archivematica access copies
1 parent cc1417e commit 3cfdd25

File tree

5 files changed

+37
-51
lines changed

5 files changed

+37
-51
lines changed

src/app/file-browser/components/file-viewer/file-viewer.component.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import type { KeysOfType } from '@shared/utilities/keysoftype';
2525
import { Subscription } from 'rxjs';
2626
import { SearchService } from '@search/services/search.service';
2727
import { ZoomingImageViewerComponent } from '@shared/components/zooming-image-viewer/zooming-image-viewer.component';
28+
import { FileFormat } from '@models/file-vo';
29+
import { GetAccessFile } from '@models/get-access-file';
2830
import { TagsService } from '../../../core/services/tags/tags.service';
2931

3032
@Component({
@@ -194,9 +196,11 @@ export class FileViewerComponent implements OnInit, OnDestroy {
194196
this.isZoomableImage =
195197
this.currentRecord.type.includes('image') &&
196198
this.currentRecord.FileVOs?.length &&
197-
ZoomingImageViewerComponent.chooseFullSizeImage(this.currentRecord);
199+
typeof ZoomingImageViewerComponent.chooseFullSizeImage(
200+
this.currentRecord,
201+
) !== 'undefined';
198202
this.isDocument = this.currentRecord.FileVOs?.some(
199-
(obj: ItemVO) => obj.type.includes('pdf') || obj.type.includes('txt'),
203+
(obj) => obj.type.includes('pdf') || obj.type.includes('txt'),
200204
);
201205
this.documentUrl = this.getDocumentUrl();
202206
this.setCurrentTags();
@@ -215,19 +219,17 @@ export class FileViewerComponent implements OnInit, OnDestroy {
215219
return false;
216220
}
217221

218-
const original = find(this.currentRecord.FileVOs, {
219-
format: 'file.format.original',
220-
}) as any;
221-
const pdf = find(this.currentRecord.FileVOs, (f) =>
222-
f.type.includes('pdf'),
223-
) as any;
222+
const original = this.currentRecord.FileVOs.find(
223+
(file) => file.format === FileFormat.Original,
224+
);
225+
const access = GetAccessFile(this.currentRecord);
224226

225227
let url;
226228

227229
if (original?.type.includes('pdf') || original?.type.includes('txt')) {
228230
url = original?.fileURL;
229-
} else if (pdf) {
230-
url = pdf?.fileURL;
231+
} else if (access) {
232+
url = access?.fileURL;
231233
}
232234

233235
if (!url) {

src/app/models/record-vo.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { LocnVOData } from './locn-vo';
1111
import { TagVOData } from './tag-vo';
1212
import { ArchiveVO } from './archive-vo';
1313
import { HasThumbnails } from './get-thumbnail';
14+
import { PermanentFile } from './file-vo';
1415

1516
interface RecordVoOptions {
1617
dataStatus: DataStatus;
@@ -107,7 +108,7 @@ export class RecordVO
107108
// Other stuff
108109
public LocnVO: LocnVOData;
109110
public TimezoneVO: TimezoneVOData;
110-
public FileVOs;
111+
public FileVOs: PermanentFile[];
111112
public TagVOs: TagVOData[];
112113
public TextDataVOs;
113114
public ArchiveVOs: ArchiveVO[];
Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,18 @@
1-
import { Component, OnInit, Input, OnChanges } from '@angular/core';
1+
/* @format */
2+
import { Component, Input, OnChanges } from '@angular/core';
23
import { RecordVO } from '@models';
3-
import { find } from 'lodash';
4+
import { GetAccessFile } from '@models/get-access-file';
45

56
@Component({
67
selector: 'pr-audio',
78
templateUrl: './audio.component.html',
8-
styleUrls: ['./audio.component.scss']
9+
styleUrls: ['./audio.component.scss'],
910
})
1011
export class AudioComponent implements OnChanges {
1112
@Input() item: RecordVO;
1213
audioSrc: string;
13-
constructor() { }
1414

1515
ngOnChanges(): void {
16-
const convertedFile = find(this.item.FileVOs, {format: 'file.format.converted'}) as any;
17-
const originalFile = find(this.item.FileVOs, {format: 'file.format.original'}) as any;
18-
19-
if (convertedFile) {
20-
this.audioSrc = convertedFile.fileURL;
21-
} else if (originalFile) {
22-
this.audioSrc = originalFile.fileURL;
23-
}
16+
this.audioSrc = GetAccessFile(this.item)?.fileURL;
2417
}
25-
2618
}
Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
/* @format */
12
import { Component, OnInit, Input, ElementRef, Renderer2 } from '@angular/core';
23
import { gsap } from 'gsap';
3-
import { find } from 'lodash';
44

55
import { RecordVO } from '@root/app/models';
6+
import { GetAccessFile } from '@models/get-access-file';
67

78
const FADE_IN_DURATION = 0.3;
89

910
@Component({
1011
selector: 'pr-video',
1112
templateUrl: './video.component.html',
12-
styleUrls: ['./video.component.scss']
13+
styleUrls: ['./video.component.scss'],
1314
})
1415
export class VideoComponent implements OnInit {
1516
@Input() item: RecordVO;
@@ -19,39 +20,34 @@ export class VideoComponent implements OnInit {
1920
public videoSrc: string;
2021
public isProcessing: boolean;
2122

22-
constructor(private elementRef: ElementRef, private renderer: Renderer2) { }
23+
constructor(
24+
private elementRef: ElementRef,
25+
private renderer: Renderer2,
26+
) {}
2327

2428
ngOnInit() {
2529
this.videoElem = this.elementRef.nativeElement.querySelector('video');
26-
this.videoWrapperElem = this.elementRef.nativeElement.querySelector('.pr-video-wrapper');
30+
this.videoWrapperElem =
31+
this.elementRef.nativeElement.querySelector('.pr-video-wrapper');
2732

2833
this.videoElem.addEventListener('loadstart', (event) => {
2934
setTimeout(() => {
3035
this.renderer.removeClass(this.videoWrapperElem, 'loading');
31-
gsap.from(
32-
this.videoElem,
33-
FADE_IN_DURATION,
34-
{
35-
opacity: 0,
36-
ease: 'Power4.easeOut'
37-
}
38-
);
36+
gsap.from(this.videoElem, FADE_IN_DURATION, {
37+
opacity: 0,
38+
ease: 'Power4.easeOut',
39+
});
3940
}, 250);
4041
});
4142

42-
const convertedFile = find(this.item.FileVOs, {type: 'type.file.video.mp4', format: 'file.format.converted'}) as any;
43-
const originalFile = find(this.item.FileVOs, {format: 'file.format.original'}) as any;
43+
const accessFile = GetAccessFile(this.item);
4444

45-
if (convertedFile) {
46-
this.videoSrc = convertedFile.fileURL;
47-
this.isProcessing = false;
48-
} else if (originalFile) {
49-
this.videoSrc = originalFile.fileURL;
45+
if (accessFile) {
46+
this.videoSrc = accessFile.fileURL;
5047
this.isProcessing = false;
5148
} else {
5249
this.renderer.removeClass(this.videoWrapperElem, 'loading');
5350
this.isProcessing = true;
5451
}
5552
}
56-
5753
}

src/app/shared/components/zooming-image-viewer/zooming-image-viewer.component.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Output,
1111
ViewChild,
1212
} from '@angular/core';
13+
import { GetAccessFile } from '@models/get-access-file';
1314
import { RecordVO } from '@models/index';
1415
import * as OpenSeaDragon from 'openseadragon';
1516
import { ZoomEvent, FullScreenEvent } from 'openseadragon';
@@ -84,13 +85,7 @@ export class ZoomingImageViewerComponent implements AfterViewInit, OnDestroy {
8485
}
8586

8687
public static chooseFullSizeImage(record: RecordVO) {
87-
if (record.FileVOs.length > 1) {
88-
const convertedUrl = record.FileVOs.find(
89-
(file) => file.format == 'file.format.converted',
90-
)?.fileURL;
91-
return convertedUrl ?? record.FileVOs[0]?.fileURL;
92-
}
93-
return record.FileVOs[0]?.fileURL;
88+
return GetAccessFile(record)?.fileURL;
9489
}
9590

9691
private enablePanning(flag: boolean): void {

0 commit comments

Comments
 (0)