close #7 and make tags all lowercase

This commit is contained in:
Tangent 2019-06-14 17:47:18 -07:00
parent a2249a48a3
commit b0be6d6b6e
2 changed files with 13 additions and 3 deletions

View File

@ -2,14 +2,12 @@ process_tags = (tags_str) ->
-- split into a table to garuntee uniqueness
unique = {}
for tag in tags_str\gmatch "%S+"
unique[tag] = true
unique[tag\lower!] = true
-- place back into an array
taglist = {}
for tag in pairs unique
table.insert taglist, tag
-- sort case-sensitively and then case-insensitively (so capitalized tags appear before their uncapitalized counterparts)
table.sort taglist
table.sort taglist, (a, b) -> a\lower! < b\lower!
return " #{table.concat taglist, " "} "
update_track = (user_input) ->

View File

@ -27,6 +27,7 @@ import Tracks from require "models"
}
add_column "tracks", unpack column
[3]: =>
-- NOTE: bad migration!
for track in *Tracks\select "*"
tags = ""
for field in *{"artist", "mood", "link", "genre"}
@ -35,4 +36,15 @@ import Tracks from require "models"
if #tags > 0
track.tags = process_tags trim(track.tags or "untagged") .. tags
track\update "tags"
[4]: =>
-- WARNING: removes all tags!
for track in *Tracks\select "*"
tags = ""
for field in *{"artist", "mood", "link", "genre"}
if track[field] and #track[field] > 0
tags ..= " #{field}:#{track[field]}"
if #tags > 0
track.tags = process_tags "untagged" .. tags
else
track.tags = " untagged "
}