make update_tracks create & update tracks
This commit is contained in:
parent
db60d9c4b8
commit
50dbfd50ed
17
helpers.moon
17
helpers.moon
@ -13,15 +13,14 @@ process_tags = (tags_str) ->
|
|||||||
return " #{table.concat taglist, " "} "
|
return " #{table.concat taglist, " "} "
|
||||||
|
|
||||||
update_track = (user_input) ->
|
update_track = (user_input) ->
|
||||||
if track = Tracks\find id: tonumber @params.id
|
|
||||||
updates = {}
|
updates = {}
|
||||||
-- automatic tags
|
-- automatic tags
|
||||||
for field in *{"artist", "mood", "link", "genre"}
|
for field in *{"artist", "mood", "link", "genre"}
|
||||||
if user_input[field] and #user_input[field] > 0 -- NOTE includes fix
|
if user_input[field] and #user_input[field] > 0 -- NOTE includes fix
|
||||||
if user_input.tags
|
if user_input.tags
|
||||||
user_input.tags ..= " #{field}:#{user_input[field]\gsub "%s*", "_"}" -- NOTE fix!
|
user_input.tags ..= " #{field}:#{user_input[field]\gsub "%s+", "_"}"
|
||||||
else
|
else
|
||||||
user_input.tags = "#{field}:#{user_input[field]\gsub "%s*", "_"}"
|
user_input.tags = "#{field}:#{user_input[field]\gsub "%s+", "_"}"
|
||||||
-- update all fields
|
-- update all fields
|
||||||
for field in pairs Tracks.fields
|
for field in pairs Tracks.fields
|
||||||
if user_input[field]
|
if user_input[field]
|
||||||
@ -36,15 +35,15 @@ update_track = (user_input) ->
|
|||||||
nil -- IDs cannot be modified
|
nil -- IDs cannot be modified
|
||||||
else
|
else
|
||||||
updates[field] = trim user_input[field]
|
updates[field] = trim user_input[field]
|
||||||
track\update updates
|
|
||||||
|
|
||||||
create_track = (user_input) ->
|
if user_input.id
|
||||||
if track = Tracks\create({})
|
if track = Tracks\find id: tonumber user_input.id
|
||||||
user_input.id = track.id
|
return track\update updates
|
||||||
update_track user_input
|
else
|
||||||
|
return Tracks\create updates
|
||||||
|
|
||||||
return {
|
return {
|
||||||
:process_tags
|
:process_tags
|
||||||
:update_track
|
:update_track
|
||||||
:create_track
|
create_track: update_track
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user