alembic 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f38cde96366dd41e05b819090a8f5b4de025b4921a08f126aa714c1d04a1e83f
4
- data.tar.gz: d187ea086b4a84eadc365ff2bcd63e4f5c73fc9b2ec7482ac3f07530177a781d
3
+ metadata.gz: b4d8ccc041b35716812e48190752b8e3f09896ead61f26c17d8b7b5e64d267e8
4
+ data.tar.gz: 5c74978edd2eafde2aec301df9ef5fb170be77d85f96bde6b29c25d713c25cc6
5
5
  SHA512:
6
- metadata.gz: bee97ec86859157faaa3f266278857238d28691c232013d70508728e70e1bf284114927d0fe950100c7093e689ac5eefce71f0775094a72ce0b708d8a6870918
7
- data.tar.gz: 6ac975ac9a9b66947401d7c77324b46f1d9a8b69cf4db209da5b074d84b70090e79d01a457752bf053656c0efa2921003cd5798d33d0dc36d723abd0499d8248
6
+ metadata.gz: a40c070306c6c59745cebb00f14a30f0c0b30d608f540794d9ec8a8dbc05bc444299f772bfdc2a0d39e39f270c3bc516ae8387e79bea08f2d54b1c5597741896
7
+ data.tar.gz: a70c7c32baa1cec0933517001f3f7112a0909ebd9ae4755ee5695c3c2cafbaf1f4e96a062fe2a8603625ad1ab916a997da7ab840c2718d0ace1bb92a029a2fc2
@@ -1,3 +1,6 @@
1
+ require "digest"
2
+ require "securerandom"
3
+
1
4
  module Alembic
2
5
  class FlowsController < EasyFlow::FlowsController
3
6
  hosted_by FLOW_HOST
@@ -28,6 +31,16 @@ module Alembic
28
31
  questions
29
32
  end
30
33
 
34
+ def shown(question)
35
+ return question unless question.respond_to?(:choices) && Flow::Summaries.new(run&.flow || flow).shuffles_answers?
36
+
37
+ question.with(choices: question.choices.sort_by { |choice| Digest::SHA256.hexdigest("#{shuffle_seed}:#{question.id}:#{choice.value}") })
38
+ end
39
+
40
+ def shuffle_seed
41
+ run&.public_code || (cookies[:alembic_shuffle_seed] ||= SecureRandom.hex(8))
42
+ end
43
+
31
44
  def shows_answer_values?
32
45
  Flow::Summaries.new(run&.flow || flow).shows_answer_values?
33
46
  end
@@ -15,6 +15,7 @@ module Alembic
15
15
  @categories = questions_of(@flow).filter_map { |node| EasyFlow::Steps::Question.category_of(node) }.uniq
16
16
  @shows_answer_values = summaries.shows_answer_values?
17
17
  @asks_on_one_page = summaries.asks_on_one_page?
18
+ @shuffles_answers = summaries.shuffles_answers?
18
19
  @branches = summaries.branches?
19
20
  @published_pages = owned_pages.where(id: Page::Version.live.select(:page_id)).order(:name)
20
21
  end
@@ -27,6 +28,7 @@ module Alembic
27
28
  summaries.finish_on(owned_pages.find_by(id: details[:summary_page_id])) unless details[:summary_page_id].nil?
28
29
  summaries.show_answer_values(details[:shows_answer_values] == "1") unless details[:shows_answer_values].nil?
29
30
  summaries.ask_on_one_page(details[:asks_on_one_page] == "1") unless details[:asks_on_one_page].nil?
31
+ summaries.shuffle_answers(details[:shuffles_answers] == "1") unless details[:shuffles_answers].nil?
30
32
  record_outputs(summaries, details[:outputs]) if details[:outputs]
31
33
 
32
34
  super
@@ -10,11 +10,15 @@ module Alembic
10
10
  helper ContentBlocksHelper
11
11
  helper KsBlocks::LayoutHelper
12
12
  after_action :keep_ended_inner_run, only: :step
13
- helper_method :flow_summary, :first_step_path, :summary_values, :intro_values, :start_over_path, :finish_link, :visited_flow_address, :answered_right?, :single_choice?, :drawing_of, :chosen_answer, :step_category
13
+ helper_method :flow_summary, :first_step_path, :summary_values, :intro_values, :start_over_path, :finish_link, :visited_flow_address, :answered_right?, :single_choice?, :drawing_of, :chosen_answer, :step_category, :shown
14
14
  end
15
15
 
16
16
  private
17
17
 
18
+ def shown(question)
19
+ question
20
+ end
21
+
18
22
  def single_choice?(question)
19
23
  @guide.step(question.id)&.type == "question"
20
24
  end
@@ -49,6 +49,14 @@ module Alembic
49
49
  details.update!(shows_answer_values: shown)
50
50
  end
51
51
 
52
+ def shuffles_answers?
53
+ details.shuffles_answers
54
+ end
55
+
56
+ def shuffle_answers(shuffled)
57
+ details.update!(shuffles_answers: shuffled)
58
+ end
59
+
52
60
  def asks_on_one_page?
53
61
  details.asks_on_one_page
54
62
  end
@@ -14,9 +14,9 @@
14
14
  <div data-one-page-question>
15
15
  <div class="mb-8"><%= ui_progress(value: index, max: @questions.size, label: "Question #{index + 1} of #{@questions.size}") %></div>
16
16
  <% if single_choice?(question) %>
17
- <%= render "alembic/flows/question", question: question, category: step_category(question), shows_values: shows_answer_values?, sends_on_choice: false %>
17
+ <%= render "alembic/flows/question", question: shown(question), category: step_category(question), shows_values: shows_answer_values?, sends_on_choice: false %>
18
18
  <% else %>
19
- <%= render drawing_of(question), step: question %>
19
+ <%= render drawing_of(question), step: shown(question) %>
20
20
  <% end %>
21
21
  <% if index.positive? %>
22
22
  <button type="button" data-one-page-previous hidden class="mt-6 ks-tone-muted cursor-pointer text-sm underline underline-offset-2 hover:text-(color:--ks-color-text) dark:hover:text-(color:--ks-color-text-dark)">← Previous</button>
@@ -26,10 +26,10 @@
26
26
  <% end %>
27
27
 
28
28
  <% if single_choice?(@question) %>
29
- <%= render "alembic/flows/question", question: @question, category: step_category(@question),
29
+ <%= render "alembic/flows/question", question: shown(@question), category: step_category(@question),
30
30
  shows_values: shows_answer_values?, chosen: chosen_answer(@question) %>
31
31
  <% else %>
32
- <%= render @drawing, step: @question, chosen: chosen_answer(@question) %>
32
+ <%= render @drawing, step: shown(@question), chosen: chosen_answer(@question) %>
33
33
  <% end %>
34
34
 
35
35
  <div class="mt-8 flex items-center gap-4">
@@ -39,6 +39,12 @@
39
39
  <%= check_box_tag "flow[asks_on_one_page]", "1", @asks_on_one_page, disabled: @branches %>
40
40
  <span>Ask every question on one page</span>
41
41
  </label>
42
+
43
+ <%= hidden_field_tag "flow[shuffles_answers]", "0", id: nil %>
44
+ <label class="mt-3 flex items-center gap-2">
45
+ <%= check_box_tag "flow[shuffles_answers]", "1", @shuffles_answers %>
46
+ <span>Show each question's answers in a random order</span>
47
+ </label>
42
48
  <% end %>
43
49
 
44
50
  <%= ui_section(title: "Where this starts") do %>
@@ -0,0 +1,5 @@
1
+ class AddShufflesAnswersToAlembicFlowDefinitionSummaries < ActiveRecord::Migration[8.1]
2
+ def change
3
+ add_column :alembic_flow_definition_summaries, :shuffles_answers, :boolean, default: false, null: false
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module Alembic
2
- VERSION = "0.9.1"
2
+ VERSION = "0.10.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alembic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider
@@ -217,6 +217,7 @@ files:
217
217
  - db/migrate/20261001120002_add_intro_page_to_alembic_flow_definition_summaries.rb
218
218
  - db/migrate/20261001170001_add_owner_to_alembic_pages.rb
219
219
  - db/migrate/20261020120000_add_kept_result_to_alembic_flow_run_summaries.rb
220
+ - db/migrate/20261025031225_add_shuffles_answers_to_alembic_flow_definition_summaries.rb
220
221
  - lib/alembic.rb
221
222
  - lib/alembic/engine.rb
222
223
  - lib/alembic/leftover_stylesheet.rb