tag pages
- fixed broken links to them - ADDED them - escape_tag helper - new view - closing #4
This commit is contained in:
parent
4cede883c5
commit
35e7e68756
32
app.moon
32
app.moon
@ -3,7 +3,8 @@ console = require "lapis.console"
|
|||||||
|
|
||||||
import respond_to from require "lapis.application"
|
import respond_to from require "lapis.application"
|
||||||
import escape_identifier from require "lapis.db"
|
import escape_identifier from require "lapis.db"
|
||||||
import create_track, update_track from require "helpers"
|
import unescape from require "lapis.util"
|
||||||
|
import create_track, update_track, escape_tag from require "helpers"
|
||||||
|
|
||||||
import Tracks, Tags from require "models"
|
import Tracks, Tags from require "models"
|
||||||
|
|
||||||
@ -50,17 +51,36 @@ class extends lapis.Application
|
|||||||
@tracks = tracks\get_page(@page)
|
@tracks = tracks\get_page(@page)
|
||||||
return render: true
|
return render: true
|
||||||
|
|
||||||
[tag: "/tag/:name(/:asc_desc)(/:page[%d])"]: =>
|
[tag: "/tag/:name(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
|
||||||
-- SHOULD GRAB A GROUP OF TRACKS AND PAGINATE THEM
|
-- validate order
|
||||||
-- REPURPOSE THE TRACKS VIEW TO BE USABLE ON ANY PAGE
|
@order = tostring(@params.order)\lower!
|
||||||
@write "Haven't made this yet!"
|
unless Tags.fields[@order]
|
||||||
|
@order = "id"
|
||||||
|
-- validate ascending/descending
|
||||||
|
@asc_desc = tostring(@params.asc_desc)\upper!
|
||||||
|
if @asc_desc != "DESC" and @asc_desc != "ASC"
|
||||||
|
@asc_desc = "ASC"
|
||||||
|
@page = tonumber(@params.page) or 1
|
||||||
|
|
||||||
|
tracks = Tracks\paginated "WHERE tags LIKE ? ORDER BY #{escape_identifier @order} #{@asc_desc}", escape_tag(unescape(@params.name)), per_page: 32
|
||||||
|
@last_page = 1
|
||||||
|
if tag = Tags\find(:name)
|
||||||
|
@last_page = 1 + math.floor tag.count / 32
|
||||||
|
-- validate page
|
||||||
|
if @page < 1
|
||||||
|
return redirect_to: @url_for "tag", name: @params.name, order: @order, asc_desc: @asc_desc, page: 1
|
||||||
|
if @page > @last_page
|
||||||
|
return redirect_to: @url_for "tag", name: @params.name, order: @order, asc_desc: @asc_desc, page: @last_page
|
||||||
|
|
||||||
|
@tracks = tags\get_page(@page)
|
||||||
|
return render: true
|
||||||
|
|
||||||
[tags: "/tags(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
|
[tags: "/tags(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
|
||||||
-- validate order
|
-- validate order
|
||||||
@order = tostring(@params.order)\lower!
|
@order = tostring(@params.order)\lower!
|
||||||
unless Tags.fields[@order]
|
unless Tags.fields[@order]
|
||||||
@order = "count"
|
@order = "count"
|
||||||
-- validate ascending/descending (ascending default)
|
-- validate ascending/descending
|
||||||
@asc_desc = tostring(@params.asc_desc)\upper!
|
@asc_desc = tostring(@params.asc_desc)\upper!
|
||||||
if @asc_desc != "DESC" and @asc_desc != "ASC"
|
if @asc_desc != "DESC" and @asc_desc != "ASC"
|
||||||
@asc_desc = "DESC"
|
@asc_desc = "DESC"
|
||||||
|
@ -14,6 +14,9 @@ process_tags = (tags_str) ->
|
|||||||
table.sort taglist
|
table.sort taglist
|
||||||
return " #{table.concat taglist, " "} "
|
return " #{table.concat taglist, " "} "
|
||||||
|
|
||||||
|
escape_tag = (str) ->
|
||||||
|
return str\gsub "[%%_]", "\\%1"
|
||||||
|
|
||||||
update_track = (user_input) ->
|
update_track = (user_input) ->
|
||||||
updates = {}
|
updates = {}
|
||||||
-- automatic tags
|
-- automatic tags
|
||||||
@ -46,6 +49,7 @@ update_track = (user_input) ->
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
:process_tags
|
:process_tags
|
||||||
|
:escape_tag
|
||||||
:update_track
|
:update_track
|
||||||
create_track: update_track
|
create_track: update_track
|
||||||
}
|
}
|
||||||
|
81
views/tag.moon
Normal file
81
views/tag.moon
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
import Widget from require "lapis.html"
|
||||||
|
|
||||||
|
import trim from require "lapis.util"
|
||||||
|
import Tracks from require "models"
|
||||||
|
|
||||||
|
class extends Widget
|
||||||
|
menu: =>
|
||||||
|
div ->
|
||||||
|
element "table", ->
|
||||||
|
tr ->
|
||||||
|
if @page != 1
|
||||||
|
td ->
|
||||||
|
a href: @url_for("tag", name: @params.name, order: @order, asc_desc: @asc_desc, page: 1), "<<"
|
||||||
|
td ->
|
||||||
|
a href: @url_for("tag", name: @params.name, order: @order, asc_desc: @asc_desc, page: @page - 1), "<"
|
||||||
|
else
|
||||||
|
td "<<"
|
||||||
|
td "<"
|
||||||
|
if @page != @last_page
|
||||||
|
td ->
|
||||||
|
a href: @url_for("tag", name: @params.name, order: @order, asc_desc: @asc_desc, page: @page + 1), ">"
|
||||||
|
td ->
|
||||||
|
a href: @url_for("tag", name: @params.name, order: @order, asc_desc: @asc_desc, page: @last_page), ">>"
|
||||||
|
else
|
||||||
|
td ">"
|
||||||
|
td ">>"
|
||||||
|
|
||||||
|
content: =>
|
||||||
|
@menu!
|
||||||
|
div ->
|
||||||
|
element "table", ->
|
||||||
|
tr ->
|
||||||
|
th "Artist"
|
||||||
|
th "Title"
|
||||||
|
th "Album"
|
||||||
|
th "Genre"
|
||||||
|
th "Mood"
|
||||||
|
th "Link"
|
||||||
|
th "Status"
|
||||||
|
th "Quality"
|
||||||
|
th "✓"
|
||||||
|
th "Tags"
|
||||||
|
|
||||||
|
for track in *@tracks
|
||||||
|
tr class: Tracks.statuses[track.status], ->
|
||||||
|
form {
|
||||||
|
action: @url_for "tracks", order: @order, asc_desc: @asc_desc, page: @page
|
||||||
|
method: "POST"
|
||||||
|
enctype: "multipart/form-data"
|
||||||
|
}, ->
|
||||||
|
td -> input type: "text", name: "artist", value: track.artist
|
||||||
|
td -> input type: "text", name: "title", value: track.title
|
||||||
|
td -> input type: "text", name: "album", value: track.album
|
||||||
|
td -> input type: "text", name: "genre", value: track.genre
|
||||||
|
td -> input type: "text", name: "mood", value: track.mood
|
||||||
|
td ->
|
||||||
|
if track.link and #track.link > 0
|
||||||
|
a href: track.link, "*"
|
||||||
|
else
|
||||||
|
text "+"
|
||||||
|
text " "
|
||||||
|
input type: "text", name: "link", value: track.link
|
||||||
|
td ->
|
||||||
|
element "select", name: "status", ->
|
||||||
|
for status_name in *Tracks.statuses
|
||||||
|
if status_name == Tracks.statuses[track.status]
|
||||||
|
option value: Tracks.statuses[status_name], selected: true, status_name
|
||||||
|
else
|
||||||
|
option value: Tracks.statuses[status_name], status_name
|
||||||
|
td ->
|
||||||
|
element "select", name: "quality", ->
|
||||||
|
for quality_name in *Tracks.qualities
|
||||||
|
if quality_name == Tracks.qualities[track.quality]
|
||||||
|
option value: Tracks.qualities[quality_name], selected: true, quality_name
|
||||||
|
else
|
||||||
|
option value: Tracks.qualities[quality_name], quality_name
|
||||||
|
td ->
|
||||||
|
input type: "hidden", name: "id", value: track.id
|
||||||
|
input type: "submit", value: "Update"
|
||||||
|
td -> input type: "text", name: "tags", value: trim(track.tags)
|
||||||
|
@menu!
|
@ -1,5 +1,7 @@
|
|||||||
import Widget from require "lapis.html"
|
import Widget from require "lapis.html"
|
||||||
|
|
||||||
|
import escape from require "lapis.util"
|
||||||
|
|
||||||
class extends Widget
|
class extends Widget
|
||||||
menu: =>
|
menu: =>
|
||||||
div ->
|
div ->
|
||||||
@ -27,11 +29,11 @@ class extends Widget
|
|||||||
div ->
|
div ->
|
||||||
element "table", ->
|
element "table", ->
|
||||||
tr ->
|
tr ->
|
||||||
th "Tag"
|
|
||||||
th "Count"
|
th "Count"
|
||||||
|
th "Tag"
|
||||||
|
|
||||||
for tag in *@tags
|
for tag in *@tags
|
||||||
tr ->
|
tr ->
|
||||||
td -> a href: @url_for("tag", id: tag.id), tag.name
|
|
||||||
td tag.count
|
td tag.count
|
||||||
|
td -> a href: @url_for("tag", name: escape tag.name), tag.name
|
||||||
@menu!
|
@menu!
|
||||||
|
Reference in New Issue
Block a user