From 7a1a1c7c17a16da51132af815ce0b8ee69cf510c Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Tue, 17 Oct 2017 01:54:22 +0200 Subject: [PATCH] Last added: Refactor identification of good album --- dashboard/src/app/dashboard.component.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/dashboard/src/app/dashboard.component.ts b/dashboard/src/app/dashboard.component.ts index dc2917e..05fc194 100644 --- a/dashboard/src/app/dashboard.component.ts +++ b/dashboard/src/app/dashboard.component.ts @@ -71,20 +71,25 @@ export class DashboardComponent implements OnInit { // For each bucket.key (album name), search artist. // 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 artist by track count + // More than one result for an album name: search good by track count albums.forEach(album => { if (album['Track Count'] === albumBucket.doc_count) { - this.albumArtists[album.Name] = album['Album Artist'] ? album['Album Artist'].toString() : album.Artist.toString(); + goodAlbum = album; } }); } else { - // Just one artistresult for album name - this.albumArtists[albums[0].Name] = albums[0]['Album Artist'] ? albums[0]['Album Artist'].toString() : albums[0].Artist.toString(); + // Just one result for album name + goodAlbum = albums[0]; } - if (this.albumArtists[albums[0].Name].length > 50) { - this.albumArtists[albums[0].Name] = this.albumArtists[albums[0].Name].substring(0, 50) + '...'; + + this.albumArtists[goodAlbum.Name] = goodAlbum['Album Artist'] ? goodAlbum['Album Artist'].toString() : goodAlbum.Artist.toString(); + + // If an album with multiple artist doesn't have 'Album Artist' field - this case should not happen + if (this.albumArtists[goodAlbum.Name].length > 50) { + this.albumArtists[goodAlbum.Name] = this.albumArtists[goodAlbum.Name].substring(0, 50) + '...'; } }); }