/** @file * @author Edouard DUPIN * @copyright 2018, Edouard DUPIN, all right reserved * @license PROPRIETARY (see license file) */ import { Component, OnInit } from '@angular/core'; import { Album, Track } from 'app/back-api'; import { ArtistService, DataService, ArianeService, AlbumService, PlayerService, TrackService } from 'app/service'; @Component({ selector: 'app-artist', templateUrl: './artist.html' }) export class ArtistScene implements OnInit { public idArtist = -1; public name: string = ''; public description: string = undefined; public covers: string[] = undefined; public albums: Album[] = undefined; public tracks: Track[] = undefined; public countSubElement: number = undefined; countTrack: (id: number) => Promise; constructor( private albumService: AlbumService, private artistService: ArtistService, private playerService: PlayerService, private trackService: TrackService, private arianeService: ArianeService, private dataService: DataService) { } countTrackCallback(albumId: number): Promise { return this.trackService.countTracksWithAlbumId(albumId); } ngOnInit() { this.countTrack = (id: number) => { return self.countTrackCallback(id); }; // this.idPlaylist = parseInt(this.route.snapshot.paramMap.get('universId')); // this.idType = parseInt(this.route.snapshot.paramMap.get('typeId')); this.idArtist = this.arianeService.getArtistId(); let self = this; this.artistService.get(this.idArtist) .then((response) => { self.name = response.name; self.description = response.description; self.covers = this.dataService.getListUrl(response.covers); }).catch((response) => { self.name = '???'; self.description = undefined; self.covers = undefined; }); //console.log(`get parameter id: ${ this.idArtist}`); this.trackService.getAlbumIdsOfAnArtist(this.idArtist) .then((albumIds: number[]) => { this.albumService.getAll(albumIds) .then((response: Album[]) => { //console.log(`>>>> get album : ${JSON.stringify(response)}`) self.albums = response; }).catch((response) => { self.albums = undefined; }); }).catch((response) => { self.albums = undefined; }); // TODO later: get all orfan tracks ... /* this.artistService.getTrack(this.idArtist) .then((response: NodeData[]) => { //console.log(`>>>> get track : ${JSON.stringify(response)}`) self.tracks = response; }).catch((response) => { self.tracks = undefined; }); */ } onSelectAlbum(event: any, idSelected: number): void { if (event.ctrlKey) { this.arianeService.navigateAlbumEdit({ id: idSelected, newWindows: event.which === 2 }); } else { this.arianeService.navigateArtist({ artistId: this.idArtist, albumId: idSelected, newWindows: event.which === 2 }); } } onSelectTrack(event: any, idSelected: number): void { if (event.ctrlKey === false) { this.arianeService.navigateTrack({ trackId: idSelected, newWindows: event.which === 2 }); } else { this.arianeService.navigateTrackEdit({ id: idSelected, newWindows: event.which === 2 }); } } getAllTracksIds(): Promise { let elements: number[] = []; for (let iii = 0; iii < this.albums.length; iii++) { elements.push(this.albums[iii].id); } return this.trackService.getTracksIdsForAlbums(elements); } playAll(): void { this.playerService.clear(); let self = this; this.getAllTracksIds() .then((response: number[]) => { self.playerService.setNewPlaylist(response); }) .catch(() => { console.log(`error to get list o ftrack ...`) }); } playShuffle(): void { this.playerService.clear(); let self = this; this.getAllTracksIds() .then((response: number[]) => { self.playerService.setNewPlaylistShuffle(response); }) .catch(() => { console.log(`error to get list o ftrack ...`) }); } }