make update_tracks create & update tracks
This commit is contained in:
parent
db60d9c4b8
commit
50dbfd50ed
55
helpers.moon
55
helpers.moon
@ -13,38 +13,37 @@ 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+", "_"}"
|
||||||
user_input.tags ..= " #{field}:#{user_input[field]\gsub "%s*", "_"}" -- NOTE fix!
|
else
|
||||||
|
user_input.tags = "#{field}:#{user_input[field]\gsub "%s+", "_"}"
|
||||||
|
-- update all fields
|
||||||
|
for field in pairs Tracks.fields
|
||||||
|
if user_input[field]
|
||||||
|
switch field
|
||||||
|
when "status"
|
||||||
|
updates.status = Tracks.statuses\for_db user_input.status
|
||||||
|
when "quality"
|
||||||
|
updates.quality = Tracks.qualities\for_db user_input.quality
|
||||||
|
when "tags"
|
||||||
|
updates.tags = process_tags user_input.tags
|
||||||
|
when "id"
|
||||||
|
nil -- IDs cannot be modified
|
||||||
else
|
else
|
||||||
user_input.tags = "#{field}:#{user_input[field]\gsub "%s*", "_"}"
|
updates[field] = trim user_input[field]
|
||||||
-- update all fields
|
|
||||||
for field in pairs Tracks.fields
|
|
||||||
if user_input[field]
|
|
||||||
switch field
|
|
||||||
when "status"
|
|
||||||
updates.status = Tracks.statuses\for_db user_input.status
|
|
||||||
when "quality"
|
|
||||||
updates.quality = Tracks.qualities\for_db user_input.quality
|
|
||||||
when "tags"
|
|
||||||
updates.tags = process_tags user_input.tags
|
|
||||||
when "id"
|
|
||||||
nil -- IDs cannot be modified
|
|
||||||
else
|
|
||||||
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