Files
iTunes/dashboard/src/app/genre/genre.component.ts
Maxence G. de Montauzan 6300e9cfc7 Refactoring
Move Top Played part.
Move pipes and dashboard
Rename object folder to model
Doc pipes
2018-03-20 23:32:21 +01:00

51 lines
1.4 KiB
TypeScript

import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { ElsService } from '../els.service';
import { SongTableComponent } from '../song-table/song-table.component';
import { Song } from '../model/song';
@Component({
selector: 'app-genre',
templateUrl: './genre.component.html',
styleUrls: ['./genre.component.css']
})
export class GenreComponent implements OnInit {
@ViewChild(SongTableComponent) songtable: SongTableComponent;
genreName = '';
songs: Array<Song> = [];
constructor(
private elsService: ElsService,
private route: ActivatedRoute
) { }
ngOnInit() {
this.route.params
.subscribe((params: Params) => this.genreName = params['name']);
this.loadSongs();
}
loadSongs(): any {
this.elsService.getGenreSongs(this.genreName, this.songs.length).subscribe(
data => {
// this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;
// Erase song array with result for first load, then add elements one by one
// instead use concat => concat will sort table at each load, very consuming! and not user friendly
if (this.songs.length === 0) {
this.songs = data;
} else {
data.forEach(song => {
this.songtable.setSortable(true);
this.songs.push(song);
});
}
}
);
}
}