Improve artist page + ELS service var
This commit is contained in:
@@ -89,18 +89,20 @@
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Name</th>
|
||||
<th>Artist</th>
|
||||
<th>Album</th>
|
||||
<th>Year</th>
|
||||
<th>Artist</th>
|
||||
<th>Album Artist</th>
|
||||
<th>Play Count</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let song of songs | sortBy : 'Album':'Track Number'">
|
||||
<tr *ngFor="let song of songs | sortBy : 'Year':'Album':'Track Number'">
|
||||
<td>{{song['Track Number'] ? (("0" + song['Track Number']).slice(-2)) : "--"}}</td>
|
||||
<td>{{song.Name}}</td>
|
||||
<td><a [routerLink]="['/artist', song.Artist]">{{song.Artist}}</a></td>
|
||||
<td><a [routerLink]="['/album', song.Album]">{{song.Album}}</a></td>
|
||||
<td>{{song.Year}}</td>
|
||||
<td><a [routerLink]="['/artist', song.Artist]">{{song.Artist}}</a></td>
|
||||
<td>{{song['Album Artist'] ? song['Album Artist'] : "-" }}</td>
|
||||
<td>{{song['Play Count']}}</td>
|
||||
</tr>
|
||||
@@ -120,4 +122,4 @@
|
||||
aria-label="Top" (click)="sort()" title="Sort by Album & Track Number">
|
||||
<span class="glyphicon glyphicon-sort-by-attributes" aria-hidden="true"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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<number> {
|
||||
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<number> {
|
||||
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<number> {
|
||||
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<number> {
|
||||
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<Song[]> {
|
||||
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<Song[]> {
|
||||
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<Album> {
|
||||
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<Artist> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user