some little fix-ups and notes
This commit is contained in:
parent
b6d377f687
commit
ff91406536
17
app.moon
17
app.moon
@ -13,6 +13,8 @@ class extends lapis.Application
|
||||
[track: "/track/:id[%d]"]: respond_to {
|
||||
GET: =>
|
||||
if @track = Tracks\find id: tonumber @params.id
|
||||
@next = @track\next!
|
||||
@previous = @track\previous!
|
||||
return render: true
|
||||
else
|
||||
return redirect_to: @url_for "tracks"
|
||||
@ -23,16 +25,17 @@ class extends lapis.Application
|
||||
if @params[field]
|
||||
switch field
|
||||
when "status"
|
||||
updates.status = Tracks.statuses\for_db @params.status
|
||||
updates.status = Tracks.statuses\for_db tonumber(@params.status) or @params.status
|
||||
when "quality"
|
||||
updates.quality = Tracks.qualities\for_db @params.quality
|
||||
updates.quality = Tracks.qualities\for_db tonumber(@params.quality) or @params.quality
|
||||
when "tags"
|
||||
-- TODO automatic tags -> artist:Artist, mood:Mood, link:Link, genre:Genre
|
||||
updates.tags = process_tags @params.tags
|
||||
when "id"
|
||||
nil -- IDs cannot be modified
|
||||
else
|
||||
updates[field] = trim @params[field]
|
||||
track\update updates
|
||||
@track\update updates
|
||||
return redirect_to: @url_for "track", id: @track.id
|
||||
else
|
||||
return redirect_to: @url_for "tracks"
|
||||
@ -74,15 +77,15 @@ class extends lapis.Application
|
||||
track = Tracks\find id: @params.id
|
||||
track\update {
|
||||
artist: @params.artist
|
||||
name: @params.name
|
||||
url: @params.url
|
||||
title: @params.title
|
||||
link: @params.link
|
||||
status: tonumber @params.status
|
||||
}
|
||||
else
|
||||
Tracks\create {
|
||||
artist: @params.artist
|
||||
name: @params.name
|
||||
url: @params.url
|
||||
title: @params.title
|
||||
link: @params.link
|
||||
status: @params.status
|
||||
}
|
||||
redirect_to: @url_for "index", page: @params.page
|
||||
|
@ -1,6 +1,11 @@
|
||||
import Model, enum from require "lapis.db.model"
|
||||
|
||||
class Tracks extends Model
|
||||
next: =>
|
||||
return @select("WHERE id < ? ORDER BY id DESC LIMIT 1", @id)[1]
|
||||
previous: =>
|
||||
return @select("WHERE id > ? ORDER BY id ASC LIMIT 1", @id)[1]
|
||||
|
||||
@statuses: enum {
|
||||
new: 1
|
||||
downloaded: 2
|
||||
|
@ -5,49 +5,60 @@ import trim from require "lapis.util"
|
||||
import Tracks from require "models"
|
||||
|
||||
class extends Widget
|
||||
menu: =>
|
||||
div ->
|
||||
if @previous
|
||||
a href: @url_for("track", id: @previous.id), "<"
|
||||
raw " "
|
||||
if @next
|
||||
a href: @url_for("track", id: @next.id), ">"
|
||||
|
||||
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!
|
||||
@menu!
|
||||
div ->
|
||||
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 "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 "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 "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"
|
||||
text "Tags: "
|
||||
input type: "text", name: "tags", value: trim(@track.tags), placeholder: "untagged"
|
||||
br!
|
||||
input type: "submit", value: "Update"
|
||||
@menu!
|
||||
|
@ -14,6 +14,7 @@ class extends Widget
|
||||
a href: @url_for("tracks", order: @order, asc_desc: @asc_desc, page: @page + 1), ">"
|
||||
raw " "
|
||||
a href: @url_for("tracks", order: @order, asc_desc: @asc_desc, page: @last_page), ">>"
|
||||
|
||||
content: =>
|
||||
@menu!
|
||||
div ->
|
||||
@ -30,7 +31,8 @@ class extends Widget
|
||||
|
||||
for track in *@tracks
|
||||
tr ->
|
||||
td track.title
|
||||
td ->
|
||||
a href: @url_for("track", id: track.id), track.title
|
||||
td track.artist
|
||||
td track.genre
|
||||
td track.mood
|
||||
|
Reference in New Issue
Block a user