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.

69 lines
2.1 KiB

5 years ago
import { Component, OnInit } from '@angular/core'
import { Router, NavigationEnd, NavigationStart, ActivatedRoute } from '@angular/router'
5 years ago
import { DomSanitizer } from '@angular/platform-browser'
5 years ago
import { Location } from '@angular/common'
import { ApisService } from '../services/apis.service'
@Component({
selector: 'app-detail',
templateUrl: './detail.component.html',
styleUrls: ['./detail.component.scss']
})
export class DetailComponent implements OnInit {
public details: any = {}
public section: string = ''
public id: number = 0
private history: string[] = []
5 years ago
constructor(
private apisService: ApisService,
private router: Router,
private location: Location,
5 years ago
private activeRoute: ActivatedRoute,
private sanitizer: DomSanitizer
) { }
5 years ago
ngOnInit(): void {
this.section = this.router.url.split('/')[2]
this.id = parseInt(this.router.url.split('/')[3])
this.showDetails(this.section, this.id)
5 years ago
}
showDetails(section, id): void {
this.apisService.getDetails(section, id).toPromise().then((response) => {
if(this.history[this.history.length - 1] != `/detail/${section}/${id}`) {
this.history.push(`/detail/${section}/${id}`)
}
5 years ago
const detail = response.item
detail.videos = detail.videos ? JSON.parse(detail.videos) : []
detail.videos.forEach((e) => {
e.code = e.url.split('/').pop()
e.embed = this.sanitizer.bypassSecurityTrustResourceUrl(`https://www.youtube.com/embed/${e.code}`)
})
5 years ago
detail.gallery = detail.gallery ? JSON.parse(detail.gallery) : []
5 years ago
this.details = detail
console.log(response.item)
5 years ago
},(error) => {
console.error('getPortfolio ERROR', error)
}).catch((e) => {
console.error('getPortfolio CATCH', e)
})
}
back(): void {
this.history.pop()
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()
}
5 years ago
}
}