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