added track edit pages
This commit is contained in:
parent
f24c00d517
commit
b6d377f687
32
app.moon
32
app.moon
@ -2,11 +2,42 @@ lapis = require "lapis"
|
|||||||
console = require "lapis.console"
|
console = require "lapis.console"
|
||||||
|
|
||||||
import respond_to from require "lapis.application"
|
import respond_to from require "lapis.application"
|
||||||
|
import trim from require "lapis.util"
|
||||||
|
import process_tags from require "helpers"
|
||||||
|
|
||||||
import Tracks from require "models"
|
import Tracks from require "models"
|
||||||
|
|
||||||
class extends lapis.Application
|
class extends lapis.Application
|
||||||
"/console": console.make!
|
"/console": console.make!
|
||||||
|
|
||||||
|
[track: "/track/:id[%d]"]: respond_to {
|
||||||
|
GET: =>
|
||||||
|
if @track = Tracks\find id: tonumber @params.id
|
||||||
|
return render: true
|
||||||
|
else
|
||||||
|
return redirect_to: @url_for "tracks"
|
||||||
|
POST: =>
|
||||||
|
if @track = Tracks\find id: tonumber @params.id
|
||||||
|
updates = {}
|
||||||
|
for field in pairs Tracks.fields
|
||||||
|
if @params[field]
|
||||||
|
switch field
|
||||||
|
when "status"
|
||||||
|
updates.status = Tracks.statuses\for_db @params.status
|
||||||
|
when "quality"
|
||||||
|
updates.quality = Tracks.qualities\for_db @params.quality
|
||||||
|
when "tags"
|
||||||
|
updates.tags = process_tags @params.tags
|
||||||
|
when "id"
|
||||||
|
nil -- IDs cannot be modified
|
||||||
|
else
|
||||||
|
updates[field] = trim @params[field]
|
||||||
|
track\update updates
|
||||||
|
return redirect_to: @url_for "track", id: @track.id
|
||||||
|
else
|
||||||
|
return redirect_to: @url_for "tracks"
|
||||||
|
}
|
||||||
|
|
||||||
-- TODO figure out why [%u] character class does not work
|
-- 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
|
||||||
@ -31,6 +62,7 @@ class extends lapis.Application
|
|||||||
@tracks = tracks\get_page @page
|
@tracks = tracks\get_page @page
|
||||||
return render: true
|
return render: true
|
||||||
|
|
||||||
|
-- NOTE deprecated
|
||||||
[index: "/(:page[%d])"]: respond_to {
|
[index: "/(:page[%d])"]: respond_to {
|
||||||
GET: =>
|
GET: =>
|
||||||
tracks = Tracks\paginated "* ORDER BY id", per_page: 32
|
tracks = Tracks\paginated "* ORDER BY id", per_page: 32
|
||||||
|
17
helpers.moon
Normal file
17
helpers.moon
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
process_tags = (tags_str) ->
|
||||||
|
-- split into a table to garuntee uniqueness
|
||||||
|
unique = {}
|
||||||
|
for tag in tags_str\gmatch "%S+"
|
||||||
|
unique[tag] = 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, " "} "
|
||||||
|
|
||||||
|
return {
|
||||||
|
:process_tags
|
||||||
|
}
|
@ -31,4 +31,5 @@ class Tracks extends Model
|
|||||||
genre: true
|
genre: true
|
||||||
tags: true
|
tags: true
|
||||||
quality: true
|
quality: true
|
||||||
|
mood: true
|
||||||
}
|
}
|
||||||
|
53
views/track.moon
Normal file
53
views/track.moon
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
import Widget from require "lapis.html"
|
||||||
|
|
||||||
|
import trim from require "lapis.util"
|
||||||
|
|
||||||
|
import Tracks from require "models"
|
||||||
|
|
||||||
|
class extends Widget
|
||||||
|
content: =>
|
||||||
|
form {
|
||||||
|
action: @url_for "track", id: @track.id
|
||||||
|
method: "POST"
|
||||||
|
enctype: "multipart/form"
|
||||||
|
}, ->
|
||||||
|
text "Artist: "
|
||||||
|
input type: "text", name: "artist", value: @track.artist, placeholder: "Artist"
|
||||||
|
text " Title: "
|
||||||
|
input type: "text", name: "title", value: @track.title, placeholder: "Title"
|
||||||
|
br!
|
||||||
|
|
||||||
|
text "Album: "
|
||||||
|
input type: "text", name: "album", value: @track.album, placeholder: "Album"
|
||||||
|
text " Link: "
|
||||||
|
input type: "text", name: "link", value: @track.link, placeholder: "Link"
|
||||||
|
br!
|
||||||
|
|
||||||
|
text "Status: "
|
||||||
|
element "select", name: "status", ->
|
||||||
|
statuses = Tracks.statuses
|
||||||
|
for status in *statuses
|
||||||
|
if status == statuses[@track.status]
|
||||||
|
option value: statuses[status], selected: true, status
|
||||||
|
else
|
||||||
|
option value: statuses[status], status
|
||||||
|
text " Quality: "
|
||||||
|
element "select", name: "quality", ->
|
||||||
|
qualities = Tracks.qualities
|
||||||
|
for quality in *qualities
|
||||||
|
if quality == qualities[@track.quality]
|
||||||
|
option value: qualities[quality], selected: true, quality
|
||||||
|
else
|
||||||
|
option value: qualities[quality], quality
|
||||||
|
br!
|
||||||
|
|
||||||
|
text "Genre: "
|
||||||
|
input type: "text", name: "genre", value: @track.genre, placeholder: "Genre"
|
||||||
|
text " Mood: "
|
||||||
|
input type: "text", name: "mood", value: @track.mood, placeholder: "Mood"
|
||||||
|
br!
|
||||||
|
|
||||||
|
text "Tags: "
|
||||||
|
input type: "text", name: "tags", value: trim(@track.tags), placeholder: "untagged"
|
||||||
|
br!
|
||||||
|
input type: "submit", value: "Update"
|
Reference in New Issue
Block a user