diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb
index af1ab147a..05b7fbeae 100644
--- a/app/controllers/legislation/processes_controller.rb
+++ b/app/controllers/legislation/processes_controller.rb
@@ -9,4 +9,24 @@ class Legislation::ProcessesController < Legislation::BaseController
def show
end
+
+ def draft_publication
+ phase :draft_publication
+ end
+
+ def allegations
+ phase :allegations
+ end
+
+ def final_version_publication
+ phase :final_version_publication
+ end
+
+ private
+
+ def phase(phase)
+ @process = ::Legislation::Process.find(params[:process_id])
+ @phase = phase
+ render :phase
+ end
end
diff --git a/app/controllers/legislation/questions_controller.rb b/app/controllers/legislation/questions_controller.rb
new file mode 100644
index 000000000..01653fca3
--- /dev/null
+++ b/app/controllers/legislation/questions_controller.rb
@@ -0,0 +1,7 @@
+class Legislation::QuestionsController < Legislation::BaseController
+ load_and_authorize_resource :process
+ load_and_authorize_resource :question, through: :process
+
+ def show
+ end
+end
diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb
index 790e21a5b..6b5fcbe87 100644
--- a/app/helpers/legislation_helper.rb
+++ b/app/helpers/legislation_helper.rb
@@ -1,5 +1,5 @@
module LegislationHelper
def format_date(date)
- l(date, format: "%d %b %Y")
+ l(date, format: "%d %b %Y") if date
end
end
diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb
index 88eccd00a..9569ebf53 100644
--- a/app/models/abilities/everyone.rb
+++ b/app/models/abilities/everyone.rb
@@ -11,7 +11,7 @@ module Abilities
can :read, User
can [:search, :read], Annotation
can :new, DirectMessage
- can [:read], Legislation::Process
+ can [:read, :draft_version_publication, :allegations, :final_version_publication], Legislation::Process
can [:read], Legislation::DraftVersion
end
end
diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb
index ac303b37d..dbc31c7b3 100644
--- a/app/models/legislation/process.rb
+++ b/app/models/legislation/process.rb
@@ -3,6 +3,7 @@ class Legislation::Process < ActiveRecord::Base
include ActsAsParanoidAliases
has_many :draft_versions, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id'
+ has_one :final_draft_version, -> { where final_version: true }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id'
has_many :questions, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id'
validates :title, presence: true
@@ -18,7 +19,38 @@ class Legislation::Process < ActiveRecord::Base
validates :allegations_end_date, presence: true
validates :final_publication_date, presence: true
- scope :open, -> {where("start_date <= ? and end_date >= ?", Time.current, Time.current) }
- scope :next, -> {where("start_date > ?", Time.current) }
- scope :past, -> {where("end_date < ?", Time.current) }
+ scope :open, -> {where("start_date <= ? and end_date >= ?", Date.current, Date.current) }
+ scope :next, -> {where("start_date > ?", Date.current) }
+ scope :past, -> {where("end_date < ?", Date.current) }
+
+ def open_phase?(phase)
+ today = Date.current
+
+ case phase
+ when :debate
+ today >= debate_start_date && today <= debate_end_date
+ when :draft_publication
+ today >= draft_publication_date
+ when :allegations
+ today >= allegations_start_date && today <= allegations_end_date
+ when :final_version_publication
+ today >= final_publication_date
+ end
+ end
+
+ def show_phase?(phase)
+ # show past phases even if they're finished
+ today = Date.current
+
+ case phase
+ when :debate
+ today >= debate_start_date
+ when :draft_publication
+ today >= draft_publication_date
+ when :allegations
+ today >= allegations_start_date
+ when :final_version_publication
+ today >= final_publication_date
+ end
+ end
end
diff --git a/app/views/legislation/processes/_debate.html.erb b/app/views/legislation/processes/_debate.html.erb
new file mode 100644
index 000000000..6bdfc26a0
--- /dev/null
+++ b/app/views/legislation/processes/_debate.html.erb
@@ -0,0 +1,14 @@
+
+
+ <% if process.questions.empty? %>
+
<%= t('.empty_questions') %>
+ <% else %>
+ <%= render process.questions %>
+ <% end %>
+
+
+
+
+
<%= t('.participate') %>
+
+
diff --git a/app/views/legislation/processes/_header_full.html.erb b/app/views/legislation/processes/_header_full.html.erb
new file mode 100644
index 000000000..4d365618e
--- /dev/null
+++ b/app/views/legislation/processes/_header_full.html.erb
@@ -0,0 +1,37 @@
+
+
+
+
<%= t('.title') %>
+
+ <%= process.title %>
+
+
+
+
+
+
+
+
<%= t('.description') %>
+ <%= markdown process.description %>
+
+
+
<%= t('.target') %>
+ <%= markdown process.target %>
+
+
+
<%= t('.how_to_participate') %>
+ <%= markdown process.how_to_participate %>
+
+
+
+
+
diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb
new file mode 100644
index 000000000..a6d921c35
--- /dev/null
+++ b/app/views/legislation/processes/_key_dates.html.erb
@@ -0,0 +1,29 @@
+
diff --git a/app/views/legislation/processes/_key_dates_svg.html.erb b/app/views/legislation/processes/_key_dates_svg.html.erb
new file mode 100644
index 000000000..c9f2eca94
--- /dev/null
+++ b/app/views/legislation/processes/_key_dates_svg.html.erb
@@ -0,0 +1,5 @@
+
diff --git a/app/views/legislation/processes/_phase_allegations.html.erb b/app/views/legislation/processes/_phase_allegations.html.erb
new file mode 100644
index 000000000..be31ddf43
--- /dev/null
+++ b/app/views/legislation/processes/_phase_allegations.html.erb
@@ -0,0 +1,9 @@
+<% if process.draft_versions.any? %>
+
+ <% process.draft_versions.each do |draft_version| %>
+ - <%= link_to draft_version.title, legislation_process_draft_version_path(process, draft_version) %>
+ <% end %>
+
+<% else %>
+ <%= t('.empty') %>
+<% end %>
diff --git a/app/views/legislation/processes/_phase_draft_publication.html.erb b/app/views/legislation/processes/_phase_draft_publication.html.erb
new file mode 100644
index 000000000..be31ddf43
--- /dev/null
+++ b/app/views/legislation/processes/_phase_draft_publication.html.erb
@@ -0,0 +1,9 @@
+<% if process.draft_versions.any? %>
+
+ <% process.draft_versions.each do |draft_version| %>
+ - <%= link_to draft_version.title, legislation_process_draft_version_path(process, draft_version) %>
+ <% end %>
+
+<% else %>
+ <%= t('.empty') %>
+<% end %>
diff --git a/app/views/legislation/processes/_phase_final_version_publication.html.erb b/app/views/legislation/processes/_phase_final_version_publication.html.erb
new file mode 100644
index 000000000..52fba50d5
--- /dev/null
+++ b/app/views/legislation/processes/_phase_final_version_publication.html.erb
@@ -0,0 +1,5 @@
+<% if process.final_draft_version %>
+ <%= legislation_process_draft_version_path(process.final_draft_version) %>
+<% else %>
+ <%= t('.empty') %>
+<% end %>
diff --git a/app/views/legislation/processes/_phase_not_open.html.erb b/app/views/legislation/processes/_phase_not_open.html.erb
new file mode 100644
index 000000000..354ff5440
--- /dev/null
+++ b/app/views/legislation/processes/_phase_not_open.html.erb
@@ -0,0 +1,13 @@
+
+
+
<%= t('.not_open') %>
+
Suscríbete al proceso para recibir un aviso en el momento en que se abra.
+
+
+
+
+
+
diff --git a/app/views/legislation/processes/_process.html.erb b/app/views/legislation/processes/_process.html.erb
index 2053cac31..9eac89a7b 100644
--- a/app/views/legislation/processes/_process.html.erb
+++ b/app/views/legislation/processes/_process.html.erb
@@ -16,25 +16,25 @@
-
<%= t('legislation.processes.common.key_dates') %>
+
<%= t('legislation.processes.shared.key_dates') %>
-
<%= t('legislation.processes.common.debate_dates') %>
+
<%= t('legislation.processes.shared.debate_dates') %>
<%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %>
-
<%= t('legislation.processes.common.draft_publication_date') %>
+
<%= t('legislation.processes.shared.draft_publication_date') %>
<%= format_date(process.draft_publication_date) %>
-
<%= t('legislation.processes.common.allegations_dates') %>
+
<%= t('legislation.processes.shared.allegations_dates') %>
<%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %>
-
<%= t('legislation.processes.common.final_publication_date') %>
+
<%= t('legislation.processes.shared.final_publication_date') %>
<%= format_date(process.final_publication_date) %>
diff --git a/app/views/legislation/processes/phase.html.erb b/app/views/legislation/processes/phase.html.erb
new file mode 100644
index 000000000..5ac6ceb85
--- /dev/null
+++ b/app/views/legislation/processes/phase.html.erb
@@ -0,0 +1,15 @@
+<%= render 'legislation/processes/header_full', process: @process %>
+
+
+ <%= render 'legislation/processes/key_dates', process: @process, phase: @phase %>
+
+
+
+ <% if @process.show_phase?(@phase) %>
+ <%= render "phase_#{@phase}", process: @process %>
+ <% else %>
+ <%= render 'legislation/processes/phase_not_open' %>
+ <% end %>
+
+
+
diff --git a/app/views/legislation/processes/show.html.erb b/app/views/legislation/processes/show.html.erb
index 7d11f6f25..8e31431e0 100644
--- a/app/views/legislation/processes/show.html.erb
+++ b/app/views/legislation/processes/show.html.erb
@@ -1,9 +1,16 @@
+
+<%= render 'header_full', process: @process %>
+
+ <%= render 'key_dates', process: @process, phase: :debate %>
-
<%= @process.title %>
-
-<% @process.draft_versions.each do |draft_version| %>
- <%= link_to draft_version.title, legislation_process_draft_version_path(@process, draft_version) %>
-<% end %>
-
+
+
+ <% if @process.show_phase?(:debate) %>
+ <%= render 'debate', process: @process %>
+ <% else %>
+ <%= render 'phase_not_open' %>
+ <% end %>
+
+
diff --git a/app/views/legislation/questions/_question.html.erb b/app/views/legislation/questions/_question.html.erb
new file mode 100644
index 000000000..750d248c1
--- /dev/null
+++ b/app/views/legislation/questions/_question.html.erb
@@ -0,0 +1,11 @@
+
+
+ <%= t('.debate') %>
+
+
+
<%= link_to question.title, legislation_process_question_path(question.process, question) %>
+
+
+ · <%= format_date question.created_at %>
+
+
diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb
new file mode 100644
index 000000000..ea3563c67
--- /dev/null
+++ b/app/views/legislation/questions/show.html.erb
@@ -0,0 +1,3 @@
+
+
<%= @question.title %>
+
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 037e0d10b..6e71969ce 100755
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -227,21 +227,45 @@ en:
show:
see_changes: See changes
processes:
- common:
- key_dates: "Key dates:"
- debate_dates: Debate
- draft_publication_date: Draft publication
- allegations_dates: Allegations
- final_publication_date: Final result publication
+ debate:
+ empty_questions: There aren't any questions
+ participate: Participate in the debate
+ header_full:
+ title: Participate
+ description: Description
+ target: Target
+ how_to_participate: How to participate
+ more_info: More information and context
index:
hightlighted_processes: HIGHLIGHTED PROCESSES
filters:
open: Open processes
next: Next
past: Past
+ phase_not_open:
+ not_open: This phase is not open yet
+ phase_draft_publication:
+ empty: There are no drafts published
+ phase_allegations:
+ empty: There are no drafts published
+ phase_final_version_publication:
+ empty: Results have not been published yet
process:
see_latest_comments: See latest comments
see_latest_comments_title: Comment on this process
+ shared:
+ key_dates: "Key dates:"
+ debate_dates: Debate
+ draft_publication_date: Draft publication
+ allegations_dates: Allegations
+ final_publication_date: Final result publication
+ questions:
+ question:
+ comments:
+ zero: No comments
+ one: "%{count} comment"
+ other: "%{count} comments"
+ debate: Debate
locale: English
notifications:
index:
diff --git a/config/locales/es.yml b/config/locales/es.yml
index 2584adcce..41a3361cf 100755
--- a/config/locales/es.yml
+++ b/config/locales/es.yml
@@ -227,21 +227,45 @@ es:
show:
see_changes: Ver cambios
processes:
- common:
- key_dates: "Fechas clave:"
- debate_dates: Debate previo
- draft_publication_date: Publicación borrador
- allegations_dates: Alegaciones
- final_publication_date: Publicación resultados
+ debate:
+ empty_questions: No hay preguntas
+ participate: Realiza tus aportaciones al debate previo participando en los siguientes temas.
+ header_full:
+ title: Colabora en la elaboración de la normativa sobre
+ description: En qué consiste
+ target: A quién va dirigido
+ how_to_participate: Cómo puedes participar
+ more_info: Más información y contexto
index:
hightlighted_processes: PROCESOS DESTACADOS
filters:
open: Procesos activos
next: Próximamente
past: Terminados
+ phase_not_open:
+ not_open: Esta fase del proceso todavía no está abierta
+ phase_draft_publication:
+ empty: No se ha publicado ningún borrador
+ phase_allegations:
+ empty: No se ha publicado ningún borrador
+ phase_final_version_publication:
+ empty: No se ha publicado el resultado todavía
process:
see_latest_comments: Ver últimas aportaciones
see_latest_comments_title: Aportar a este proceso
+ shared:
+ key_dates: "Fechas clave:"
+ debate_dates: Debate previo
+ draft_publication_date: Publicación borrador
+ allegations_dates: Alegaciones
+ final_publication_date: Publicación resultados
+ questions:
+ question:
+ comments:
+ zero: Sin comentarios
+ one: "%{count} comentario"
+ other: "%{count} comentarios"
+ debate: Debate
locale: Español
notifications:
index:
diff --git a/config/routes.rb b/config/routes.rb
index b62cabc7a..731d0323a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -92,6 +92,12 @@ Rails.application.routes.draw do
namespace :legislation do
resources :processes, only: [:index, :show] do
+ get :draft_publication
+ get :allegations
+ get :final_version_publication
+ resources :questions, only: [:show] do
+ resources :answers, only: [:create]
+ end
resources :draft_versions, only: [:show] do
get :changes
resources :annotations
diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb
index 2d3d0bdb8..c4241698e 100644
--- a/spec/features/legislation/processes_spec.rb
+++ b/spec/features/legislation/processes_spec.rb
@@ -35,4 +35,24 @@ feature 'Legislation' do
expect(page).to have_content('Process past')
end
end
+
+ context 'processes#show' do
+ scenario 'Debate phase not open' do
+ process = create(:legislation_process, title: "Process open",
+ debate_start_date: Date.current + 1.day, debate_end_date: Date.current + 2.days)
+
+ visit legislation_process_path(process)
+
+ expect(page).to have_content("This phase is not open yet")
+ end
+
+ scenario 'Debate phase open' do
+ process = create(:legislation_process, title: "Process open",
+ debate_start_date: Date.current - 1.day, debate_end_date: Date.current + 2.days)
+
+ visit legislation_process_path(process)
+
+ expect(page).to have_content("Participate in the debate")
+ end
+ end
end
diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb
index 4302293bd..8db980327 100644
--- a/spec/models/legislation/process_spec.rb
+++ b/spec/models/legislation/process_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe Legislation::Process, type: :model do
@process_3 = create(:legislation_process, start_date: Date.current - 4.days, end_date: Date.current - 3.days)
end
- it "filter open" do
+ it "filters open" do
open_processes = ::Legislation::Process.open
expect(open_processes).to include(@process_1)
@@ -22,7 +22,7 @@ RSpec.describe Legislation::Process, type: :model do
expect(open_processes).to_not include(@process_3)
end
- it "filter next" do
+ it "filters next" do
next_processes = ::Legislation::Process.next
expect(next_processes).to include(@process_2)
@@ -30,7 +30,7 @@ RSpec.describe Legislation::Process, type: :model do
expect(next_processes).to_not include(@process_3)
end
- it "filter past" do
+ it "filters past" do
past_processes = ::Legislation::Process.past
expect(past_processes).to include(@process_3)
@@ -38,4 +38,152 @@ RSpec.describe Legislation::Process, type: :model do
expect(past_processes).to_not include(@process_1)
end
end
+
+ describe "#open_phase?" do
+ it "checks debate phase" do
+ process = create(:legislation_process)
+
+ # future
+ process.update_attributes(debate_start_date: Date.current + 2.days, debate_end_date: Date.current + 3.days)
+ expect(process.open_phase?(:debate)).to be false
+
+ # started
+ process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current + 1.day)
+ expect(process.open_phase?(:debate)).to be true
+
+ # starts today
+ process.update_attributes(debate_start_date: Date.current, debate_end_date: Date.current + 1.day)
+ expect(process.open_phase?(:debate)).to be true
+
+ # past
+ process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day)
+ expect(process.open_phase?(:debate)).to be false
+ end
+
+ it "checks allegations phase" do
+ process = create(:legislation_process)
+
+ # future
+ process.update_attributes(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days)
+ expect(process.open_phase?(:allegations)).to be false
+
+ # started
+ process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current + 1.day)
+ expect(process.open_phase?(:allegations)).to be true
+
+ # starts today
+ process.update_attributes(allegations_start_date: Date.current, allegations_end_date: Date.current + 1.day)
+ expect(process.open_phase?(:allegations)).to be true
+
+ # past
+ process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current - 1.day)
+ expect(process.open_phase?(:allegations)).to be false
+ end
+
+ it "checks draft publication phase" do
+ process = create(:legislation_process)
+
+ # future
+ process.update_attributes(draft_publication_date: Date.current + 2.days)
+ expect(process.open_phase?(:draft_publication)).to be false
+
+ # past
+ process.update_attributes(draft_publication_date: Date.current - 2.days)
+ expect(process.open_phase?(:draft_publication)).to be true
+
+ # starts today
+ process.update_attributes(draft_publication_date: Date.current)
+ expect(process.open_phase?(:draft_publication)).to be true
+ end
+
+ it "checks final version publication phase" do
+ process = create(:legislation_process)
+
+ # future
+ process.update_attributes(final_publication_date: Date.current + 2.days)
+ expect(process.open_phase?(:final_version_publication)).to be false
+
+ # past
+ process.update_attributes(final_publication_date: Date.current - 2.days)
+ expect(process.open_phase?(:final_version_publication)).to be true
+
+ # starts today
+ process.update_attributes(final_publication_date: Date.current)
+ expect(process.open_phase?(:final_version_publication)).to be true
+ end
+ end
+
+ describe "#show_phase?" do
+ it "checks debate phase" do
+ process = create(:legislation_process)
+
+ # future
+ process.update_attributes(debate_start_date: Date.current + 2.days, debate_end_date: Date.current + 3.days)
+ expect(process.show_phase?(:debate)).to be false
+
+ # started
+ process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current + 1.day)
+ expect(process.show_phase?(:debate)).to be true
+
+ # starts today
+ process.update_attributes(debate_start_date: Date.current, debate_end_date: Date.current + 1.day)
+ expect(process.show_phase?(:debate)).to be true
+
+ # past
+ process.update_attributes(debate_start_date: Date.current - 2.days, debate_end_date: Date.current - 1.day)
+ expect(process.show_phase?(:debate)).to be true
+ end
+
+ it "checks allegations phase" do
+ process = create(:legislation_process)
+
+ # future
+ process.update_attributes(allegations_start_date: Date.current + 2.days, allegations_end_date: Date.current + 3.days)
+ expect(process.show_phase?(:allegations)).to be false
+
+ # started
+ process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current + 1.day)
+ expect(process.show_phase?(:allegations)).to be true
+
+ # starts today
+ process.update_attributes(allegations_start_date: Date.current, allegations_end_date: Date.current + 1.day)
+ expect(process.show_phase?(:allegations)).to be true
+
+ # past
+ process.update_attributes(allegations_start_date: Date.current - 2.days, allegations_end_date: Date.current - 1.day)
+ expect(process.show_phase?(:allegations)).to be true
+ end
+
+ it "checks draft publication phase" do
+ process = create(:legislation_process)
+
+ # future
+ process.update_attributes(draft_publication_date: Date.current + 2.days)
+ expect(process.show_phase?(:draft_publication)).to be false
+
+ # past
+ process.update_attributes(draft_publication_date: Date.current - 2.days)
+ expect(process.show_phase?(:draft_publication)).to be true
+
+ # starts today
+ process.update_attributes(draft_publication_date: Date.current)
+ expect(process.show_phase?(:draft_publication)).to be true
+ end
+
+ it "checks final version publication phase" do
+ process = create(:legislation_process)
+
+ # future
+ process.update_attributes(final_publication_date: Date.current + 2.days)
+ expect(process.show_phase?(:final_version_publication)).to be false
+
+ # past
+ process.update_attributes(final_publication_date: Date.current - 2.days)
+ expect(process.show_phase?(:final_version_publication)).to be true
+
+ # starts today
+ process.update_attributes(final_publication_date: Date.current)
+ expect(process.show_phase?(:final_version_publication)).to be true
+ end
+ end
end