diff --git a/app/controllers/codebooks_controller.rb b/app/controllers/codebooks_controller.rb index 7831b6f..a804774 100644 --- a/app/controllers/codebooks_controller.rb +++ b/app/controllers/codebooks_controller.rb @@ -1,20 +1,20 @@ class CodebooksController < ApplicationController def index - @contexts = Question::QUESTIONS + @questions = Question.all.order(:created_at) end def show - @question = Question.find_by(key: params[:id]) + @question = Question.find(params[:id]) @context = @question.context @context_key = @context.name @enqueued_at = params[:enqueued_at].present? ? Time.at(params[:enqueued_at].to_i).strftime("%T %Z") : nil # Support the previous/next navigation controls - sections = Question.all.pluck(:key) - previous_index = (sections.index(@question.key) - 1) - next_index = (sections.index(@question.key) + 1) % sections.length + sections = Question.all.pluck(:id) + previous_index = (sections.index(@question.id) - 1) + next_index = (sections.index(@question.id) + 1) % sections.length @section_name = @question.label @previous_section = sections[previous_index] @next_section = sections[next_index] @@ -24,7 +24,7 @@ def show @frequencies = Identity.histogram(@context.name) @frequencies_by_keys = @frequencies.sort{|a, b| a[0] <=> b[0]} @frequencies_by_values = @frequencies.sort{|a, b| a[1] <=> b[1]} - elsif @question.is_experience? + else # Experience fields have associated Code and Category objects. @frequencies = Code.histogram(@context.name) @frequencies_by_keys = @frequencies.sort{|a, b| a[0] <=> b[0]} @@ -37,7 +37,7 @@ def show end def enqueue_categories - context = Question.find_by(params[:codebook_id]).context.name + context = Question.find(params[:codebook_id]).context.name CategoryExtractorJob.perform_async(context) redirect_to(action: :show, id: params[:codebook_id], params: {enqueued_at: Time.now.strftime("%s")}) end diff --git a/app/models/response.rb b/app/models/response.rb index 29db57e..37271f6 100644 --- a/app/models/response.rb +++ b/app/models/response.rb @@ -1,5 +1,6 @@ class Response < ApplicationRecord + # TODO I need this to run under normal circumstances but NOT during the db migration that creates the records. after_save_commit :enqueue_export_to_graph belongs_to :survey_response diff --git a/app/views/codebooks/index.html.erb b/app/views/codebooks/index.html.erb index 55faa4b..b61f264 100644 --- a/app/views/codebooks/index.html.erb +++ b/app/views/codebooks/index.html.erb @@ -2,11 +2,11 @@

Browse the Codebook.

-

Contexts

+

Questions

diff --git a/app/views/codebooks/show.html.erb b/app/views/codebooks/show.html.erb index 642b6e8..8bf62d2 100644 --- a/app/views/codebooks/show.html.erb +++ b/app/views/codebooks/show.html.erb @@ -3,10 +3,10 @@

<%= pluralize(@frequencies.count, "Code") %> for "<%= @section_name %>".

<% if @previous_section %> - <%= link_to "<", codebook_path(@previous_section), class: "flip", id: "flip-left" %> + <%= link_to "<", codebook_path(id: @previous_section), class: "flip", id: "flip-left" %> <% end %> <% if @next_section %> - <%= link_to ">", codebook_path(@next_section), class: "flip", id: "flip-right" %> + <%= link_to ">", codebook_path(id: @next_section), class: "flip", id: "flip-right" %> <% end %> <% if @categories_histogram %> diff --git a/app/views/questions/show.html.erb b/app/views/questions/show.html.erb index f824c5d..21bf6ce 100644 --- a/app/views/questions/show.html.erb +++ b/app/views/questions/show.html.erb @@ -7,7 +7,7 @@

Reference:

diff --git a/db/migrate/20241029012413_populate_responses.rb b/db/migrate/20241029012413_populate_responses.rb index 961373b..81b6bf9 100644 --- a/db/migrate/20241029012413_populate_responses.rb +++ b/db/migrate/20241029012413_populate_responses.rb @@ -1,26 +1,28 @@ class PopulateResponses < ActiveRecord::Migration[7.2] def up - SurveyResponse.all.each do |survey_response| - Response.create(question_id: Question.find_by(key: 'age_given').id, survey_response_id: survey_response.id, value: survey_response.age_given, raw_codes: survey_response.age_id_codes) - Response.create(question_id: Question.find_by(key: 'age_exp').id, survey_response_id: survey_response.id, value: survey_response.age_exp, raw_codes: survey_response.age_exp_codes) - Response.create(question_id: Question.find_by(key: 'klass_given').id, survey_response_id: survey_response.id, value: survey_response.klass_given, raw_codes: survey_response.klass_id_codes) - Response.create(question_id: Question.find_by(key: 'klass_exp').id, survey_response_id: survey_response.id, value: survey_response.klass_exp, raw_codes: survey_response.klass_exp_codes) - Response.create(question_id: Question.find_by(key: 'race_ethnicity_given').id, survey_response_id: survey_response.id, value: survey_response.race_ethnicity_given, raw_codes: survey_response.race_ethnicity_id_codes) - Response.create(question_id: Question.find_by(key: 'race_ethnicity_exp').id, survey_response_id: survey_response.id, value: survey_response.race_ethnicity_exp, raw_codes: survey_response.race_ethnicity_exp_codes) - Response.create(question_id: Question.find_by(key: 'religion_given').id, survey_response_id: survey_response.id, value: survey_response.religion_given, raw_codes: survey_response.religion_id_codes) - Response.create(question_id: Question.find_by(key: 'religion_exp').id, survey_response_id: survey_response.id, value: survey_response.religion_exp, raw_codes: survey_response.religion_exp_codes) - Response.create(question_id: Question.find_by(key: 'disability_given').id, survey_response_id: survey_response.id, value: survey_response.disability_given, raw_codes: survey_response.disability_id_codes) - Response.create(question_id: Question.find_by(key: 'disability_exp').id, survey_response_id: survey_response.id, value: survey_response.disability_exp, raw_codes: survey_response.disability_exp_codes) - Response.create(question_id: Question.find_by(key: 'neurodiversity_given').id, survey_response_id: survey_response.id, value: survey_response.neurodiversity_given, raw_codes: survey_response.neurodiversity_id_codes) - Response.create(question_id: Question.find_by(key: 'neurodiversity_exp').id, survey_response_id: survey_response.id, value: survey_response.neurodiversity_exp, raw_codes: survey_response.neurodiversity_exp_codes) - Response.create(question_id: Question.find_by(key: 'gender_given').id, survey_response_id: survey_response.id, value: survey_response.gender_given, raw_codes: survey_response.gender_id_codes) - Response.create(question_id: Question.find_by(key: 'gender_exp').id, survey_response_id: survey_response.id, value: survey_response.gender_exp, raw_codes: survey_response.gender_exp_codes) - Response.create(question_id: Question.find_by(key: 'lgbtqia_given').id, survey_response_id: survey_response.id, value: survey_response.lgbtqia_given, raw_codes: survey_response.lgbtqia_id_codes) - Response.create(question_id: Question.find_by(key: 'lgbtqia_exp').id, survey_response_id: survey_response.id, value: survey_response.lgbtqia_exp, raw_codes: survey_response.lgbtqia_exp_codes) - Response.create(question_id: Question.find_by(key: 'pronouns_given').id, survey_response_id: survey_response.id, value: survey_response.pronouns_given, raw_codes: survey_response.pronouns_id_codes) - Response.create(question_id: Question.find_by(key: 'pronouns_exp').id, survey_response_id: survey_response.id, value: survey_response.pronouns_exp, raw_codes: survey_response.pronouns_exp_codes) - Response.create(question_id: Question.find_by(key: 'pronouns_feel').id, survey_response_id: survey_response.id, value: survey_response.pronouns_feel, raw_codes: survey_response.pronouns_feel_codes) - Response.create(question_id: Question.find_by(key: 'affinity').id, survey_response_id: survey_response.id, value: survey_response.affinity, raw_codes: survey_response.affinity_codes) + Response.suppress do + SurveyResponse.all.each do |survey_response| + Response.create(question_id: Question.find_by(key: 'age_given').id, survey_response_id: survey_response.id, value: survey_response.age_given, raw_codes: survey_response.age_id_codes) + Response.create(question_id: Question.find_by(key: 'age_exp').id, survey_response_id: survey_response.id, value: survey_response.age_exp, raw_codes: survey_response.age_exp_codes) + Response.create(question_id: Question.find_by(key: 'klass_given').id, survey_response_id: survey_response.id, value: survey_response.klass_given, raw_codes: survey_response.klass_id_codes) + Response.create(question_id: Question.find_by(key: 'klass_exp').id, survey_response_id: survey_response.id, value: survey_response.klass_exp, raw_codes: survey_response.klass_exp_codes) + Response.create(question_id: Question.find_by(key: 'race_ethnicity_given').id, survey_response_id: survey_response.id, value: survey_response.race_ethnicity_given, raw_codes: survey_response.race_ethnicity_id_codes) + Response.create(question_id: Question.find_by(key: 'race_ethnicity_exp').id, survey_response_id: survey_response.id, value: survey_response.race_ethnicity_exp, raw_codes: survey_response.race_ethnicity_exp_codes) + Response.create(question_id: Question.find_by(key: 'religion_given').id, survey_response_id: survey_response.id, value: survey_response.religion_given, raw_codes: survey_response.religion_id_codes) + Response.create(question_id: Question.find_by(key: 'religion_exp').id, survey_response_id: survey_response.id, value: survey_response.religion_exp, raw_codes: survey_response.religion_exp_codes) + Response.create(question_id: Question.find_by(key: 'disability_given').id, survey_response_id: survey_response.id, value: survey_response.disability_given, raw_codes: survey_response.disability_id_codes) + Response.create(question_id: Question.find_by(key: 'disability_exp').id, survey_response_id: survey_response.id, value: survey_response.disability_exp, raw_codes: survey_response.disability_exp_codes) + Response.create(question_id: Question.find_by(key: 'neurodiversity_given').id, survey_response_id: survey_response.id, value: survey_response.neurodiversity_given, raw_codes: survey_response.neurodiversity_id_codes) + Response.create(question_id: Question.find_by(key: 'neurodiversity_exp').id, survey_response_id: survey_response.id, value: survey_response.neurodiversity_exp, raw_codes: survey_response.neurodiversity_exp_codes) + Response.create(question_id: Question.find_by(key: 'gender_given').id, survey_response_id: survey_response.id, value: survey_response.gender_given, raw_codes: survey_response.gender_id_codes) + Response.create(question_id: Question.find_by(key: 'gender_exp').id, survey_response_id: survey_response.id, value: survey_response.gender_exp, raw_codes: survey_response.gender_exp_codes) + Response.create(question_id: Question.find_by(key: 'lgbtqia_given').id, survey_response_id: survey_response.id, value: survey_response.lgbtqia_given, raw_codes: survey_response.lgbtqia_id_codes) + Response.create(question_id: Question.find_by(key: 'lgbtqia_exp').id, survey_response_id: survey_response.id, value: survey_response.lgbtqia_exp, raw_codes: survey_response.lgbtqia_exp_codes) + Response.create(question_id: Question.find_by(key: 'pronouns_given').id, survey_response_id: survey_response.id, value: survey_response.pronouns_given, raw_codes: survey_response.pronouns_id_codes) + Response.create(question_id: Question.find_by(key: 'pronouns_exp').id, survey_response_id: survey_response.id, value: survey_response.pronouns_exp, raw_codes: survey_response.pronouns_exp_codes) + Response.create(question_id: Question.find_by(key: 'pronouns_feel').id, survey_response_id: survey_response.id, value: survey_response.pronouns_feel, raw_codes: survey_response.pronouns_feel_codes) + Response.create(question_id: Question.find_by(key: 'affinity').id, survey_response_id: survey_response.id, value: survey_response.affinity, raw_codes: survey_response.affinity_codes) + end end end