mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
116 lines
3.3 KiB
TypeScript
116 lines
3.3 KiB
TypeScript
import {Component, ElementRef, EventEmitter, Input, Output} from '@angular/core';
|
|
import {CameraMetadata, PhotoDTO, PositionMetaData} from '../../../../../common/entities/PhotoDTO';
|
|
import {Config} from '../../../../../common/config/public/Config';
|
|
import {MediaDTO} from '../../../../../common/entities/MediaDTO';
|
|
import {VideoDTO, VideoMetadata} from '../../../../../common/entities/VideoDTO';
|
|
import {Utils} from '../../../../../common/Utils';
|
|
|
|
@Component({
|
|
selector: 'app-info-panel',
|
|
styleUrls: ['./info-panel.lightbox.gallery.component.css'],
|
|
templateUrl: './info-panel.lightbox.gallery.component.html',
|
|
})
|
|
export class InfoPanelLightboxComponent {
|
|
@Input() media: MediaDTO;
|
|
@Output() closed = new EventEmitter();
|
|
|
|
public mapEnabled = true;
|
|
|
|
constructor(public elementRef: ElementRef) {
|
|
this.mapEnabled = Config.Client.Map.enabled;
|
|
}
|
|
|
|
isPhoto() {
|
|
return this.media && MediaDTO.isPhoto(this.media);
|
|
}
|
|
|
|
calcMpx() {
|
|
return (this.media.metadata.size.width * this.media.metadata.size.height / 1000000).toFixed(2);
|
|
}
|
|
|
|
renderDuration(time: number) {
|
|
const h = Math.floor(time / 1000 / 60 / 60);
|
|
time %= 1000 * 60 * 60;
|
|
const m = Math.floor(time / 1000 / 60);
|
|
time %= 1000 * 60;
|
|
const s = Math.floor(time / 1000);
|
|
return Utils.zeroPrefix(h, 2) + ':' + Utils.zeroPrefix(m, 2) + ':' + Utils.zeroPrefix(s, 2);
|
|
}
|
|
|
|
calcSize(size: number) {
|
|
const postFixes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
let index = 0;
|
|
while (size > 1000 && index < postFixes.length - 1) {
|
|
size /= 1000;
|
|
index++;
|
|
}
|
|
return size.toFixed(2) + postFixes[index];
|
|
}
|
|
|
|
isThisYear() {
|
|
return (new Date()).getFullYear() ===
|
|
(new Date(this.media.metadata.creationDate)).getFullYear();
|
|
}
|
|
|
|
|
|
getTime() {
|
|
const date = new Date(this.media.metadata.creationDate);
|
|
return date.toTimeString().split(' ')[0];
|
|
}
|
|
|
|
|
|
toFraction(f) {
|
|
if (f > 1) {
|
|
return f;
|
|
}
|
|
return '1/' + (1 / f);
|
|
}
|
|
|
|
get VideoData(): VideoMetadata {
|
|
if (typeof (<VideoDTO>this.media).metadata.bitRate === 'undefined') {
|
|
return null;
|
|
}
|
|
return (<VideoDTO>this.media).metadata;
|
|
}
|
|
|
|
hasPositionData(): boolean {
|
|
return !!(<PhotoDTO>this.media).metadata.positionData &&
|
|
!!((<PhotoDTO>this.media).metadata.positionData.city ||
|
|
(<PhotoDTO>this.media).metadata.positionData.state ||
|
|
(<PhotoDTO>this.media).metadata.positionData.country);
|
|
}
|
|
|
|
hasGPS() {
|
|
return (<PhotoDTO>this.media).metadata.positionData && (<PhotoDTO>this.media).metadata.positionData.GPSData &&
|
|
(<PhotoDTO>this.media).metadata.positionData.GPSData.latitude && (<PhotoDTO>this.media).metadata.positionData.GPSData.longitude;
|
|
}
|
|
|
|
get PositionData(): PositionMetaData {
|
|
return (<PhotoDTO>this.media).metadata.positionData;
|
|
}
|
|
|
|
getPositionText(): string {
|
|
if (!(<PhotoDTO>this.media).metadata.positionData) {
|
|
return '';
|
|
}
|
|
let str = (<PhotoDTO>this.media).metadata.positionData.city ||
|
|
(<PhotoDTO>this.media).metadata.positionData.state || '';
|
|
|
|
if (str.length !== 0) {
|
|
str += ', ';
|
|
}
|
|
str += (<PhotoDTO>this.media).metadata.positionData.country || '';
|
|
|
|
return str;
|
|
}
|
|
|
|
get CameraData(): CameraMetadata {
|
|
return (<PhotoDTO>this.media).metadata.cameraData;
|
|
}
|
|
|
|
close() {
|
|
this.closed.emit();
|
|
}
|
|
}
|
|
|