From 95f80b6b11a7ba310677e1e6c9cec3180069d2ed Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Thu, 5 Oct 2017 18:53:56 +0200 Subject: [PATCH] Show last added albums --- dashboard/src/app/dashboard.component.html | 20 +++++++++++-- dashboard/src/app/dashboard.component.ts | 4 +++ dashboard/src/app/els.service.ts | 33 ++++++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/dashboard/src/app/dashboard.component.html b/dashboard/src/app/dashboard.component.html index 40c7773..223e680 100644 --- a/dashboard/src/app/dashboard.component.html +++ b/dashboard/src/app/dashboard.component.html @@ -1,6 +1,4 @@
-
{{errorMessage}}
-

iTunes stats


@@ -79,6 +77,24 @@
+
+

Last added albums

+ + + + + + + + + + + + + +
Album
{{album.key}}{{album.doc_count}}
+
+

Top Played Songs

diff --git a/dashboard/src/app/dashboard.component.ts b/dashboard/src/app/dashboard.component.ts index 86a22b5..7561f63 100644 --- a/dashboard/src/app/dashboard.component.ts +++ b/dashboard/src/app/dashboard.component.ts @@ -24,6 +24,8 @@ export class DashboardComponent implements OnInit { mostPlayedSongs: Song[] = []; + lastAddedAlbums: Bucket[] = []; + constructor(private elsService: ElsService) { } ngOnInit(): void { @@ -53,6 +55,8 @@ export class DashboardComponent implements OnInit { this.elsService.getGenres().subscribe(data => this.topGenres = data); this.elsService.getGenres('asc').subscribe(data => this.bottomGenres = data); this.elsService.getGenreCount().subscribe(data => console.log(data)); + + this.elsService.getLastAddedAlbums().subscribe(data => this.lastAddedAlbums = data); } diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts index bb1da7f..f8a1473 100644 --- a/dashboard/src/app/els.service.ts +++ b/dashboard/src/app/els.service.ts @@ -276,6 +276,39 @@ export class ElsService { .map(res => res.json().aggregations.genres.value); } + getLastAddedAlbums(): Observable { + return this.http + .post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH, + JSON.stringify({ + 'query': { + 'range' : { + 'Date Added' : { + 'gte' : 'now-6M/d', + 'lte' : 'now/d' + } + } + }, + 'aggs' : { + 'album' : { + 'terms' : { + 'field' : 'Album.original', + 'size': 5 + } + } + }, + 'size': 0 + }), {headers: this.headers}) + .map(res => res.json().aggregations.album.buckets) + .map((hits: Array) => { + // TODO Refactor this duplicated code to a method + const result: Array = []; + hits.forEach((bucket) => { + result.push(bucket); + }); + return result; + }); + } + private handleError(error: any): Promise { console.error('An error occurred', error); // for demo purposes only return Promise.reject(error.message || error);