From ff91406536c4a04798b209621be2e0b1aefad95f Mon Sep 17 00:00:00 2001 From: Tangent Date: Wed, 17 Apr 2019 23:43:26 -0700 Subject: [PATCH] some little fix-ups and notes --- app.moon | 17 +++++---- models/Tracks.moon | 5 +++ views/track.moon | 93 ++++++++++++++++++++++++++-------------------- views/tracks.moon | 4 +- 4 files changed, 70 insertions(+), 49 deletions(-) diff --git a/app.moon b/app.moon index 7f1c253..6c854ef 100644 --- a/app.moon +++ b/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 diff --git a/models/Tracks.moon b/models/Tracks.moon index c9dd58d..dab8d7d 100644 --- a/models/Tracks.moon +++ b/models/Tracks.moon @@ -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 diff --git a/views/track.moon b/views/track.moon index bcb7148..ac42a1e 100644 --- a/views/track.moon +++ b/views/track.moon @@ -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! diff --git a/views/tracks.moon b/views/tracks.moon index b1c4aa1..129c2fb 100644 --- a/views/tracks.moon +++ b/views/tracks.moon @@ -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