diff --git a/dashboard/src/app/els-sort.service.ts b/dashboard/src/app/els-sort.service.ts index ef432c2..8a421cd 100644 --- a/dashboard/src/app/els-sort.service.ts +++ b/dashboard/src/app/els-sort.service.ts @@ -115,7 +115,7 @@ export class ElsSortService extends ElsService { getNbAlbums(): Promise { return this.http - .post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH, + .post(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH, JSON.stringify({ 'query': { 'bool': { @@ -142,9 +142,9 @@ export class ElsSortService extends ElsService { .catch(error => this.handleError(error, 'getNbAlbums()')); } - getAlbums(): Observable { + getAlbums(): Observable { return this.http - .post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH, + .post(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH, JSON.stringify({ query: { bool: { @@ -157,19 +157,13 @@ export class ElsSortService extends ElsService { ] } }, - 'size': 0, - 'aggs': { - 'albums' : { - 'terms': { - 'field' : 'Album.raw', - 'order': { '_key': 'asc' }, - 'size': 50 - } - } - } + 'size': 550, + "sort": [ + { "Play Count": "desc"} + ] }), {headers: this.headers}) .pipe( - map(res => this.responseAggregationToBucket(res, "albums")), + map(res => this.responseToAlbums(res)), catchError(error => this.handleError(error, 'getAlbums')) ); } diff --git a/dashboard/src/app/to-sort/to-sort.component.html b/dashboard/src/app/to-sort/to-sort.component.html index 67c028e..2c3ebf0 100644 --- a/dashboard/src/app/to-sort/to-sort.component.html +++ b/dashboard/src/app/to-sort/to-sort.component.html @@ -91,22 +91,22 @@ - + - {{album.key}}  + {{album.Name}}  - {{albums[album.key]['Track Count']}} + {{album['Track Count']}} - + - {{albums[album.key]['Album Artist']}}  + {{album['Album Artist']}}  - {{albums[album.key].Artist}}  + {{album.Artist}}  @@ -117,12 +117,12 @@ - {{albums[album.key]['Play Count']}} ({{albums[album.key]['Play Count']/albums[album.key]['Track Count'] | number:'1.0-0'}}/songs) + {{album['Play Count']}} ({{album['Play Count']/album['Track Count'] | number:'1.0-0'}}/songs) - - - + + + diff --git a/dashboard/src/app/to-sort/to-sort.component.ts b/dashboard/src/app/to-sort/to-sort.component.ts index d139a6f..eccdd02 100644 --- a/dashboard/src/app/to-sort/to-sort.component.ts +++ b/dashboard/src/app/to-sort/to-sort.component.ts @@ -1,8 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { ElsSortService } from '../els-sort.service'; -import { Album } from '../model/album'; import { Bucket } from '../model/bucket'; -import { Song } from '../model/song'; import { Utils } from '../utils'; @@ -34,58 +32,7 @@ export class ToSortComponent implements OnInit { this.elsService.getCountNeverListenSong().then(result => this.neverListenSong = result); this.elsService.getNbAlbums().then(result => this.nbAlbums = result); - // **** GET ALBUMS ****// - const tmpToSortAlbums: Bucket[] = []; - this.elsService.getAlbums().subscribe(buckets => { - buckets.forEach(bucket => { - if (tmpToSortAlbums.length === 0) { - tmpToSortAlbums.push(bucket); - } else { - let found = false; - tmpToSortAlbums.forEach(element => { - if (element.key === bucket.key) { - element.doc_count += bucket.doc_count; - found = true; - } - }); - if (!found) { - tmpToSortAlbums.push(bucket); - } - } - }); - - this.toSortAlbum = tmpToSortAlbums; - this.toSortAlbum.forEach(bucket => this.getAlbum(bucket)); - // console.log(this.toSortAlbum) - // console.log(this.albums) - }); - } - - private getAlbum(albumBucket: Bucket) { - // For each bucket.key (album name), get Album document - // Use track count to compare - this.elsService.getArtistFromAlbumName(albumBucket.key).subscribe(albums => { - // Identification of the good album - let goodAlbum; - if (albums.length > 1) { - // More than one result for an album name: search good by track count - albums.forEach(album => { - if (album['Track Count'] === albumBucket.doc_count) { - goodAlbum = album; - } - }); - } else { - // Just one result for album name - goodAlbum = albums[0]; - } - - // TODO Crap security if no good album found - if (goodAlbum == undefined) { - goodAlbum = albums[0] - } - - this.albums[albumBucket.key] = goodAlbum; - }); + this.elsService.getAlbums().subscribe(data => this.albums = data) } }