decidim-templates 0.24.3 → 0.25.0.rc4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of decidim-templates might be problematic. Click here for more details.

Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/app/commands/decidim/templates/admin/apply_questionnaire_template.rb +3 -27
  3. data/app/commands/decidim/templates/admin/copy_questionnaire_template.rb +2 -26
  4. data/app/commands/decidim/templates/admin/questionnaire_copier.rb +65 -0
  5. data/app/controllers/decidim/templates/admin/questionnaire_templates_controller.rb +3 -2
  6. data/app/packs/entrypoints/decidim_templates.js +4 -0
  7. data/app/packs/entrypoints/decidim_templates.scss +1 -0
  8. data/app/{assets/images/decidim/templates/icon.svg → packs/images/decidim/templates/decidim_templates.svg} +0 -0
  9. data/app/{assets → packs}/stylesheets/decidim/templates/templates.scss +0 -0
  10. data/app/views/decidim/templates/admin/questionnaire_templates/_choose.html.erb +1 -1
  11. data/app/views/decidim/templates/admin/questionnaire_templates/_preview.html.erb +1 -1
  12. data/app/views/layouts/decidim/admin/templates.html.erb +1 -1
  13. data/config/assets.rb +8 -0
  14. data/config/locales/ca.yml +7 -0
  15. data/config/locales/cs.yml +7 -0
  16. data/config/locales/en.yml +7 -0
  17. data/config/locales/fi-plain.yml +7 -0
  18. data/config/locales/fi.yml +7 -0
  19. data/config/locales/fr-CA.yml +7 -0
  20. data/config/locales/fr-LU.yml +67 -0
  21. data/config/locales/fr.yml +7 -0
  22. data/config/locales/gl.yml +7 -0
  23. data/config/locales/it.yml +8 -0
  24. data/config/locales/ja.yml +7 -0
  25. data/config/locales/lb-LU.yml +1 -0
  26. data/config/locales/nl.yml +7 -0
  27. data/config/locales/pl.yml +1 -1
  28. data/config/locales/pt-BR.yml +66 -0
  29. data/config/locales/ro-RO.yml +7 -0
  30. data/db/seeds.rb +2 -2
  31. data/lib/decidim/templates/admin_engine.rb +9 -14
  32. data/lib/decidim/templates/engine.rb +0 -4
  33. data/lib/decidim/templates/test/factories.rb +7 -0
  34. data/lib/decidim/templates/test/shared_examples/copies_all_questionnaire_contents_examples.rb +67 -0
  35. data/lib/decidim/templates/version.rb +1 -1
  36. metadata +21 -17
  37. data/app/assets/config/decidim_templates_manifest.css +0 -3
  38. data/app/assets/config/decidim_templates_manifest.js +0 -0
  39. data/app/helpers/decidim/templates/admin/templates_menu_helper.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c53f82e351aede44479637b64b2071cb2098bcacd554167e459886cd794e3c4d
4
- data.tar.gz: 171dfc6e86bd01c8ae3393b44b12263233b6363ff0573aa3b14018df2ef06044
3
+ metadata.gz: 6b539d55d24870366656ad094e3fc9fe74589565f4d5e0ae4db83beda03a38f2
4
+ data.tar.gz: 701f43b32e4df6040be7609db0f14501be89021dcc1c09e0ccd8edd5307e164f
5
5
  SHA512:
6
- metadata.gz: b2d08717c3a953da658af608a07b8bcb1892ecfa41168e4f7f5788cd4805283e4e7115a7e8ac2a5d599aa5d217eef23fdbdec4bfb964cf1e89d829db46fffbaf
7
- data.tar.gz: 2583e558a268e584ef7ade63161f36baecfad69d62e225f89fe1979e070236ffaf365cd6e5d73a52669b76a913d6a3cc74bdfe9ac4f1611053174d74a0fdb63d
6
+ metadata.gz: 22c0f7cb68b255ed447894a7b1fd8f0d92713f5adc1511c1065d40f1deacdb82c1ffcf07fd06f66948d4ca0e842793ad991a49b0a7731720f79bfd45536ee374
7
+ data.tar.gz: 65dbf079a5dab5b463321b94f834ad10fcf9b82103ec94822295905b1b93fd34e15fa8e89ae1608282b4d25ff7dfc8446369f029a69d40020e3da51987e11f06
@@ -5,6 +5,8 @@ module Decidim
5
5
  # A command with all the business logic when duplicating a questionnaire template
6
6
  module Admin
7
7
  class ApplyQuestionnaireTemplate < Rectify::Command
8
+ include Decidim::Templates::Admin::QuestionnaireCopier
9
+
8
10
  # Public: Initializes the command.
9
11
  #
10
12
  # template - The template we want to apply
@@ -21,7 +23,7 @@ module Decidim
21
23
  #
22
24
  # Returns nothing.
23
25
  def call
24
- return broadcast(:invalid) unless @template.valid?
26
+ return broadcast(:invalid) unless @template && @template.valid?
25
27
 
26
28
  Template.transaction do
27
29
  apply_template
@@ -42,32 +44,6 @@ module Decidim
42
44
  tos: @template.templatable.tos
43
45
  )
44
46
  end
45
-
46
- def copy_questionnaire_questions(original_questionnaire, new_questionnaire)
47
- original_questionnaire.questions.each do |original_question|
48
- new_question = original_question.dup
49
- new_question.questionnaire = new_questionnaire
50
- new_question.save!
51
- copy_questionnaire_answer_options(original_question, new_question)
52
- copy_questionnaire_matrix_rows(original_question, new_question)
53
- end
54
- end
55
-
56
- def copy_questionnaire_answer_options(original_question, new_question)
57
- original_question.answer_options.each do |original_answer_option|
58
- new_answer_option = original_answer_option.dup
59
- new_answer_option.question = new_question
60
- new_answer_option.save!
61
- end
62
- end
63
-
64
- def copy_questionnaire_matrix_rows(original_question, new_question)
65
- original_question.matrix_rows.each do |original_matrix_row|
66
- new_matrix_row = original_matrix_row.dup
67
- new_matrix_row.question = new_question
68
- new_matrix_row.save!
69
- end
70
- end
71
47
  end
72
48
  end
73
49
  end
@@ -5,6 +5,8 @@ module Decidim
5
5
  # A command with all the business logic when duplicating a questionnaire template
6
6
  module Admin
7
7
  class CopyQuestionnaireTemplate < Rectify::Command
8
+ include Decidim::Templates::Admin::QuestionnaireCopier
9
+
8
10
  # Public: Initializes the command.
9
11
  #
10
12
  # template - A template we want to duplicate
@@ -47,32 +49,6 @@ module Decidim
47
49
 
48
50
  @copied_template.update!(templatable: @resource)
49
51
  end
50
-
51
- def copy_questionnaire_questions(original_questionnaire, new_questionnaire)
52
- original_questionnaire.questions.each do |original_question|
53
- new_question = original_question.dup
54
- new_question.questionnaire = new_questionnaire
55
- new_question.save!
56
- copy_questionnaire_answer_options(original_question, new_question)
57
- copy_questionnaire_matrix_rows(original_question, new_question)
58
- end
59
- end
60
-
61
- def copy_questionnaire_answer_options(original_question, new_question)
62
- original_question.answer_options.each do |original_answer_option|
63
- new_answer_option = original_answer_option.dup
64
- new_answer_option.question = new_question
65
- new_answer_option.save!
66
- end
67
- end
68
-
69
- def copy_questionnaire_matrix_rows(original_question, new_question)
70
- original_question.matrix_rows.each do |original_matrix_row|
71
- new_matrix_row = original_matrix_row.dup
72
- new_matrix_row.question = new_question
73
- new_matrix_row.save!
74
- end
75
- end
76
52
  end
77
53
  end
78
54
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Templates
5
+ # All the business logic to duplicate a questionnaire
6
+ module Admin
7
+ module QuestionnaireCopier
8
+ def copy_questionnaire_questions(original_questionnaire, new_questionnaire)
9
+ # start by copying the questions so that they already exist when cross referencing them in the conditions
10
+ original_questionnaire.questions.includes(:answer_options, :matrix_rows, :display_conditions).load
11
+ original_questionnaire.questions.each do |original_question|
12
+ new_question = original_question.dup
13
+ new_question.questionnaire = new_questionnaire
14
+ new_question.save!
15
+ copy_questionnaire_answer_options(original_question, new_question)
16
+ copy_questionnaire_matrix_rows(original_question, new_question)
17
+ end
18
+ # once all questions are copied, copy display conditions
19
+ original_questionnaire.questions.zip(new_questionnaire.questions.load).each do |original_question, new_question|
20
+ copy_question_display_conditions(original_question, new_question)
21
+ end
22
+ end
23
+
24
+ def copy_questionnaire_answer_options(original_question, new_question)
25
+ original_question.answer_options.each do |original_answer_option|
26
+ new_answer_option = original_answer_option.dup
27
+ new_answer_option.question = new_question
28
+ new_answer_option.save!
29
+ end
30
+ end
31
+
32
+ def copy_questionnaire_matrix_rows(original_question, new_question)
33
+ original_question.matrix_rows.each do |original_matrix_row|
34
+ new_matrix_row = original_matrix_row.dup
35
+ new_matrix_row.question = new_question
36
+ new_matrix_row.save!
37
+ end
38
+ end
39
+
40
+ def copy_question_display_conditions(original_question, destination_question)
41
+ original_question.display_conditions.each do |original_display_condition|
42
+ new_display_condition = original_display_condition.dup
43
+ new_display_condition.question = destination_question
44
+
45
+ destination_question_to_be_checked = find_question_by_position(destination_question.questionnaire.questions, original_display_condition.condition_question.position)
46
+ new_display_condition.condition_question = destination_question_to_be_checked
47
+
48
+ if original_display_condition.answer_option
49
+ new_display_condition.answer_option = find_answer_option_by_body(destination_question_to_be_checked.answer_options, original_display_condition.answer_option.body)
50
+ end
51
+ new_display_condition.save!
52
+ end
53
+ end
54
+
55
+ def find_question_by_position(questions, position)
56
+ questions.to_a.find { |q| q.position == position }
57
+ end
58
+
59
+ def find_answer_option_by_body(answer_options, body)
60
+ answer_options.to_a.find { |ao| ao.body == body }
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -103,7 +103,7 @@ module Decidim
103
103
 
104
104
  def apply
105
105
  questionnaire = Decidim::Forms::Questionnaire.find_by(id: params[:questionnaire_id])
106
- template = Decidim::Templates::Template.find_by(id: params[:questionnaire][:questionnaire_template_id])
106
+ template = Decidim::Templates::Template.find_by(id: params.dig(:questionnaire, :questionnaire_template_id))
107
107
 
108
108
  ApplyQuestionnaireTemplate.call(questionnaire, template) do
109
109
  on(:ok) do
@@ -111,7 +111,8 @@ module Decidim
111
111
  redirect_to params[:url]
112
112
  end
113
113
  on(:invalid) do
114
- flash.now[:error] = I18n.t("templates.apply.error", scope: "decidim.admin")
114
+ flash[:error] = I18n.t("templates.apply.error", scope: "decidim.admin")
115
+ redirect_to EngineRouter.admin_proxy(questionnaire.questionnaire_for.component).survey_path
115
116
  end
116
117
  end
117
118
  end
@@ -0,0 +1,4 @@
1
+ import "entrypoints/decidim_templates.scss";
2
+
3
+ // Images
4
+ require.context("../images", true)
@@ -0,0 +1 @@
1
+ @import "stylesheets/decidim/templates/templates";
@@ -32,4 +32,4 @@
32
32
  </div>
33
33
  </div>
34
34
 
35
- <%= stylesheet_link_tag "decidim/templates/templates", media: "all" %>
35
+ <%= stylesheet_pack_tag "decidim_templates", media: "all" %>
@@ -70,4 +70,4 @@
70
70
  </div>
71
71
  </div>
72
72
 
73
- <%= stylesheet_link_tag "decidim/templates/templates", media: "all" %>
73
+ <%= stylesheet_pack_tag "decidim_templates", media: "all" %>
@@ -1,5 +1,5 @@
1
1
  <% content_for :sidebar_menu_nav do %>
2
- <%= template_types_menu.render %>
2
+ <%= sidebar_menu(:admin_template_types_menu).render %>
3
3
  <% end %>
4
4
 
5
5
  <%= render "layouts/decidim/admin/application" do %>
data/config/assets.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ base_path = File.expand_path("..", __dir__)
4
+
5
+ Decidim::Webpacker.register_path("#{base_path}/app/packs")
6
+ Decidim::Webpacker.register_entrypoints(
7
+ decidim_templates: "#{base_path}/app/packs/entrypoints/decidim_templates.js"
8
+ )
@@ -1,4 +1,11 @@
1
1
  ca:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Títol
6
+ template:
7
+ description: Descripció
8
+ name: Nom
2
9
  decidim:
3
10
  admin:
4
11
  menu:
@@ -1,4 +1,11 @@
1
1
  cs:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Název
6
+ template:
7
+ description: Popis
8
+ name: Jméno
2
9
  decidim:
3
10
  admin:
4
11
  menu:
@@ -1,5 +1,12 @@
1
1
  ---
2
2
  en:
3
+ activemodel:
4
+ attributes:
5
+ questionnaire:
6
+ title: Title
7
+ template:
8
+ description: Description
9
+ name: Name
3
10
  decidim:
4
11
  admin:
5
12
  menu:
@@ -1,4 +1,11 @@
1
1
  fi-pl:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Otsikko
6
+ template:
7
+ description: Kuvaus
8
+ name: Nimi
2
9
  decidim:
3
10
  admin:
4
11
  menu:
@@ -1,4 +1,11 @@
1
1
  fi:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Otsikko
6
+ template:
7
+ description: Kuvaus
8
+ name: Nimi
2
9
  decidim:
3
10
  admin:
4
11
  menu:
@@ -1,4 +1,11 @@
1
1
  fr-CA:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Titre
6
+ template:
7
+ description: Description
8
+ name: Nom
2
9
  decidim:
3
10
  admin:
4
11
  menu:
@@ -0,0 +1,67 @@
1
+ fr-LU:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Titre
6
+ template:
7
+ description: Description
8
+ name: Nom
9
+ decidim:
10
+ admin:
11
+ menu:
12
+ templates: Modèles de questionnaire
13
+ templates:
14
+ apply:
15
+ error: Une erreur est survenue lors de l'application de ce modèle.
16
+ success: Modèle appliqué avec succès
17
+ copy:
18
+ error: Une erreur est survenue lors de la copie de ce modèle.
19
+ success: Modèle copié avec succès
20
+ create:
21
+ error: Une erreur est survenue pendant la création du modèle.
22
+ success: Modèle créé avec succès
23
+ destroy:
24
+ success: Modèle supprimé avec succès
25
+ empty: Il n'y a pas de modèle pour l'instant.
26
+ update:
27
+ error: Une erreur est survenue pendant la mise à jour du modèle.
28
+ success: Modèle mis à jour avec succès
29
+ titles:
30
+ template_types:
31
+ questionnaires: Modèles de questionnaire
32
+ templates: Modèles
33
+ models:
34
+ questionnaire_template:
35
+ fields:
36
+ questions: Nombre de questions
37
+ title: Nom du questionnaire
38
+ template:
39
+ fields:
40
+ created_at: Créé le
41
+ name: Modèle
42
+ templates:
43
+ admin:
44
+ questionnaire_templates:
45
+ choose:
46
+ create_from_template: Créer depuis un modèle
47
+ description: Vous êtes sur le point de créer un nouveau questionnaire. Vous pouvez choisir un modèle prédéfini et le modifier par la suite.
48
+ label: Choisir un modèle
49
+ placeholder: Choisir un modèle
50
+ skip_template: Passer
51
+ edit:
52
+ edit: Modifier
53
+ empty: Il n'y a pas encore de question
54
+ questionnaire: Questionnaire
55
+ form:
56
+ save: Sauvegarder
57
+ template_title: Informations sur le modèle
58
+ title: Modèle de questionnaire %{questionnaire_for}
59
+ index:
60
+ confirm_delete: Êtes-vous sûr de vouloir supprimer ce modèle?
61
+ title: Modèles de questionnaire
62
+ preview:
63
+ current_step: Étape %{step}
64
+ of_total_steps: sur %{total_steps}
65
+ tos_agreement: En participant, vous acceptez ces conditions d'utilisation
66
+ template_types:
67
+ questionnaires: Questionnaires
@@ -1,4 +1,11 @@
1
1
  fr:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Titre
6
+ template:
7
+ description: Description
8
+ name: Nom
2
9
  decidim:
3
10
  admin:
4
11
  menu:
@@ -1,4 +1,11 @@
1
1
  gl:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Título
6
+ template:
7
+ description: Descrición
8
+ name: Nome
2
9
  decidim:
3
10
  admin:
4
11
  menu:
@@ -1,4 +1,11 @@
1
1
  it:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Titolo
6
+ template:
7
+ description: Descrizione
8
+ name: Nome
2
9
  decidim:
3
10
  admin:
4
11
  menu:
@@ -48,6 +55,7 @@ it:
48
55
  form:
49
56
  save: Salva
50
57
  template_title: Informazioni del modello
58
+ title: Template del questionario %{questionnaire_for}
51
59
  index:
52
60
  confirm_delete: Sei sicuro di voler eliminare questo modello?
53
61
  title: Modelli di questionari
@@ -1,4 +1,11 @@
1
1
  ja:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: タイトル
6
+ template:
7
+ description: 説明
8
+ name: 名前
2
9
  decidim:
3
10
  admin:
4
11
  menu:
@@ -0,0 +1 @@
1
+ lb:
@@ -1,4 +1,11 @@
1
1
  nl:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Titel
6
+ template:
7
+ description: Beschrijving
8
+ name: Naam
2
9
  decidim:
3
10
  admin:
4
11
  menu:
@@ -55,6 +55,6 @@ pl:
55
55
  preview:
56
56
  current_step: Krok %{step}
57
57
  of_total_steps: z %{total_steps}
58
- tos_agreement: Biorąc udział akceptujesz Regulamin korzystania z serwisu
58
+ tos_agreement: Biorąc udział akceptujesz Warunki korzystania z Platformy
59
59
  template_types:
60
60
  questionnaires: Kwestionariusze
@@ -1 +1,67 @@
1
1
  pt:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Título
6
+ template:
7
+ description: Descrição
8
+ name: Nome
9
+ decidim:
10
+ admin:
11
+ menu:
12
+ templates: Modelos
13
+ templates:
14
+ apply:
15
+ error: Ocorreu um erro ao aplicar este modelo.
16
+ success: Modelo aplicado com sucesso
17
+ copy:
18
+ error: Ocorreu um erro ao copiar este modelo.
19
+ success: Modelo copiado com sucesso
20
+ create:
21
+ error: Ocorreu um erro ao criar este modelo.
22
+ success: Modelo criado com sucesso
23
+ destroy:
24
+ success: Modelo excluído com sucesso
25
+ empty: Ainda não existem modelos.
26
+ update:
27
+ error: Ocorreu um erro ao atualizar este modelo.
28
+ success: Modelo atualizado com sucesso
29
+ titles:
30
+ template_types:
31
+ questionnaires: Modelos de questionário
32
+ templates: Modelos
33
+ models:
34
+ questionnaire_template:
35
+ fields:
36
+ questions: Número de Questões
37
+ title: Nome do questionário
38
+ template:
39
+ fields:
40
+ created_at: Criado em
41
+ name: Modelo
42
+ templates:
43
+ admin:
44
+ questionnaire_templates:
45
+ choose:
46
+ create_from_template: Criar a partir de modelo
47
+ description: Você está prestes a criar um novo questionário. Você pode escolher um modelo predefinido e modificá-lo depois.
48
+ label: Selecionar modelo
49
+ placeholder: Selecionar modelo
50
+ skip_template: Ignorar
51
+ edit:
52
+ edit: Editar
53
+ empty: Ainda não há questões
54
+ questionnaire: Questionário
55
+ form:
56
+ save: Salvar
57
+ template_title: Informações do Template
58
+ title: Modelo de questionário %{questionnaire_for}
59
+ index:
60
+ confirm_delete: Tem certeza de que deseja excluir este modelo?
61
+ title: Modelos de questionário
62
+ preview:
63
+ current_step: Passo %{step}
64
+ of_total_steps: de %{total_steps}
65
+ tos_agreement: Ao participar você aceita os Termos de Serviço
66
+ template_types:
67
+ questionnaires: Questionários
@@ -1,4 +1,11 @@
1
1
  ro:
2
+ activemodel:
3
+ attributes:
4
+ questionnaire:
5
+ title: Titlu
6
+ template:
7
+ description: Descriere
8
+ name: Nume
2
9
  decidim:
3
10
  admin:
4
11
  menu:
data/db/seeds.rb CHANGED
@@ -69,9 +69,9 @@ if !Rails.env.production? || ENV["SEED"]
69
69
  question_type: matrix_question_type
70
70
  )
71
71
 
72
- 3.times do
72
+ 3.times do |idx|
73
73
  question.answer_options.create!(body: Decidim::Faker::Localized.sentence)
74
- question.matrix_rows.create!(body: Decidim::Faker::Localized.sentence)
74
+ question.matrix_rows.create!(body: Decidim::Faker::Localized.sentence, position: idx)
75
75
  end
76
76
  end
77
77
 
@@ -30,18 +30,12 @@ module Decidim
30
30
  root to: "questionnaire_templates#index"
31
31
  end
32
32
 
33
- initializer "decidim_templates.action_controller" do |_app|
34
- ActiveSupport.on_load :action_controller do
35
- helper Decidim::Templates::Admin::TemplatesMenuHelper if respond_to?(:helper)
36
- end
37
- end
38
-
39
33
  initializer "decidim_participatory_processes.admin_participatory_processes_menu" do
40
34
  Decidim.menu :admin_template_types_menu do |menu|
41
35
  template_types.each_pair do |name, url|
42
- menu.item name, url,
43
- if: allowed_to?(:index, :templates),
44
- active: is_active_link?(url)
36
+ menu.add_item name, name, url,
37
+ if: allowed_to?(:index, :templates),
38
+ active: is_active_link?(url)
45
39
  end
46
40
  end
47
41
  end
@@ -54,11 +48,12 @@ module Decidim
54
48
 
55
49
  initializer "decidim_templates.admin_menu" do
56
50
  Decidim.menu :admin_menu do |menu|
57
- menu.item I18n.t("menu.templates", scope: "decidim.admin", default: "Templates"),
58
- decidim_admin_templates.questionnaire_templates_path,
59
- icon_name: "document",
60
- position: 12,
61
- active: :inclusive
51
+ menu.add_item :questionnaire_templates,
52
+ I18n.t("menu.templates", scope: "decidim.admin", default: "Templates"),
53
+ decidim_admin_templates.questionnaire_templates_path,
54
+ icon_name: "document",
55
+ position: 12,
56
+ active: :inclusive
62
57
  end
63
58
  end
64
59
 
@@ -14,10 +14,6 @@ module Decidim
14
14
  resources :templates
15
15
  # root to: "templates#index"
16
16
  end
17
-
18
- initializer "decidim_templates.assets" do |app|
19
- app.config.assets.precompile += %w(decidim_templates_manifest.js decidim_templates_manifest.css)
20
- end
21
17
  end
22
18
  end
23
19
  end
@@ -18,6 +18,13 @@ FactoryBot.define do
18
18
  end
19
19
  end
20
20
 
21
+ trait :with_all_questions do
22
+ after(:create) do |template|
23
+ template.templatable = create(:questionnaire, :with_all_questions, questionnaire_for: template)
24
+ template.save!
25
+ end
26
+ end
27
+
21
28
  after(:create) do |template|
22
29
  template.templatable = create(:questionnaire, questionnaire_for: template)
23
30
  template.save!
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ shared_examples_for "copies all questionnaire contents" do
6
+ describe "when the questionnaire has all contents" do
7
+ it "copies all template contents to the questionnaire" do
8
+ destination_questionnaire.reload
9
+
10
+ check_copy_questionnaire_questions(template.templatable, destination_questionnaire)
11
+ end
12
+
13
+ def check_copy_questionnaire_questions(source_questionnaire, new_questionnaire)
14
+ expect(source_questionnaire.questions.size).to eq(new_questionnaire.questions.size)
15
+
16
+ source_questionnaire.questions.each_with_index do |source_question, idx|
17
+ new_question = new_questionnaire.questions[idx]
18
+
19
+ expect(source_question.position).to eq(new_question.position)
20
+ expect(source_question.question_type).to eq(new_question.question_type)
21
+ expect(source_question.mandatory).to eq(new_question.mandatory)
22
+ expect(source_question.body).to eq(new_question.body)
23
+ expect(source_question.description).to eq(new_question.description)
24
+ expect(source_question.max_choices).to eq(new_question.max_choices)
25
+
26
+ check_answer_options(source_question, new_question)
27
+ check_matrix_rows(source_question, new_question)
28
+ check_display_conditions(source_question.display_conditions, new_question.display_conditions)
29
+ check_display_conditions(source_question.display_conditions_for_other_questions, new_question.display_conditions_for_other_questions)
30
+ end
31
+ end
32
+
33
+ def check_answer_options(source_question, new_question)
34
+ expect(source_question.answer_options.size).to eq(new_question.answer_options.size)
35
+
36
+ source_question.answer_options.each_with_index do |source_answer_option, idx|
37
+ new_answer_option = new_question.answer_options[idx]
38
+
39
+ expect(source_answer_option.body).to eq(new_answer_option.body)
40
+ end
41
+ end
42
+
43
+ def check_matrix_rows(source_question, new_question)
44
+ expect(source_question.matrix_rows.size).to eq(new_question.matrix_rows.size)
45
+
46
+ source_question.matrix_rows.each_with_index do |source_matrix_row, idx|
47
+ new_matrix_row = new_question.matrix_rows[idx]
48
+
49
+ expect(source_matrix_row.body).to eq(new_matrix_row.body)
50
+ expect(source_matrix_row.position).to eq(new_matrix_row.position)
51
+ end
52
+ end
53
+
54
+ def check_display_conditions(source_display_conditions, new_display_conditions)
55
+ expect(source_display_conditions.size).to eq(new_display_conditions.size)
56
+
57
+ source_display_conditions.each_with_index do |source_matrix_row, idx|
58
+ new_matrix_row = new_display_conditions[idx]
59
+
60
+ expect(source_matrix_row.condition_type).to eq(new_matrix_row.condition_type)
61
+ expect(source_matrix_row.condition_value).to eq(new_matrix_row.condition_value)
62
+ expect(source_matrix_row.mandatory).to eq(new_matrix_row.mandatory)
63
+ expect(new_matrix_row).to be_persisted
64
+ end
65
+ end
66
+ end
67
+ end
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-templates version.
5
5
  module Templates
6
6
  def self.version
7
- "0.24.3"
7
+ "0.25.0.rc4"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-templates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.3
4
+ version: 0.25.0.rc4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vera Rojman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-01 00:00:00.000000000 Z
11
+ date: 2021-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: decidim-core
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.24.3
19
+ version: 0.25.0.rc4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.24.3
26
+ version: 0.25.0.rc4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: decidim-forms
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.24.3
33
+ version: 0.25.0.rc4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.24.3
40
+ version: 0.25.0.rc4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: decidim-admin
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 0.24.3
47
+ version: 0.25.0.rc4
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.24.3
54
+ version: 0.25.0.rc4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: decidim-dev
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.24.3
61
+ version: 0.25.0.rc4
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.24.3
68
+ version: 0.25.0.rc4
69
69
  description: This module provides a solution to create templates for different Decidim
70
70
  models, such as Proposals and Questionnaires..
71
71
  email:
@@ -77,14 +77,11 @@ files:
77
77
  - LICENSE-AGPLv3.txt
78
78
  - README.md
79
79
  - Rakefile
80
- - app/assets/config/decidim_templates_manifest.css
81
- - app/assets/config/decidim_templates_manifest.js
82
- - app/assets/images/decidim/templates/icon.svg
83
- - app/assets/stylesheets/decidim/templates/templates.scss
84
80
  - app/commands/decidim/templates/admin/apply_questionnaire_template.rb
85
81
  - app/commands/decidim/templates/admin/copy_questionnaire_template.rb
86
82
  - app/commands/decidim/templates/admin/create_questionnaire_template.rb
87
83
  - app/commands/decidim/templates/admin/destroy_template.rb
84
+ - app/commands/decidim/templates/admin/questionnaire_copier.rb
88
85
  - app/commands/decidim/templates/admin/update_template.rb
89
86
  - app/controllers/decidim/templates/admin/application_controller.rb
90
87
  - app/controllers/decidim/templates/admin/concerns/templatable.rb
@@ -93,11 +90,14 @@ files:
93
90
  - app/controllers/decidim/templates/application_controller.rb
94
91
  - app/forms/decidim/templates/admin/template_form.rb
95
92
  - app/helpers/decidim/templates/admin/templates_helper.rb
96
- - app/helpers/decidim/templates/admin/templates_menu_helper.rb
97
93
  - app/helpers/decidim/templates/application_helper.rb
98
94
  - app/models/concerns/decidim/templates/templatable.rb
99
95
  - app/models/decidim/templates/application_record.rb
100
96
  - app/models/decidim/templates/template.rb
97
+ - app/packs/entrypoints/decidim_templates.js
98
+ - app/packs/entrypoints/decidim_templates.scss
99
+ - app/packs/images/decidim/templates/decidim_templates.svg
100
+ - app/packs/stylesheets/decidim/templates/templates.scss
101
101
  - app/permissions/decidim/templates/admin/permissions.rb
102
102
  - app/views/decidim/templates/admin/questionnaire_templates/_choose.html.erb
103
103
  - app/views/decidim/templates/admin/questionnaire_templates/_form.html.erb
@@ -107,6 +107,7 @@ files:
107
107
  - app/views/decidim/templates/admin/questionnaire_templates/new.html.erb
108
108
  - app/views/decidim/templates/admin/questionnaire_templates/preview.js.erb
109
109
  - app/views/layouts/decidim/admin/templates.html.erb
110
+ - config/assets.rb
110
111
  - config/locales/am-ET.yml
111
112
  - config/locales/ar.yml
112
113
  - config/locales/bg.yml
@@ -125,6 +126,7 @@ files:
125
126
  - config/locales/fi-plain.yml
126
127
  - config/locales/fi.yml
127
128
  - config/locales/fr-CA.yml
129
+ - config/locales/fr-LU.yml
128
130
  - config/locales/fr.yml
129
131
  - config/locales/ga-IE.yml
130
132
  - config/locales/gl.yml
@@ -136,6 +138,7 @@ files:
136
138
  - config/locales/ja.yml
137
139
  - config/locales/ko-KR.yml
138
140
  - config/locales/ko.yml
141
+ - config/locales/lb-LU.yml
139
142
  - config/locales/lt.yml
140
143
  - config/locales/lv.yml
141
144
  - config/locales/mt.yml
@@ -168,6 +171,7 @@ files:
168
171
  - lib/decidim/templates/admin_engine.rb
169
172
  - lib/decidim/templates/engine.rb
170
173
  - lib/decidim/templates/test/factories.rb
174
+ - lib/decidim/templates/test/shared_examples/copies_all_questionnaire_contents_examples.rb
171
175
  - lib/decidim/templates/test/shared_examples/uses_questionnaire_templates.rb
172
176
  - lib/decidim/templates/version.rb
173
177
  homepage: https://github.com/decidim/decidim-module-templates
@@ -185,9 +189,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
189
  version: '2.7'
186
190
  required_rubygems_version: !ruby/object:Gem::Requirement
187
191
  requirements:
188
- - - ">="
192
+ - - ">"
189
193
  - !ruby/object:Gem::Version
190
- version: '0'
194
+ version: 1.3.1
191
195
  requirements: []
192
196
  rubygems_version: 3.1.2
193
197
  signing_key:
@@ -1,3 +0,0 @@
1
- /*
2
- *= link decidim/templates/templates.scss
3
- */
File without changes
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Templates
5
- module Admin
6
- module TemplatesMenuHelper
7
- include Decidim::Admin::SidebarMenuHelper
8
-
9
- def template_types_menu
10
- @template_types_menu ||= sidebar_menu(:admin_template_types_menu)
11
- end
12
- end
13
- end
14
- end
15
- end