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