minor changes/fixes

This commit is contained in:
Tangent 2019-04-17 22:32:55 -07:00
parent 8af3343aa2
commit f24c00d517

View File

@ -9,12 +9,14 @@ class extends lapis.Application
-- TODO figure out why [%u] character class does not work -- TODO figure out why [%u] character class does not work
[tracks: "/tracks(/:order[%a])(/:asc_desc)(/:page[%d])"]: => [tracks: "/tracks(/:order[%a])(/:asc_desc)(/:page[%d])"]: =>
@order = tostring(@params.order)\lower!
-- validate order field -- validate order field
@order = "id" unless Tracks.fields[@order] @order = tostring(@params.order)\lower!
unless Tracks.fields[@order]
@order = "id"
-- validate ascending/descending (ascending default)
@asc_desc = tostring(@params.asc_desc)\upper! @asc_desc = tostring(@params.asc_desc)\upper!
-- descending or ascending only, ascending default if @asc_desc != "DESC" and @asc_desc != "ASC"
@asc_desc = "ASC" if @asc_desc != "DESC" @asc_desc = "ASC"
@page = tonumber(@params.page) or 1 @page = tonumber(@params.page) or 1
tracks = Tracks\paginated "* ORDER BY #{@order} #{@asc_desc}", per_page: 32 tracks = Tracks\paginated "* ORDER BY #{@order} #{@asc_desc}", per_page: 32
@ -25,6 +27,7 @@ class extends lapis.Application
return redirect_to: @url_for "tracks", order: @order, asc_desc: @asc_desc, page: 1 return redirect_to: @url_for "tracks", order: @order, asc_desc: @asc_desc, page: 1
if @page > @last_page if @page > @last_page
return redirect_to: @url_for "tracks", order: @order, asc_desc: @asc_desc, page: @last_page return redirect_to: @url_for "tracks", order: @order, asc_desc: @asc_desc, page: @last_page
@tracks = tracks\get_page @page @tracks = tracks\get_page @page
return render: true return render: true