Skip to content
Open
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
6 changes: 6 additions & 0 deletions app/controllers/admin/sensemaker/jobs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def new
processes.each do |process|
collection = []

collection << { title: I18n.t("admin.sensemaker.new.analyse_all_questions",
model_label: I18n.t("activerecord.models.legislation/question.other"),
default: "Analyse all questions"),
object: process }
@result_count += 1

unless process.proposals.empty?
collection << {
title: I18n.t("activerecord.models.legislation/proposal.other"),
Expand Down
35 changes: 35 additions & 0 deletions app/lib/conversation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ def comments
else
Comment.none
end
elsif @target.is_a?(Legislation::Process)
questions = @target.questions

questions.flat_map.with_index do |question, index|
question_number = index + 1

question.comments.includes(:user).where(hidden_at: nil).map do |comment|
CommentLikeItem.new(
id: comment.id,
body: "(Q#{question_number}) #{comment.body}",
cached_votes_up: comment.cached_votes_up,
cached_votes_down: comment.cached_votes_down,
cached_votes_total: comment.cached_votes_total,
user_id: comment.user_id
)
end
end
elsif @target.is_a?(Budget) || @target.is_a?(Budget::Group)
investments = @target.investments.includes(:author).where(hidden_at: nil)
investments.map do |investment|
Expand Down Expand Up @@ -321,6 +338,24 @@ def self.compile_class_specific_context(target, i18n_scope:)
parts << I18n.t("#{i18n_scope}.budget_group.budget",
budget_name: target.budget.name)
end
when "Legislation::Process"
questions = target.questions
if questions.any?
parts << I18n.t("#{i18n_scope}.legislation_process.questions_header",
default: "## Questions in this process")
questions.each_with_index do |question, index|
parts << I18n.t("#{i18n_scope}.legislation_process.question_line",
number: index + 1,
title: question.title)
if question.respond_to?(:description) && question.description.present?
parts << I18n.t("#{i18n_scope}.legislation_process.question_description",
description: sanitize_html(question.description))
end
end
default_note = "Note: Comments are prefixed with (Qn) to indicate which question they refer to."
parts << I18n.t("#{i18n_scope}.legislation_process.prefix_note",
default: default_note)
end
end

parts
Expand Down
1 change: 1 addition & 0 deletions app/models/sensemaker/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Job < ApplicationRecord
"Proposal",
"Poll",
"Poll::Question",
"Legislation::Process",
"Legislation::Question",
"Legislation::Proposal",
"Legislation::QuestionOption",
Expand Down
1 change: 1 addition & 0 deletions config/locales/en/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1795,6 +1795,7 @@ en:
segment_by_option: "Segment by option"
no_free_text_to_analyse: "No free text to analyse for this question"
or_analyse_all_proposals: "or analyse all proposals"
analyse_all_questions: "Analyse all questions"
search_placeholder: "Search for %{model_label}..."
clear_search: "Clear search"
select_script_blank: "Select a script..."
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en/conversation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ en:
budget/group: "Participatory budget group"
proposal: "Citizen proposal"
debate: "Citizen debate"
legislation/process: "Collaborative legislation process"
legislation/proposal: "Collaborative legislation proposal"
legislation/question: "Collaborative legislation debate"
legislation/question_option: "Collaborative legislation debate segmented by option"
Expand All @@ -37,6 +38,12 @@ en:
responses_header: "### Debate Responses"
option: "- %{value} (%{answers_count} responses)"

legislation_process:
questions_header: "## Questions in this process"
question_line: " Q%{number}: %{title}"
question_description: " - %{description}"
prefix_note: "Note: Comments are prefixed with (Qn) to indicate which question they refer to."

question_option:
filter_note: "Note: Comments in this analysis are filtered to only include comments from users who selected the option \"%{option_value}\" in their response to this debate."

Expand Down
1 change: 1 addition & 0 deletions config/locales/es/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,7 @@ es:
segment_by_option: "Segmentar por opción"
no_free_text_to_analyse: "No hay texto libre para analizar en esta pregunta"
or_analyse_all_proposals: "o analizar todas las propuestas"
analyse_all_questions: "Analizar todas las preguntas"
search_placeholder: "Buscar %{model_label}..."
clear_search: "Limpiar búsqueda"
select_script_blank: "Seleccionar un script..."
Expand Down
7 changes: 7 additions & 0 deletions config/locales/es/conversation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ es:
budget/group: "Grupo de presupuesto participativo"
proposal: "Propuesta ciudadana"
debate: "Debate ciudadano"
legislation/process: "Proceso legislativo colaborativo"
legislation/proposal: "Propuesta legislativa colaborativa"
legislation/question: "Debate legislativo colaborativo"
legislation/question_option: "Debate legislativo colaborativo segmentado por opción"
Expand All @@ -37,6 +38,12 @@ es:
responses_header: "### Respuestas del Debate"
option: "- %{value} (%{answers_count} respuestas)"

legislation_process:
questions_header: "## Preguntas en este proceso"
question_line: " Q%{number}: %{title}"
question_description: " - %{description}"
prefix_note: "Nota: Los comentarios incluyen el prefijo (Qn) para indicar a qué pregunta se refieren."

question_option:
filter_note: "Nota: Los comentarios en este análisis están filtrados para incluir solo los comentarios de usuarios que seleccionaron la opción \"%{option_value}\" en su respuesta a este debate."

Expand Down
39 changes: 39 additions & 0 deletions spec/lib/conversation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,26 @@ def expect_no_html_tags(content, tags = HTML_TAGS)
)
expect(context_result).to include("Q1 (Open ended): Open Question")
end

it "can compile context for Legislation::Process with questions index and prefix note" do
process = create(:legislation_process, title: "Test Process")
question_1 = create(:legislation_question, process: process, title: "First question")
question_2 = create(:legislation_question, process: process, title: "Second question")

create(:comment, commentable: question_1, user: user, body: "Comment for Q1")
create(:comment, commentable: question_2, user: user, body: "Comment for Q2")

conversation = Conversation.new("Legislation::Process", process.id)
context_result = conversation.compile_context

expect(context_result).to be_present
expect(context_result).to include("Analysing Collaborative legislation process")
expect(context_result).to include("## Questions in this process")
expect(context_result).to include("Q1: First question")
expect(context_result).to include("Q2: Second question")
expect(context_result).to include("prefixed with (Qn)")
expect(context_result).to include("- Comments: #{conversation.comments.size}")
end
end

describe "#comments" do
Expand Down Expand Up @@ -354,6 +374,25 @@ def expect_no_html_tags(content, tags = HTML_TAGS)
end
end

describe "handles Legislation::Process (aggregates question comments with prefixes)" do
it "prefixes comment-like items with the question number (Qn)" do
process = create(:legislation_process, title: "Test Process")
question_1 = create(:legislation_question, process: process, title: "First question")
question_2 = create(:legislation_question, process: process, title: "Second question")

comment_1 = create(:comment, commentable: question_1, user: user, body: "Hello from Q1")
comment_2 = create(:comment, commentable: question_2, user: user, body: "Hello from Q2")

conversation = Conversation.new("Legislation::Process", process.id)
items = conversation.comments

expect(items.size).to eq(2)
expect(items).to all(be_a(Conversation::CommentLikeItem))
expect(items.map(&:id)).to contain_exactly(comment_1.id, comment_2.id)
expect(items.map(&:body)).to contain_exactly("(Q1) Hello from Q1", "(Q2) Hello from Q2")
end
end

describe "handles Poll with standard comments" do
it "collects standard comments on the poll when poll has only multi-choice questions" do
poll = create(:poll)
Expand Down