-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
43 changed files
with
8,033 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ | |
@import modules/typography | ||
|
||
@import custom | ||
|
||
@import dialog-polyfill/dialog-polyfill |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.