Compare commits
9 Commits
poc/sugges
...
bb51af68cd
| Author | SHA1 | Date | |
|---|---|---|---|
| bb51af68cd | |||
| 5ee9781463 | |||
| 00a5427950 | |||
| fada5f475b | |||
| d307012aca | |||
| 755f5e5c24 | |||
| f40ee2b6d2 | |||
| d011d5738f | |||
| e5de38b9d9 |
@@ -18,7 +18,6 @@
|
||||
"main": "src/main.ts",
|
||||
"tsConfig": "tsconfig.app.json",
|
||||
"polyfills": "src/polyfills.ts",
|
||||
"aot": true,
|
||||
"assets": [
|
||||
"src/assets",
|
||||
"src/favicon.ico"
|
||||
@@ -27,7 +26,13 @@
|
||||
"src/styles.css",
|
||||
"node_modules/bootstrap/dist/css/bootstrap.min.css"
|
||||
],
|
||||
"scripts": []
|
||||
"scripts": [],
|
||||
"vendorChunk": true,
|
||||
"extractLicenses": false,
|
||||
"buildOptimizer": false,
|
||||
"sourceMap": true,
|
||||
"optimization": false,
|
||||
"namedChunks": true
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
@@ -57,7 +62,8 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultConfiguration": ""
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
|
||||
25902
dashboard/package-lock.json
generated
25902
dashboard/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -11,31 +11,32 @@
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "~11.0.4",
|
||||
"@angular/common": "~11.0.4",
|
||||
"@angular/compiler": "~11.0.4",
|
||||
"@angular/core": "~11.0.4",
|
||||
"@angular/forms": "~11.0.4",
|
||||
"@angular/platform-browser": "~11.0.4",
|
||||
"@angular/platform-browser-dynamic": "~11.0.4",
|
||||
"@angular/router": "~11.0.4",
|
||||
"@ng-bootstrap/ng-bootstrap": "^9.1.3",
|
||||
"@angular/animations": "~12.2.2",
|
||||
"@angular/common": "~12.2.2",
|
||||
"@angular/compiler": "~12.2.2",
|
||||
"@angular/core": "~12.2.2",
|
||||
"@angular/forms": "~12.2.2",
|
||||
"@angular/localize": "~12.2.2",
|
||||
"@angular/platform-browser": "~12.2.2",
|
||||
"@angular/platform-browser-dynamic": "~12.2.2",
|
||||
"@angular/router": "~12.2.2",
|
||||
"@ng-bootstrap/ng-bootstrap": "^10.0.0",
|
||||
"bootstrap": "^3.3.7",
|
||||
"rxjs": "~6.6.0",
|
||||
"tslib": "^2.0.0",
|
||||
"zone.js": "~0.10.2"
|
||||
"zone.js": "~0.11.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@angular-devkit/build-angular": "~0.1100.4",
|
||||
"@angular/cli": "~11.0.4",
|
||||
"@angular/compiler-cli": "~11.0.4",
|
||||
"@angular/localize": "^11.0.4",
|
||||
"@angular-devkit/build-angular": "~12.2.2",
|
||||
"@angular/cli": "~12.2.2",
|
||||
"@angular/compiler-cli": "~12.2.2",
|
||||
"@angular/localize": "^12.2.2",
|
||||
"@types/jasmine": "~3.6.0",
|
||||
"@types/node": "^12.11.1",
|
||||
"codelyzer": "^6.0.0",
|
||||
"jasmine-core": "~3.6.0",
|
||||
"jasmine-spec-reporter": "~5.0.0",
|
||||
"karma": "~5.1.0",
|
||||
"karma": "~6.3.4",
|
||||
"karma-chrome-launcher": "~3.1.0",
|
||||
"karma-coverage": "~2.0.3",
|
||||
"karma-jasmine": "~4.0.0",
|
||||
@@ -43,6 +44,6 @@
|
||||
"protractor": "~7.0.0",
|
||||
"ts-node": "~8.3.0",
|
||||
"tslint": "~6.1.0",
|
||||
"typescript": "~4.0.2"
|
||||
"typescript": "~4.3.5"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export class AlbumsComponent implements OnInit {
|
||||
this.loadData();
|
||||
}
|
||||
|
||||
private editQuery(field: string, value: string, type: query_edit_type): void {
|
||||
private editQuery(field: string, value: Album, type: query_edit_type): void {
|
||||
// TODO Move this method to a service
|
||||
if (value[field] instanceof Array) {
|
||||
value[field] = value[field][0]
|
||||
@@ -49,12 +49,12 @@ export class AlbumsComponent implements OnInit {
|
||||
this.queryEdited = true;
|
||||
}
|
||||
|
||||
exlude(field: string, value: string): void {
|
||||
exlude(field: string, value: Album): void {
|
||||
this.editQuery(field, value, query_edit_type.exclude)
|
||||
this.loadData()
|
||||
}
|
||||
|
||||
select(field: string, value: string): void {
|
||||
select(field: string, value: Album): void {
|
||||
this.editQuery(field, value, query_edit_type.select)
|
||||
this.loadData()
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { ArtistComponent } from './artist/artist.component';
|
||||
import { GenreComponent } from './genre/genre.component';
|
||||
import { TopPlayedComponent } from './top-played/top-played.component';
|
||||
import { AlbumsComponent } from './albums/albums.component';
|
||||
import { ToSortComponent } from './to-sort/to-sort.component';
|
||||
|
||||
const routes: Routes = [
|
||||
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
|
||||
@@ -15,7 +16,8 @@ const routes: Routes = [
|
||||
{ path: 'album', component: AlbumsComponent },
|
||||
{ path: 'artist/:name', component: ArtistComponent },
|
||||
{ path: 'genre/:name', component: GenreComponent },
|
||||
{ path: 'top-played', component: TopPlayedComponent }
|
||||
{ path: 'top-played', component: TopPlayedComponent },
|
||||
{ path: 'to-sort', component: ToSortComponent }
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
||||
@@ -36,7 +36,8 @@ nav a.active {
|
||||
|
||||
/* FIXME Code Repetition */
|
||||
.btn-top {
|
||||
display: inline-block;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
-webkit-transition: opacity .3s 0s, visibility 0s 0s;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<nav>
|
||||
<a class="btn-top" routerLink="/dashboard" routerLinkActive="active"><span class="glyphicon glyphicon-home"></span></a><br />
|
||||
<a class="btn-top" routerLink="/album" routerLinkActive="active"><span class="glyphicon glyphicon-cd"></span></a>
|
||||
<div class="btn-top">
|
||||
<a routerLink="/dashboard" routerLinkActive="active"><span class="glyphicon glyphicon-home"></span></a><br />
|
||||
<a routerLink="/album" routerLinkActive="active"><span class="glyphicon glyphicon-cd"></span></a>
|
||||
<a routerLink="/to-sort" routerLinkActive="active"><span class="glyphicon glyphicon-sort"></span></a>
|
||||
</div>
|
||||
</nav>
|
||||
<router-outlet></router-outlet>
|
||||
|
||||
@@ -22,6 +22,7 @@ import { SortByPipe } from './pipes/sort-by.pipe';
|
||||
import { ConvertSizeToStringPipe } from './pipes/convert-size-to-string.pipe';
|
||||
import { RoundPipe } from './pipes/round.pipe';
|
||||
import { AlbumsComponent } from './albums/albums.component';
|
||||
import { ToSortComponent } from './to-sort/to-sort.component';
|
||||
|
||||
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
@@ -46,7 +47,8 @@ import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
|
||||
SortByPipe,
|
||||
ConvertSizeToStringPipe,
|
||||
TopPlayedComponent,
|
||||
RoundPipe
|
||||
RoundPipe,
|
||||
ToSortComponent
|
||||
],
|
||||
providers: [
|
||||
ElsService,
|
||||
|
||||
16
dashboard/src/app/els-sort.service.spec.ts
Normal file
16
dashboard/src/app/els-sort.service.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ElsSortService } from './els-sort.service';
|
||||
|
||||
describe('ElsSortService', () => {
|
||||
let service: ElsSortService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ElsSortService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
147
dashboard/src/app/els-sort.service.ts
Normal file
147
dashboard/src/app/els-sort.service.ts
Normal file
@@ -0,0 +1,147 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { ElsService } from './els.service';
|
||||
import { Album } from './model/album';
|
||||
import { Bucket } from './model/bucket';
|
||||
import { Song } from './model/song';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ElsSortService extends ElsService {
|
||||
|
||||
constructor(protected http: HttpClient) {
|
||||
super(http);
|
||||
}
|
||||
|
||||
getTime(): Promise<number> {
|
||||
return this.http
|
||||
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
query: {
|
||||
bool: {
|
||||
must_not: [
|
||||
{
|
||||
term: {
|
||||
"Location.tree": "/F:/Musique"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
aggs: {
|
||||
sum_time: {
|
||||
sum: { field: 'Total Time'}
|
||||
}
|
||||
},
|
||||
'size': 0
|
||||
}), {headers: this.headers})
|
||||
.toPromise()
|
||||
.then(res => res.aggregations.sum_time.value as number)
|
||||
.catch(error => this.handleError(error, 'getTime()'));
|
||||
}
|
||||
|
||||
getSize(): Promise<number> {
|
||||
return this.http
|
||||
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
query: {
|
||||
bool: {
|
||||
must_not: [
|
||||
{
|
||||
term: {
|
||||
"Location.tree": "/F:/Musique"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
aggs: {
|
||||
sum_time: {
|
||||
sum: { field: 'Size' }
|
||||
}
|
||||
},
|
||||
'size': 0
|
||||
}), {headers: this.headers})
|
||||
.toPromise()
|
||||
.then(res => res.aggregations.sum_time.value as number)
|
||||
.catch(error => this.handleError(error, 'getSize()'));
|
||||
}
|
||||
|
||||
getCountSong(): Promise<number> {
|
||||
return this.http
|
||||
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_COUNT,
|
||||
JSON.stringify({
|
||||
query: {
|
||||
bool: {
|
||||
must_not: [
|
||||
{
|
||||
term: {
|
||||
"Location.tree": "/F:/Musique"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}), {headers: this.headers})
|
||||
.toPromise()
|
||||
.then(res => res.count as number)
|
||||
.catch(error => this.handleError(error, 'getCountSong()'));
|
||||
}
|
||||
|
||||
getCountNeverListenSong(): Promise<number> {
|
||||
return this.http
|
||||
.post<any>(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_COUNT,
|
||||
JSON.stringify({
|
||||
'query': {
|
||||
'bool': {
|
||||
'must_not': [
|
||||
{
|
||||
'exists': { 'field': 'Play Count'}
|
||||
}, {
|
||||
term: {
|
||||
"Location.tree": "/F:/Musique"
|
||||
} }
|
||||
]
|
||||
}
|
||||
}
|
||||
}), {headers: this.headers})
|
||||
.toPromise()
|
||||
.then(res => res.count as number)
|
||||
.catch(error => this.handleError(error, 'getCountNeverListenSong()'));
|
||||
}
|
||||
|
||||
getAlbums(): Observable<Bucket[]> {
|
||||
return this.http
|
||||
.post(this.elsUrl + ElsService.SONG_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
query: {
|
||||
bool: {
|
||||
must_not: [
|
||||
{
|
||||
term: {
|
||||
"Location.tree": "/F:/Musique"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
'size': 0,
|
||||
'aggs': {
|
||||
'albums' : {
|
||||
'terms': {
|
||||
'field' : 'Album.raw',
|
||||
'order': { '_term': 'asc' },
|
||||
'size': 50
|
||||
}
|
||||
}
|
||||
}
|
||||
}), {headers: this.headers})
|
||||
.pipe(
|
||||
map(res => this.responseAggregationToBucket(res, "albums")),
|
||||
catchError(error => this.handleError(error, 'getAlbums'))
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -339,7 +339,7 @@ export class ElsService {
|
||||
// TODO Take in consideration "sum_other_doc_count"
|
||||
}
|
||||
|
||||
getArtistFromAlbumName(albumname: string): Observable<Album[]> {
|
||||
getArtistFromAlbumName(albumname: string): Observable<Album[]> { // TODO Rename ?
|
||||
return this.http
|
||||
.post<any>(this.elsUrl + ElsService.ALBUM_INDEX_NAME + ElsService.ACTION_SEARCH,
|
||||
JSON.stringify({
|
||||
@@ -436,7 +436,7 @@ export class ElsService {
|
||||
*
|
||||
* @param res Response to process
|
||||
*/
|
||||
private responseToSongs(res: any): Song[] {
|
||||
protected responseToSongs(res: any): Song[] {
|
||||
const result: Array<Song> = [];
|
||||
res.hits.hits.forEach((hit) => {
|
||||
result.push(hit._source);
|
||||
@@ -474,7 +474,7 @@ export class ElsService {
|
||||
* @param res Response to process
|
||||
* @param name Name of aggregation
|
||||
*/
|
||||
private responseAggregationToBucket(res: any, name: string): Bucket[] {
|
||||
protected responseAggregationToBucket(res: any, name: string): Bucket[] {
|
||||
const result: Array<Bucket> = [];
|
||||
res.aggregations[name].buckets.forEach((bucket) => {
|
||||
result.push(bucket);
|
||||
|
||||
38
dashboard/src/app/to-sort/to-sort.component.css
Normal file
38
dashboard/src/app/to-sort/to-sort.component.css
Normal file
@@ -0,0 +1,38 @@
|
||||
.panel-stat {
|
||||
min-height: 102px;
|
||||
}
|
||||
|
||||
.panel-green {
|
||||
background-color: #16a085;
|
||||
color:white;
|
||||
}
|
||||
.panel-yellow {
|
||||
background-color: #f1c40f;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.panel-red {
|
||||
background-color: #d9534f;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.panel-purple {
|
||||
background-color: #9b59b6;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.panel-blue {
|
||||
background-color: #3498db;
|
||||
color:white;
|
||||
}
|
||||
|
||||
.stats_icon {
|
||||
font-size: 3em;
|
||||
}
|
||||
|
||||
.circle {
|
||||
border-radius: 50%;
|
||||
background-color: #9b59b6;
|
||||
margin: 0 auto;
|
||||
|
||||
}
|
||||
130
dashboard/src/app/to-sort/to-sort.component.html
Normal file
130
dashboard/src/app/to-sort/to-sort.component.html
Normal file
@@ -0,0 +1,130 @@
|
||||
<div class="container">
|
||||
<h1>To sort Songs - </h1>
|
||||
|
||||
<br />
|
||||
<div class="row cardAdmin">
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-blue">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-time stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!totalTime"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="totalTime">{{totalTime | convertMs}}</h3>
|
||||
</div>
|
||||
<div><br>Total time ({{totalTime | convertMoreExact}})</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-green">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-hdd stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!totalSize"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="totalSize">{{totalSize | convertSizeToString}}</h3>
|
||||
</div>
|
||||
<div><br>Total size</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-yellow">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-play stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!trackCountSong"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="trackCountSong">{{trackCountSong}}</h3>
|
||||
</div>
|
||||
<div><br>Total Songs</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-3 col-md-3">
|
||||
<div class="panel panel-red">
|
||||
<div class="panel-heading">
|
||||
<div class="row">
|
||||
<div class="col-xs-3">
|
||||
<span class="glyphicon glyphicon-stop stats_icon"></span>
|
||||
</div>
|
||||
<div class="col-xs-9 text-right">
|
||||
<div>
|
||||
<h3 *ngIf="!neverListenSong"><span class="glyphicon glyphicon-refresh loading"></span></h3>
|
||||
<h3 *ngIf="neverListenSong">{{neverListenSong}}</h3>
|
||||
</div>
|
||||
<div><br>Never list. songs (~{{neverListenSong / trackCountSong * 100 | round}}%)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<table class="table table-striped" style="white-space: nowrap;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Album</th>
|
||||
<th>Track Count</th>
|
||||
<th>Artist/Album Artist</th>
|
||||
<th>Play Count</th>
|
||||
<th>Rating</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr *ngFor="let album of toSortAlbum">
|
||||
<td>
|
||||
<a [routerLink]="['/album', album.key]">{{album.key}}</a>
|
||||
</td>
|
||||
|
||||
<td>{{albums[album.key]['Track Count']}}</td>
|
||||
|
||||
<ng-template [ngIf]="albums[album.key]['Album Artist']" [ngIfElse]="artistSection">
|
||||
<td>
|
||||
<a [routerLink]="['/artist', albums[album.key]['Album Artist']]">{{albums[album.key]['Album Artist']}}</a>
|
||||
</td>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #artistSection>
|
||||
<td>
|
||||
<a [routerLink]="['/artist', albums[album.key].Artist[0]]">{{albums[album.key].Artist}}</a>
|
||||
</td>
|
||||
</ng-template>
|
||||
|
||||
<ng-template #artistSection>
|
||||
<td>
|
||||
<a [routerLink]="['/artist', albums[album.key].Artist[0]]">{{albums[album.key].Artist}}</a>
|
||||
</td>
|
||||
</ng-template>
|
||||
|
||||
<td>
|
||||
{{albums[album.key]['Play Count']}} ({{albums[album.key]['Play Count']/albums[album.key]['Track Count'] | number:'1.0-0'}}/songs)
|
||||
</td>
|
||||
|
||||
<td class="star" [title]="(albums[album.key]['Album Rating Computed']?'Computed Rating: ':'Rating: ') + albums[album.key]['Album Rating']">
|
||||
<span *ngFor="let item of numberToArray(albums[album.key]['Album Rating'], 20)">
|
||||
<span class="glyphicon" [ngClass]="albums[album.key]['Album Rating Computed']?'glyphicon-star-empty':'glyphicon-star'"></span>
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
25
dashboard/src/app/to-sort/to-sort.component.spec.ts
Normal file
25
dashboard/src/app/to-sort/to-sort.component.spec.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ToSortComponent } from './to-sort.component';
|
||||
|
||||
describe('ToSortComponent', () => {
|
||||
let component: ToSortComponent;
|
||||
let fixture: ComponentFixture<ToSortComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ ToSortComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ToSortComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
89
dashboard/src/app/to-sort/to-sort.component.ts
Normal file
89
dashboard/src/app/to-sort/to-sort.component.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ElsSortService } from '../els-sort.service';
|
||||
import { Album } from '../model/album';
|
||||
import { Bucket } from '../model/bucket';
|
||||
import { Song } from '../model/song';
|
||||
|
||||
import { Utils } from '../utils';
|
||||
|
||||
@Component({
|
||||
selector: 'app-to-sort',
|
||||
templateUrl: './to-sort.component.html',
|
||||
styleUrls: ['./to-sort.component.css']
|
||||
})
|
||||
export class ToSortComponent implements OnInit {
|
||||
numberToArray = Utils.numberToArray;
|
||||
// Stats var
|
||||
totalTime = 0;
|
||||
totalSize = 0;
|
||||
trackCountSong = 0;
|
||||
neverListenSong = 0;
|
||||
|
||||
// Global var
|
||||
toSortAlbum: Bucket[] = [];
|
||||
albums = []
|
||||
|
||||
constructor(private elsService: ElsSortService) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
// **** GET STATS ****//
|
||||
this.elsService.getTime().then(result => this.totalTime = result);
|
||||
this.elsService.getSize().then(result => this.totalSize = result);
|
||||
this.elsService.getCountSong().then(result => this.trackCountSong = result);
|
||||
this.elsService.getCountNeverListenSong().then(result => this.neverListenSong = result);
|
||||
|
||||
// **** GET ALBUMS ****//
|
||||
const tmpToSortAlbums: Bucket[] = [];
|
||||
this.elsService.getAlbums().subscribe(buckets => {
|
||||
buckets.forEach(bucket => {
|
||||
if (tmpToSortAlbums.length === 0) {
|
||||
tmpToSortAlbums.push(bucket);
|
||||
} else {
|
||||
let found = false;
|
||||
tmpToSortAlbums.forEach(element => {
|
||||
if (element.key === bucket.key) {
|
||||
element.doc_count += bucket.doc_count;
|
||||
found = true;
|
||||
}
|
||||
});
|
||||
if (!found) {
|
||||
tmpToSortAlbums.push(bucket);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.toSortAlbum = tmpToSortAlbums;
|
||||
this.toSortAlbum.forEach(bucket => this.getAlbum(bucket));
|
||||
// console.log(this.toSortAlbum)
|
||||
// console.log(this.albums)
|
||||
});
|
||||
}
|
||||
|
||||
private getAlbum(albumBucket: Bucket) {
|
||||
// For each bucket.key (album name), get Album document
|
||||
// Use track count to compare
|
||||
this.elsService.getArtistFromAlbumName(albumBucket.key).subscribe(albums => {
|
||||
// Identification of the good album
|
||||
let goodAlbum;
|
||||
if (albums.length > 1) {
|
||||
// More than one result for an album name: search good by track count
|
||||
albums.forEach(album => {
|
||||
if (album['Track Count'] === albumBucket.doc_count) {
|
||||
goodAlbum = album;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Just one result for album name
|
||||
goodAlbum = albums[0];
|
||||
}
|
||||
|
||||
// TODO Crap security if no good album found
|
||||
if (goodAlbum == undefined) {
|
||||
goodAlbum = albums[0]
|
||||
}
|
||||
|
||||
this.albums[albumBucket.key] = goodAlbum;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,4 +13,4 @@ export const environment = {
|
||||
* This import should be commented out in production mode because it will have a negative impact
|
||||
* on performance if an error is thrown.
|
||||
*/
|
||||
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
|
||||
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.
|
||||
|
||||
@@ -59,7 +59,7 @@ import '@angular/localize/init';
|
||||
/***************************************************************************************************
|
||||
* Zone JS is required by default for Angular itself.
|
||||
*/
|
||||
import 'zone.js/dist/zone'; // Included with Angular CLI.
|
||||
import 'zone.js'; // Included with Angular CLI.
|
||||
|
||||
|
||||
/***************************************************************************************************
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||
|
||||
import 'zone.js/dist/zone-testing';
|
||||
import 'zone.js/testing';
|
||||
import { getTestBed } from '@angular/core/testing';
|
||||
import {
|
||||
BrowserDynamicTestingModule,
|
||||
|
||||
@@ -16,5 +16,8 @@
|
||||
"es2018",
|
||||
"dom"
|
||||
]
|
||||
},
|
||||
"angularCompilerOptions": {
|
||||
"strictTemplates": true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user