(front) Use a 'tosort' filter
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
<div class="container">
|
||||
<h1>{{albumName}}</h1>
|
||||
|
||||
<div *ngIf="toSort" class="alert alert-danger">
|
||||
To sort filter applyed. Songs are filter on location.
|
||||
</div>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
<h3>Debug Zone</h3>
|
||||
Returned song: {{songs.length}}<br />
|
||||
@@ -20,7 +24,7 @@
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!album"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="album">{{album.Rating}}/100</h3>
|
||||
<h3 *ngIf="album">{{album['Album Rating']}}/100</h3>
|
||||
</div>
|
||||
<div><br>Rating</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
import { Location } from '@angular/common';
|
||||
|
||||
import { ElsService } from './../els.service';
|
||||
import { Song } from './../model/song';
|
||||
@@ -19,6 +18,7 @@ export class AlbumComponent implements OnInit {
|
||||
albumName = '';
|
||||
songs: Array<Song> = [];
|
||||
album: Album = new Album(); // If album not found, will be replaced by 'undefined'
|
||||
toSort: boolean = false; // Show only song to sort
|
||||
|
||||
// Prevent useless data load + activate button in interface var
|
||||
moreDataAvailable = true;
|
||||
@@ -26,13 +26,12 @@ export class AlbumComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private elsService: ElsService,
|
||||
private route: ActivatedRoute,
|
||||
private location: Location
|
||||
private route: ActivatedRoute
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.params
|
||||
.subscribe((params: Params) => this.albumName = params['name']);
|
||||
this.route.params.subscribe((params: Params) => this.albumName = params['name']);
|
||||
this.route.queryParams.subscribe(params => { this.toSort = params.tosort ?? false; });
|
||||
|
||||
this.loadSongs();
|
||||
|
||||
@@ -50,7 +49,7 @@ export class AlbumComponent implements OnInit {
|
||||
}
|
||||
|
||||
this.lockLoadData = true;
|
||||
this.elsService.getAlbumSongs(this.albumName, this.songs.length).subscribe(
|
||||
this.elsService.getAlbumSongs(this.albumName, this.songs.length, this.toSort).subscribe(
|
||||
data => {
|
||||
this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ export class ElsService {
|
||||
|
||||
protected elsUrl = 'http://localhost:9200';
|
||||
protected headers = new HttpHeaders({'Content-Type': 'application/json'});
|
||||
protected defaultLocation = "/F:/Musique" // TODO Use conf
|
||||
|
||||
constructor(protected http: HttpClient) { }
|
||||
|
||||
@@ -172,20 +173,52 @@ export class ElsService {
|
||||
);
|
||||
}
|
||||
|
||||
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> {
|
||||
console.info('getAlbumSongs- Album name: ' + albumName + ' - from: ' + from);
|
||||
return this.http
|
||||
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'match_phrase': { 'Album': albumName }
|
||||
getAlbumSongs(albumName: string, from: number = 0, toSortFilter = false): Observable<Song[]> {
|
||||
// TODO Move in els-album service
|
||||
console.info(
|
||||
"getAlbumSongs- Album name: " + albumName + " - from: " + from
|
||||
);
|
||||
|
||||
let query = {
|
||||
query: {
|
||||
bool: {
|
||||
must: [
|
||||
{
|
||||
match_phrase: {
|
||||
"Album.raw": albumName,
|
||||
},
|
||||
'size': ElsService.DEFAULT_SIZE,
|
||||
'from': from
|
||||
}), {headers: this.headers})
|
||||
},
|
||||
],
|
||||
must_not: [],
|
||||
},
|
||||
},
|
||||
size: ElsService.DEFAULT_SIZE,
|
||||
from: from,
|
||||
};
|
||||
|
||||
if (toSortFilter) {
|
||||
console.log("getAlbumSongs- TO SORT filter enabled");
|
||||
query.query.bool.must_not.push({
|
||||
term: {
|
||||
"Location.tree": this.defaultLocation,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return this.http
|
||||
.post(
|
||||
this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify(query),
|
||||
{ headers: this.headers }
|
||||
)
|
||||
.pipe(
|
||||
map(res => this.responseToSongs(res)),
|
||||
catchError(error => this.handleError(error, 'getAlbumSongs(' + albumName + ',' + from + ')'))
|
||||
map((res) => this.responseToSongs(res)),
|
||||
catchError((error) =>
|
||||
this.handleError(
|
||||
error,
|
||||
"getAlbumSongs(" + albumName + "," + from + ")"
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
<tbody>
|
||||
<tr *ngFor="let album of albums">
|
||||
<td>
|
||||
<a [routerLink]="['/album', album.Name]">{{album.Name}}</a>
|
||||
<a [routerLink]="['/album', album.Name]" [queryParams]="{tosort: true}">{{album.Name}}</a>
|
||||
</td>
|
||||
|
||||
<td>{{album['Track Count']}}</td>
|
||||
|
||||
Reference in New Issue
Block a user