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, " "} "
|
||||
|
||||
update_track = (user_input) ->
|
||||
if track = Tracks\find id: tonumber @params.id
|
||||
updates = {}
|
||||
-- automatic tags
|
||||
for field in *{"artist", "mood", "link", "genre"}
|
||||
if user_input[field] and #user_input[field] > 0 -- NOTE includes fix
|
||||
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
|
||||
user_input.tags = "#{field}:#{user_input[field]\gsub "%s*", "_"}"
|
||||
user_input.tags = "#{field}:#{user_input[field]\gsub "%s+", "_"}"
|
||||
-- update all fields
|
||||
for field in pairs Tracks.fields
|
||||
if user_input[field]
|
||||
@ -36,15 +35,15 @@ update_track = (user_input) ->
|
||||
nil -- IDs cannot be modified
|
||||
else
|
||||
updates[field] = trim user_input[field]
|
||||
track\update updates
|
||||
|
||||
create_track = (user_input) ->
|
||||
if track = Tracks\create({})
|
||||
user_input.id = track.id
|
||||
update_track user_input
|
||||
if user_input.id
|
||||
if track = Tracks\find id: tonumber user_input.id
|
||||
return track\update updates
|
||||
else
|
||||
return Tracks\create updates
|
||||
|
||||
return {
|
||||
:process_tags
|
||||
:update_track
|
||||
:create_track
|
||||
create_track: update_track
|
||||
}
|
||||
|
Reference in New Issue
Block a user