TSLint acceptance
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, Params } from '@angular/router'
|
import { ActivatedRoute, Params } from '@angular/router';
|
||||||
import { Location } from '@angular/common'
|
import { Location } from '@angular/common';
|
||||||
|
|
||||||
import { ElsService } from './els.service'
|
import { ElsService } from './els.service';
|
||||||
import { Song } from './object/song';
|
import { Song } from './object/song';
|
||||||
import { Album } from './object/album';
|
import { Album } from './object/album';
|
||||||
|
|
||||||
@@ -13,23 +13,23 @@ import { Album } from './object/album';
|
|||||||
})
|
})
|
||||||
|
|
||||||
export class AlbumComponent implements OnInit {
|
export class AlbumComponent implements OnInit {
|
||||||
|
albumName = '';
|
||||||
|
songs: Array<Song> = [];
|
||||||
|
album: Album = new Album(); // If album not found, will be replaced by 'undefined'
|
||||||
|
moreDataAvailable: boolean = false;
|
||||||
|
atBottom: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private elsService: ElsService,
|
private elsService: ElsService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private location: Location
|
private location: Location
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
albumName = "";
|
|
||||||
songs: Array<Song> = [];
|
|
||||||
album: Album = new Album(); // If album not found, will be replaced by 'undefined'
|
|
||||||
moreDataAvailable: boolean = false;
|
|
||||||
atBottom: boolean = false;
|
|
||||||
|
|
||||||
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.loadSongs()
|
this.loadSongs();
|
||||||
|
|
||||||
this.elsService.getAlbum(this.albumName).subscribe(data => this.album = data);
|
this.elsService.getAlbum(this.albumName).subscribe(data => this.album = data);
|
||||||
}
|
}
|
||||||
@@ -37,11 +37,11 @@ export class AlbumComponent implements OnInit {
|
|||||||
loadSongs(): void {
|
loadSongs(): void {
|
||||||
this.elsService.getAlbumSongs(this.albumName, this.songs.length).subscribe(
|
this.elsService.getAlbumSongs(this.albumName, this.songs.length).subscribe(
|
||||||
data => {
|
data => {
|
||||||
this.moreDataAvailable = data.length == ElsService.DEFAULT_SIZE
|
this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;
|
||||||
|
|
||||||
// Erase song array with result for first load, then add elements one by one
|
// Erase song array with result for first load, then add elements one by one
|
||||||
// instead use concat => concat will sort table at each load, very consuming! and not user friendly
|
// instead use concat => concat will sort table at each load, very consuming! and not user friendly
|
||||||
if (this.songs.length == 0) {
|
if (this.songs.length === 0) {
|
||||||
this.songs = data;
|
this.songs = data;
|
||||||
} else {
|
} else {
|
||||||
data.forEach(song => {
|
data.forEach(song => {
|
||||||
@@ -53,7 +53,7 @@ export class AlbumComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scrollTop(): void {
|
scrollTop(): void {
|
||||||
window.scrollTo(0,0);
|
window.scrollTo(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -73,7 +73,7 @@ export class AlbumComponent implements OnInit {
|
|||||||
this.atBottom = true;
|
this.atBottom = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.scrollY == 0) {
|
if (window.scrollY === 0) {
|
||||||
this.atBottom = false;
|
this.atBottom = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
import { FormsModule } from '@angular/forms'
|
import { FormsModule } from '@angular/forms';
|
||||||
import { HttpModule } from '@angular/http'
|
import { HttpModule } from '@angular/http';
|
||||||
|
|
||||||
// Imports for loading & configuring the in-memory web api
|
// Imports for loading & configuring the in-memory web api
|
||||||
// import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
|
// import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
|
||||||
@@ -10,17 +10,17 @@ import { HttpModule } from '@angular/http'
|
|||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { HeroDetailComponent } from './hero-detail.component';
|
import { HeroDetailComponent } from './hero-detail.component';
|
||||||
import { HeroesComponent } from './heroes.component';
|
import { HeroesComponent } from './heroes.component';
|
||||||
import { DashboardComponent } from './dashboard.component'
|
import { DashboardComponent } from './dashboard.component';
|
||||||
import { AlbumComponent } from './album.component'
|
import { AlbumComponent } from './album.component';
|
||||||
import { ArtistComponent } from './artist.component'
|
import { ArtistComponent } from './artist.component';
|
||||||
import { HeroService } from './hero.service';
|
import { HeroService } from './hero.service';
|
||||||
|
|
||||||
import { ElsService } from './els.service';
|
import { ElsService } from './els.service';
|
||||||
|
|
||||||
import { AppRoutingModule } from './app-routing.module'
|
import { AppRoutingModule } from './app-routing.module';
|
||||||
|
|
||||||
import { ConvertMsPipe } from './convertms.pipe'
|
import { ConvertMsPipe } from './convertms.pipe';
|
||||||
import { SortPipe } from './sortby.pipe'
|
import { SortPipe } from './sortby.pipe';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, Params } from '@angular/router'
|
import { ActivatedRoute, Params } from '@angular/router';
|
||||||
import { Location } from '@angular/common'
|
import { Location } from '@angular/common';
|
||||||
|
|
||||||
import { ElsService } from './els.service'
|
import { ElsService } from './els.service';
|
||||||
import { Song } from './object/song';
|
import { Song } from './object/song';
|
||||||
import { Artist } from './object/artist';
|
import { Artist } from './object/artist';
|
||||||
|
|
||||||
import { SortPipe } from './sortby.pipe'
|
import { SortPipe } from './sortby.pipe';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'artist-component',
|
selector: 'artist-component',
|
||||||
@@ -15,13 +15,7 @@ import { SortPipe } from './sortby.pipe'
|
|||||||
})
|
})
|
||||||
|
|
||||||
export class ArtistComponent implements OnInit {
|
export class ArtistComponent implements OnInit {
|
||||||
constructor(
|
artistName = '';
|
||||||
private elsService: ElsService,
|
|
||||||
private route: ActivatedRoute,
|
|
||||||
private location: Location
|
|
||||||
) { }
|
|
||||||
|
|
||||||
artistName = "";
|
|
||||||
songs: Array<Song> = [];
|
songs: Array<Song> = [];
|
||||||
artist: Artist = new Artist();
|
artist: Artist = new Artist();
|
||||||
// To activate button in interface var
|
// To activate button in interface var
|
||||||
@@ -31,6 +25,12 @@ export class ArtistComponent implements OnInit {
|
|||||||
|
|
||||||
lockLoadData: boolean = false;
|
lockLoadData: boolean = false;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private elsService: ElsService,
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private location: Location
|
||||||
|
) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.route.params.subscribe((params: Params) => this.artistName = params['name']);
|
this.route.params.subscribe((params: Params) => this.artistName = params['name']);
|
||||||
|
|
||||||
@@ -41,18 +41,18 @@ export class ArtistComponent implements OnInit {
|
|||||||
// TODO Duplicate code!
|
// TODO Duplicate code!
|
||||||
loadSongs(): void {
|
loadSongs(): void {
|
||||||
if (this.lockLoadData) {
|
if (this.lockLoadData) {
|
||||||
console.debug("Loading data locked");
|
console.debug('Loading data locked');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.lockLoadData = true;
|
this.lockLoadData = true;
|
||||||
this.elsService.getArtistSongs(this.artistName, this.songs.length).subscribe(
|
this.elsService.getArtistSongs(this.artistName, this.songs.length).subscribe(
|
||||||
data => {
|
data => {
|
||||||
this.moreDataAvailable = data.length == ElsService.DEFAULT_SIZE;
|
this.moreDataAvailable = data.length === ElsService.DEFAULT_SIZE;
|
||||||
|
|
||||||
// Erase song array with result for first load, then add elements one by one
|
// Erase song array with result for first load, then add elements one by one
|
||||||
// instead use concat => concat will sort table at each load, very consuming! and not user friendly
|
// instead use concat => concat will sort table at each load, very consuming! and not user friendly
|
||||||
if (this.songs.length == 0) {
|
if (this.songs.length === 0) {
|
||||||
this.songs = data;
|
this.songs = data;
|
||||||
} else {
|
} else {
|
||||||
this.sortable = true;
|
this.sortable = true;
|
||||||
@@ -60,14 +60,14 @@ export class ArtistComponent implements OnInit {
|
|||||||
this.songs.push(song);
|
this.songs.push(song);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.debug("Unlock load data");
|
console.debug('Unlock load data');
|
||||||
this.lockLoadData = false;
|
this.lockLoadData = false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollTop(): void {
|
scrollTop(): void {
|
||||||
window.scrollTo(0,0);
|
window.scrollTo(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +87,7 @@ export class ArtistComponent implements OnInit {
|
|||||||
this.atBottom = true;
|
this.atBottom = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.scrollY == 0) {
|
if (window.scrollY === 0) {
|
||||||
this.atBottom = false;
|
this.atBottom = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
||||||
@Pipe({name: "convertMs"})
|
@Pipe({name: 'convertMs'})
|
||||||
export class ConvertMsPipe implements PipeTransform {
|
export class ConvertMsPipe implements PipeTransform {
|
||||||
transform(timeMs: number): string {
|
transform(timeMs: number): string {
|
||||||
let x = timeMs / 1000
|
let x = timeMs / 1000;
|
||||||
|
|
||||||
let seconds = Math.round(x % 60)
|
let seconds = Math.round(x % 60);
|
||||||
x /= 60
|
x /= 60;
|
||||||
|
|
||||||
let minutes = 0
|
let minutes = 0;
|
||||||
if (x > 1) minutes = Math.round(x % 60)
|
if (x > 1) { minutes = Math.round(x % 60); }
|
||||||
x /= 60
|
x /= 60;
|
||||||
|
|
||||||
let hours = 0
|
let hours = 0;
|
||||||
if (x > 1) hours = Math.round(x % 24)
|
if (x > 1) { hours = Math.round(x % 24); }
|
||||||
// TODO Enable/disable day
|
// TODO Enable/disable day
|
||||||
x /= 24
|
x /= 24;
|
||||||
let days = Math.round(x);
|
let days = Math.round(x);
|
||||||
|
|
||||||
// Final string
|
// Final string
|
||||||
let ret = "";
|
let ret = '';
|
||||||
if (days > 0) ret += ('0' + days).slice(-2) + ":";
|
if (days > 0) { ret += ('0' + days).slice(-2) + ':'; }
|
||||||
if (hours > 0) ret += ('0' + hours).slice(-2) + ":";
|
if (hours > 0) { ret += ('0' + hours).slice(-2) + ':'; }
|
||||||
if (minutes > 0) ret += ('0' + minutes).slice(-2) + ":";
|
if (minutes > 0) { ret += ('0' + minutes).slice(-2) + ':'; }
|
||||||
if (seconds > 0) ret += ('0' + seconds).slice(-2);
|
if (seconds > 0) { ret += ('0' + seconds).slice(-2); }
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
// return ('0' + days).slice(-2) + ":" + ('0' + hours).slice(-2) + ":" + ('0' + minutes).slice(-2) + ":" + ('0' + seconds).slice(-2);
|
// return ('0' + days).slice(-2) + ':' + ('0' + hours).slice(-2) + ':' + ('0' + minutes).slice(-2) + ':' + ('0' + seconds).slice(-2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
|
||||||
import { Hero } from './hero'
|
import { Hero } from './hero';
|
||||||
import { HeroService } from './hero.service'
|
import { HeroService } from './hero.service';
|
||||||
import { ElsService } from './els.service'
|
import { ElsService } from './els.service';
|
||||||
import { Song } from './object/song';
|
import { Song } from './object/song';
|
||||||
import { Bucket } from './object/bucket';
|
import { Bucket } from './object/bucket';
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ import { Bucket } from './object/bucket';
|
|||||||
export class DashboardComponent implements OnInit {
|
export class DashboardComponent implements OnInit {
|
||||||
totalTime: number = 0;
|
totalTime: number = 0;
|
||||||
totalSize: number = 0;
|
totalSize: number = 0;
|
||||||
totalSizeSt = "";
|
totalSizeSt = '';
|
||||||
trackCountSong: number = 0;
|
trackCountSong: number = 0;
|
||||||
trackCountArtist: number = 0;
|
trackCountArtist: number = 0;
|
||||||
trackCountAlbum: number = 0;
|
trackCountAlbum: number = 0;
|
||||||
@@ -38,11 +38,11 @@ export class DashboardComponent implements OnInit {
|
|||||||
this.totalSizeSt = this.convertSizeToString(result);
|
this.totalSizeSt = this.convertSizeToString(result);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.elsService.getCountSong("song")
|
this.elsService.getCountSong('song')
|
||||||
.then(result => this.trackCountSong = result);
|
.then(result => this.trackCountSong = result);
|
||||||
this.elsService.getCountSong("artist")
|
this.elsService.getCountSong('artist')
|
||||||
.then(result => this.trackCountArtist = result);
|
.then(result => this.trackCountArtist = result);
|
||||||
this.elsService.getCountSong("album")
|
this.elsService.getCountSong('album')
|
||||||
.then(result => this.trackCountAlbum = result);
|
.then(result => this.trackCountAlbum = result);
|
||||||
|
|
||||||
this.elsService.getCountNeverListenSong()
|
this.elsService.getCountNeverListenSong()
|
||||||
@@ -53,7 +53,7 @@ export class DashboardComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.elsService.getGenres().subscribe(data => this.topGenres = data);
|
this.elsService.getGenres().subscribe(data => this.topGenres = data);
|
||||||
this.elsService.getGenres("asc").subscribe(data => this.bottomGenres = data);
|
this.elsService.getGenres('asc').subscribe(data => this.bottomGenres = data);
|
||||||
this.elsService.getGenreCount().subscribe(data => console.log(data));
|
this.elsService.getGenreCount().subscribe(data => console.log(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,11 +65,12 @@ export class DashboardComponent implements OnInit {
|
|||||||
convertSizeToString(size: number) {
|
convertSizeToString(size: number) {
|
||||||
let units = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'];
|
let units = ['Bytes', 'KiB', 'MiB', 'GiB', 'TiB'];
|
||||||
|
|
||||||
if (size == 0)
|
if (size === 0) {
|
||||||
return '0 Byte';
|
return '0 Byte';
|
||||||
|
}
|
||||||
|
|
||||||
let i = Math.floor(Math.log(size) / Math.log(1024));
|
let i = Math.floor(Math.log(size) / Math.log(1024));
|
||||||
let calcSize = size / Math.pow(1024, i)
|
let calcSize = size / Math.pow(1024, i);
|
||||||
calcSize = Math.round(calcSize * 100) / 100;
|
calcSize = Math.round(calcSize * 100) / 100;
|
||||||
|
|
||||||
return calcSize + ' ' + units[i];
|
return calcSize + ' ' + units[i];
|
||||||
|
|||||||
@@ -12,22 +12,31 @@ import { Bucket } from './object/bucket';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ElsService {
|
export class ElsService {
|
||||||
public static readonly DEFAULT_SIZE:number = 50;
|
public static readonly DEFAULT_SIZE: number = 50;
|
||||||
private static readonly INDEX_NAME = "itunessongs";
|
private static readonly INDEX_NAME = 'itunessongs';
|
||||||
|
|
||||||
private static readonly ACTION_SEARCH = "/_search";
|
private static readonly ACTION_SEARCH = '/_search';
|
||||||
private static readonly ACTION_COUNT = "/_count";
|
private static readonly ACTION_COUNT = '/_count';
|
||||||
|
|
||||||
private elsUrl = 'http://localhost:9200/' + ElsService.INDEX_NAME + "/";
|
private elsUrl = 'http://localhost:9200/' + ElsService.INDEX_NAME + '/';
|
||||||
private headers = new Headers({'Content-Type': 'application/json'});
|
private headers = new Headers({'Content-Type': 'application/json'});
|
||||||
|
|
||||||
constructor(private http: Http) { }
|
constructor(private http: Http) { }
|
||||||
|
|
||||||
getTime(): Promise<number> {
|
getTime(): Promise<number> {
|
||||||
return this.http.post(this.elsUrl + 'song/' + ElsService.ACTION_SEARCH, JSON.stringify({aggs:{sum_time:{sum:{field:"Total Time"}}},"size":0}), {headers: this.headers})
|
return this.http
|
||||||
.toPromise()
|
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||||
.then(res => res.json().aggregations.sum_time.value as number)
|
JSON.stringify({
|
||||||
.catch(this.handleError);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTimeSlowly(): Promise<number> {
|
getTimeSlowly(): Promise<number> {
|
||||||
@@ -37,10 +46,19 @@ export class ElsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSize(): Promise<number> {
|
getSize(): Promise<number> {
|
||||||
return this.http.post(this.elsUrl + ElsService.ACTION_SEARCH, JSON.stringify({aggs:{sum_time:{sum:{field:"Size"}}},"size":0}), {headers: this.headers})
|
return this.http
|
||||||
.toPromise()
|
.post(this.elsUrl + ElsService.ACTION_SEARCH,
|
||||||
.then(res => res.json().aggregations.sum_time.value as number)
|
JSON.stringify({
|
||||||
.catch(this.handleError);
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
getSizeSlowly(): Promise<number> {
|
getSizeSlowly(): Promise<number> {
|
||||||
@@ -50,17 +68,25 @@ export class ElsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getCountSong(type: string): Promise<number> {
|
getCountSong(type: string): Promise<number> {
|
||||||
return this.http.get(this.elsUrl + type + ElsService.ACTION_COUNT)
|
return this.http
|
||||||
.toPromise()
|
.get(this.elsUrl + type + ElsService.ACTION_COUNT)
|
||||||
.then(res => res.json().count as number)
|
.toPromise()
|
||||||
.catch(this.handleError);
|
.then(res => res.json().count as number)
|
||||||
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCountNeverListenSong(): Promise<number> {
|
getCountNeverListenSong(): Promise<number> {
|
||||||
return this.http
|
return this.http
|
||||||
.post(this.elsUrl + "song" + ElsService.ACTION_COUNT,
|
.post(this.elsUrl + 'song' + ElsService.ACTION_COUNT,
|
||||||
JSON.stringify({"query":{"bool":{"must_not": {"exists": {"field": "Play Count"}}}}}),
|
JSON.stringify({
|
||||||
{headers: this.headers})
|
'query': {
|
||||||
|
'bool': {
|
||||||
|
'must_not': {
|
||||||
|
'exists': { 'field': 'Play Count'}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}), {headers: this.headers})
|
||||||
.toPromise()
|
.toPromise()
|
||||||
.then(res => res.json().count as number)
|
.then(res => res.json().count as number)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
@@ -78,21 +104,20 @@ export class ElsService {
|
|||||||
|
|
||||||
// Could be shorter but I think it's more readable like this.
|
// Could be shorter but I think it's more readable like this.
|
||||||
return this.http
|
return this.http
|
||||||
.post(this.elsUrl + "song" + ElsService.ACTION_SEARCH,
|
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||||
JSON.stringify(
|
JSON.stringify({
|
||||||
{
|
'sort': [ {
|
||||||
"sort": [ {
|
'Play Count': {
|
||||||
"Play Count": {
|
'order': 'desc'
|
||||||
"order": "desc"
|
}
|
||||||
} } ],
|
} ],
|
||||||
"size": 5
|
'size': 5
|
||||||
}),
|
}), {headers: this.headers})
|
||||||
{headers: this.headers})
|
|
||||||
.map(res => {
|
.map(res => {
|
||||||
return res.json().hits.hits;
|
return res.json().hits.hits;
|
||||||
})
|
})
|
||||||
.map((hits: Array<any>) => {
|
.map((hits: Array<any>) => {
|
||||||
let result:Array<Song> = [];
|
let result: Array<Song> = [];
|
||||||
hits.forEach((hit) => {
|
hits.forEach((hit) => {
|
||||||
result.push(hit._source);
|
result.push(hit._source);
|
||||||
});
|
});
|
||||||
@@ -109,16 +134,21 @@ export class ElsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> {
|
getAlbumSongs(albumName: string, from: number = 0): Observable<Song[]> {
|
||||||
console.debug("getAlbumSongs- Album name: " + albumName + " - from: " + from);
|
console.debug('getAlbumSongs- Album name: ' + albumName + ' - from: ' + from);
|
||||||
return this.http
|
return this.http
|
||||||
.post(this.elsUrl + "song" + ElsService.ACTION_SEARCH,
|
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||||
JSON.stringify({"query":{"match_phrase":{"Album":albumName}},"size": ElsService.DEFAULT_SIZE, "from": from}),
|
JSON.stringify({
|
||||||
{headers: this.headers})
|
'query': {
|
||||||
|
'match_phrase': { 'Album': albumName }
|
||||||
|
},
|
||||||
|
'size': ElsService.DEFAULT_SIZE,
|
||||||
|
'from': from
|
||||||
|
}), {headers: this.headers})
|
||||||
.map(res => {
|
.map(res => {
|
||||||
return res.json().hits.hits;
|
return res.json().hits.hits;
|
||||||
})
|
})
|
||||||
.map((hits: Array<any>) => {
|
.map((hits: Array<any>) => {
|
||||||
let result:Array<Song> = [];
|
let result: Array<Song> = [];
|
||||||
hits.forEach((hit) => {
|
hits.forEach((hit) => {
|
||||||
result.push(hit._source);
|
result.push(hit._source);
|
||||||
});
|
});
|
||||||
@@ -127,28 +157,26 @@ export class ElsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getArtistSongs(artistName: string, from: number = 0): Observable<Song[]> {
|
getArtistSongs(artistName: string, from: number = 0): Observable<Song[]> {
|
||||||
console.debug("getArtistSongs- Artist name: " + artistName + " - from: " + from);
|
console.debug('getArtistSongs- Artist name: ' + artistName + ' - from: ' + from);
|
||||||
return this.http
|
return this.http
|
||||||
.post(this.elsUrl + "song" + ElsService.ACTION_SEARCH,
|
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||||
JSON.stringify(
|
JSON.stringify({
|
||||||
{
|
'query': {
|
||||||
"query": {
|
'bool': {
|
||||||
"bool": {
|
'should': [
|
||||||
"should": [
|
{'match_phrase' : { 'Album Artist' : artistName }},
|
||||||
{"match_phrase" : { "Album Artist" : artistName }},
|
{'match_phrase' : { 'Artist' : artistName }}
|
||||||
{"match_phrase" : { "Artist" : artistName }}
|
]
|
||||||
]
|
}
|
||||||
}
|
},
|
||||||
},
|
'size': ElsService.DEFAULT_SIZE,
|
||||||
"size": ElsService.DEFAULT_SIZE,
|
'from': from
|
||||||
"from": from
|
}), {headers: this.headers})
|
||||||
}),
|
|
||||||
{headers: this.headers})
|
|
||||||
.map(res => {
|
.map(res => {
|
||||||
return res.json().hits.hits;
|
return res.json().hits.hits;
|
||||||
})
|
})
|
||||||
.map((hits: Array<any>) => {
|
.map((hits: Array<any>) => {
|
||||||
let result:Array<Song> = [];
|
let result: Array<Song> = [];
|
||||||
hits.forEach((hit) => {
|
hits.forEach((hit) => {
|
||||||
result.push(hit._source);
|
result.push(hit._source);
|
||||||
});
|
});
|
||||||
@@ -158,9 +186,13 @@ export class ElsService {
|
|||||||
|
|
||||||
getAlbum(albumName: string): Observable<Album> {
|
getAlbum(albumName: string): Observable<Album> {
|
||||||
return this.http
|
return this.http
|
||||||
.post(this.elsUrl + "album" + ElsService.ACTION_SEARCH,
|
.post(this.elsUrl + 'album' + ElsService.ACTION_SEARCH,
|
||||||
JSON.stringify({"query":{"match_phrase":{"Album":albumName}},"size": ElsService.DEFAULT_SIZE}),
|
JSON.stringify({
|
||||||
{headers: this.headers})
|
'query': {
|
||||||
|
'match_phrase': { 'Album': albumName }
|
||||||
|
},
|
||||||
|
'size': ElsService.DEFAULT_SIZE
|
||||||
|
}), {headers: this.headers})
|
||||||
.map(res => {
|
.map(res => {
|
||||||
return res.json().hits.hits;
|
return res.json().hits.hits;
|
||||||
})
|
})
|
||||||
@@ -178,9 +210,13 @@ export class ElsService {
|
|||||||
|
|
||||||
getArtist(artistName: string): Observable<Artist> {
|
getArtist(artistName: string): Observable<Artist> {
|
||||||
return this.http
|
return this.http
|
||||||
.post(this.elsUrl + "artist" + ElsService.ACTION_SEARCH,
|
.post(this.elsUrl + 'artist' + ElsService.ACTION_SEARCH,
|
||||||
JSON.stringify({"query":{"match_phrase":{"Artist":artistName}},"size": ElsService.DEFAULT_SIZE}),
|
JSON.stringify({
|
||||||
{headers: this.headers})
|
'query': {
|
||||||
|
'match_phrase': { 'Artist': artistName }
|
||||||
|
},
|
||||||
|
'size': ElsService.DEFAULT_SIZE
|
||||||
|
}), {headers: this.headers})
|
||||||
.map(res => res.json().hits.hits)
|
.map(res => res.json().hits.hits)
|
||||||
.map((hits: Array<any>) => {
|
.map((hits: Array<any>) => {
|
||||||
// Theorically, my script prevent to found two documents with this query.
|
// Theorically, my script prevent to found two documents with this query.
|
||||||
@@ -191,7 +227,7 @@ export class ElsService {
|
|||||||
}
|
}
|
||||||
if (hits.length > 1) {
|
if (hits.length > 1) {
|
||||||
console.error('More than one artist "' + artistName + '" found (' + hits.length + '), return the first.');
|
console.error('More than one artist "' + artistName + '" found (' + hits.length + '), return the first.');
|
||||||
console.error('This is not normal!')
|
console.error('This is not normal!');
|
||||||
}
|
}
|
||||||
return hits[0]._source;
|
return hits[0]._source;
|
||||||
});
|
});
|
||||||
@@ -199,48 +235,44 @@ export class ElsService {
|
|||||||
|
|
||||||
getGenres(ordering: string = 'desc'): Observable<Bucket[]> {
|
getGenres(ordering: string = 'desc'): Observable<Bucket[]> {
|
||||||
return this.http
|
return this.http
|
||||||
.post(this.elsUrl + "song" + ElsService.ACTION_SEARCH,
|
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||||
JSON.stringify(
|
JSON.stringify({
|
||||||
{
|
'aggs' : {
|
||||||
"aggs" : {
|
'genres' : {
|
||||||
"genres" : {
|
'terms' : {
|
||||||
"terms" : {
|
'field' : 'Genre.original',
|
||||||
"field" : "Genre.original",
|
'size' : 10,
|
||||||
"size" : 10,
|
'missing': 'N/A',
|
||||||
"missing": "N/A",
|
'order': { '_count' : ordering }
|
||||||
"order": { "_count" : ordering }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"size": 0
|
},
|
||||||
}),
|
'size': 0
|
||||||
{headers: this.headers})
|
}), {headers: this.headers})
|
||||||
.map(res => res.json().aggregations.genres.buckets)
|
.map(res => res.json().aggregations.genres.buckets)
|
||||||
.map((hits: Array<any>) => {
|
.map((hits: Array<any>) => {
|
||||||
let result:Array<Bucket> = [];
|
let result: Array<Bucket> = [];
|
||||||
hits.forEach((bucket) => {
|
hits.forEach((bucket) => {
|
||||||
result.push(bucket);
|
result.push(bucket);
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
});;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getGenreCount(): Observable<number> {
|
getGenreCount(): Observable<number> {
|
||||||
return this.http
|
return this.http
|
||||||
.post(this.elsUrl + "song" + ElsService.ACTION_SEARCH,
|
.post(this.elsUrl + 'song' + ElsService.ACTION_SEARCH,
|
||||||
JSON.stringify(
|
JSON.stringify({
|
||||||
{
|
'aggs' : {
|
||||||
"aggs" : {
|
'genres' : {
|
||||||
"genres" : {
|
'cardinality' : {
|
||||||
"cardinality" : {
|
'field' : 'Genre.original',
|
||||||
"field" : "Genre.original",
|
'missing': 'N/A',
|
||||||
"missing": "N/A",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"size": 0
|
},
|
||||||
}),
|
'size': 0
|
||||||
{headers: this.headers})
|
}), {headers: this.headers})
|
||||||
.map(res => res.json().aggregations.genres.value);
|
.map(res => res.json().aggregations.genres.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import 'rxjs/add/operator/switchMap';
|
import 'rxjs/add/operator/switchMap';
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute, Params } from '@angular/router'
|
import { ActivatedRoute, Params } from '@angular/router';
|
||||||
import { Location } from '@angular/common'
|
import { Location } from '@angular/common';
|
||||||
|
|
||||||
import { HeroService } from './hero.service'
|
import { HeroService } from './hero.service';
|
||||||
import { Hero } from './hero';
|
import { Hero } from './hero';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export class HeroesComponent implements OnInit {
|
|||||||
add(name: string): void {
|
add(name: string): void {
|
||||||
name = name.trim();
|
name = name.trim();
|
||||||
if (!name) {
|
if (!name) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.heroService.create(name)
|
this.heroService.create(name)
|
||||||
|
|||||||
@@ -3,21 +3,21 @@
|
|||||||
|
|
||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
|
||||||
@Pipe({name: "sortBy"})
|
@Pipe({name: 'sortBy'})
|
||||||
export class SortPipe implements PipeTransform {
|
export class SortPipe implements PipeTransform {
|
||||||
transform(array: Array<any>, ...args: any[]): Array<any> {
|
transform(array: Array<any>, ...args: any[]): Array<any> {
|
||||||
array.sort((a: any, b: any) => {
|
array.sort((a: any, b: any) => {
|
||||||
for (let i = 0; i < array.length; i++) {
|
for (let i = 0; i < array.length; i++) {
|
||||||
let arg = args[i];
|
let arg = args[i];
|
||||||
|
|
||||||
if (a[arg] == undefined && b[arg] != undefined) return -1;
|
if (a[arg] === undefined && b[arg] !== undefined) { return -1; }
|
||||||
if (a[arg] != undefined && b[arg] == undefined) return 1;
|
if (a[arg] !== undefined && b[arg] === undefined) { return 1; }
|
||||||
|
|
||||||
if (a[arg] < b[arg]) return -1;
|
if (a[arg] < b[arg]) { return -1; }
|
||||||
if (a[arg] > b[arg]) return 1;
|
if (a[arg] > b[arg]) { return 1; }
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user