diff --git a/dashboard/src/app/artist.component.html b/dashboard/src/app/artist.component.html index 138fa22..aee6378 100644 --- a/dashboard/src/app/artist.component.html +++ b/dashboard/src/app/artist.component.html @@ -89,18 +89,20 @@ Name - Artist Album + Year + Artist Album Artist Play Count - + {{song['Track Number'] ? (("0" + song['Track Number']).slice(-2)) : "--"}} {{song.Name}} - {{song.Artist}} {{song.Album}} + {{song.Year}} + {{song.Artist}} {{song['Album Artist'] ? song['Album Artist'] : "-" }} {{song['Play Count']}} @@ -120,4 +122,4 @@ aria-label="Top" (click)="sort()" title="Sort by Album & Track Number"> - \ No newline at end of file + diff --git a/dashboard/src/app/artist.component.ts b/dashboard/src/app/artist.component.ts index e88e969..8db8628 100644 --- a/dashboard/src/app/artist.component.ts +++ b/dashboard/src/app/artist.component.ts @@ -32,12 +32,10 @@ export class ArtistComponent implements OnInit { lockLoadData: boolean = false; ngOnInit(): void { - this.route.params - .subscribe((params: Params) => this.artistName = params['name']); - - this.loadSongs(); + this.route.params.subscribe((params: Params) => this.artistName = params['name']); this.elsService.getArtist(this.artistName).subscribe(data => this.artist = data); + this.loadSongs(); } // TODO Duplicate code! @@ -95,7 +93,7 @@ export class ArtistComponent implements OnInit { } sort(): void { - this.songs = new SortPipe().transform(this.songs, 'Album', 'Track Number', 'Play Count'); + this.songs = new SortPipe().transform(this.songs, 'Year', 'Album', 'Track Number', 'Play Count'); this.sortable = false; } -} \ No newline at end of file +} diff --git a/dashboard/src/app/dashboard.component.ts b/dashboard/src/app/dashboard.component.ts index fe256e3..b78a3a6 100644 --- a/dashboard/src/app/dashboard.component.ts +++ b/dashboard/src/app/dashboard.component.ts @@ -67,7 +67,7 @@ export class DashboardComponent implements OnInit { x /= 24 let days = Math.round(x); - return days + "d" + hours + ":" + minutes + "." + seconds; + return days + ":" + hours + ":" + minutes + "." + seconds; // return days + " days, " + hours + " hours, " + minutes + " minutes and " + seconds + " seconds"; } diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts index c0ec601..dd6da39 100644 --- a/dashboard/src/app/els.service.ts +++ b/dashboard/src/app/els.service.ts @@ -11,15 +11,19 @@ import { Artist } from './object/artist'; @Injectable() export class ElsService { - private elsUrl = 'http://localhost:9200/itunessongs/'; - private headers = new Headers({'Content-Type': 'application/json'}); - public static readonly DEFAULT_SIZE:number = 50; + private static readonly INDEX_NAME = "itunessongs"; + + private static readonly ACTION_SEARCH = "/_search"; + private static readonly ACTION_COUNT = "/_count"; + + private elsUrl = 'http://localhost:9200/' + ElsService.INDEX_NAME + "/"; + private headers = new Headers({'Content-Type': 'application/json'}); constructor(private http: Http) { } getTime(): Promise { - return this.http.post(this.elsUrl + "_search", JSON.stringify({aggs:{sum_time:{sum:{field:"Total Time"}}},"size":0}), {headers: this.headers}) + return this.http.post(this.elsUrl + ElsService.ACTION_SEARCH, JSON.stringify({aggs:{sum_time:{sum:{field:"Total Time"}}},"size":0}), {headers: this.headers}) .toPromise() .then(res => res.json().aggregations.sum_time.value as number) .catch(this.handleError); @@ -32,7 +36,7 @@ export class ElsService { } getSize(): Promise { - return this.http.post(this.elsUrl + "_search", JSON.stringify({aggs:{sum_time:{sum:{field:"Size"}}},"size":0}), {headers: this.headers}) + return this.http.post(this.elsUrl + ElsService.ACTION_SEARCH, JSON.stringify({aggs:{sum_time:{sum:{field:"Size"}}},"size":0}), {headers: this.headers}) .toPromise() .then(res => res.json().aggregations.sum_time.value as number) .catch(this.handleError); @@ -45,7 +49,7 @@ export class ElsService { } getCountSong(type: string): Promise { - return this.http.get(this.elsUrl + type + "/_count") + return this.http.get(this.elsUrl + type + ElsService.ACTION_COUNT) .toPromise() .then(res => res.json().count as number) .catch(this.handleError); @@ -53,7 +57,7 @@ export class ElsService { getCountNeverListenSong(): Promise { return this.http - .post(this.elsUrl + "song/_count", + .post(this.elsUrl + "song" + ElsService.ACTION_COUNT, JSON.stringify({"query":{"bool":{"must_not": {"exists": {"field": "Play Count"}}}}}), {headers: this.headers}) .toPromise() @@ -73,8 +77,15 @@ export class ElsService { // Could be shorter but I think it's more readable like this. return this.http - .post(this.elsUrl + "song/_search", - JSON.stringify({"sort":[{"Play Count":{"order":"desc"}}],"size": 5}), + .post(this.elsUrl + "song" + ElsService.ACTION_SEARCH, + JSON.stringify( + { + "sort": [ { + "Play Count": { + "order": "desc" + } } ], + "size": 10 + }), {headers: this.headers}) .map(res => { return res.json().hits.hits; @@ -99,7 +110,7 @@ export class ElsService { getAlbumSongs(albumName: string, from: number = 0): Observable { console.debug("getAlbumSongs- Album name: " + albumName + " - from: " + from); return this.http - .post(this.elsUrl + "song/_search", + .post(this.elsUrl + "song" + ElsService.ACTION_SEARCH, JSON.stringify({"query":{"match_phrase":{"Album":albumName}},"size": ElsService.DEFAULT_SIZE, "from": from}), {headers: this.headers}) .map(res => { @@ -117,7 +128,7 @@ export class ElsService { getArtistSongs(artistName: string, from: number = 0): Observable { console.debug("getArtistSongs- Artist name: " + artistName + " - from: " + from); return this.http - .post(this.elsUrl + "song/_search", + .post(this.elsUrl + "song" + ElsService.ACTION_SEARCH, JSON.stringify( { "query": { @@ -146,7 +157,7 @@ export class ElsService { getAlbum(albumName: string): Observable { return this.http - .post(this.elsUrl + "album/_search", + .post(this.elsUrl + "album" + ElsService.ACTION_SEARCH, JSON.stringify({"query":{"match_phrase":{"Album":albumName}},"size": ElsService.DEFAULT_SIZE}), {headers: this.headers}) .map(res => { @@ -166,7 +177,7 @@ export class ElsService { getArtist(artistName: string): Observable { return this.http - .post(this.elsUrl + "artist/_search", + .post(this.elsUrl + "artist" + ElsService.ACTION_SEARCH, JSON.stringify({"query":{"match_phrase":{"Artist":artistName}},"size": ElsService.DEFAULT_SIZE}), {headers: this.headers}) .map(res => res.json().hits.hits) @@ -189,4 +200,4 @@ export class ElsService { console.error('An error occurred', error); // for demo purposes only return Promise.reject(error.message || error); } -} \ No newline at end of file +}