From e95cdad5ecf4a853d788eaaf0ca1c8e0ff5374c5 Mon Sep 17 00:00:00 2001 From: sandoz Date: Sat, 11 Apr 2009 19:39:01 +0200 Subject: [PATCH 1/3] Added ordergroups view to foodcoop namespace. * For now just a searchable list. Nothing more. --- app/controllers/foodcoop_controller.rb | 20 ++++++++++++++++++++ app/views/foodcoop/_ordergroups.html.haml | 23 +++++++++++++++++++++++ app/views/foodcoop/ordergroups.html.haml | 21 +++++++++++++++++++++ app/views/layouts/_main_tabnav.html.erb | 1 + 4 files changed, 65 insertions(+) create mode 100644 app/views/foodcoop/_ordergroups.html.haml create mode 100644 app/views/foodcoop/ordergroups.html.haml diff --git a/app/controllers/foodcoop_controller.rb b/app/controllers/foodcoop_controller.rb index e43d4a79..e9018906 100644 --- a/app/controllers/foodcoop_controller.rb +++ b/app/controllers/foodcoop_controller.rb @@ -41,6 +41,26 @@ class FoodcoopController < ApplicationController @groups = Workgroup.find :all, :order => "name" end + def ordergroups + #@order_groups = Ordergroup.find :all, :order => "name" + if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100) + @per_page = params[:per_page].to_i + else + @per_page = 20 + end + + # if somebody uses the search field: + conditions = ["name LIKE ?", "%#{params[:query]}%"] unless params[:query].blank? + + @total = Ordergroup.count(:conditions => conditions) + @order_groups = Ordergroup.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "name") + + respond_to do |format| + format.html # index.html.erb + format.js { render :partial => "ordergroups" } + end + end + def group end diff --git a/app/views/foodcoop/_ordergroups.html.haml b/app/views/foodcoop/_ordergroups.html.haml new file mode 100644 index 00000000..c6da5330 --- /dev/null +++ b/app/views/foodcoop/_ordergroups.html.haml @@ -0,0 +1,23 @@ +%p +%table{:style => "width:100%"} + %tr + %td + = pagination_links_remote @order_groups, :update => :order_groups + %td{:style => "text-align:right"} + - if @total > 20 + = items_per_page :update => :order_groups + +%table.list + %thead + %tr + %th Name + %th #Mitglieder + %th Kontakt + + %tbody + - for order_group in @order_groups + %tr{:class => cycle('even','odd', :name => 'order_group')} + %td=h order_group.name + %th=h order_group.users.length + %td=h order_group.contact + diff --git a/app/views/foodcoop/ordergroups.html.haml b/app/views/foodcoop/ordergroups.html.haml new file mode 100644 index 00000000..0027b211 --- /dev/null +++ b/app/views/foodcoop/ordergroups.html.haml @@ -0,0 +1,21 @@ +%h1 Bestellgruppen der Foodcoop + +.left_column{:style => "width:100%"} + .box_title + %h2 Übersicht + .column_content + #user_filter{:style => "margin-right:2em;"} + %form{:name=>"sform", :action=>"", :style=>"display:inline;"} + %label{:for => 'article_name'} Suche nach Name: + = text_field_tag("query", params['query'], :size => 10 ) + + = observe_field 'query', :frequency => 2, | + :before => "Element.show('loader')", | + :success => "Element.hide('loader')", | + :url => {:action => 'ordergroups'}, | + :update => :order_groups, | + :with => 'query', | + :method => :get | + + #order_groups + = render :partial => "ordergroups" \ No newline at end of file diff --git a/app/views/layouts/_main_tabnav.html.erb b/app/views/layouts/_main_tabnav.html.erb index feb2604e..7ae665ce 100644 --- a/app/views/layouts/_main_tabnav.html.erb +++ b/app/views/layouts/_main_tabnav.html.erb @@ -12,6 +12,7 @@ :subnav => [ { :name => "Mitglieder", :url => "/foodcoop/members"}, { :name => "Abeitsgruppen", :url => "/foodcoop/workgroups"}, + { :name => "Bestellgruppen", :url => "/foodcoop/ordergroups"}, { :name => "Nachrichten", :url => "/messages"}, { :name => "Aufgaben", :url => "/tasks"} ] From e32e97d178b1ce292abeaae912b1c2dfcddf31dc Mon Sep 17 00:00:00 2001 From: sandoz Date: Sat, 18 Apr 2009 15:35:29 +0200 Subject: [PATCH 2/3] Added "ordergroups" view to list the ordergroups * You can search in the name. * You can show only active order groups (order in last 3 months) * Future feature: generate text and pdf files for the box labels --- app/controllers/foodcoop_controller.rb | 16 ++++++++++++---- app/views/foodcoop/ordergroups.html.haml | 17 +++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/controllers/foodcoop_controller.rb b/app/controllers/foodcoop_controller.rb index e9018906..ac162808 100644 --- a/app/controllers/foodcoop_controller.rb +++ b/app/controllers/foodcoop_controller.rb @@ -49,11 +49,19 @@ class FoodcoopController < ApplicationController @per_page = 20 end - # if somebody uses the search field: - conditions = ["name LIKE ?", "%#{params[:query]}%"] unless params[:query].blank? + if (params[:only_active].to_i == 1) + if (! params[:query].blank?) + conditions = ["orders.starts >= ? AND name LIKE ?", Time.now.months_ago(3), "%#{params[:query]}%"] + else + conditions = ["orders.starts >= ?", Time.now.months_ago(3)] + end + else + # if somebody uses the search field: + conditions = ["name LIKE ?", "%#{params[:query]}%"] unless params[:query].blank? + end - @total = Ordergroup.count(:conditions => conditions) - @order_groups = Ordergroup.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "name") + @total = Ordergroup.count(:conditions => conditions, :include => "orders") + @order_groups = Ordergroup.paginate(:page => params[:page], :per_page => @per_page, :conditions => conditions, :order => "name", :include => "orders") respond_to do |format| format.html # index.html.erb diff --git a/app/views/foodcoop/ordergroups.html.haml b/app/views/foodcoop/ordergroups.html.haml index 0027b211..8de23e41 100644 --- a/app/views/foodcoop/ordergroups.html.haml +++ b/app/views/foodcoop/ordergroups.html.haml @@ -5,17 +5,18 @@ %h2 Übersicht .column_content #user_filter{:style => "margin-right:2em;"} - %form{:name=>"sform", :action=>"", :style=>"display:inline;"} + %form{:id=>"sform", :action=>"", :style=>"display:inline;"} %label{:for => 'article_name'} Suche nach Name: = text_field_tag("query", params['query'], :size => 10 ) + %label{:for => 'only_active'} Nur aktive: + = check_box_tag('only_active') - = observe_field 'query', :frequency => 2, | - :before => "Element.show('loader')", | - :success => "Element.hide('loader')", | - :url => {:action => 'ordergroups'}, | - :update => :order_groups, | - :with => 'query', | - :method => :get | + = observe_form 'sform', :frequency => 2, | + :before => "Element.show('loader')", | + :success => "Element.hide('loader')", | + :url => {:action => 'ordergroups'}, | + :update => :order_groups, | + :method => :get | #order_groups = render :partial => "ordergroups" \ No newline at end of file From b1f16d5342fcb7fa7c751ae01e37cecd15e74535 Mon Sep 17 00:00:00 2001 From: sandoz Date: Sat, 18 Apr 2009 18:08:33 +0200 Subject: [PATCH 3/3] Calculate total prices correctly. (Closes #6) --- app/models/order_article.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 0d6e9feb..b2191d9d 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -79,12 +79,12 @@ class OrderArticle < ActiveRecord::Base # Calculate price for ordered quantity. def total_price - units_to_order * price.price + units_to_order * price.unit_quantity * price.price end # Calculate gross price for ordered qunatity. def total_gross_price - units_to_order * price.gross_price + units_to_order * price.unit_quantity * price.gross_price end def ordered_quantities_equal_to_group_orders?