From f24c00d517171a1afbd047edd0611f1f819e1371 Mon Sep 17 00:00:00 2001 From: Tangent Date: Wed, 17 Apr 2019 22:32:55 -0700 Subject: [PATCH] minor changes/fixes --- app.moon | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app.moon b/app.moon index 33eb7f2..95e1443 100644 --- a/app.moon +++ b/app.moon @@ -9,12 +9,14 @@ class extends lapis.Application -- TODO figure out why [%u] character class does not work [tracks: "/tracks(/:order[%a])(/:asc_desc)(/:page[%d])"]: => - @order = tostring(@params.order)\lower! -- 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! - -- descending or ascending only, ascending default - @asc_desc = "ASC" if @asc_desc != "DESC" + if @asc_desc != "DESC" and @asc_desc != "ASC" + @asc_desc = "ASC" @page = tonumber(@params.page) or 1 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 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