added automatic tags
This commit is contained in:
parent
60930e5d5c
commit
717b5b7dc0
10
app.moon
10
app.moon
@ -21,6 +21,14 @@ class extends lapis.Application
|
|||||||
POST: =>
|
POST: =>
|
||||||
if @track = Tracks\find id: tonumber @params.id
|
if @track = Tracks\find id: tonumber @params.id
|
||||||
updates = {}
|
updates = {}
|
||||||
|
-- automatic tags
|
||||||
|
for field in *{"artist", "mood", "link", "genre"}
|
||||||
|
if @params[field]
|
||||||
|
if @params.tags
|
||||||
|
@params.tags ..= " #{field}:#{@params[field]}"
|
||||||
|
else
|
||||||
|
@params.tags = "#{field}:#{@params[field]}"
|
||||||
|
-- update all fields
|
||||||
for field in pairs Tracks.fields
|
for field in pairs Tracks.fields
|
||||||
if @params[field]
|
if @params[field]
|
||||||
switch field
|
switch field
|
||||||
@ -29,7 +37,6 @@ class extends lapis.Application
|
|||||||
when "quality"
|
when "quality"
|
||||||
updates.quality = Tracks.qualities\for_db tonumber(@params.quality) or @params.quality
|
updates.quality = Tracks.qualities\for_db tonumber(@params.quality) or @params.quality
|
||||||
when "tags"
|
when "tags"
|
||||||
-- TODO automatic tags -> artist:Artist, mood:Mood, link:Link, genre:Genre
|
|
||||||
updates.tags = process_tags @params.tags
|
updates.tags = process_tags @params.tags
|
||||||
when "id"
|
when "id"
|
||||||
nil -- IDs cannot be modified
|
nil -- IDs cannot be modified
|
||||||
@ -41,7 +48,6 @@ class extends lapis.Application
|
|||||||
return redirect_to: @url_for "tracks"
|
return redirect_to: @url_for "tracks"
|
||||||
}
|
}
|
||||||
|
|
||||||
-- TODO figure out why [%u] character class does not work
|
|
||||||
[tracks: "/tracks(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
|
[tracks: "/tracks(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
|
||||||
-- validate order field
|
-- validate order field
|
||||||
@order = tostring(@params.order)\lower!
|
@order = tostring(@params.order)\lower!
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import create_table, rename_column, add_column, types from require "lapis.db.schema"
|
import create_table, rename_column, add_column, types from require "lapis.db.schema"
|
||||||
|
import trim from require "lapis.util"
|
||||||
|
import process_tags from require "helpers"
|
||||||
|
import Tracks from require "models"
|
||||||
|
|
||||||
{
|
{
|
||||||
[1]: =>
|
[1]: =>
|
||||||
@ -23,4 +26,13 @@ import create_table, rename_column, add_column, types from require "lapis.db.sch
|
|||||||
{ "mood", types.text null: true }
|
{ "mood", types.text null: true }
|
||||||
}
|
}
|
||||||
add_column "tracks", unpack column
|
add_column "tracks", unpack column
|
||||||
|
[3]: =>
|
||||||
|
for track in *Tracks\select "*"
|
||||||
|
tags = ""
|
||||||
|
for field in *{"artist", "mood", "link", "genre"}
|
||||||
|
if track[field]
|
||||||
|
tags ..= " #{field}:#{track[field]}"
|
||||||
|
if #tags > 0
|
||||||
|
track.tags = process_tags trim(track.tags or "untagged") .. tags
|
||||||
|
track\update "tags"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user