-
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
39 changed files
with
616 additions
and
40 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
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 |
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,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 |
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,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 |
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
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,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 |
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,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 |
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,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(); |
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
Oops, something went wrong.