2018-03-31 03:30:30 +08:00
|
|
|
import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core';
|
|
|
|
import {AuthenticationService} from '../model/network/authentication.service';
|
|
|
|
import {ActivatedRoute, Params, Router} from '@angular/router';
|
|
|
|
import {GalleryService} from './gallery.service';
|
|
|
|
import {GalleryGridComponent} from './grid/grid.gallery.component';
|
|
|
|
import {GallerySearchComponent} from './search/search.gallery.component';
|
|
|
|
import {SearchTypes} from '../../../common/entities/AutoCompleteItem';
|
|
|
|
import {Config} from '../../../common/config/public/Config';
|
|
|
|
import {DirectoryDTO} from '../../../common/entities/DirectoryDTO';
|
|
|
|
import {SearchResultDTO} from '../../../common/entities/SearchResultDTO';
|
|
|
|
import {ShareService} from './share.service';
|
|
|
|
import {NavigationService} from '../model/navigation.service';
|
|
|
|
import {UserRoles} from '../../../common/entities/UserDTO';
|
2018-05-04 06:23:48 +08:00
|
|
|
import {interval} from 'rxjs/observable/interval';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {ContentWrapper} from '../../../common/entities/ConentWrapper';
|
2018-05-10 01:56:02 +08:00
|
|
|
import {PageHelper} from '../model/page.helper';
|
2016-03-13 18:28:29 +08:00
|
|
|
|
|
|
|
@Component({
|
2017-06-11 04:32:56 +08:00
|
|
|
selector: 'gallery',
|
|
|
|
templateUrl: './gallery.component.html',
|
|
|
|
styleUrls: ['./gallery.component.css']
|
2016-03-13 18:28:29 +08:00
|
|
|
})
|
2017-07-04 01:17:49 +08:00
|
|
|
export class GalleryComponent implements OnInit, OnDestroy {
|
2016-03-19 16:58:27 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
@ViewChild(GallerySearchComponent) search: GallerySearchComponent;
|
|
|
|
@ViewChild(GalleryGridComponent) grid: GalleryGridComponent;
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2018-05-04 06:23:48 +08:00
|
|
|
public showSearchBar = false;
|
|
|
|
public showShare = false;
|
2017-06-21 17:46:23 +08:00
|
|
|
public directories: DirectoryDTO[] = [];
|
2017-06-22 03:32:57 +08:00
|
|
|
public isPhotoWithLocation = false;
|
2017-07-09 18:03:17 +08:00
|
|
|
private $counter;
|
2017-07-04 01:17:49 +08:00
|
|
|
private subscription = {
|
|
|
|
content: null,
|
2017-07-09 18:03:17 +08:00
|
|
|
route: null,
|
|
|
|
timer: null
|
2017-07-04 01:17:49 +08:00
|
|
|
};
|
2017-07-09 18:03:17 +08:00
|
|
|
public countDown = null;
|
2017-07-14 05:39:09 +08:00
|
|
|
public mapEnabled = true;
|
2016-05-16 17:03:11 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
constructor(public _galleryService: GalleryService,
|
|
|
|
private _authService: AuthenticationService,
|
|
|
|
private _router: Router,
|
2017-07-04 01:17:49 +08:00
|
|
|
private shareService: ShareService,
|
2017-07-09 18:03:17 +08:00
|
|
|
private _route: ActivatedRoute,
|
|
|
|
private _navigation: NavigationService) {
|
2017-07-14 05:39:09 +08:00
|
|
|
this.mapEnabled = Config.Client.Map.enabled;
|
2016-05-11 03:33:58 +08:00
|
|
|
|
2018-05-10 01:56:02 +08:00
|
|
|
PageHelper.showScrollY();
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-09 18:03:17 +08:00
|
|
|
updateTimer(t: number) {
|
|
|
|
if (this.shareService.sharing.value == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
t = Math.floor((this.shareService.sharing.value.expires - Date.now()) / 1000);
|
|
|
|
this.countDown = {};
|
|
|
|
this.countDown.day = Math.floor(t / 86400);
|
|
|
|
t -= this.countDown.day * 86400;
|
|
|
|
this.countDown.hour = Math.floor(t / 3600) % 24;
|
|
|
|
t -= this.countDown.hour * 3600;
|
|
|
|
this.countDown.minute = Math.floor(t / 60) % 60;
|
|
|
|
t -= this.countDown.minute * 60;
|
|
|
|
this.countDown.second = t % 60;
|
|
|
|
}
|
2017-07-04 01:17:49 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
private onRoute = async (params: Params) => {
|
|
|
|
const searchText = params['searchText'];
|
2018-05-04 06:23:48 +08:00
|
|
|
if (searchText && searchText !== '') {
|
|
|
|
const typeString = params['type'];
|
2017-07-09 18:03:17 +08:00
|
|
|
|
2018-05-04 06:23:48 +08:00
|
|
|
if (typeString && typeString !== '') {
|
|
|
|
const type: SearchTypes = <any>SearchTypes[typeString];
|
2018-03-31 03:30:30 +08:00
|
|
|
this._galleryService.search(searchText, type);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-19 16:58:27 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
this._galleryService.search(searchText);
|
|
|
|
return;
|
|
|
|
}
|
2017-06-21 17:46:23 +08:00
|
|
|
|
2018-05-04 06:23:48 +08:00
|
|
|
if (params['sharingKey'] && params['sharingKey'] !== '') {
|
2018-03-31 03:30:30 +08:00
|
|
|
const sharing = await this.shareService.getSharing();
|
|
|
|
this._router.navigate(['/gallery', sharing.path], {queryParams: {sk: this.shareService.getSharingKey()}});
|
|
|
|
return;
|
2017-07-09 18:03:17 +08:00
|
|
|
}
|
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
let directoryName = params['directory'];
|
|
|
|
directoryName = directoryName || '';
|
|
|
|
|
|
|
|
this._galleryService.getDirectory(directoryName);
|
|
|
|
|
|
|
|
};
|
2017-06-11 04:32:56 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.subscription.content !== null) {
|
|
|
|
this.subscription.content.unsubscribe();
|
|
|
|
}
|
|
|
|
if (this.subscription.route !== null) {
|
|
|
|
this.subscription.route.unsubscribe();
|
|
|
|
}
|
2017-07-20 04:40:27 +08:00
|
|
|
if (this.subscription.timer !== null) {
|
|
|
|
this.subscription.timer.unsubscribe();
|
|
|
|
}
|
2017-07-04 01:17:49 +08:00
|
|
|
}
|
2016-05-16 17:03:11 +08:00
|
|
|
|
2017-07-21 03:06:48 +08:00
|
|
|
private onContentChange = (content: ContentWrapper) => {
|
2017-07-04 01:17:49 +08:00
|
|
|
const dirSorter = (a: DirectoryDTO, b: DirectoryDTO) => {
|
|
|
|
return a.name.localeCompare(b.name);
|
|
|
|
};
|
2016-05-16 17:03:11 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
const tmp = <DirectoryDTO | SearchResultDTO>(content.searchResult || content.directory || {
|
|
|
|
directories: [],
|
|
|
|
photos: []
|
|
|
|
});
|
|
|
|
this.directories = tmp.directories.sort(dirSorter);
|
|
|
|
this.isPhotoWithLocation = false;
|
|
|
|
for (let i = 0; i < tmp.photos.length; i++) {
|
|
|
|
if (tmp.photos[i].metadata &&
|
|
|
|
tmp.photos[i].metadata.positionData &&
|
|
|
|
tmp.photos[i].metadata.positionData.GPSData &&
|
|
|
|
tmp.photos[i].metadata.positionData.GPSData.longitude
|
|
|
|
) {
|
|
|
|
this.isPhotoWithLocation = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
async ngOnInit() {
|
|
|
|
await this.shareService.wait();
|
|
|
|
if (!this._authService.isAuthenticated() &&
|
|
|
|
(!this.shareService.isSharing() ||
|
2018-05-10 01:37:21 +08:00
|
|
|
(this.shareService.isSharing() && Config.Client.Sharing.passwordProtected === true))) {
|
2016-05-16 17:03:11 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
return this._navigation.toLogin();
|
2017-07-04 01:17:49 +08:00
|
|
|
}
|
2018-03-31 03:30:30 +08:00
|
|
|
this.showSearchBar = Config.Client.Search.enabled && this._authService.isAuthorized(UserRoles.Guest);
|
|
|
|
this.showShare = Config.Client.Sharing.enabled && this._authService.isAuthorized(UserRoles.User);
|
2016-06-22 22:34:44 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
this.subscription.content = this._galleryService.content.subscribe(this.onContentChange);
|
|
|
|
this.subscription.route = this._route.params.subscribe(this.onRoute);
|
2016-05-16 17:03:11 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
if (this.shareService.isSharing()) {
|
2018-05-04 06:23:48 +08:00
|
|
|
this.$counter = interval(1000);
|
2018-03-31 03:30:30 +08:00
|
|
|
this.subscription.timer = this.$counter.subscribe((x) => this.updateTimer(x));
|
|
|
|
}
|
2016-05-16 17:03:11 +08:00
|
|
|
|
2018-03-31 03:30:30 +08:00
|
|
|
}
|
2016-05-01 00:01:54 +08:00
|
|
|
|
2017-06-22 03:32:57 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
onLightboxLastElement() {
|
|
|
|
this.grid.renderARow();
|
|
|
|
}
|
2016-07-04 22:58:10 +08:00
|
|
|
|
2016-04-26 21:10:05 +08:00
|
|
|
|
2016-03-13 18:28:29 +08:00
|
|
|
}
|
|
|
|
|