diff --git a/dashboard/src/app/album.component.ts b/dashboard/src/app/album.component.ts index 82ae3e4..3e91ded 100644 --- a/dashboard/src/app/album.component.ts +++ b/dashboard/src/app/album.component.ts @@ -31,11 +31,7 @@ export class AlbumComponent implements OnInit { this.loadSongs() - this.elsService.getAlbum(this.albumName).subscribe(data => { - this.album = data; - console.log(this.album); - }); - + this.elsService.getAlbum(this.albumName).subscribe(data => this.album = data); } loadSongs(): void { diff --git a/dashboard/src/app/artist.component.html b/dashboard/src/app/artist.component.html index ee5b8ed..4c20545 100644 --- a/dashboard/src/app/artist.component.html +++ b/dashboard/src/app/artist.component.html @@ -15,10 +15,10 @@
-

-

{{albumNames.length}}

+

+

{{artist.Album?.length}}

-

Total time
+

albums
diff --git a/dashboard/src/app/artist.component.ts b/dashboard/src/app/artist.component.ts index 205fee6..b6bc120 100644 --- a/dashboard/src/app/artist.component.ts +++ b/dashboard/src/app/artist.component.ts @@ -4,6 +4,7 @@ import { Location } from '@angular/common' import { ElsService } from './els.service' import { Song } from './object/song'; +import { Artist } from './object/artist'; @Component({ selector: 'artist-component', @@ -20,10 +21,10 @@ export class ArtistComponent implements OnInit { artistName = ""; songs: Array = []; - + artist: Artist = new Artist(); moreDataAvailable: boolean = false; atBottom: boolean = false; - albumNames: string[]; + lockLoadData: boolean = true; ngOnInit(): void { this.route.params @@ -31,14 +32,13 @@ export class ArtistComponent implements OnInit { this.loadSongs(); - this.elsService.getArtistAlbums(this.artistName).subscribe(data => this.albumNames = data ); + this.elsService.getArtist(this.artistName).subscribe(data => this.artist = data); } // TODO Duplicate code! loadSongs(): void { this.elsService.getArtistSongs(this.artistName, this.songs.length).subscribe( data => { - console.log(this.moreDataAvailable); this.moreDataAvailable = data.length == ElsService.DEFAULT_SIZE; // Erase song array with result for first load, then add elements one by one @@ -50,6 +50,7 @@ export class ArtistComponent implements OnInit { this.songs.push(song); }); } + this.lockLoadData = false; } ); } @@ -66,8 +67,9 @@ export class ArtistComponent implements OnInit { * @param event scroll event */ onScroll(event: any) { - if (this.moreDataAvailable && + if (this.moreDataAvailable && !this.lockLoadData && (window.innerHeight + window.scrollY) >= document.body.offsetHeight) { + this.lockLoadData = true; this.loadSongs(); } diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts index e5b529d..1886bb6 100644 --- a/dashboard/src/app/els.service.ts +++ b/dashboard/src/app/els.service.ts @@ -7,6 +7,7 @@ import 'rxjs/add/operator/map'; import { Song } from './object/song'; import { Album } from './object/album'; +import { Artist } from './object/artist'; @Injectable() export class ElsService { @@ -118,17 +119,17 @@ export class ElsService { return this.http .post(this.elsUrl + "song/_search", JSON.stringify({ - "query": { - "bool": { - "should": [ - {"match_phrase" : { "Album Artist" : artistName }}, - {"match_phrase" : { "Artist" : artistName }} - ] - } - }, - "size": ElsService.DEFAULT_SIZE, - "from": from -}), + "query": { + "bool": { + "should": [ + {"match_phrase" : { "Album Artist" : artistName }}, + {"match_phrase" : { "Artist" : artistName }} + ] + } + }, + "size": ElsService.DEFAULT_SIZE, + "from": from + }), {headers: this.headers}) .map(res => { return res.json().hits.hits; @@ -162,10 +163,10 @@ export class ElsService { }); } - getArtistAlbums(artistName: string): Observable { + getArtist(artistName: string): Observable { return this.http .post(this.elsUrl + "artist/_search", - JSON.stringify({"fields": "Album","query":{"match_phrase":{"Artist":artistName}},"size": ElsService.DEFAULT_SIZE}), + JSON.stringify({"query":{"match_phrase":{"Artist":artistName}},"size": ElsService.DEFAULT_SIZE}), {headers: this.headers}) .map(res => res.json().hits.hits) .map((hits: Array) => { @@ -179,7 +180,7 @@ export class ElsService { console.error('More than one artist "' + artistName + '" found, return the first.'); console.error('This is not normal!') } - return hits[0].fields.Album; + return hits[0]._source; }); } diff --git a/dashboard/src/app/object/artist.ts b/dashboard/src/app/object/artist.ts new file mode 100644 index 0000000..35a5417 --- /dev/null +++ b/dashboard/src/app/object/artist.ts @@ -0,0 +1,10 @@ +export class Artist { + Name: string; + Album: string[]; + Artist: string; + Rating: number; + Genre: Array; + "Track Count": number; + "Persistent ID": string; + "Play Count": number; +} \ No newline at end of file