Skip to content

Commit

Permalink
Fixed a few pages... added a Summary page for the treasurer
Browse files Browse the repository at this point in the history
  • Loading branch information
rtlong committed Jun 3, 2010
1 parent fdf20e7 commit 344e5dc
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 70 deletions.
3 changes: 2 additions & 1 deletion app/controllers/admin/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class Admin::AdminController < ApplicationController

def set_actions
@actions = [
["View All", {:action => 'index'}]]
["View All", {:action => 'index'}]
]
end

end
4 changes: 2 additions & 2 deletions app/controllers/admin/businesses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def index
@actions.push ["Download", {:action => 'index', :format => 'csv'}]
respond_to do |format|
format.html do
@responded_businesses = Business.responded.full_search(params[:q]).all(:include => :contribution, :order => 'responded_at DESC')
@other_businesses = Business.not_responded.full_search(params[:q]).all
@businesses = Business.full_search(params[:q]).all(:include => :contribution, :order => 'name ASC')
#@other_businesses = Business.not_responded.full_search(params[:q]).all
end

format.csv do
Expand Down
25 changes: 19 additions & 6 deletions app/controllers/admin/contributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,37 @@ class Admin::ContributionsController < Admin::AdminController
before_filter :get_business, :except => [:index, :unthanked, :summary]

def index
@actions.push ["Printable Summary", {:action => 'summary'}]
@actions.push ["Unthanked", {:action => 'unthanked'}]

@contributions = Contribution.all :include => :business, :order => 'created_at DESC'
end

def unthanked
@contributions = Contribution.unthanked :include => :business, :order => 'created_at DESC'
@contributions = Contribution.unthanked.all :include => :business, :order => 'created_at DESC'
end

def summary
@contributions = Contribution.all( :include => :business ).sort{|a,b| a.business.name <=> b.business.name}

@headers = ['Business', 'Contribution Nature', 'Contribution Value']

@total_value = DollarValue.new( @contributions.sum{|c| c.value.to_f } ).to_s
@total_liquid_value = DollarValue.new( @contributions.sum{|c| c.liquid_value? ? c.value.to_f : 0.0 } ).to_s

flash[:notice] = "For best results, print this using Firefox"

respond_to do |wants|
wants.html do
# render template
end
wants.csv do
csv_data_matrix = []
# Headers
csv_data_matrix << ['Business', 'Contribution Nature', 'Contribution Value', 'Liquid Value?']
csv_data_matrix << (@headers.push 'Liquid Value?')
# Data
@contributions.each do |c|
csv_data_matrix << [c.business.name, c.nature, c.value.to_f.to_s, (/cash|check/i === c.nature).to_s]
csv_data_matrix << [c.business.name, c.nature, c.value.to_f.to_s]
end

# allot for Ruby1.8 on DH servers
Expand Down Expand Up @@ -73,7 +86,7 @@ def create

@contribution = @business.build_contribution(params[:contribution])
if @contribution.save
@business.update_attributes :responded_at => Time.now
#@business.update_attributes :responded_at => Time.now
flash[:notice] = "Successfully added contribution."
redirect_to admin_business_contribution_path(@business)
else
Expand All @@ -97,8 +110,8 @@ def update
params['contribution'].delete 'received'

success = @contribution.update_attributes(params[:contribution])
@business.responded_at ||= Time.now
@business.save
#@business.responded_at ||= Time.now
#@business.save
if success
flash[:notice] = "Successfully updated contribution."
else
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/businesses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def new

def create
@business = Business.new(params[:business])
@business.responded_at = Time.now
#@business.responded_at = Time.now
if @business.save
flash[:notice] = "Successfully added business info."
redirect_to new_business_contribution_path(@business)
Expand All @@ -55,7 +55,7 @@ def edit

def update
@business = Business.find(params[:id])
@business.responded_at ||= Time.now
#@business.responded_at ||= Time.now
@business.save
if @business.update_attributes(params[:business])
flash[:notice] = "Successfully updated business info."
Expand Down
4 changes: 2 additions & 2 deletions app/models/business.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class Business < ActiveRecord::Base
end
}

named_scope :responded, :conditions => 'responded_at IS NOT NULL'
named_scope :not_responded, :conditions => 'responded_at IS NULL'
#named_scope :responded, :conditions => 'responded_at IS NOT NULL'
#named_scope :not_responded, :conditions => 'responded_at IS NULL'

def phone=(phone)
# If two extensions are provided, only the first is stored
Expand Down
4 changes: 4 additions & 0 deletions app/models/contribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ def received?
received_at?
end

def liquid_value?
/cash|check/i === nature
end

end
51 changes: 13 additions & 38 deletions app/views/admin/businesses/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,68 +11,43 @@
= link_to "[reset]", admin_businesses_path

- form_tag nil, :id => :businesses do
.responded_businesses
%h2
Responded
- unless @responded_businesses.empty?
.note #{@responded_businesses.count} businesses
- if @responded_businesses.empty?
.no-results There are no businesses that have responded and match your filter.
.businesses
- if @businesses.empty?
.no-results There are no businesses that match your filter.
- else
.note These are the businesses that actually responded using the website AND businesses that have a contribution filed. If their response was added via this interface, they will not appear here unless a contribution was added as well.
%table
%thead
%tr
%th.centered{ :colspan => 3 } Business
%th.centered{ :colspan => 3 } Contribution
%tr
%th.centered{:width => '1%'}
%abbr{:title => "Needs to be mailed"} M
%th{:width => '25%'} Name
%th{:width => '25%'} Location
%th{:width => '15%'} Date Responded
%th{:width => '*'} Contribution
%th{:width => '15%'} Date
%th{:width => '*'} Nature
%th{:width => '15%'} Date Received
%tfoot
%tr
%th#responded_businesses_count{:colspan => 6}= pluralize(@responded_businesses.count, 'business')
%th#businesses_count{:colspan => 6}= pluralize(@businesses.count, 'business')
%tbody
- @responded_businesses.each_with_index do |business, i|
- @businesses.each_with_index do |business, i|
%tr[business]{:class => ('a' if i.even?)}
%td= business.mailing_required ? 'Y':'N'
%td= h business.display_name
%td
%a{:href => "/admin/businesses/#{business.id}"}= business.street
%td= time_ago_in_words(business.responded_at)
%td
- if business.contribution
= time_ago_in_words(business.contribution.created_at)
%td
- if business.contribution
= link_to( business.contribution.nature, admin_business_contribution_path(business) )
%td
- if business.contribution and business.contribution.received
= business.contribution.received_at.to_words

.other_businesses
%h2
Not Responded
- unless @other_businesses.empty?
.note #{@other_businesses.count} businesses
- if @other_businesses.empty?
.no-results There are no businesses that have not responded and match your filter.
- else
%table
%thead
%tr
%th.centered{:width => '1%'}
%abbr{:title => "Needs to be mailed"} M
%th{:width => '25%'} Name
%th{:width => '*'} Location
%tfoot
%tr
%th#other_businesses_count{:colspan => 3}= pluralize(@other_businesses.count, 'business')
%tbody
- @other_businesses.each_with_index do |business, i|
%tr[business]{:class => ('a' if i.even?)}
%td= business.mailing_required ? 'Y':'N'
%td= h business.display_name
%td
%a{:href => "/admin/businesses/#{business.id}"}= business.street

:javascript
// Grab all table rows and add the controls
Expand Down
7 changes: 4 additions & 3 deletions app/views/admin/businesses/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
.business
= render :partial => 'businesses/display', :locals => {:business => @business}

- if @business.responded_at
.responded_at
%h3 Responded #{time_ago_in_words(@business.responded_at)}
-#
- if @business.responded_at
.responded_at
%h3 Responded #{time_ago_in_words(@business.responded_at)}
.contribution
- if @contribution
Expand Down
7 changes: 0 additions & 7 deletions app/views/admin/businesses/update.rjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
row_id = "business_#{@business.id}"

#page.visual_effect :highlight, row_id, :startcolor => "#19ff19"
if @business.mailing_required
page << "$('#{row_id}').firstDescendant().addClassName('hi');"
else
page << "$('#{row_id}').firstDescendant().removeClassName('hi');"
end

#flash.each do |name, msg|
# page << %div{:id => "flash_#{name}"}= msg
#end
flash.clear

#if @business.errors
# page << "console.debug('Errors on saving business: #{@business.errors.full_messages.join(" ")}');"
#end
28 changes: 28 additions & 0 deletions app/views/admin/contributions/summary.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- title "Contributions Summary"


Retrieved #{Time.now.strftime("%a %d %B %Y @ %I:%M %p")}

%table#contributions_summary
%thead
%tr
- @headers.each do |header|
%th= header

%tfoot
%tr
%th.right{ :colspan => 2 } Total Value
%th.right= @total_value
%tr
%th.right{ :colspan => 2 } Total Liquid Value
%th.right= @total_liquid_value

%tbody
- @contributions.each do |c|
%tr{:class => cycle('a','b')}
%td= c.business.name
%td= c.nature
%td.right= c.value.to_s



2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
admin.signup '1198c38a11dbdf935af35342d959fb24ca07cecc', :controller => 'users', :action => 'new'
admin.logout 'logout', :controller => 'sessions', :action => 'destroy'
admin.login 'login', :controller => 'sessions', :action => 'new'
admin.root :controller => 'businesses', :action => 'index'
admin.root :controller => 'contributions', :action => 'index'
end

map.resources :businesses, :except => :show, :collection => {:search => [:get,:post]}, :new => {:new => :post} do |business|
Expand Down
19 changes: 11 additions & 8 deletions public/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ function update_business(element, value){
function delete_business(event) {
conf = confirm("Are you sure? This business and its contribution, if it has one, will be destroyed.")
if(conf){
business_id = event.srcElement.parentNode.parentNode.id.split("_")[1];

if(event.target){
eventTarget = event.target;
} else {
eventTarget = event.srcElement;
}
business_id = eventTarget.parentNode.parentNode.id.split("_")[1];

new Ajax.Request(
'/admin/businesses/' + business_id + ".js", {
asynchronous: true,
Expand All @@ -37,13 +44,9 @@ function delete_business(event) {
}

function set_totals(){
var responded_businesses_count_td = $("responded_businesses_count");
var other_businesses_count_td = $("other_businesses_count");
if(responded_businesses_count_td){
responded_businesses_count_td.innerHTML = responded_businesses_count_td.up('tfoot').next('tbody').select('tr').length + ' businesses';
}
if(other_businesses_count_td){
other_businesses_count.innerHTML = other_businesses_count_td.up('tfoot').next('tbody').select('tr').length + ' businesses';
var businesses_count_td = $("businesses_count");
if(businesses_count_td){
businesses_count_td.innerHTML = businesses_count_td.up('tfoot').next('tbody').select('tr').length + ' businesses';
}
}

Expand Down
20 changes: 20 additions & 0 deletions public/stylesheets/sass/admin.print.sass
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ menu#actions, menu#nav, #userinfo, #search_box
h5, input
:display none

#flash_notice, .noprint
:display none

.note
:font-size smaller
:font-style oblique
Expand Down Expand Up @@ -51,3 +54,20 @@ menu#actions, menu#nav, #userinfo, #search_box
hr
:clear both
:margin 10px 0

table
th
:text-align left
tr
:border-bottom 1px grey solid

.right
:text-align right

.left
:text-align left

table#contributions_summary
:border-collapse collapse

:font-size 8pt
6 changes: 6 additions & 0 deletions public/stylesheets/sass/application.sass
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ blockquote

table
:text-align left

.right
:text-align right

.left
:text-align left

.big
:font-size xx-large
Expand Down

0 comments on commit 344e5dc

Please sign in to comment.