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,7 +5,17 @@ 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: =>
|
||||
@menu!
|
||||
div ->
|
||||
form {
|
||||
action: @url_for "track", id: @track.id
|
||||
method: "POST"
|
||||
@ -51,3 +61,4 @@ class extends Widget
|
||||
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