summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormr <mr@mrautenberg.de>2011-08-31 11:21:56 +0200
committermr <mr@mrautenberg.de>2011-08-31 11:21:56 +0200
commitfe6260b895c855fc7e453bc141ea7aa18baf6623 (patch)
treeb537a06847ce9fe9384b0e29b91c401ad9a28f30
parentdb81a67c87a4f048f297d60ee60a7632f4595854 (diff)
parentc242bfc291a7dab733c424968509709813e6e331 (diff)
solve merge conflicts
-rw-r--r--application.rb15
-rw-r--r--helper.rb5
-rw-r--r--views/models.haml11
-rw-r--r--views/models_navigation.haml61
-rw-r--r--views/style.sass23
5 files changed, 110 insertions, 5 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
diff --git a/helper.rb b/helper.rb
index 80707c3..799135b 100644
--- a/helper.rb
+++ b/helper.rb
@@ -91,5 +91,10 @@ helpers do
haml :neighbors_navigation, :layout => false
end
+ def models_navigation
+ @page = 0 unless @page
+ haml :models_navigation, :layout => false
+ end
+
end
diff --git a/views/models.haml b/views/models.haml
index e4f35b6..6a181df 100644
--- a/views/models.haml
+++ b/views/models.haml
@@ -17,10 +17,13 @@
= haml :regression, :layout => false
= haml :similarity, :layout => false
= haml :significant_fragments, :layout => false
+-# - if is_authorized(model.web_uri, "GET")
-- if @models
- - @models.each do |model|
- - if is_authorized(model.web_uri, "GET")
- = haml :model, :locals=>{:model=>model}, :layout => false
+- first = 5*@page
+- last = first+4
+= models_navigation
+- if @models[first..last]
+ - @models[first..last].each do |model|
+ = haml :model, :locals=>{:model=>model}, :layout => false
-if @models.size == 0
.notice There are currently no models. You have to create a model first.
diff --git a/views/models_navigation.haml b/views/models_navigation.haml
new file mode 100644
index 0000000..fa5bd31
--- /dev/null
+++ b/views/models_navigation.haml
@@ -0,0 +1,61 @@
+.models_navigation
+
+ %form{:name => "nav", :action => url_for('/models'), :method => "get", :id => "nav"}
+ %input{:type => :hidden, :name => :sort_by, :id => "sort_by", :value => params[:sort_by]}
+ %input{:type => :hidden, :name => :order, :id => "order", :value => params[:order]}
+ %input{:type => :hidden, :name => :subjectid, :value => session[:subjectid]}
+ %input{:type => :hidden, :name => :page, :id => "page", :value => params[:page]}
+
+ Models are sorted by:
+ - ["id","created_at","name","type"].each do |s|
+ - idname = s == "created_at" ? "date" : s
+ - if params[:sort_by] == s
+ %div{:id => idname, :class => "active"}
+ %span="#{idname}"
+ - if params[:order] == "ASC"
+ #up{:class => "link"}= "&dArr;"
+ - else
+ #down{:class => "link"}= "&uArr;"
+ - else
+ %div{:id => idname, :class => "link"}="#{idname}"
+ |
+ models:
+
+ #prev= "prev" unless @page.to_i == 0
+
+ - if @models.size < 5*@page+5
+ - last = @models.size
+ - else
+ - last = 5*@page+5
+
+ = "(#{5*@page+1}-#{last}/#{@models.size})"
+
+ #next= "next" unless 5*@page.to_i+5 >= @models.size
+
+ - js = ""
+ - ["id","created_at","name","type"].each do |s|
+ - idname = s == "created_at" ? "date" : s
+ - js += "$('##{idname}').click(function() \{ \n "
+ - js += " $('#sort_by').val('#{s}');\n "
+ - js += " $('#nav').submit();\n "
+ - js += "});\n "
+
+ :javascript
+ $("#prev").click(function() {
+ $("#page").val(#{@page-1});
+ $("#nav").submit();
+ });
+ $("#next").click(function() {
+ $("#page").val(#{@page+1});
+ $("#nav").submit();
+ });
+ #{js}
+ $("#down").click(function() {
+ $("#order").val("ASC");
+ $("#nav").submit();
+ });
+ $("#up").click(function() {
+ $("#order").val("DESC");
+ $("#nav").submit();
+ });
+ \ No newline at end of file
diff --git a/views/style.sass b/views/style.sass
index 15ae256..9f055e4 100644
--- a/views/style.sass
+++ b/views/style.sass
@@ -267,3 +267,26 @@ dl
margin-left: 16px
margin-right: 16px
float: left
+
+.models_navigation
+ #prev
+ @extend a
+ display: inline
+ cursor: pointer
+ #next
+ @extend a
+ display: inline
+ cursor: pointer
+ .link
+ @extend a
+ display: inline
+ cursor: pointer
+ .active
+ display: inline
+ color: #000
+ font-weight: bold
+ padding: 0 1px
+ .thin
+ font-weight: 100
+ span
+ text-decoration: underline