Skip to content

Commit

Permalink
v1.4.7
Browse files Browse the repository at this point in the history
Merge pull request #450 from TechforgoodCAST/develop
  • Loading branch information
suninthesky authored Sep 15, 2017
2 parents b33188e + 6b1347a commit acd5e09
Show file tree
Hide file tree
Showing 58 changed files with 917 additions and 861 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
inherit_from: .rubocop_todo.yml

Style/IndentationConsistency:
Layout/IndentationConsistency:
EnforcedStyle: rails

Style/Documentation:
Expand Down
17 changes: 8 additions & 9 deletions app/admin/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
span class: 'blank_slate' do
h3 'Users'
h5 'Non-profits'
h1 number_with_delimiter(User.user.count)
h1 number_with_delimiter(User.recipient.count)
h5 'Funders'
h1 User.funder.count
end
Expand Down Expand Up @@ -43,7 +43,7 @@
span class: 'blank_slate' do
h3 'Funders'
h5 'Active'
h1 Funder.where('active_on_beehive = ?', true).count
h1 Funder.where(active: true).count
h5 'Total'
h1 Funder.all.count
end
Expand All @@ -65,14 +65,13 @@
end

def user_count
User.user.group_by_week(:created_at,
week_start: :mon,
last: 12,
format: 'w/o %d %b').count
User.recipient.group_by_week(
:created_at, week_start: :mon, last: 12, format: 'w/o %d %b'
).count
end

def user_count_by_month
User.user.group_by_month(:created_at, last: 12, format: '%b %Y').count
User.recipient.group_by_month(:created_at, last: 12, format: '%b %Y').count
end

def recipient_count
Expand Down Expand Up @@ -101,7 +100,7 @@ def proposal_count(state)
end

def proposal_count_by_month
Proposal.where(state: %w(registered complete))
Proposal.where(state: %w[registered complete])
.group_by_month(:created_at, last: 12, format: '%b %Y').count
end

Expand Down Expand Up @@ -145,7 +144,7 @@ def percentage(count, i)
end
tr do
td 'Proposals'
proposal_count(%w(initial registered complete))
proposal_count(%w[initial registered complete])
.each_with_index do |count, i|
td percentage(count, i) if count[1].positive?
end
Expand Down
38 changes: 7 additions & 31 deletions app/admin/funder.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
ActiveAdmin.register Funder do
config.sort_order = 'created_at_asc'

permit_params :name, :contact_number, :website, :street_address, :city,
:region, :postal_code, :country, :charity_number,
:company_number, :founded_on, :registered_on, :mission, :status,
:registered, :active_on_beehive, :slug, :org_type,
:operating_for, :multi_national, :income_band, :employees,
:volunteers, :skip_validation, organisation_ids: []
permit_params :name, :slug, :website, :charity_number, :company_number, :active

controller do
def find_resource
Expand All @@ -22,12 +17,12 @@ def find_resource
column 'Funder', :name do |funder|
link_to funder.name, [:admin, funder]
end
column :active_on_beehive
column :active
column :has_funds do |funder|
funder.funds.count > 0
funder.funds.count.positive?
end
column :funds do |funder|
funder.funds.count
funder.funds.size
end
column :created_at
actions
Expand All @@ -39,38 +34,19 @@ def find_resource
row :name
row :website
row :charity_number
row :active_on_beehive
row :company_number
row :active
end

panel "Funds" do
panel 'Funds' do
table_for funder.funds do
column :slug
column :active
column 'org_type' do |fund|
check_presence(fund, 'org_type_distribution')
end
column 'income' do |fund|
check_presence(fund, 'income_distribution')
end
column :actions do |fund|
link_to 'View', [:admin, fund]
link_to 'Edit', [:edit_admin, fund]
end
end
end
end

form do |f|
f.inputs do
inputs 'Basics' do
f.input :slug
f.input :name
f.input :website
f.input :charity_number
f.input :active_on_beehive, as: :boolean
f.input :skip_validation, as: :boolean, input_html: { checked: 'checked' }
end
end
f.actions
end
end
4 changes: 2 additions & 2 deletions app/admin/proposal_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ def get_proposals

column do
panel "Recipient age" do
render partial: "bar_chart", locals: {data: get_proposals.joins(:recipient).group('org_type IN (2,4)').group(:operating_for).count.sort_by { |key, val| key[1].to_i }.map { |k, v| [[(k[0] ? 'Registered charity' : 'Other organisation'), (k[1] == nil ? 'Unknown' : Organisation::OPERATING_FOR[k[1].to_i][0].upcase_first)], v] }.to_h}
render partial: "bar_chart", locals: {data: get_proposals.joins(:recipient).group('org_type IN (2,4)').group(:operating_for).count.sort_by { |key, val| key[1].to_i }.map { |k, v| [[(k[0] ? 'Registered charity' : 'Other organisation'), (k[1] == nil ? 'Unknown' : Recipient::OPERATING_FOR[k[1].to_i][0].upcase_first)], v] }.to_h}
end
end

column do
panel "Recipient size" do
render partial: "bar_chart", locals: {data: get_proposals.joins(:recipient).group('org_type IN (2,4)').group(:income_band).count.sort_by { |key, val| key[1].to_i }.map { |k, v| [[(k[0] ? 'Registered charity' : 'Other organisation'), (k[1] == nil ? 'Unknown' : Organisation::INCOME_BANDS[k[1]][0])], v] }.to_h}
render partial: "bar_chart", locals: {data: get_proposals.joins(:recipient).group('org_type IN (2,4)').group(:income_band).count.sort_by { |key, val| key[1].to_i }.map { |k, v| [[(k[0] ? 'Registered charity' : 'Other organisation'), (k[1] == nil ? 'Unknown' : Recipient::INCOME_BANDS[k[1]][0])], v] }.to_h}
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/admin/restriction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
f.inputs do
f.input :details, label: 'Are you seeking funding for ___ ?'
f.input :invert
f.input :category, collection: %w(Proposal Organisation),
f.input :category, collection: %w[Proposal Recipient],
input_html: { class: 'chosen-select' }
end
f.actions
Expand All @@ -17,7 +17,7 @@
row :invert
row :category
end
panel "Funds with this restriction" do
panel 'Funds with this restriction' do
table_for restriction.funds do
column :slug
column :funder
Expand Down
9 changes: 4 additions & 5 deletions app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
config.per_page = 10

permit_params :first_name, :last_name, :org_type, :agree_to_terms,
:email, :password, :password_confirmation, :role,
:organisation_id
:email, :password, :password_confirmation, :organisation_id,
:organisation_type

controller do
def scoped_collection
Expand Down Expand Up @@ -47,9 +47,8 @@ def scoped_collection

form do |f|
f.inputs 'User Details' do
f.input :organisation, required: true,
input_html: { class: 'chosen-select' }
f.input :role
f.input :organisation_id
f.input :organisation_type, as: :select, collection: %w[Recipient Funder]
f.input :org_type, as: :select, collection: ORG_TYPES
f.input :first_name
f.input :last_name
Expand Down
4 changes: 2 additions & 2 deletions app/cells/eligibility_quiz/show.slim
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ p.uk-margin-bottom
=<> counts[:restrictions]
| criteria.

- if @restrictions[:Organisation].present?
- if @restrictions[:Recipient].present?
h4.uk-text-bold Is your organisation?
- @restrictions[:Organisation].each do |r|
- @restrictions[:Recipient].each do |r|
.recipient_restriction
= render view: :restriction, locals: {r: r, f: f, e: r.eligibility(@proposal)}

Expand Down
7 changes: 7 additions & 0 deletions app/cells/footer_themes/show.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ul
- themes.each do |theme|
li.mb10
- if proposal.present?
= link_to theme.name, theme_proposal_funds_path(proposal, theme), class: 'slate'
- else
= link_to theme.name, public_funds_theme_path(theme), class: 'slate'
15 changes: 15 additions & 0 deletions app/cells/footer_themes_cell.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class FooterThemesCell < Cell::ViewModel
def show
render locals: {themes: get_top_themes, proposal: options[:proposal]}
end

private

def get_top_themes
Theme.joins(:funds)
.group(:id)
.order('COUNT(funds.id) DESC')
.limit(4)
end

end
10 changes: 9 additions & 1 deletion app/cells/fund_insight_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def themes
model.themes.map do |theme|
link_to(
theme.name,
theme_proposal_funds_path(options[:proposal], theme),
theme_path(theme),
class: 'blue'
)
end.join('<span class="mid-gray"> &middot; </span>')
Expand Down Expand Up @@ -83,4 +83,12 @@ def months_to_str(months)
"#{months_to_str(months - (months % 12))} and #{months % 12} months"
end
end

def theme_path(theme)
if options[:proposal]
theme_proposal_funds_path(options[:proposal], theme)
else
public_funds_theme_path(theme)
end
end
end
8 changes: 4 additions & 4 deletions app/cells/recipient_form/show.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@

.uk-width-medium-1-1.uk-margin-top.name
.label How long has your organisation or project been operating for?
= f.input :operating_for, as: :select, collection: Organisation::OPERATING_FOR, input_html: { class: 'large uk-width-1-1' }
= f.input :operating_for, as: :select, collection: Recipient::OPERATING_FOR, input_html: { class: 'large uk-width-1-1' }

.uk-width-medium-1-1.uk-margin-top.name
.label What is the annual income of your organisation or project?
= f.input :income_band, as: :select, collection: Organisation::INCOME_BANDS, input_html: { class: 'large uk-width-1-1' }
= f.input :income_band, as: :select, collection: Recipient::INCOME_BANDS, input_html: { class: 'large uk-width-1-1' }

.uk-width-medium-1-1.uk-margin-top.name
.label How many employees does your organisation or project have?
= f.input :employees, as: :select, collection: Organisation::EMPLOYEES, input_html: { class: 'large uk-width-1-1' }
= f.input :employees, as: :select, collection: Recipient::EMPLOYEES, input_html: { class: 'large uk-width-1-1' }

.uk-width-medium-1-1.uk-margin-top.name
.label How many volunteers does your organisation or project have?
= f.input :volunteers, as: :select, collection: Organisation::EMPLOYEES, input_html: { class: 'large uk-width-1-1' }
= f.input :volunteers, as: :select, collection: Recipient::EMPLOYEES, input_html: { class: 'large uk-width-1-1' }

.uk-width-medium-1-1
.uk-grid
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def current_user
end

def load_recipient
return unless logged_in?
return unless logged_in? && current_user.organisation.is_a?(Recipient)
@recipient = current_user.organisation
end

Expand All @@ -45,7 +45,7 @@ def load_last_proposal
end

def funder? # NOTE: legacy support
current_user.role == 'Funder'
current_user.organisation.is_a? Funder
end

def ensure_logged_in
Expand Down
22 changes: 13 additions & 9 deletions app/controllers/funds_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class FundsController < ApplicationController
before_action :ensure_logged_in, :update_legacy_suitability, except: :sources
before_action :query, only: %i[index themed]

def show
@fund = Fund.includes(:funder).find_by(slug: params[:id])
Expand All @@ -9,21 +10,17 @@ def show
end

def index
query = Fund.active
.includes(:funder, :themes)
.eligibility(@proposal, params[:eligibility])
.duration(@proposal, params[:duration])
.order_by(@proposal, params[:sort])

query = @query.order_by(@proposal, params[:sort])
@fund_count = query.size
@funds = Kaminari.paginate_array(query).page(params[:page])
end

def themed
@theme = Theme.find_by(slug: params[:theme]) if params[:theme].present?
@funds = Fund.active
.includes(:funder, :themes)
.where(themes: { id: @theme })
query = @query.where(themes: { id: @theme })
.order_by(@proposal, params[:sort])
@funds = Kaminari.paginate_array(query).page(params[:page])
@fund_count = query.size
redirect_to root_path, alert: 'Not found' if @funds.empty?
end

Expand All @@ -32,4 +29,11 @@ def themed
def update_legacy_suitability
@proposal.update_legacy_suitability
end

def query
@query = Fund.active
.includes(:funder, :themes)
.eligibility(@proposal, params[:eligibility])
.duration(@proposal, params[:duration])
end
end
9 changes: 9 additions & 0 deletions app/controllers/public_funds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ def show
@restrictions = @fund.restrictions.pluck(:category, :details)
end

def themed
@theme = Theme.find_by(slug: params[:theme]) if params[:theme].present?
@funds = Fund.active
.includes(:funder, :themes)
.where(themes: { id: @theme })
.page(params[:page])
redirect_to public_funds_path, alert: 'Not found' if @funds.empty?
end

private

def ensure_logged_out
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ def v2_layout? # TODO: remove @ v2
permitted = {
articles: %i[index show],
errors: %i[not_found gone internal_server_error],
funds: %i[index],
funds: %i[index themed],
pages: %i[about faq forfunders privacy terms],
password_resets: %i[new create edit update],
public_funds: %i[index show],
public_funds: %i[index show themed],
signup: %i[user create_user]
}
controller = params[:controller].to_sym
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/funds_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def org_type_desc(fund)

def income_desc(fund)
arr = fund.income_distribution.select do |hash|
hash['label'] == Organisation::INCOME_BANDS[@recipient.income_band][0]
hash['label'] == Recipient::INCOME_BANDS[@recipient.income_band][0]
end
return if arr.empty?
return if arr[0]['percent']==0
Expand Down
8 changes: 8 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ def markdown(str)

markdown.render(str)
end

def generate_slug(obj, col, n = 1)
return nil unless col
slug = col.parameterize
slug += "-#{n}" if n > 1
return slug unless obj.class.find_by(slug: slug)
generate_slug(obj, col, n + 1)
end
end
5 changes: 0 additions & 5 deletions app/models/feature.rb

This file was deleted.

Loading

0 comments on commit acd5e09

Please sign in to comment.