Skip to content

Commit

Permalink
v1.10.0
Browse files Browse the repository at this point in the history
Merge pull request #621 from TechforgoodCAST/develop
  • Loading branch information
suninthesky authored Mar 6, 2018
2 parents 94838c3 + 75678b8 commit 6441311
Show file tree
Hide file tree
Showing 43 changed files with 8,033 additions and 363 deletions.
2 changes: 0 additions & 2 deletions app/admin/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

span class: 'blank_slate' do
h3 'Non-profits'
h5 'Unlocks'
h1 number_with_delimiter RecipientFunderAccess.all.count
h5 'Quiz answers'
h1 number_with_delimiter Answer.all.count
end
Expand Down
1 change: 0 additions & 1 deletion app/admin/recipient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def find_resource
filter :registered
filter :founded_on
filter :created_at
filter :recipient_funder_accesses_count, label: 'Unlocks'

index do
selectable_column
Expand Down
2 changes: 2 additions & 0 deletions app/assets/stylesheets/v2/application.sass
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
@import modules/typography

@import custom

@import dialog-polyfill/dialog-polyfill
20 changes: 19 additions & 1 deletion app/assets/stylesheets/v2/custom.sass
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ article.featured
.copy
text-align: left

.filter
#sort-form
select
+prefix(appearance, none, webkit moz)
border: none
Expand Down Expand Up @@ -383,3 +383,21 @@ article.featured
max-height: 0
overflow: hidden
+prefix(transition, max-height .40s, webkit o)

// Dialog
// =========================================================================
// native
dialog::backdrop
background-color: rgba(0, 0, 0, 0.8) !important
// polyfill
dialog + .backdrop
background-color: rgba(0, 0, 0, 0.8) !important

dialog
min-width: 320px
padding: 0 !important

.js-open-modal
height: 100vh
overflow: hidden
3 changes: 3 additions & 0 deletions app/assets/stylesheets/v2/modules/button.sass
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
color: inherit
background-color: transparent
border-radius: $base-radius
transition: opacity .2s

&:hover
text-decoration: none
opacity: .6
cursor: pointer

&:focus
outline: none
Expand Down
2 changes: 1 addition & 1 deletion app/cells/current_proposal_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def incompelte
model.assessments.group(:eligibility_status).size
)[INCOMPLETE]
str = pluralize(incomplete, 'fund') + ' unchecked'
link_to(str, funds_path(model, eligibility: 'to_check'))
link_to(str, funds_path(model, eligibility: 'to-check'))
end

def proposal_summary
Expand Down
30 changes: 23 additions & 7 deletions app/cells/filter/show.slim
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
form.filter.fs15.flex.flex-wrap
.p20
.flex.justify-between.mb10
h5.bold Filter by
.fs15 = clear_filters
.fs15.lh20 = active_filters

.md.inline-block.mr10
| Eligibility:
= select 'eligibility', %w[all eligible ineligible to_check]
dialog.rounded.shadow.border.border-silver
.p20.bg-ice.flex.justify-between.items-center
h4.bold Filter funds by
a.js-close-modal Close

.md.inline-block
| Grant duration:
= select 'duration', [["all", "All"], proposal_duration, ["up-to-2y", "Up to 2 years"], ["2y-plus", "More than 2 years"]].compact
= form_tag(query_path, method: :get, enforce_utf8: false) do
.p20.border-top.border-silver
.mb15
h6.bold.slate.mb5 Eligibility
= select_tag :eligibility, eligibility_options, class: 'input'
.mb15
h6.bold.slate.mb5 Funding Type
= select_tag :type, funding_type_options, class: 'input'
h6.bold.slate.mb5 Country
= select_tag :country, country_options, class: 'input', prompt: 'All'

.p20.border-top.border-silver.center.bg-ice
= submit_tag 'Filter', name: nil, class: 'white btn bg-blue'
= link_to 'Reset', funds_path(@proposal), class: 'btn blue bg-white border-blue ml10'
52 changes: 40 additions & 12 deletions app/cells/filter_cell.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,55 @@
include ERB::Util
include ActionView::Helpers::FormOptionsHelper

class FilterCell < Cell::ViewModel
def show
@proposal = options[:proposal]
@url = options[:url]
render
end

private

def selected?(id, value)
model[id.to_sym] == value
def country_options
options_from_collection_for_select(
Country.order(priority: :desc).all, :alpha2, :name, model[:country]
)
end

def select(id, options)
tag.select id: id do
options.map do |opt|
opt = [opt, opt.humanize.capitalize] unless opt.is_a?(Array)
tag.option(opt[1], value: url_encode(opt[0]), selected: selected?(id, opt[0]))
end.reduce(:+)
def eligibility_options
options_for_select(
opts(['All', 'Eligible', 'Ineligible', 'To check']), model[:eligibility]
)
end

def funding_type_options
options_for_select(opts(%w[All Capital Revenue]), model[:type])
end

def opts(arr)
arr.map { |opt| [opt, opt.parameterize] }.to_h
end

def filter_params
model.permit(:country, :eligibility, :type)
end

def clear_filters
if filter_params.empty?
'<a class="blue js-show-modal">Add filter</a>'
else
[
'<a class="blue js-show-modal">Edit</a>',
link_to('Clear filters', funds_path(@proposal))
].join(' • ')
end
end

def proposal_duration
['proposal', "Your proposal (#{options[:funding_duration]} months)"] if
options[:funding_duration]
def active_filters
return 'None' if filter_params.empty?
filter_params.to_h.map { |k, v| "#{k}:#{v}" }.join(', ')
end

def query_path
@url || funds_path(@proposal)
end
end
11 changes: 10 additions & 1 deletion app/controllers/funds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ def show
def index
update_analysis(query) if @proposal
@funds = query.page(params[:page])
load_stubs(@funds)
end

def themed
@theme = Theme.find_by(slug: params[:theme])
redirect_to funds_path(@proposal), alert: 'Not found' unless @theme
@funds = themed_query.page(params[:page])
load_stubs(@funds)
end

def hidden
Expand Down Expand Up @@ -49,8 +51,10 @@ def query
Fund.join(@proposal)
.includes(:funder, :themes, :geo_area)
.order_by(params[:sort])
.country(params[:country])
.eligibility(params[:eligibility])
.duration(@proposal, params[:duration])
.funding_type(params[:type])
.revealed(params[:revealed])
.active
.select('funds.*', 'assessments.eligibility_status')
end
Expand All @@ -64,4 +68,9 @@ def load_fund
.where("state = 'active' OR state = 'stub'")
.find_by_hashid(params[:id])
end

def load_stubs(funds)
@fund_stubs = Fund.stubs.includes(:funder).order('RANDOM()').limit(5) if
funds.empty?
end
end
7 changes: 4 additions & 3 deletions app/controllers/reveals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ class RevealsController < ApplicationController

def create
authorize :reveal
fund = Fund.find_by_hashid(params[:fund])
@recipient.reveals << fund.slug
assessment = Assessment.find(params[:assessment])
assessment.update(revealed: true)
@recipient.reveals << assessment.fund.slug
@recipient.save
redirect_to fund_path(fund, @proposal)
redirect_to fund_path(assessment.fund, @proposal)
end

private
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/funds_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include ActionView::Helpers::SanitizeHelper

module FundsHelper
def selected(value, params = {})
params['eligibility'] == value ? 'selected' : nil
Expand Down
26 changes: 26 additions & 0 deletions app/javascript/__tests__/dialog.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-env jest */

import Dialog from '../modules/dialog'

const dialog = new Dialog()

document.body.innerHTML = `
<body>
<a class="js-show-modal">Show</a>
<a class="js-close-modal">Close</a>
<dialog></dialog>
</body>
`
dialog.init()

const $dialog = document.querySelector('dialog')

test('#init, show modal', () => {
document.querySelector('.js-show-modal').click()
expect($dialog.hasAttribute('open')).toEqual(true)
})

test('#init, close modal', () => {
document.querySelector('.js-close-modal').click()
expect($dialog.hasAttribute('open')).toEqual(false)
})
36 changes: 0 additions & 36 deletions app/javascript/__tests__/filter.test.js

This file was deleted.

36 changes: 36 additions & 0 deletions app/javascript/__tests__/sort.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-env jest */

import Sort from '../modules/sort'

const sort = new Sort()

const triggerChange = (id) => {
const $form = document.getElementById(id)
$form.dispatchEvent(new Event('change'))
}

document.body.innerHTML = `
<form id="sort-form">
<select id="sort">
<option value="eligibility">Eligibility</option>
<option value="name">Name</option>
</select>
</form>
`

Object.defineProperty(
window.location, 'search', { value: '?existing=query', writable: true }
)

sort.init('sort-form')

test('appends query string', () => {
triggerChange('sort-form')
expect(window.location.search).toEqual('existing=query&sort=eligibility')
})

test('appends query string', () => {
document.getElementById('sort').children[1].selected = true
triggerChange('sort-form')
expect(window.location.search).toEqual('existing=query&sort=name')
})
19 changes: 19 additions & 0 deletions app/javascript/modules/dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import dialogPolyfill from 'dialog-polyfill'

export default class Dialog {
init ($body = document.body, dialog = 'dialog') {
const $modal = document.querySelector(dialog)
if (!$modal) return
dialogPolyfill.registerDialog($modal)

document.querySelector('.js-show-modal').onclick = () => {
$body.classList.add('js-open-modal')
$modal.showModal()
}

document.querySelector('.js-close-modal').onclick = () => {
$body.classList.remove('js-open-modal')
$modal.close()
}
}
}
30 changes: 0 additions & 30 deletions app/javascript/modules/filter.js

This file was deleted.

Loading

0 comments on commit 6441311

Please sign in to comment.