Show last added albums

This commit is contained in:
2017-10-05 18:53:56 +02:00
parent 31fd9f27e9
commit 95f80b6b11
3 changed files with 55 additions and 2 deletions

View File

@@ -1,6 +1,4 @@
<div class="container">
<div class="error" *ngIf="errorMessage">{{errorMessage}}</div>
<h1>iTunes stats</h1>
<br />
@@ -79,6 +77,24 @@
</div>
</div>
<div class="col-md-12">
<h3>Last added albums</h3>
<table class="table table-striped">
<thead>
<tr>
<th>Album</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let album of lastAddedAlbums">
<td>{{album.key}}</td>
<td>{{album.doc_count}}</td>
</tr>
</tbody>
</table>
</div>
<h3>Top Played Songs</h3>
<table class="table table-striped">
<thead>

View File

@@ -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);
}

View File

@@ -276,6 +276,39 @@ export class ElsService {
.map(res => res.json().aggregations.genres.value);
}
getLastAddedAlbums(): Observable<Bucket[]> {
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<any>) => {
// TODO Refactor this duplicated code to a method
const result: Array<Bucket> = [];
hits.forEach((bucket) => {
result.push(bucket);
});
return result;
});
}
private handleError(error: any): Promise<any> {
console.error('An error occurred', error); // for demo purposes only
return Promise.reject(error.message || error);