adding new fields

This commit is contained in:
Tangent 2019-04-17 22:08:09 -07:00
parent fa367a28f1
commit 10a66adb7c
8 changed files with 109 additions and 9 deletions

1
.gitignore vendored
View File

@ -2,4 +2,5 @@
*_temp/ *_temp/
logs/ logs/
import/ import/
static/links/
nginx.conf.compiled nginx.conf.compiled

View File

@ -7,6 +7,25 @@ import Tracks from require "models"
class extends lapis.Application class extends lapis.Application
"/console": console.make! "/console": console.make!
[tracks: "/tracks(/:order[%a])(/:asc_desc[%u])(/:page[%d])"]: =>
@order = tostring(@params.order)\lower!
-- validate order field
@order = "id" unless Tracks.fields[@order]
@asc_desc = tostring(@params.asc_desc)\upper!
-- descending or ascending only, ascending default
@asc_desc = "ASC" if @asc_desc != "DESC"
@page = tonumber(@params.page) or 1
tracks = Tracks\paginated "* ORDER BY ? ?", @order, @asc_desc, per_page: 32
@last_page = tracks\num_pages!
-- validate page
if @page < 1
return redirect_to: @url_for "tracks", order: @order, asc_desc: @asc_desc, page: 1
if @page > @last_page
return redirect_to: @url_for "tracks", order: @order, asc_desc: @asc_desc, page: @last_page
@tracks = tracks\get_page @page
return render: true
[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

0
import/.nomedia Normal file
View File

View File

@ -1,4 +1,4 @@
import create_table, types from require "lapis.db.schema" import create_table, rename_column, add_column, types from require "lapis.db.schema"
{ {
[1]: => [1]: =>
@ -9,4 +9,18 @@ import create_table, types from require "lapis.db.schema"
{ "url", types.text null: true } { "url", types.text null: true }
{ "status", types.integer default: 1 } { "status", types.integer default: 1 }
} }
[2]: =>
rename_column "tracks", "name", "title"
rename_column "tracks", "url", "link"
for column in *{
{ "art_url", types.text null: true }
{ "file_url", types.text null: true }
{ "file_size", types.integer null: true }
{ "album", types.text null: true }
{ "genre", types.text null: true }
{ "tags", types.text default: " untagged " }
{ "quality", types.integer default: 1 }
{ "mood", types.text null: true }
}
add_column "tracks", unpack column
} }

View File

@ -9,3 +9,26 @@ class Tracks extends Model
ignored: 5 ignored: 5
imported: 6 imported: 6
} }
@qualities: enum {
not_available: 1
lossless: 2
high: 3
acceptable: 4
low: 5
unacceptable: 6
}
@fields = {
id: true
artist: true
title: true
link: true
status: true
art_url: true
file_url: true
file_size: true
album: true
genre: true
tags: true
quality: true
}

0
static/links/.nomedia Normal file
View File

View File

@ -11,8 +11,8 @@ class extends Widget
element "table", -> element "table", ->
tr -> tr ->
th "Artist" th "Artist"
th "Name" th "Title"
th "URL" th "Link"
th "Status" th "Status"
th "✓" th "✓"
@ -24,14 +24,14 @@ class extends Widget
enctype: "multipart/form-data" enctype: "multipart/form-data"
}, -> }, ->
td -> input type: "text", name: "artist", value: track.artist td -> input type: "text", name: "artist", value: track.artist
td -> input type: "text", name: "name", value: track.name td -> input type: "text", name: "title", value: track.title
td -> td ->
if track.url and #track.url > 0 if track.link and #track.link > 0
a href: track.url, "*" a href: track.link, "*"
else else
text "+" text "+"
text " " text " "
input type: "text", name: "url", value: track.url input type: "text", name: "link", value: track.link
td -> td ->
element "select", name: "status", -> element "select", name: "status", ->
for status in *Tracks.statuses for status in *Tracks.statuses
@ -50,10 +50,10 @@ class extends Widget
enctype: "multipart/form-data" enctype: "multipart/form-data"
}, -> }, ->
td -> input type: "text", name: "artist", placeholder: "artist" td -> input type: "text", name: "artist", placeholder: "artist"
td -> input type: "text", name: "name", placeholder: "name" td -> input type: "text", name: "title", placeholder: "title"
td -> td ->
raw "&nbsp;&nbsp;&nbsp;" raw "&nbsp;&nbsp;&nbsp;"
input type: "text", name: "url", placeholder: "url" input type: "text", name: "link", placeholder: "link"
td -> td ->
element "select", name: "status", -> element "select", name: "status", ->
for status in *Tracks.statuses for status in *Tracks.statuses

43
views/tracks.moon Normal file
View File

@ -0,0 +1,43 @@
import Widget from require "lapis.html"
import Tracks from require "models"
class extends Widget
@menu: =>
div ->
if @page != 1
a href: @url_for("tracks", order: @order, asc_desc: @asc_desc, page: 1), "<<"
raw "&nbsp;"
a href: @url_for("tracks", order: @order, asc_desc: @asc_desc, page: @page - 1), "<"
raw "&nbsp;"
if @page != @last_page
a href: @url_for("tracks", order: @order, asc_desc: @asc_desc, page: @page + 1), ">"
raw "&nbsp;"
a href: @url_for("tracks", order: @order, asc_desc: @asc_desc, page: @last_page), ">>"
content: =>
@menu!
div ->
element "table", ->
tr ->
th "Title"
th "Artist"
th "Genre"
th "Mood"
th "Album"
th "Link"
th "Status"
th "Quality"
for track in *@tracks
tr ->
td track.title
td track.artist
td track.genre
td track.mood
td track.album
td ->
if track.link and #track.link > 0
a href: track.link, track.link
td Tracks.statuses[track.status]
td Tracks.qualities[track.quality]
@menu!