summaryrefslogtreecommitdiff
path: root/application.rb
diff options
context:
space:
mode:
authormr <mr@mrautenberg.de>2011-08-30 17:07:56 +0200
committermr <mr@mrautenberg.de>2011-08-30 17:07:56 +0200
commitc242bfc291a7dab733c424968509709813e6e331 (patch)
tree71d5e411294e3f8f29f7db3db0227773e612f1d1 /application.rb
parenta8f6072f32ef5ae650216a4612d13eeb6b310c7e (diff)
add model sorting
Diffstat (limited to 'application.rb')
-rw-r--r--application.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/application.rb b/application.rb
index 9ef50f8..c03915c 100644
--- a/application.rb
+++ b/application.rb
@@ -90,7 +90,20 @@ get '/login' do
end
get '/models/?' do
- @models = ToxCreateModel.all.sort(:order => "DESC")
+ @page = params[:page] ? params[:page].to_i : 0
+ order = params["order"] == "ASC" ? "ASC" : "DESC"
+ params["order"] = order
+ sort_by = params["sort_by"]
+ if sort_by
+ case sort_by
+ when "name", "created_at", "type", "id"
+ @models = ToxCreateModel.all.sort_by(sort_by.to_sym, :order => "#{order} ALPHA")
+ end
+ else
+ params["sort_by"] = "id"
+ end
+
+ @models = ToxCreateModel.all.sort(:order => "DESC") unless @models
@models.each{|m| raise "internal redis error: model is nil" unless m}
haml :models, :locals=>{:models=>@models}
end