Refactored selectMatches to selectOneMatch.
This commit is contained in:
parent
32ad70c405
commit
976eb97b07
@ -301,23 +301,23 @@ Configuration:
|
|||||||
def items
|
def items
|
||||||
if (current) {
|
if (current) {
|
||||||
if (!curMediaFile) {
|
if (!curMediaFile) {
|
||||||
setErr "No media is currently selected."
|
setErr "No media is currently playing."
|
||||||
return null }
|
return null }
|
||||||
|
|
||||||
option = line.poll()
|
option = line.poll()
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 'album':
|
case 'album':
|
||||||
return select(getExactlyOne(Album, library.getAlbumsWhere({
|
return select(Album, getExactlyOne(Album,
|
||||||
mediaFileId: curMediaFile.id})))
|
library.getAlbumsWhere({ mediaFileId: curMediaFile.id})))
|
||||||
case 'artist':
|
case 'artist':
|
||||||
return selectMatches(library.getArtistsWhere({
|
return selectOneMatch(library.getArtistsWhere({
|
||||||
mediaFileId: curMediaFile.id}))
|
mediaFileId: curMediaFile.id}))
|
||||||
case 'playlist':
|
case 'playlist':
|
||||||
return selectMatches(playQueue)
|
return selectOneMatch(playQueue)
|
||||||
case 'file':
|
case 'file':
|
||||||
return selectMatches(curMediaFile)
|
return selectOneMatch(curMediaFile)
|
||||||
case 'tags':
|
case 'tags':
|
||||||
return selectMatches(library.getTagsWhere({
|
return select(tags: library.getTagsWhere({
|
||||||
mediaFileId: curMediaFile.id}))
|
mediaFileId: curMediaFile.id}))
|
||||||
default:
|
default:
|
||||||
setErr("Unrecognized option to ${promptStyle}select " +
|
setErr("Unrecognized option to ${promptStyle}select " +
|
||||||
@ -327,16 +327,16 @@ Configuration:
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 'album': return selectMatches(
|
case 'album': return selectOneMatch(
|
||||||
library.getByIdOrName(Album, line.join(' ')))
|
library.getByIdOrName(Album, line.join(' ')))
|
||||||
case 'artist': return selectMatches(
|
case 'artist': return selectOneMatch(
|
||||||
library.getByIdOrName(Artist, line.join(' ')))
|
library.getByIdOrName(Artist, line.join(' ')))
|
||||||
case 'playlist': return selectMatches(
|
case 'playlist': return selectOneMatch(
|
||||||
library.getByIdOrName(Playlist, line.join(' ')))
|
library.getByIdOrName(Playlist, line.join(' ')))
|
||||||
case 'file': return selectMatches(
|
case 'file': return selectOneMatch(
|
||||||
library.getByIdOrName(MediaFile, line.join(' ')))
|
library.getByIdOrName(MediaFile, line.join(' ')))
|
||||||
case 'tags': return selectMatches(
|
case 'tags': return select(tags:
|
||||||
library.getByIdOrName(Tag, line.join(' ')))
|
line.map { library.getByIdOrName(Tag, it) }.filter().flatten())
|
||||||
|
|
||||||
default:
|
default:
|
||||||
setErr("Unrecognized option to ${promptStyle}select${errorStyle}")
|
setErr("Unrecognized option to ${promptStyle}select${errorStyle}")
|
||||||
@ -345,6 +345,7 @@ Configuration:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def processAdd(LinkedList line) {
|
private def processAdd(LinkedList line) {
|
||||||
|
|
||||||
def option = line.poll()
|
def option = line.poll()
|
||||||
def thingToAddId, targetPlaylistId
|
def thingToAddId, targetPlaylistId
|
||||||
|
|
||||||
@ -532,7 +533,7 @@ Configuration:
|
|||||||
public def getExactlyOne(Class modelClass, def criteria) {
|
public def getExactlyOne(Class modelClass, def criteria) {
|
||||||
return ensureExactlyOne(library.getByIdOrName(modelClass, criteria)) }
|
return ensureExactlyOne(library.getByIdOrName(modelClass, criteria)) }
|
||||||
|
|
||||||
public def selectMatches(def matches) {
|
public def selectOneMatch(def matches) {
|
||||||
def match = ensureExactlyOne(matches)
|
def match = ensureExactlyOne(matches)
|
||||||
if (match) selection[uncapitalize(match.class.simpleName)] = match
|
if (match) selection[uncapitalize(match.class.simpleName)] = match
|
||||||
return match }
|
return match }
|
||||||
@ -629,12 +630,14 @@ Configuration:
|
|||||||
return list = library.getMediaFilesWhere(
|
return list = library.getMediaFilesWhere(
|
||||||
playlistId: selection?.playlist?.id,
|
playlistId: selection?.playlist?.id,
|
||||||
artistId: selection?.artist?.id,
|
artistId: selection?.artist?.id,
|
||||||
albumId: selection?.album?.id) }
|
albumId: selection?.album?.id,
|
||||||
|
tags: selection?.tags) }
|
||||||
|
|
||||||
private String setSelection(Map s) {
|
private String select(Map s) {
|
||||||
['artist', 'album', 'playlist', 'file', 'tags'].each {
|
['artist', 'album', 'playlist', 'file', 'tags'].each {
|
||||||
this.selection[it] = s[it] }
|
this.selection[it] = s[it] }
|
||||||
resetStatus()
|
resetStatus()
|
||||||
|
return selection
|
||||||
}
|
}
|
||||||
|
|
||||||
private String resetStatus() {
|
private String resetStatus() {
|
||||||
|
Loading…
Reference in New Issue
Block a user