You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

191 lines
5.2 KiB

import { Component, OnInit, ViewChild, ViewEncapsulation} from '@angular/core'
import { Router, NavigationEnd, NavigationStart, ActivatedRoute } from '@angular/router'
import { DomSanitizer } from '@angular/platform-browser'
import { Location } from '@angular/common'
// import { NgxImageGalleryComponent, GALLERY_IMAGE, GALLERY_CONF } from "ngx-image-gallery"
import { ApisService } from '../services/apis.service'
import { Title } from '@angular/platform-browser';
import { environment } from '../../environments/environment'
@Component({
selector: 'app-detail',
templateUrl: './detail.component.html',
styleUrls: ['./detail.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class DetailComponent implements OnInit {
public basePath = `${environment.BASE_PATH}`
public loaded = false
public init = false
//@ViewChild(NgxImageGalleryComponent) ngxImageGallery: NgxImageGalleryComponent
public details: any = {}
public section: string = ''
public id: number = 0
private history: string[] = []
/*
public conf: GALLERY_CONF = {
imageOffset: '0px',
showDeleteControl: false,
showImageTitle: false,
showArrows: false
}*/
public galleryImages: any[] = []
public loadedImages: boolean[] = []
constructor(
private apisService: ApisService,
private router: Router,
private location: Location,
private activeRoute: ActivatedRoute,
private sanitizer: DomSanitizer,
private titleService: Title
) { }
ngOnInit(): void {
this.section = this.router.url.split('/')[2]
this.id = parseInt(this.router.url.split('/')[3])
this.showDetails(this.section, this.id)
}
ngAfterContentInit() {
this.init = true
}
showDetails(section, id): void {
this.galleryImages = []
this.apisService.getDetails(section, id).toPromise().then((response) => {
this.details = response.item
if(this.history[this.history.length - 1] != `/detail/${section}/${id}/${this.parseTitle(this.details.title)}`) {
this.history.push(`/detail/${section}/${id}/${this.parseTitle(this.details.title)}`)
}
this.details.videos = this.details.videos ? JSON.parse(this.details.videos) : []
this.details.videos.forEach((e) => {
e.code = e.url.split('/').pop()
switch(e.type) {
case 'youtube':
e.embed = this.sanitizer.bypassSecurityTrustResourceUrl(`https://www.youtube.com/embed/${e.code}`)
break
case 'vimeo':
e.embed = this.sanitizer.bypassSecurityTrustResourceUrl(`https://player.vimeo.com/video/${e.code}`)
break
case 'embed':
e.embed = this.sanitizer.bypassSecurityTrustHtml(e.url)
break
}
})
this.details.gallery = this.details.gallery ? JSON.parse(this.details.gallery) : []
this.details.gallery.forEach((e) => {
if(!e.main) {
this.galleryImages.push({
url: `${this.basePath}${e.url}`,
altText: e.title,
title: e.title,
thumbnailUrl: `${this.basePath}${e.url}`
})
this.loadedImages.push(true)
}
})
this.loaded = !this.loadedImages.length
this.titleService.setTitle(`Dslak | New-media arts | ${this.details.title}`)
},(error) => {
console.error('getPortfolio ERROR', error)
}).catch((e) => {
console.error('getPortfolio CATCH', e)
})
}
back(): void {
this.history.pop()
let title = ''
if(this.history.length > 0) {
const last = this.history[this.history.length - 1]
this.section = last.split('/')[2]
this.id = parseInt(last.split('/')[3])
this.showDetails(this.section, this.id)
this.location.back()
} else {
this.location.back()
title = this.router.url.split('/')[2]
this.titleService.setTitle(`Dslak | New media arts | ${title.charAt(0).toUpperCase() + title.slice(1)}`)
}
}
onLoad(index): void {
this.loadedImages[index] = false
this.loaded = this.init && this.loadedImages.every( (val) => !val)
}
parseTitle(title): string {
return title.toLowerCase().replace(/[^a-zA-Z0-9]/g, '-').replace('--', '-').replace('--', '-')
}
/*
openGallery(index: number = 0) {
//this.ngxImageGallery.open(index)
}
// close gallery
closeGallery() {
//this.ngxImageGallery.close()
}
// set new active(visible) image in gallery
newImage(index: number = 0) {
this.ngxImageGallery.setActiveImage(index)
}
// next image in gallery
nextImage(index: number = 0) {
this.ngxImageGallery.next()
}
// prev image in gallery
prevImage(index: number = 0) {
this.ngxImageGallery.prev()
}
// EVENTS
// callback on gallery opened
galleryOpened(index) {
console.info('Gallery opened at index ', index)
}
// callback on gallery closed
galleryClosed() {
console.info('Gallery closed.')
}
// callback on gallery image clicked
galleryImageClicked(index) {
console.info('Gallery image clicked with index ', index)
}
// callback on gallery image changed
galleryImageChanged(index) {
console.info('Gallery image changed to index ', index)
}
// callback on user clicked delete button
deleteImage(index) {
console.info('Delete image at index ', index)
}*/
}