Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

206 take two #263

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions app/assets/javascripts/vote.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
var ready = function() {

$('#event-progress').hide();

$('#choice-submit').click(function() {
event.preventDefault();
var choiceValue = $( "input:radio[name=choice]:checked" ).val();
$.post('/votes',{ choice: choiceValue });
$('.question').hide();
$('.holding-message').show();
answerSubmit(choiceValue);
// $.post('/votes',{ choice: choiceValue });
// $('.question').hide();
// $(".graphs#" + ($('#question-id-hold').text())).show();
});

var channel, pusher;
Expand All @@ -18,12 +21,13 @@ var ready = function() {

function pusherKey(){
var event_number = $('#pusher-key').text();
return event_number
return event_number;
};

pusher = new Pusher(pusherKey(), {
encrypted: true
});

channel = pusher.subscribe('test_channel');
return channel.bind(myEvent(), function(data) {
buildQuestion(data);
Expand All @@ -34,23 +38,42 @@ var ready = function() {
return "event_" + event_number
};

function showCurrentChoice(){
console.log(currentChoice);
};
};

$(document).ready(ready);
$(document).on('page:load', ready);
function answerSubmit(choiceValue){
$.post('/votes',{ choice: choiceValue });
$('.question').hide();
$(".graphs#" + ($('#question-id-hold').text())).show();
};

function showProgress(){
$('#event-progress').show();
$('.graphs').hide();
};

function buildQuestion(data) {
$('.question').show();
$('.holding-message').hide();
$('#testing').text(data.test);
$('#question-number').text(data.question.question_number);
$('#question-title').text(data.question.content);
$('#question-id-hold').text(data.question.id);

var $choiceOptions = $('#dvOptions');
$choiceOptions.empty();
for ( var i = 0; i < data.choices.length; i++) {
$choiceOptions.append($('<li class="list-group-item"><input type="radio" name="choice" value="'
+ data.choices[i].id + '"><label for="choice">'
+ data.choices[i].content + '</label></li>'));
};
$( ".question-form").submit(function(){
console.log("hiya")
});
showProgress();
};

$(document).ready(ready);
$(document).on('page:load', ready);
39 changes: 31 additions & 8 deletions app/views/events/vote.html.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
<div class='voting-page-wrapper'>

<section>
<h1><%= @event.title %></h1>
<h4><%= @event.description %></h4>
</section>

<h1 id="question-id-hold" style="display:none"></h1>
<div id="event-id" style="display:none;"><%= @event.id %></div>
<div id="pusher-key" style="display:none;"><%= Pusher.key %></div>

<section class="space-50"></section>

<div class="holding-message">
<h5>Awaiting Question</h5>
<h2>Awaiting Question</h2>
<h4><%= @event.description %></h4>
<div id="canvasloader-container"></div>
</div>

<div class="question">
<h3>Question <span id="question-number">?</span> of <%= @event.questions.count %>:</h3>
<h2 id="question-title"></h2>
<div id="event-progress" style="display:none">
<h2>Question <span id="question-number"></span> of <%= @event.questions.count %>:</h2>
</div>
<h1 id="question-title"></h1>

<div class="container question">
<form class="question-form">
<p id="question-id"><p>
<ul class='list-group'>
<div id="dvOptions"></div>
</ul>
<button id="choice-submit" type="submit" class="btn btn-primary btn-lg">Submit Answer</button>
</form>
</div>
</div>

<% @event.questions.each do |question| %>
<% if question.choices.any? %>
<div class="graphs" id="<%= question.id%>" style="display:none" >
<h4>Results:</h4>
<% question.choices.each do |choice| %>
<%= div_for choice, 'data-votecount' => choice.votes.count || 0 do %>
<%= choice.content %>
<p class='vote-count' >
Votes: <%= choice.votes.count || 0 %>
</p>
<div class="progress">
<div class="<%= graph_colour %>" role="progressbar" style="width: <%= (((choice.votes.count.to_f)) / ((total_votes(choice.question).to_f) )* 100 ).to_i || 0 if choice.votes.any? %>%">
</div>
</div>
<% end %>
<% end %>
</div>
<% end %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion spec/features/questions_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
page.execute_script("$(document).ready(function() { choiceVotebuilder(#{vote_creator(@choice1.id, "2")}) });")
expect(page).to have_css("#choice_#{@choice1.id}[data-votecount='2']")
page.execute_script("$(document).ready(function() { choiceVotebuilder(#{vote_creator(@choice1.id, "3")}) });")
expect(page).to have_css("#choice_#{@choice1.id}[data-votecount='3']")
expect(page).to have_css("#choice_#{@choice1.id}[data-votecount='3']")
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/features/voting_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
expect(page).to have_content 'Yes'
expect(page).to have_content 'No'
expect(page).to have_content 'Maybe'
click_button "Submit Answer"
page.execute_script("$(document).ready(function() { buildQuestion(#{data_creator("2")}) });")
expect(page).to have_content 'Question 2 of 2'
page.execute_script("$(document).ready(function() { answerSubmit(#{@choice.id}) });")
expect(page).to have_content 'Results:'
expect(page).to have_css("#choice_#{@choice.id} .progress .progress-bar")
end
end
end