Files
iTunes/dashboard/src/app/song-table/song-table.component.ts
2017-10-19 00:31:51 +02:00

62 lines
1.4 KiB
TypeScript

import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { Song } from './../object/song';
import { SortByPipe } from './../sort-by.pipe';
@Component({
selector: 'app-song-table',
templateUrl: './song-table.component.html',
styleUrls: ['./song-table.component.css']
})
export class SongTableComponent implements OnChanges {
@Input() songs: Array<Song> = [];
@Input() sortable: boolean;
@Output() atBottom = new EventEmitter();
// To activate button in interface var
moreDataAvailable = false;
bottomReached = false;
nbSong = 0;
constructor() { }
ngOnChanges(changes: SimpleChanges) {
console.log(changes);
}
/**
* Handle scroll:
* - load data if at bottom of screen (if needed)
* - hide/show "go to top" button
*
* @param event scroll event
*/
onScroll(event: any) {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
this.atBottom.emit();
}
// Show/hide 'at top' button
if (window.scrollY > window.innerHeight) {
this.bottomReached = true;
}
if (window.scrollY === 0) {
this.bottomReached = false;
}
}
scrollTop(): void {
window.scrollTo(0, 0);
}
roundBitRate(bitRate: number) {
return Math.round(bitRate / 64);
}
sort(): void {
this.songs = new SortByPipe().transform(this.songs, 'Year', 'Album', 'Track Number', 'Play Count');
this.sortable = false;
}
}