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.
67 lines
2.0 KiB
67 lines
2.0 KiB
import { Component, OnInit } from '@angular/core'
|
|
import { Router, NavigationEnd, NavigationStart, ActivatedRoute } from '@angular/router'
|
|
import { DomSanitizer } from '@angular/platform-browser'
|
|
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[] = []
|
|
|
|
constructor(
|
|
private apisService: ApisService,
|
|
private router: Router,
|
|
private location: Location,
|
|
private activeRoute: ActivatedRoute,
|
|
private sanitizer: DomSanitizer
|
|
) { }
|
|
|
|
ngOnInit(): void {
|
|
this.section = this.router.url.split('/')[2]
|
|
this.id = parseInt(this.router.url.split('/')[3])
|
|
this.showDetails(this.section, this.id)
|
|
}
|
|
|
|
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}`)
|
|
}
|
|
|
|
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}`)
|
|
})
|
|
this.details = detail
|
|
console.log(response.item)
|
|
|
|
},(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()
|
|
}
|
|
}
|
|
}
|