Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@

# Ignore application configuration
/config/application.yml

# Ignore ctags
/tags
2 changes: 1 addition & 1 deletion app/assets/javascripts/mixins/customSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var customSelect = {
newSelect = me.createSelect(oldSelect);

oldSelect.className = 'hide';
scope.appendChild(newSelect);
scope.insertBefore(newSelect, oldSelect);
me.manageSelect(newSelect, oldSelect);

})();
Expand Down
23 changes: 21 additions & 2 deletions app/assets/stylesheets/custom/_admin-dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
.datagrid-filter {
width: 80%;
.select-wrapper {
margin-left: 10px;
&:nth-of-type(1) {
margin-right: 10px;
&:nth-of-type(2) {
width: 10%;
}
}
margin-bottom: 20px;
}

.datagrid-filter, .select-wrapper, .datagrid-submit, .datagrid-actions, .order {
Expand Down Expand Up @@ -53,3 +54,21 @@
margin-left: 5px;
}

.separator {
font-size: 40px;
display: inline-block;
vertical-align: text-bottom;
}

.date_filter {
width: 25%;
padding: 12px 10px;
font-size: 12pt;
background-color: #fff;
border-radius: 5px;
border: solid 1px #999999;
}

.datagrid-filter .select-wrapper {
height: 44px;
}
61 changes: 20 additions & 41 deletions app/controllers/admin/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,34 @@ def index
@grant_report = GrantReport.new(params[:grant_report])
respond_to do |f|
f.html do
@grant_report.scope {|scope| scope.page(params[:page]) }
@grant_report.scope {|scope| scope.page(params[:page]).per_page(25)}
end
f.csv do
send_data @grant_report.to_csv,
type: "text/csv",
disposition: 'inline',
filename: "grant-report-#{Time.now.to_s}.csv"
if params[:csv_type] == "grant"
send_data @grant_report.to_csv,
type: "text/csv",
disposition: 'inline',
filename: "grant-report-#{Time.now.to_s}.csv"
end
end
end
order = params[:order]
if order && order == 'Status'
@grants.sort_by! {|g| [g.order_status, g.title]}
elsif order && order == 'Title'
@grants.sort_by! {|g| g.title}
elsif order && order == 'Last Created Date'
@grants.sort_by! {|g| g.created_at}.reverse!
elsif order && order == 'Last Updated Date'
@grants.sort_by! {|g| g.updated_at}.reverse!
end

@donors = User.donors
donated = params[:donated]
if donated && donated == 'Donated'
@donors = User.donors.select {|user| user.payments.length > 0}
elsif donated && donated == 'Have Not Donated'
@donors = User.donors.select {|user| user.payments.length == 0}
end
@donors.sort_by! {|u| [u.last_name, u.first_name]}
@donors = @donors.paginate page: params[:page], per_page: 6

@recipients = Recipient.all
school = params[:school]
if school && school != 'All'
schoolId = School.find_by_name(school).id
@recipients = Recipient.select {|recip| recip.profile.school_id == schoolId }
@donor_report = DonorReport.new(params[:donor_report])
respond_to do |f|
f.html do
@donor_report.scope {|scope| scope.page(params[:page]).per_page(25)}
end
f.csv do
if params[:csv_type] == "donor"
send_data @donor_report.to_csv,
type: "text/csv",
disposition: 'inline',
filename: "donor-report-#{Time.now.to_s}.csv"
end
end
end
@recipients.sort_by! {|u| [u.last_name, u.first_name]}
@recipients = @recipients.paginate page: params[:page], per_page: 6

end

def grant_event
@grant = Grant.find params[:id]
@grant.send params[:state]
respond_to do |format|
format.html { redirect_to admin_dashboard_path }
format.js
end
end

def load_distributions
@successful = successful
Expand Down
35 changes: 35 additions & 0 deletions app/models/donor_report.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class DonorReport
include Datagrid

#
# Scope
#

scope do
User.donors
end

#
# Filters
#

filter(:condition, :dynamic, :header => "Custom Filters:")
filter(:updated_at, :date, header: "Updated Between:", :range => true, :default => proc { [3.month.ago.to_date, Date.today]})
filter(:donated, :xboolean) do |value|
self.includes(:payments).where('payments.id is not null = ?', value)
end

#
# Columns
#

column(:id, :mandatory => true)
column(:first_name, mandatory: true)
column(:email, mandatory: true)
column(:updated_at, mandatory: true) do |user|
user.updated_at.to_formatted_s(:long)
end
column(:donated, mandatory: true) do |user|
user.donated? ? "Yes" : "No"
end
end
25 changes: 20 additions & 5 deletions app/models/grant_report.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class GrantReport
include Datagrid
include Rails.application.routes.url_helpers


#
# Scope
Expand All @@ -13,15 +15,28 @@ class GrantReport
# Filters
#

filter(:condition, :dynamic, :header => "Customizeable Conditions")
filter(:condition, :dynamic, :header => "Custom Filter:")
filter(:updated_at, :date, header: "Updated Between:", :range => true, :default => proc { [3.month.ago.to_date, Date.today]})

#
# Columns
#

column(:id, :mandatory => true)
column(:title, :mandatory => true)
column(:status, :mandatory => true)
column(:updated_at, :mandatory => true)

column(:teacher_name, mandatory: true)
column(:title, mandatory: true) do |grant|
format(grant.title) do |value|
link_to value, grant_path(grant)
end
end
column(:status, order: :state , mandatory: true)
column(:current_funds, header: "Current Funds", mandatory: true) do |grant|
grant.current_funds
end
column(:goal, header: "Goal", mandatory: true) do |grant|
grant.total_budget or 0
end
column(:updated_at, mandatory: true) do |grant|
grant.updated_at.to_formatted_s(:long)
end
end
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ def default_card
def last4
default_card[:last4] if default_card
end

def donated?
self.payments.length > 0
end
end
22 changes: 8 additions & 14 deletions app/views/admin/dashboard/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,22 @@
.twelve.columns.centered.centalign
ul.tab-nav
li#grants
a href="#" Grants
a href="#" Grants & Teachers
li#donors
a href="#" Donors
li#recipients
a href="#" Recipients
li#distributions
a href="#" Data Distributions
.tab-content
= datagrid_form_for @grant_report, :url => admin_dashboard_path
= datagrid_table(@grant_report)
= will_paginate @grant_report.assets
.large.primary.btn.centered.columns.three
= link_to "Get Grant CSV", url_for(format: 'csv', grant_report: params[:grant_report])
.large.primary.btn.centered.columns.four
= link_to "Download CSV", url_for(format: 'csv', grant_report: params[:grant_report], csv_type: "grant")
.tab-content
= render 'donated'
= render partial: 'shared/table', locals: { heads: %w[Name Email], partials: [['users', @donors, :user, "There are no users"]] }
.ten.columns.centered.centalign
= will_paginate @donors
.tab-content
= render 'school'
= render partial: 'shared/table', locals: { heads: %w[Name Email], partials: [['users', @recipients, :user, "There are no recipients"]] }
.ten.columns.centered.centalign
= will_paginate @recipients
= datagrid_form_for @donor_report, :url => admin_dashboard_path
= datagrid_table(@donor_report)
= will_paginate @donor_report.assets
.large.primary.btn.centered.columns.four
= link_to "Download CSV", url_for(format: 'csv', donor_report: params[:donor_report], csv_type: "donor")
.tab-content data-bp-get='/admin/load_distributions'
#distributions-tab
2 changes: 1 addition & 1 deletion app/views/datagrid/_range_filter.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%= form.text_field(filter.name, from_options) %>
<span class="separator <%= filter.type %>"> - </span>
<div class="separator <%= filter.type %>"> - </div>
<%= form.text_field(filter.name, to_options) %>
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Application < Rails::Application

# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
config.time_zone = 'Pacific Time (US & Canada)'

# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
Expand Down