(front) Use a 'tosort' filter

This commit is contained in:
2023-01-30 00:06:57 +01:00
parent 2ddafaff1b
commit 9f4ef952b3
4 changed files with 56 additions and 20 deletions

View File

@@ -1,6 +1,10 @@
<div class="container"> <div class="container">
<h1>{{albumName}}</h1> <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"> <div class="alert alert-warning">
<h3>Debug Zone</h3> <h3>Debug Zone</h3>
Returned song: {{songs.length}}<br /> Returned song: {{songs.length}}<br />
@@ -20,7 +24,7 @@
<div class="col-xs-9 text-right"> <div class="col-xs-9 text-right">
<div> <div>
<h3 *ngIf="!album"><span class="glyphicon glyphicon-refresh loading"></span></h3> <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>
<div><br>Rating</div> <div><br>Rating</div>
</div> </div>

View File

@@ -1,6 +1,5 @@
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router'; import { ActivatedRoute, Params } from '@angular/router';
import { Location } from '@angular/common';
import { ElsService } from './../els.service'; import { ElsService } from './../els.service';
import { Song } from './../model/song'; import { Song } from './../model/song';
@@ -19,6 +18,7 @@ export class AlbumComponent implements OnInit {
albumName = ''; albumName = '';
songs: Array<Song> = []; songs: Array<Song> = [];
album: Album = new Album(); // If album not found, will be replaced by 'undefined' 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 // Prevent useless data load + activate button in interface var
moreDataAvailable = true; moreDataAvailable = true;
@@ -26,13 +26,12 @@ export class AlbumComponent implements OnInit {
constructor( constructor(
private elsService: ElsService, private elsService: ElsService,
private route: ActivatedRoute, private route: ActivatedRoute
private location: Location
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
this.route.params this.route.params.subscribe((params: Params) => this.albumName = params['name']);
.subscribe((params: Params) => this.albumName = params['name']); this.route.queryParams.subscribe(params => { this.toSort = params.tosort ?? false; });
this.loadSongs(); this.loadSongs();
@@ -50,7 +49,7 @@ export class AlbumComponent implements OnInit {
} }
this.lockLoadData = true; this.lockLoadData = true;
this.elsService.getAlbumSongs(this.albumName, this.songs.length).subscribe( this.elsService.getAlbumSongs(this.albumName, this.songs.length, this.toSort).subscribe(
data => { data => {
this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE; this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;

View File

@@ -23,6 +23,7 @@ export class ElsService {
protected elsUrl = 'http://localhost:9200'; protected elsUrl = 'http://localhost:9200';
protected headers = new HttpHeaders({'Content-Type': 'application/json'}); protected headers = new HttpHeaders({'Content-Type': 'application/json'});
protected defaultLocation = "/F:/Musique" // TODO Use conf
constructor(protected http: HttpClient) { } constructor(protected http: HttpClient) { }
@@ -172,20 +173,52 @@ export class ElsService {
); );
} }
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> { getAlbumSongs(albumName: string, from: number = 0, toSortFilter = false): Observable<Song[]> {
console.info('getAlbumSongs- Album name: ' + albumName + ' - from: ' + from); // TODO Move in els-album service
return this.http console.info(
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH, "getAlbumSongs- Album name: " + albumName + " - from: " + from
JSON.stringify({ );
'query': {
'match_phrase': { 'Album': albumName } 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( .pipe(
map(res => this.responseToSongs(res)), map((res) => this.responseToSongs(res)),
catchError(error => this.handleError(error, 'getAlbumSongs(' + albumName + ',' + from + ')')) catchError((error) =>
this.handleError(
error,
"getAlbumSongs(" + albumName + "," + from + ")"
)
)
); );
} }

View File

@@ -93,7 +93,7 @@
<tbody> <tbody>
<tr *ngFor="let album of albums"> <tr *ngFor="let album of albums">
<td> <td>
<a [routerLink]="['/album', album.Name]">{{album.Name}}</a>&nbsp; <a [routerLink]="['/album', album.Name]" [queryParams]="{tosort: true}">{{album.Name}}</a>&nbsp;
</td> </td>
<td>{{album['Track Count']}}</td> <td>{{album['Track Count']}}</td>