some little fix-ups and notes

This commit is contained in:
Tangent 2019-04-17 23:43:26 -07:00
parent b6d377f687
commit ff91406536
4 changed files with 70 additions and 49 deletions

View File

@ -13,6 +13,8 @@ class extends lapis.Application
[track: "/track/:id[%d]"]: respond_to { [track: "/track/:id[%d]"]: respond_to {
GET: => GET: =>
if @track = Tracks\find id: tonumber @params.id if @track = Tracks\find id: tonumber @params.id
@next = @track\next!
@previous = @track\previous!
return render: true return render: true
else else
return redirect_to: @url_for "tracks" return redirect_to: @url_for "tracks"
@ -23,16 +25,17 @@ class extends lapis.Application
if @params[field] if @params[field]
switch field switch field
when "status" when "status"
updates.status = Tracks.statuses\for_db @params.status updates.status = Tracks.statuses\for_db tonumber(@params.status) or @params.status
when "quality" when "quality"
updates.quality = Tracks.qualities\for_db @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
else else
updates[field] = trim @params[field] updates[field] = trim @params[field]
track\update updates @track\update updates
return redirect_to: @url_for "track", id: @track.id return redirect_to: @url_for "track", id: @track.id
else else
return redirect_to: @url_for "tracks" return redirect_to: @url_for "tracks"
@ -74,15 +77,15 @@ class extends lapis.Application
track = Tracks\find id: @params.id track = Tracks\find id: @params.id
track\update { track\update {
artist: @params.artist artist: @params.artist
name: @params.name title: @params.title
url: @params.url link: @params.link
status: tonumber @params.status status: tonumber @params.status
} }
else else
Tracks\create { Tracks\create {
artist: @params.artist artist: @params.artist
name: @params.name title: @params.title
url: @params.url link: @params.link
status: @params.status status: @params.status
} }
redirect_to: @url_for "index", page: @params.page redirect_to: @url_for "index", page: @params.page

View File

@ -1,6 +1,11 @@
import Model, enum from require "lapis.db.model" import Model, enum from require "lapis.db.model"
class Tracks extends 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 { @statuses: enum {
new: 1 new: 1
downloaded: 2 downloaded: 2

View File

@ -5,49 +5,60 @@ import trim from require "lapis.util"
import Tracks from require "models" import Tracks from require "models"
class extends Widget class extends Widget
menu: =>
div ->
if @previous
a href: @url_for("track", id: @previous.id), "<"
raw "&nbsp;"
if @next
a href: @url_for("track", id: @next.id), ">"
content: => content: =>
form { @menu!
action: @url_for "track", id: @track.id div ->
method: "POST" form {
enctype: "multipart/form" action: @url_for "track", id: @track.id
}, -> method: "POST"
text "Artist: " enctype: "multipart/form"
input type: "text", name: "artist", value: @track.artist, placeholder: "Artist" }, ->
text " Title: " text "Artist: "
input type: "text", name: "title", value: @track.title, placeholder: "Title" input type: "text", name: "artist", value: @track.artist, placeholder: "Artist"
br! text " Title: "
input type: "text", name: "title", value: @track.title, placeholder: "Title"
br!
text "Album: " text "Album: "
input type: "text", name: "album", value: @track.album, placeholder: "Album" input type: "text", name: "album", value: @track.album, placeholder: "Album"
text " Link: " text " Link: "
input type: "text", name: "link", value: @track.link, placeholder: "Link" input type: "text", name: "link", value: @track.link, placeholder: "Link"
br! br!
text "Status: " text "Status: "
element "select", name: "status", -> element "select", name: "status", ->
statuses = Tracks.statuses statuses = Tracks.statuses
for status in *statuses for status in *statuses
if status == statuses[@track.status] if status == statuses[@track.status]
option value: statuses[status], selected: true, status option value: statuses[status], selected: true, status
else else
option value: statuses[status], status option value: statuses[status], status
text " Quality: " text " Quality: "
element "select", name: "quality", -> element "select", name: "quality", ->
qualities = Tracks.qualities qualities = Tracks.qualities
for quality in *qualities for quality in *qualities
if quality == qualities[@track.quality] if quality == qualities[@track.quality]
option value: qualities[quality], selected: true, quality option value: qualities[quality], selected: true, quality
else else
option value: qualities[quality], quality option value: qualities[quality], quality
br! br!
text "Genre: " text "Genre: "
input type: "text", name: "genre", value: @track.genre, placeholder: "Genre" input type: "text", name: "genre", value: @track.genre, placeholder: "Genre"
text " Mood: " text " Mood: "
input type: "text", name: "mood", value: @track.mood, placeholder: "Mood" input type: "text", name: "mood", value: @track.mood, placeholder: "Mood"
br! br!
text "Tags: " text "Tags: "
input type: "text", name: "tags", value: trim(@track.tags), placeholder: "untagged" input type: "text", name: "tags", value: trim(@track.tags), placeholder: "untagged"
br! br!
input type: "submit", value: "Update" input type: "submit", value: "Update"
@menu!

View File

@ -14,6 +14,7 @@ class extends Widget
a href: @url_for("tracks", order: @order, asc_desc: @asc_desc, page: @page + 1), ">" a href: @url_for("tracks", order: @order, asc_desc: @asc_desc, page: @page + 1), ">"
raw "&nbsp;" raw "&nbsp;"
a href: @url_for("tracks", order: @order, asc_desc: @asc_desc, page: @last_page), ">>" a href: @url_for("tracks", order: @order, asc_desc: @asc_desc, page: @last_page), ">>"
content: => content: =>
@menu! @menu!
div -> div ->
@ -30,7 +31,8 @@ class extends Widget
for track in *@tracks for track in *@tracks
tr -> tr ->
td track.title td ->
a href: @url_for("track", id: track.id), track.title
td track.artist td track.artist
td track.genre td track.genre
td track.mood td track.mood