1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/gallery/lightbox/infopanel/info-panel.lightbox.gallery.component.ts

92 lines
2.3 KiB
TypeScript
Raw Normal View History

2018-03-31 03:30:30 +08:00
import {Component, ElementRef, EventEmitter, Input, Output} from '@angular/core';
import {PhotoDTO} from '../../../../../common/entities/PhotoDTO';
import {Config} from '../../../../../common/config/public/Config';
@Component({
2018-05-04 07:17:08 +08:00
selector: 'app-info-panel',
styleUrls: ['./info-panel.lightbox.gallery.component.css'],
templateUrl: './info-panel.lightbox.gallery.component.html',
})
export class InfoPanelLightboxComponent {
@Input() photo: PhotoDTO;
2017-07-18 00:30:16 +08:00
@Output('onClose') onClose = new EventEmitter();
2017-07-14 05:39:09 +08:00
public mapEnabled = true;
2017-07-11 04:00:22 +08:00
constructor(public elementRef: ElementRef) {
2017-07-14 05:39:09 +08:00
this.mapEnabled = Config.Client.Map.enabled;
}
calcMpx() {
return (this.photo.metadata.size.width * this.photo.metadata.size.height / 1000000).toFixed(2);
}
calcFileSize() {
2018-05-04 07:17:08 +08:00
const postFixes = ['B', 'KB', 'MB', 'GB', 'TB'];
let index = 0;
let size = this.photo.metadata.fileSize;
while (size > 1000 && index < postFixes.length - 1) {
size /= 1000;
index++;
}
return size.toFixed(2) + postFixes[index];
}
getCurrentYear() {
return (new Date()).getFullYear();
}
getYear() {
const date = new Date(this.photo.metadata.creationDate);
return date.getFullYear();
}
getDate() {
const date = new Date(this.photo.metadata.creationDate);
2018-05-04 07:17:08 +08:00
const locale = 'en-us';
2018-03-31 03:30:30 +08:00
return date.toLocaleString(locale, {month: 'long'}) + ' ' + date.getDate();
}
getTime() {
const date = new Date(this.photo.metadata.creationDate);
2017-07-22 01:33:24 +08:00
return date.toTimeString().split(' ')[0];
}
getDay() {
const date = new Date(this.photo.metadata.creationDate);
2018-05-04 07:17:08 +08:00
const locale = 'en-us';
2018-03-31 03:30:30 +08:00
return date.toLocaleString(locale, {weekday: 'long'});
}
toFraction(f) {
if (f > 1) {
return f;
}
2018-03-31 03:30:30 +08:00
return '1/' + (1 / f);
}
hasGPS() {
return this.photo.metadata.positionData && this.photo.metadata.positionData.GPSData &&
2018-03-31 03:30:30 +08:00
this.photo.metadata.positionData.GPSData.latitude && this.photo.metadata.positionData.GPSData.longitude;
}
getPositionText(): string {
if (!this.photo.metadata.positionData) {
2018-03-31 03:30:30 +08:00
return '';
}
let str = this.photo.metadata.positionData.city ||
this.photo.metadata.positionData.state;
2018-05-04 07:17:08 +08:00
if (str.length !== 0) {
2018-03-31 03:30:30 +08:00
str += ', ';
}
str += this.photo.metadata.positionData.country;
return str;
}
2017-07-18 00:30:16 +08:00
close() {
this.onClose.emit();
}
}