Skip to content

Commit

Permalink
v3.1.0
Browse files Browse the repository at this point in the history
Merge pull request #801 from TechforgoodCAST/develop
  • Loading branch information
suninthesky authored Dec 5, 2018
2 parents 7dec5f9 + 7bed327 commit 43f07f0
Show file tree
Hide file tree
Showing 39 changed files with 616 additions and 40 deletions.
6 changes: 4 additions & 2 deletions app/assets/stylesheets/custom.sass
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,12 @@ dialog + .backdrop
dialog
min-width: 320px
padding: 0 !important
label
cursor: default !important

.js-open-modal
height: 100vh
overflow: hidden
height: auto !important
overflow: inherit !important

// Footer
// =========================================================================
Expand Down
18 changes: 18 additions & 0 deletions app/controllers/answers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class AnswersController < ApplicationController
def show
@assessment = Assessment.find_by(id: params[:id])
@criteria_type = %w[restrictions priorities].select do |i|
i == params[:criteria_type]
end[0]

if @assessment && @criteria_type
@criteria = @assessment.fund.send(@criteria_type)

@answers = Answer.where(
'category_id = ? OR category_id = ?',
@assessment.recipient_id,
@assessment.proposal_id
).pluck(:criterion_id, :eligible).to_h
end
end
end
37 changes: 37 additions & 0 deletions app/controllers/votes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class VotesController < ApplicationController
before_action :load_assessment

def new
if @assessment
@vote = @assessment.votes.new
else
redirect_back(fallback_location: opportunities_path)
end
end

def create
@vote = @assessment.votes.new(form_params)

if @vote.save
redirect_to(
report_path(@assessment.proposal, anchor: "assessment-#{@assessment.id}"),
notice: "Successfully voted on assessment ##{@assessment.id}"
)
else
render :new
end
end

private

def form_params
params.require(:vote).permit(
:relationship_to_assessment, :relationship_details, :agree_with_rating,
:reason
)
end

def load_assessment
@assessment = Assessment.find_by(id: params[:id])
end
end
16 changes: 16 additions & 0 deletions app/helpers/answers_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module AnswersHelper
def yes_selected?(eligible, inverted)
case [eligible, inverted]
when [true, false]
false
when [false, true]
false
when [true, true]
true
when [false, false]
true
else
nil
end
end
end
5 changes: 0 additions & 5 deletions app/javascript/modules/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ export default class 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()
Expand Down
8 changes: 8 additions & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ document.addEventListener("turbolinks:load", function () {
"national": ["proposal_country_id"],
"international": ["proposal_countries"]
});

select.init("vote_relationship_to_assessment", {
"Another role": ["vote_relationship_details"]
});

select.init("vote_agree_with_rating", {
"false": ["vote_reason"]
});
}, false);

// Utility
Expand Down
2 changes: 2 additions & 0 deletions app/models/assessment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Assessment < ApplicationRecord
belongs_to :proposal, counter_cache: true
belongs_to :recipient

has_many :votes, dependent: :destroy

validates :eligibility_status, inclusion: {
in: [INELIGIBLE, INCOMPLETE, ELIGIBLE]
}
Expand Down
1 change: 0 additions & 1 deletion app/models/country.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ class Country < ApplicationRecord
has_many :funds, through: :geo_areas
has_many :funders, -> { distinct }, through: :funds

# TODO: test
has_many :recipients

has_and_belongs_to_many :geo_areas
Expand Down
1 change: 0 additions & 1 deletion app/models/district.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class District < ApplicationRecord
has_many :funds, through: :geo_areas
has_many :funders, -> { distinct }, through: :funds

# TODO: test
has_many :recipients

has_and_belongs_to_many :geo_areas
Expand Down
3 changes: 1 addition & 2 deletions app/models/funder.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
class Funder < ApplicationRecord
has_many :funds
has_many :proposals, as: :collection # TODO: test
has_many :proposals, as: :collection

# TODO: test
has_many :criteria, -> { distinct }, through: :funds
has_many :priorities, -> { distinct }, through: :funds
has_many :restrictions, -> { distinct }, through: :funds
Expand Down
5 changes: 2 additions & 3 deletions app/models/theme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ class Theme < ApplicationRecord

belongs_to :parent, class_name: 'Theme', optional: true

has_many :proposals, as: :collection # TODO: test
has_many :proposals, as: :collection

has_many :themes, foreign_key: 'parent_id'
has_many :fund_themes, dependent: :destroy
has_many :funds, through: :fund_themes

# TODO: test
has_many :criteria, -> { distinct }, through: :funds
has_many :priorities, -> { distinct }, through: :funds
has_many :restrictions, -> { distinct }, through: :funds

validates :name, :slug, uniqueness: true
validates :classes, presence: true

# TODO: drop column?
# TODO: drop column and review parent?
# See app/validators/hash_validator.rb
validates :related, hash: { key_in: pluck(:name), value_in: :number }

Expand Down
31 changes: 31 additions & 0 deletions app/models/vote.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Vote < ApplicationRecord
belongs_to :assessment

ROLES = [
'I created the report',
'I work for the opportunity provider',
'Another role'
].freeze

validates :relationship_to_assessment, presence: { in: ROLES }

validates :relationship_details, presence: true, if: ->(o) {
o.relationship_to_assessment == 'Another role'
}

validates :agree_with_rating, inclusion: { in: [true, false] }

validates :reason, presence: true, unless: :agree_with_rating

after_save :update_counter_caches

private

def update_counter_caches
if agree_with_rating
Assessment.increment_counter(:agree_count, assessment)
else
Assessment.increment_counter(:disagree_count, assessment)
end
end
end
4 changes: 2 additions & 2 deletions app/services/rating/eligibility/quiz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Quiz
include Rating::Base

def link
# TODO: removed for v3 deplpy
# "<a href='##{@assessment_id}'>View answers</a>".html_safe
"<a data-remote='true' href='/assessments/#{@assessment_id}/answers" \
"?criteria_type=restrictions'>View answers</a>".html_safe
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/services/rating/suitability/quiz.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Quiz
include Rating::Base

def link
# TODO: removed for v3 deplpy
# "<a href='##{@assessment_id}'>View answers</a>".html_safe
"<a data-remote='true' href='/assessments/#{@assessment_id}/answers" \
"?criteria_type=priorities'>View answers</a>".html_safe
end

private
Expand Down
28 changes: 28 additions & 0 deletions app/views/answers/_dialog.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.p20.bg-ice.flex.justify-between.items-center.border-bottom.border-mist
%h4.bold
Your answers for assessment
= precede '#' do
= @assessment.id

.px20.pt20
- @criteria&.each do |c|

.flex.items-center.quiz.mb20
.input_wrapper.boolean

- if yes_selected?(@answers[c.id], c.invert)
%input{ type: 'radio', checked: true }
%label Yes
%input{ type: 'radio' }
%label No
- else
%input{ type: 'radio' }
%label Yes
%input{ type: 'radio', checked: true }
%label No

%label.mx20.fs15
= c.details

- if @answers[c.id] == false
.fs14.red.mt7 You do not meet this criteria
8 changes: 8 additions & 0 deletions app/views/answers/show.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%- if @assessment && @criteria_type %>
document.getElementById('answers').innerHTML = "<%= j render(partial: 'dialog') %>";
<%- else %>
document.getElementById('answers').innerHTML = "<%= j render(template: 'errors/not_found') %>";
<%- end %>

document.body.classList.add('js-open-modal');
document.querySelector('dialog').showModal();
1 change: 0 additions & 1 deletion app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
= link_to 'Change settings', privacy_path(anchor: 'cookies', read_cookies_notice: true), class: 'btn-sm white'
= link_to 'Continue', update_cookies_path(functional_cookies: true, performance_cookies: true, read_cookies_notice: true), class: 'btn-sm bg-blue white shadow'

-# TODO: spec
- if logged_in? && (@current_user&.update_version != UPDATE_VERSION)
.bg-night.border-bottom.border-slate.fs14.lh18.white
.maxw1050.mx-auto.px15.py10.flex.items-center.justify-between
Expand Down
33 changes: 21 additions & 12 deletions app/views/reports/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
= content_for :title, "#{@proposal.name} #{@proposal.identifier}"

%dialog.rounded.shadow.border.border-silver.col2.my40.px15
#answers
.px20.pb20
%a.btn.btn-wide.bg-blue.white.js-close-modal Close

%main.bg-ice

%header.bg-primary
= render partial: 'shared/nav', locals: { color: 'white' }
-# TODO: spec
- if @collection
= breadcrumbs('Opportunities' => opportunities_path, @collection.name => opportunity_path(@collection), @proposal.identifier => report_path(@proposal))
- else
Expand All @@ -25,7 +29,6 @@
ago

%div
-# TODO: spec
- if @collection
= link_to('New report', new_recipient_path(@collection), class: 'btn bg-secondary')

Expand All @@ -39,7 +42,7 @@

- @proposal.assessments.includes(fund: [:funder]).each do |a|

.bg-white.rounded.shadow.mb40
.bg-white.rounded.shadow.mb40{ id: "assessment-#{a.id}" }
.pb5.rounded-top{ class: a.banner.indicator }

%h4.p20.border-bottom.border-mist
Expand All @@ -56,10 +59,21 @@
- a.fund.links.each do |text, href|
= link_to text, href, target: '_blank', rel: 'noopener', class: 'btn blue border-mist', onclick: "trackOutboundLink('#{href}');"

.p20.border-top-thick.border-bottom-thick{ class: a.banner.background }
.flex.items-center
.dot.ml5.mr15{ class: a.banner.indicator }
.heading.bold{ class: a.banner.color }= a.banner.text
.px20.pt10.border-top-thick.border-bottom-thick{ class: a.banner.background }
.flex.flex-wrap.justify-between

.flex.items-center.mb10
.dot.ml5.mr15{ class: a.banner.indicator }
.heading.bold{ class: a.banner.color }= a.banner.text

.mb10
%span.fs14.night.mr10
= a.agree_count
agree
= a.disagree_count
disagree
= link_to 'Vote', new_assessment_vote_path(a), class: 'btn btn-sm white bg-blue'

%h5.p20 Rating details

Expand All @@ -84,7 +98,6 @@
.m20
.fs14.heading.bold.night.mb5 Support type
.fs14.lh18.slate= support_type
-# TODO: spec
- if @proposal.seeking_funding?
.m20
.fs14.heading.bold.night.mb5 Amount sought
Expand All @@ -99,7 +112,6 @@
.border.border-mist.rounded
.p20.border-bottom.border-mist
%h6.bold.slate Recipient
-# TODO: spec
- unless @proposal.recipient.individual?
.m20
.fs14.heading.bold.night.mb5 Name
Expand All @@ -110,20 +122,17 @@
.m20
.fs14.heading.bold.night.mb5 Country
.fs14.slate= @proposal.recipient.country.name
-# TODO: spec
- if @proposal.recipient.district
.m20
.fs14.heading.bold.night.mb5 Area
.fs14.slate= @proposal.recipient.district.name
-# TODO: spec
- unless @proposal.recipient.individual?
.m20
.fs14.heading.bold.night.mb5 Annual income
.fs14.slate= @proposal.recipient.income_band_name
.m20
.fs14.heading.bold.night.mb5 Operating for
.fs14.slate= @proposal.recipient.operating_for_name
-# TODO: spec
- if @proposal.recipient.website.present?
.m20
.fs14.heading.bold.night.mb5 Website
Expand Down
Loading

0 comments on commit 43f07f0

Please sign in to comment.