(front) Albums: Add select button
Improve edit ELS Query method
This commit is contained in:
@@ -25,14 +25,16 @@
|
||||
<td>
|
||||
<!-- {{album['Album Artist'] ? album['Album Artist'] : album.Artist}} -->
|
||||
<span *ngIf="album['Album Artist']; else artistSection">
|
||||
<a [routerLink]="['/artist', album['Album Artist']]">{{album['Album Artist']}}</a>
|
||||
<span class="glyphicon glyphicon-ban-circle" style="cursor:pointer" (click)="exlude('Album Artist', album)"></span>
|
||||
<span class="glyphicon glyphicon-zoom-in" style="cursor:pointer" (click)="select('Album Artist', album)"></span>
|
||||
<a [routerLink]="['/artist', album['Album Artist']]">{{album['Album Artist']}}</a>
|
||||
</span>
|
||||
|
||||
<ng-template #artistSection>
|
||||
<span>
|
||||
<a [routerLink]="['/artist', album.Artist[0]]">{{album.Artist}}</a>
|
||||
<span class="glyphicon glyphicon-ban-circle" style="cursor:pointer" (click)="exlude('Artist', album)"></span>
|
||||
<span class="glyphicon glyphicon-zoom-in" style="cursor:pointer" (click)="select('Artist', album)"></span>
|
||||
<a [routerLink]="['/artist', album.Artist[0]]">{{album.Artist}}</a>
|
||||
</span>
|
||||
</ng-template>
|
||||
</td>
|
||||
|
||||
@@ -5,6 +5,11 @@ import { Album } from '../model/album';
|
||||
|
||||
import { Utils } from '../utils';
|
||||
|
||||
enum query_edit_type {
|
||||
exclude = 'must_not',
|
||||
select = 'must'
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-albums',
|
||||
templateUrl: './albums.component.html',
|
||||
@@ -21,34 +26,37 @@ export class AlbumsComponent implements OnInit {
|
||||
this.loadData();
|
||||
}
|
||||
|
||||
exlude(field: string, value: string): void {
|
||||
private editQuery(field: string, value: string, type: query_edit_type): void {
|
||||
// TODO Move this method to a service
|
||||
if (value[field] instanceof Array) {
|
||||
value[field] = value[field][0]
|
||||
}
|
||||
|
||||
if (this.filterQuery['query']) {
|
||||
this.filterQuery['query']['bool']['must_not'].push({
|
||||
'match_phrase': {
|
||||
[field]: value[field]
|
||||
}
|
||||
})
|
||||
} else {
|
||||
// If firt edit, add needed fields in ELS Query
|
||||
if (!this.filterQuery['query']) {
|
||||
this.filterQuery['query'] = {
|
||||
'bool': {
|
||||
'must': [],
|
||||
'filter': [ { 'match_all': {} } ],
|
||||
'should': [],
|
||||
'must_not': [
|
||||
{
|
||||
'match_phrase': {
|
||||
[field]: value[field]
|
||||
}
|
||||
}
|
||||
]
|
||||
'must_not': []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.filterQuery['query']['bool'][type].push({
|
||||
'match_phrase': {
|
||||
[field]: value[field]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
exlude(field: string, value: string): void {
|
||||
this.editQuery(field, value, query_edit_type.exclude)
|
||||
this.loadData()
|
||||
}
|
||||
|
||||
select(field: string, value: string): void {
|
||||
this.editQuery(field, value, query_edit_type.select)
|
||||
this.loadData()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user