69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import {Component, OnInit} from '@angular/core';
|
|
|
|
import {Album} from "../shared/album.model";
|
|
import {ActivatedRoute} from "@angular/router";
|
|
import {Title} from "@angular/platform-browser";
|
|
import {DisplayImageService} from "../display-image/display-image.service";
|
|
|
|
@Component({
|
|
selector: 'app-album',
|
|
templateUrl: './album.component.html',
|
|
styleUrls: ['./album.component.css']
|
|
})
|
|
export class AlbumComponent implements OnInit {
|
|
|
|
public album: Album = new Album();
|
|
|
|
constructor(private titleService: Title,
|
|
private route: ActivatedRoute,
|
|
private displayImageService: DisplayImageService) {}
|
|
|
|
ngOnInit() {
|
|
this.titleService.setTitle('Album');
|
|
this.route.data.subscribe((data: { albums: Array<Album>}) => {
|
|
this.album = data.albums.find(album => album.slug == this.route.snapshot.params.slug);
|
|
if(this.route.snapshot.params.image) {
|
|
this.imageClick(
|
|
this.route.snapshot.params.slug,
|
|
this.route.snapshot.params.image
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
public imageClick(slug: string, path: string) {
|
|
this.displayImageService.activate(slug, path);
|
|
}
|
|
|
|
public switchImage(evnt:{direction: string, currentPath: string}) {
|
|
switch (evnt.direction) {
|
|
case 'next':
|
|
this.nextImage(evnt.currentPath);
|
|
break;
|
|
case 'prev':
|
|
this.prevImage(evnt.currentPath);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private nextImage(path: string) {
|
|
let currentIndex: number = this.album.images.findIndex(image => image.path == path);
|
|
if(this.album.images.length-1 > currentIndex) {
|
|
this.displayImageService.activate(
|
|
this.album.slug,
|
|
this.album.images[currentIndex+1].path
|
|
)
|
|
}
|
|
}
|
|
|
|
private prevImage(path: string) {
|
|
let currentIndex: number = this.album.images.findIndex(image => image.path == path);
|
|
if(0 < currentIndex) {
|
|
this.displayImageService.activate(
|
|
this.album.slug,
|
|
this.album.images[currentIndex-1].path
|
|
)
|
|
}
|
|
}
|
|
}
|