wip #4, missing tag pages themselves
This commit is contained in:
parent
c5556526b0
commit
4d91f73d31
31
app.moon
31
app.moon
@ -5,7 +5,7 @@ import respond_to from require "lapis.application"
|
||||
import escape_identifier from require "lapis.db"
|
||||
import create_track, update_track from require "helpers"
|
||||
|
||||
import Tracks from require "models"
|
||||
import Tracks, Tags from require "models"
|
||||
|
||||
class extends lapis.Application
|
||||
layout: "layout"
|
||||
@ -28,7 +28,7 @@ class extends lapis.Application
|
||||
|
||||
[tracks: "/tracks(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
|
||||
update_track(@params) if @params.id -- update a track if needed
|
||||
-- validate order field
|
||||
-- validate order
|
||||
@order = tostring(@params.order)\lower!
|
||||
unless Tracks.fields[@order]
|
||||
@order = "id"
|
||||
@ -49,6 +49,33 @@ class extends lapis.Application
|
||||
@tracks = tracks\get_page(@page)
|
||||
return render: true
|
||||
|
||||
[tag: "/tag/:name(/:asc_desc)(/:page[%d])"]: =>
|
||||
-- SHOULD GRAB A GROUP OF TRACKS AND PAGINATE THEM
|
||||
-- REPURPOSE THE TRACKS VIEW TO BE USABLE ON ANY PAGE
|
||||
@write "Haven't made this yet!"
|
||||
|
||||
[tags: "/tags(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
|
||||
-- validate order
|
||||
@order = tostring(@params.order)\lower!
|
||||
unless Tags.fields[@order]
|
||||
@order = "id"
|
||||
-- validate ascending/descending (ascending default)
|
||||
@asc_desc = tostring(@params.asc_desc)\upper!
|
||||
if @asc_desc != "DESC" and @asc_desc != "ASC"
|
||||
@asc_desc = "ASC"
|
||||
@page = tonumber(@params.page) or 1
|
||||
|
||||
tags = Tags\paginated "* ORDER BY #{escape_identifier @order} #{@asc_desc}", per_page: 32
|
||||
@last_page = 1 + math.floor Tags\count("true") / 32 -- copying from tracks since num_pages wasn't working then
|
||||
-- validate page
|
||||
if @page < 1
|
||||
return redirect_to: @url_for "tags", order: @order, asc_desc: @asc_desc, page: 1
|
||||
else
|
||||
return redirect_to: @url_for "tags", order: @order, asc_desc: @asc_desc, page: @last_page
|
||||
|
||||
@tags = tags\get_page(@page)
|
||||
return render: true
|
||||
|
||||
[new_track: "/new"]: respond_to {
|
||||
GET: => render: true
|
||||
POST: =>
|
||||
|
@ -8,3 +8,9 @@ class Tags extends Model
|
||||
-- link: 4
|
||||
-- genre: 5
|
||||
-- }
|
||||
|
||||
@fields = {
|
||||
id: true
|
||||
name: true
|
||||
count: true
|
||||
}
|
||||
|
37
views/tags.moon
Normal file
37
views/tags.moon
Normal file
@ -0,0 +1,37 @@
|
||||
import Widget from require "lapis.html"
|
||||
|
||||
class extends Widget
|
||||
menu: =>
|
||||
div ->
|
||||
element "table", ->
|
||||
tr ->
|
||||
if @page != 1
|
||||
td ->
|
||||
a href: @url_for("tags", order: @order, asc_desc: @asc_desc, page: 1), "<<"
|
||||
td ->
|
||||
a href: @url_for("tags", order: @order, asc_desc: @asc_desc, page: @page - 1), "<"
|
||||
else
|
||||
td "<<"
|
||||
td "<"
|
||||
if @page != @last_page
|
||||
td ->
|
||||
a href: @url_for("tags", order: @order, asc_desc: @asc_desc, page: @page + 1), ">"
|
||||
td ->
|
||||
a href: @url_for("tags", order: @order, asc_desc: @asc_desc, page: @last_page), ">>"
|
||||
else
|
||||
td ">"
|
||||
td ">>"
|
||||
|
||||
content: =>
|
||||
@menu!
|
||||
div ->
|
||||
element "table", ->
|
||||
tr ->
|
||||
th "Tag"
|
||||
th "Count"
|
||||
|
||||
for tag in *@tags
|
||||
tr ->
|
||||
td -> a href: @url_for("tag", id: tag.id), tag.name
|
||||
td tag.count
|
||||
@menu!
|
Reference in New Issue
Block a user