-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy paththumbnail.component.ts
130 lines (108 loc) · 3.86 KB
/
thumbnail.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import type { OnInit, ElementRef, OnDestroy } from '@angular/core';
import { Component, Input, Output, EventEmitter, ViewChild } from '@angular/core';
import { FilePathService } from '../file-path.service';
import { metaAppear, textAppear } from '../../../common/animations';
import type { ImageElement } from '../../../../../interfaces/final-object.interface';
import type { VideoClickEmit, RightClickEmit } from '../../../../../interfaces/shared-interfaces';
@Component({
selector: 'app-thumbnail',
templateUrl: './thumbnail.component.html',
styleUrls: [
'../clip-and-preview.scss',
'../time-and-rez.scss',
'./thumbnail.component.scss',
'../selected.scss'
],
animations: [ textAppear,
metaAppear ]
})
export class ThumbnailComponent implements OnInit, OnDestroy {
@ViewChild('filmstripHolder', { static: false }) filmstripHolder: ElementRef;
@Output() sheetClick = new EventEmitter<any>(); // does not emit data of any kind
@Output() videoClick = new EventEmitter<VideoClickEmit>();
@Output() rightClick = new EventEmitter<RightClickEmit>();
@Input() video: ImageElement;
@Input() compactView: boolean;
@Input() connected: boolean;
@Input() darkMode: boolean;
@Input() elHeight: number;
@Input() elWidth: number;
@Input() folderPath: string;
@Input() hoverScrub: boolean;
@Input() hubName: string;
@Input() imgHeight: number;
@Input() largerFont: boolean;
@Input() returnToFirstScreenshot: boolean;
@Input() showMeta: boolean;
@Input() thumbAutoAdvance: boolean;
containerWidth: number;
firstFilePath = '';
folderThumbPaths: string[] = [];
fullFilePath = '';
hover: boolean;
indexToShow = 1;
percentOffset = 0;
scrollInterval: any = null;
constructor(
public filePathService: FilePathService
) { }
ngOnInit() {
// multiple hashes == folder view
if (this.video.hash.indexOf(':') !== -1) {
const hashes = this.video.hash.split(':');
hashes.slice(0, 4).forEach((hash) => {
this.folderThumbPaths.push(this.filePathService.createFilePath(this.folderPath, this.hubName, 'thumbnails', hash));
});
} else {
this.firstFilePath = this.filePathService.createFilePath(this.folderPath, this.hubName, 'thumbnails', this.video.hash);
if (this.video.type == 'image') {
this.fullFilePath = this.firstFilePath;
} else {
this.fullFilePath = this.filePathService.createFilePath(this.folderPath, this.hubName, 'filmstrips', this.video.hash);
}
this.folderThumbPaths.push(this.firstFilePath);
}
if (this.video.defaultScreen) {
this.hover = true;
this.percentOffset = this.defaultScreenOffset(this.video);
}
}
defaultScreenOffset(video: ImageElement): number {
return 100 * video.defaultScreen / (video.screens - 1);
}
mouseEntered() {
this.containerWidth = this.filmstripHolder.nativeElement.getBoundingClientRect().width;
if (this.thumbAutoAdvance) {
this.hover = true;
this.scrollInterval = setInterval(() => {
this.percentOffset = this.indexToShow * (100 / (this.video.screens - 1));
this.indexToShow++;
}, 750);
} else if (this.hoverScrub) {
this.hover = true;
}
}
mouseLeft() {
if (this.thumbAutoAdvance) {
clearInterval(this.scrollInterval);
}
if (this.returnToFirstScreenshot) {
if (this.video.defaultScreen !== undefined) {
this.percentOffset = this.defaultScreenOffset(this.video);
} else {
this.hover = false;
this.percentOffset = 0;
}
}
}
mouseIsMoving($event: any) {
if (this.hoverScrub) {
const cursorX = $event.layerX;
this.indexToShow = Math.floor(cursorX * (this.video.screens / this.containerWidth));
this.percentOffset = this.indexToShow * (100 / (this.video.screens - 1));
}
}
ngOnDestroy() {
clearInterval(this.scrollInterval);
}
}