From 264356e5a1647675d8a1f7799bb0b5b466651eb8 Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Thu, 4 May 2017 19:07:56 +0200 Subject: [PATCH] Load more song for album (+ fake size) Note how to have static var! --- dashboard/src/app/album.component.html | 6 +++++- dashboard/src/app/album.component.ts | 15 ++++++++++++--- dashboard/src/app/els.service.ts | 9 ++++++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/dashboard/src/app/album.component.html b/dashboard/src/app/album.component.html index cce3572..82fd308 100644 --- a/dashboard/src/app/album.component.html +++ b/dashboard/src/app/album.component.html @@ -35,4 +35,8 @@ {{song['Play Count']}} - \ No newline at end of file + + + \ No newline at end of file diff --git a/dashboard/src/app/album.component.ts b/dashboard/src/app/album.component.ts index 78fb679..6ea99ab 100644 --- a/dashboard/src/app/album.component.ts +++ b/dashboard/src/app/album.component.ts @@ -20,20 +20,29 @@ export class AlbumComponent implements OnInit { ) { } albumName = ""; - songs: Array = []; - album: Album = new Album(); // If album not found, will be replaced by 'undefined' + more: boolean = false; ngOnInit(): void { this.route.params .subscribe((params: Params) => this.albumName = params['name']); + this.loadMore() + this.elsService.getAlbum(this.albumName).subscribe(data => { this.album = data; console.log(this.album); }); - this.elsService.getAlbumSongs(this.albumName).subscribe(data => this.songs = data); + } + + loadMore(): void { + this.elsService.getAlbumSongs(this.albumName, this.songs.length).subscribe( + data => { + this.more = data.length == ElsService.DEFAULT_SIZE + this.songs = this.songs.concat(data); // TODO NOt contact, add! + } + ); } } \ No newline at end of file diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts index 34493b9..53a5ff7 100644 --- a/dashboard/src/app/els.service.ts +++ b/dashboard/src/app/els.service.ts @@ -13,6 +13,8 @@ export class ElsService { private elsUrl = 'http://localhost:9200/itunessongs/'; private headers = new Headers({'Content-Type': 'application/json'}); + public static readonly DEFAULT_SIZE:number = 5; + constructor(private http: Http) { } getTime(): Promise { @@ -83,10 +85,11 @@ export class ElsService { // }); } - getAlbumSongs(albumName: string): Observable { + getAlbumSongs(albumName: string, from: number = 0): Observable { + console.debug("Album name: " + albumName + " - from: " + from); return this.http .post(this.elsUrl + "song/_search", - JSON.stringify({"query":{"match_phrase":{"Album":albumName}},"size": 50}), // TODO Dynamic size + JSON.stringify({"query":{"match_phrase":{"Album":albumName}},"size": ElsService.DEFAULT_SIZE, "from": from}), // TODO Dynamic size {headers: this.headers}) .map(res => { return res.json().hits.hits; @@ -103,7 +106,7 @@ export class ElsService { getAlbum(albumName: string): Observable { return this.http .post(this.elsUrl + "album/_search", - JSON.stringify({"query":{"match_phrase":{"Album":albumName}},"size": 50}), // TODO Dynamic size + JSON.stringify({"query":{"match_phrase":{"Album":albumName}},"size": ElsService.DEFAULT_SIZE}), // TODO Dynamic size {headers: this.headers}) .map(res => { return res.json().hits.hits;