late render quiz results, to avoid unnecessary bandwidth usage
This commit is contained in:
parent
71f152c659
commit
ee7723c986
3 changed files with 24 additions and 21 deletions
|
@ -6,11 +6,6 @@
|
|||
<% end %>
|
||||
</div>
|
||||
<div id="resultWrapper" class="hidden">
|
||||
<% all_groups().each do |group| %>
|
||||
<div id="d_<%= group[:id] %>" style="display: none;">
|
||||
<%= render '/partials/pretty_link.*', :item => group %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="buttons">
|
||||
<button id="previousButton" onclick="window.history.back()">
|
||||
|
@ -21,14 +16,8 @@
|
|||
</button>
|
||||
</div>
|
||||
<script>
|
||||
// This is always the same, like a static macro
|
||||
const _groups = (function resetGroups() {
|
||||
const groups = {};
|
||||
<% all_groups().each do |group| %>
|
||||
groups["d_<%= group[:id] %>"] = document.getElementById("d_<%= group[:id] %>");
|
||||
<% end %>
|
||||
return groups;
|
||||
})();
|
||||
const result_wrapper = document.getElementById("resultWrapper");
|
||||
const _results = <%= to_partials(all_groups()) %>;
|
||||
|
||||
// This keeps the state of the current question/result
|
||||
// So navigating between questions works without reload
|
||||
|
@ -129,14 +118,14 @@
|
|||
}
|
||||
|
||||
function show_result(result) {
|
||||
for (let ver in result) {
|
||||
if (result[ver] == 0) {
|
||||
_groups["d_"+ver].style.display = "none";
|
||||
} else {
|
||||
_groups["d_"+ver].style.display = "block";
|
||||
_groups["d_"+ver].style.order = -1 * result[ver];
|
||||
}
|
||||
}
|
||||
while (result_wrapper.lastElementChild) {
|
||||
result_wrapper.removeChild(result_wrapper.lastElementChild);
|
||||
}
|
||||
for (let ver in result) {
|
||||
const create_wrapper= document.createElement('div');
|
||||
create_wrapper.innerHTML = _results["d_"+ver];
|
||||
result_wrapper.appendChild(create_wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
function save_state() {
|
||||
|
|
13
lib/helpers/quiz.rb
Normal file
13
lib/helpers/quiz.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
require 'json'
|
||||
require 'nokogiri'
|
||||
|
||||
module QuizHelper
|
||||
def to_partials(items)
|
||||
my_hash = {}
|
||||
|
||||
items.each do |item|
|
||||
my_hash["d_"+(item[:id] || "none")] = (render '/partials/pretty_link.*', :item => item).gsub("\n", '')
|
||||
end
|
||||
my_hash.to_json
|
||||
end
|
||||
end
|
|
@ -6,4 +6,5 @@ use_helper NavigationHelper
|
|||
use_helper VerenigingenHelper
|
||||
use_helper FontAwesomeHelper
|
||||
use_helper SearchHelper
|
||||
use_helper QuizHelper
|
||||
use_helper UtilHelper
|
||||
|
|
Loading…
Reference in a new issue