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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render readonly questionnaire to non logged participant #4991

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -67,6 +67,7 @@ end
- **decidim-admin**: Add css variables for multitenant custom colors. [\#4882](https://github.com/decidim/decidim/pull/4882)
- **decidim-verifications**: Allow definition of attributes in settings manifest to be required always on authorizations. [\#4911](https://github.com/decidim/decidim/pull/4911)
- **decidim-verifications**: Allow resending SMS code. [\#4928](https://github.com/decidim/decidim/pull/4928)
- **decidim-forms** Render readonly questionnaire to non logged participants [\#4991](https://github.com/decidim/decidim/pull/4991)

**Changed**:

Expand Down
3 changes: 3 additions & 0 deletions decidim-forms/app/assets/config/decidim_forms_manifest.css
@@ -0,0 +1,3 @@
/*
*= link decidim/forms/forms.scss
*/
37 changes: 37 additions & 0 deletions decidim-forms/app/assets/stylesheets/decidim/forms/forms.scss
@@ -0,0 +1,37 @@
.questionnaire-question_readonly{
font-weight: bold;
font-size: .875rem;

p{
margin-bottom: .5rem;
}

em{
font-weight: normal;
font-size: 90%;
}

p + ul{
margin-top: -.5rem;
}
}

.questionnaire-question_readonly-answers{
margin-bottom: .5rem;

&.single_option{
list-style-type: disc;
}

&.multiple_option{
list-style-type: square;
}

&.sorting{
list-style-type: circle;
}
}

.questionnaire-question_readonly-answer{
font-weight: normal;
}
@@ -0,0 +1,3 @@
<li class="questionnaire-question_readonly-answer">
<%= translated_attribute(model.body) %>
</li>
9 changes: 9 additions & 0 deletions decidim-forms/app/cells/decidim/forms/answer_readonly_cell.rb
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Decidim
module Forms
# This cell renders a possible answer of a question (readonly)
class AnswerReadonlyCell < Decidim::ViewModel
end
end
end
15 changes: 15 additions & 0 deletions decidim-forms/app/cells/decidim/forms/question_readonly/show.erb
@@ -0,0 +1,15 @@
<li class="questionnaire-question_readonly">
<p>
<%= translated_attribute(model.body) %>
<br />
<em>
(<%= t(model.question_type, scope: "decidim.forms.question_types") %>)
</em>
</p>

<% if model.multiple_choice? %>
<ul class="questionnaire-question_readonly-answers <%= model.question_type %>">
<%= cell("decidim/forms/answer_readonly", collection: model.answer_options) %>
</ul>
<% end %>
</li>
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Decidim
module Forms
# This cell renders a question (readonly) of a questionnaire
class QuestionReadonlyCell < Decidim::ViewModel
end
end
end
Expand Up @@ -66,6 +66,10 @@
<p>
<%= t(".answer_questionnaire.anonymous_user_message", sign_in_link: decidim.new_user_session_path, sign_up_link: decidim.new_user_registration_path).html_safe %>
</p>

<ol>
<%= cell("decidim/forms/question_readonly", collection: @questionnaire.questions) %>
</ol>
</div>
<% end %>
<% else %>
Expand Down
6 changes: 5 additions & 1 deletion decidim-forms/lib/decidim/forms/engine.rb
Expand Up @@ -6,8 +6,12 @@ module Forms
class Engine < ::Rails::Engine
isolate_namespace Decidim::Forms

initializer "decidim_forms.add_cells_view_paths" do
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Forms::Engine.root}/app/cells")
end

initializer "decidim_forms.assets" do |app|
app.config.assets.precompile += %w(decidim_forms_manifest.js)
app.config.assets.precompile += %w(decidim_forms_manifest.js decidim_forms_manifest.css)
end
end
end
Expand Down
Expand Up @@ -10,7 +10,11 @@
expect(page).to have_i18n_content(questionnaire.title, upcase: true)
expect(page).to have_i18n_content(questionnaire.description)

expect(page).to have_no_i18n_content(question.body)
expect(page).not_to have_css(".form.answer-questionnaire")

within ".questionnaire-question_readonly" do
expect(page).to have_i18n_content(question.body)
end

expect(page).to have_content("Sign in with your account or sign up to answer the form.")
end
Expand Down
6 changes: 5 additions & 1 deletion decidim-meetings/spec/system/meeting_registrations_spec.rb
Expand Up @@ -125,7 +125,11 @@ def questionnaire_public_path
expect(page).to have_i18n_content(questionnaire.title, upcase: true)
expect(page).to have_i18n_content(questionnaire.description)

expect(page).to have_no_i18n_content(question.body)
expect(page).not_to have_css(".form.answer-questionnaire")

within ".questionnaire-question_readonly" do
expect(page).to have_i18n_content(question.body)
end

expect(page).to have_content("Sign in with your account or sign up to answer the form")
end
Expand Down
@@ -1,3 +1,5 @@
@import "decidim/forms/forms";

form.answer-questionnaire{
.radio-button-collection,
.check-box-collection,
Expand Down
6 changes: 5 additions & 1 deletion decidim-surveys/spec/system/private_space_survey_spec.rb
Expand Up @@ -55,7 +55,11 @@ def visit_component
expect(page).to have_i18n_content(questionnaire.title, upcase: true)
expect(page).to have_i18n_content(questionnaire.description)

expect(page).to have_no_i18n_content(question.body)
expect(page).not_to have_css(".form.answer-questionnaire")

within ".questionnaire-question_readonly" do
expect(page).to have_i18n_content(question.body)
end

expect(page).to have_content("Sign in with your account or sign up to answer the form.")
end
Expand Down