diff --git a/.gitignore b/.gitignore index 9040b0c2..9245c560 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,6 @@ # Ignore application configuration /config/application.yml + +# Ignore ctags +/tags diff --git a/app/assets/javascripts/mixins/customSelect.js b/app/assets/javascripts/mixins/customSelect.js index 8915caf8..3b71d115 100644 --- a/app/assets/javascripts/mixins/customSelect.js +++ b/app/assets/javascripts/mixins/customSelect.js @@ -14,7 +14,7 @@ var customSelect = { newSelect = me.createSelect(oldSelect); oldSelect.className = 'hide'; - scope.appendChild(newSelect); + scope.insertBefore(newSelect, oldSelect); me.manageSelect(newSelect, oldSelect); })(); diff --git a/app/assets/stylesheets/custom/_admin-dashboard.scss b/app/assets/stylesheets/custom/_admin-dashboard.scss index e676813e..9b66a71a 100644 --- a/app/assets/stylesheets/custom/_admin-dashboard.scss +++ b/app/assets/stylesheets/custom/_admin-dashboard.scss @@ -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 { @@ -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; +} diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 5331f701..a28c59ea 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -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 diff --git a/app/models/donor_report.rb b/app/models/donor_report.rb new file mode 100644 index 00000000..71fbdf20 --- /dev/null +++ b/app/models/donor_report.rb @@ -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 diff --git a/app/models/grant_report.rb b/app/models/grant_report.rb index a8e19e1c..c4c849f8 100644 --- a/app/models/grant_report.rb +++ b/app/models/grant_report.rb @@ -1,5 +1,7 @@ class GrantReport include Datagrid + include Rails.application.routes.url_helpers + # # Scope @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index aa65199f..73f8c67e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -57,4 +57,8 @@ def default_card def last4 default_card[:last4] if default_card end + + def donated? + self.payments.length > 0 + end end diff --git a/app/views/admin/dashboard/index.html.slim b/app/views/admin/dashboard/index.html.slim index 96fd1171..a67514fe 100644 --- a/app/views/admin/dashboard/index.html.slim +++ b/app/views/admin/dashboard/index.html.slim @@ -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 diff --git a/app/views/datagrid/_range_filter.html.erb b/app/views/datagrid/_range_filter.html.erb index 2bfba446..6804cd0c 100644 --- a/app/views/datagrid/_range_filter.html.erb +++ b/app/views/datagrid/_range_filter.html.erb @@ -1,3 +1,3 @@ <%= form.text_field(filter.name, from_options) %> - - +
-
<%= form.text_field(filter.name, to_options) %> diff --git a/config/application.rb b/config/application.rb index 0f63fed9..75f0ac27 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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]