From 9f4ef952b333ec9e575a5f770c07e11d7d0c4957 Mon Sep 17 00:00:00 2001 From: "Maxence G. de Montauzan" Date: Mon, 30 Jan 2023 00:06:57 +0100 Subject: [PATCH] (front) Use a 'tosort' filter --- dashboard/src/app/album/album.component.html | 6 +- dashboard/src/app/album/album.component.ts | 11 ++-- dashboard/src/app/els.service.ts | 57 +++++++++++++++---- .../src/app/to-sort/to-sort.component.html | 2 +- 4 files changed, 56 insertions(+), 20 deletions(-) diff --git a/dashboard/src/app/album/album.component.html b/dashboard/src/app/album/album.component.html index 9a47c61..8adf089 100644 --- a/dashboard/src/app/album/album.component.html +++ b/dashboard/src/app/album/album.component.html @@ -1,6 +1,10 @@

{{albumName}}

+
+ To sort filter applyed. Songs are filter on location. +
+

Debug Zone

Returned song: {{songs.length}}
@@ -20,7 +24,7 @@

-

{{album.Rating}}/100

+

{{album['Album Rating']}}/100


Rating
diff --git a/dashboard/src/app/album/album.component.ts b/dashboard/src/app/album/album.component.ts index c27e491..c750fcc 100644 --- a/dashboard/src/app/album/album.component.ts +++ b/dashboard/src/app/album/album.component.ts @@ -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 = []; 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; diff --git a/dashboard/src/app/els.service.ts b/dashboard/src/app/els.service.ts index 0a25f1a..91469ba 100644 --- a/dashboard/src/app/els.service.ts +++ b/dashboard/src/app/els.service.ts @@ -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 { - 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 { + // 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 + ")" + ) + ) ); } diff --git a/dashboard/src/app/to-sort/to-sort.component.html b/dashboard/src/app/to-sort/to-sort.component.html index 2c3ebf0..4dc2c79 100644 --- a/dashboard/src/app/to-sort/to-sort.component.html +++ b/dashboard/src/app/to-sort/to-sort.component.html @@ -93,7 +93,7 @@ - {{album.Name}}  + {{album.Name}}  {{album['Track Count']}}