Merge pull request #114 from medialab-prado/103-redirect-to-main-phase
Redirect to main phase and activate/deactivate phases
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
//= require markdown-it
|
||||
//= require markdown_editor
|
||||
//= require cocoon
|
||||
//= require legislation_admin
|
||||
//= require legislation
|
||||
//= require legislation_allegations
|
||||
//= require legislation_annotatable
|
||||
@@ -83,6 +84,7 @@ var initialize_modules = function() {
|
||||
App.Banners.initialize();
|
||||
App.SocialShare.initialize();
|
||||
App.MarkdownEditor.initialize();
|
||||
App.LegislationAdmin.initialize();
|
||||
App.LegislationAllegations.initialize();
|
||||
App.Legislation.initialize();
|
||||
if ( $(".legislation-annotatable").length )
|
||||
|
||||
14
app/assets/javascripts/legislation_admin.js.coffee
Normal file
14
app/assets/javascripts/legislation_admin.js.coffee
Normal file
@@ -0,0 +1,14 @@
|
||||
App.LegislationAdmin =
|
||||
|
||||
initialize: ->
|
||||
$("input[type='checkbox'][data-disable-date]").on
|
||||
change: ->
|
||||
checkbox = $(this)
|
||||
parent = $(this).parents('.row:eq(0)')
|
||||
date_selector = $(this).data('disable-date')
|
||||
parent.find("input[type='text'][id^='"+date_selector+"']").each ->
|
||||
if checkbox.is(':checked')
|
||||
$(this).removeAttr("disabled")
|
||||
else
|
||||
$(this).val("")
|
||||
|
||||
@@ -8,8 +8,20 @@ class Legislation::ProcessesController < Legislation::BaseController
|
||||
end
|
||||
|
||||
def show
|
||||
if @process.active_phase?(:allegations) && @process.show_phase?(:allegations) && draft_version = @process.draft_versions.published.last
|
||||
redirect_to legislation_process_draft_version_path(@process, draft_version)
|
||||
elsif @process.active_phase?(:debate)
|
||||
redirect_to legislation_process_debate_path(@process)
|
||||
else
|
||||
redirect_to legislation_process_allegations_path(@process)
|
||||
end
|
||||
end
|
||||
|
||||
def debate
|
||||
phase :debate
|
||||
|
||||
if @process.show_phase?(:debate)
|
||||
render :show
|
||||
render :debate
|
||||
else
|
||||
render :phase_not_open
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@ module Abilities
|
||||
can [:read], Budget::Group
|
||||
can [:read, :print], Budget::Investment
|
||||
can :new, DirectMessage
|
||||
can [:read, :draft_publication, :allegations, :final_version_publication], Legislation::Process
|
||||
can [:read, :debate, :draft_publication, :allegations, :final_version_publication], Legislation::Process
|
||||
can [:read, :changes, :go_to_version], Legislation::DraftVersion
|
||||
can [:read], Legislation::Question
|
||||
can [:create], Legislation::Answer
|
||||
|
||||
@@ -9,12 +9,10 @@ class Legislation::Process < ActiveRecord::Base
|
||||
validates :title, presence: true
|
||||
validates :start_date, presence: true
|
||||
validates :end_date, presence: true
|
||||
validates :debate_start_date, presence: true
|
||||
validates :debate_end_date, presence: true
|
||||
validates :draft_publication_date, presence: true
|
||||
validates :allegations_start_date, presence: true
|
||||
validates :allegations_end_date, presence: true
|
||||
validates :final_publication_date, presence: true
|
||||
validates :debate_start_date, presence: true, if: :debate_end_date?
|
||||
validates :debate_end_date, presence: true, if: :debate_start_date?
|
||||
validates :allegations_start_date, presence: true, if: :allegations_end_date?
|
||||
validates :allegations_end_date, presence: true, if: :allegations_start_date?
|
||||
validate :valid_date_ranges
|
||||
|
||||
scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current).order('id DESC') }
|
||||
@@ -26,13 +24,13 @@ class Legislation::Process < ActiveRecord::Base
|
||||
|
||||
case phase
|
||||
when :debate
|
||||
today >= debate_start_date && today <= debate_end_date
|
||||
active_phase?(:debate) && today >= debate_start_date && today <= debate_end_date
|
||||
when :draft_publication
|
||||
today >= draft_publication_date
|
||||
active_phase?(:draft_publication) && today >= draft_publication_date
|
||||
when :allegations
|
||||
today >= allegations_start_date && today <= allegations_end_date
|
||||
active_phase?(:allegations) && today >= allegations_start_date && today <= allegations_end_date
|
||||
when :final_version_publication
|
||||
today >= final_publication_date
|
||||
active_phase?(:final_version_publication) && today >= final_publication_date
|
||||
end
|
||||
end
|
||||
|
||||
@@ -42,13 +40,26 @@ class Legislation::Process < ActiveRecord::Base
|
||||
|
||||
case phase
|
||||
when :debate
|
||||
today >= debate_start_date
|
||||
active_phase?(:debate) && today >= debate_start_date
|
||||
when :draft_publication
|
||||
today >= draft_publication_date
|
||||
active_phase?(:draft_publication) && today >= draft_publication_date
|
||||
when :allegations
|
||||
today >= allegations_start_date
|
||||
active_phase?(:allegations) && today >= allegations_start_date
|
||||
when :final_version_publication
|
||||
today >= final_publication_date
|
||||
active_phase?(:final_version_publication) && today >= final_publication_date
|
||||
end
|
||||
end
|
||||
|
||||
def active_phase?(phase)
|
||||
case phase
|
||||
when :debate
|
||||
debate_start_date.present? && debate_end_date.present?
|
||||
when :draft_publication
|
||||
draft_publication_date.present?
|
||||
when :allegations
|
||||
allegations_start_date.present? && allegations_end_date.present?
|
||||
when :final_version_publication
|
||||
final_publication_date.present?
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -63,6 +63,10 @@
|
||||
class: "js-calendar-full",
|
||||
id: "debate_end_date" %>
|
||||
</div>
|
||||
<div class="small-12 medium-2 column">
|
||||
<%= check_box_tag :debate_phase_active, @process.active_phase?(:debate), @process.new_record? || @process.active_phase?(:debate), data: {disable_date: "debate"} %>
|
||||
<%= label_tag :debate_phase_active, t('admin.legislation.processes.form.active') %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-4 column">
|
||||
<label><%= t('admin.legislation.processes.form.allegations_phase') %></label>
|
||||
@@ -87,7 +91,13 @@
|
||||
class: "js-calendar-full",
|
||||
id: "allegations_end_date" %>
|
||||
</div>
|
||||
<div class="small-12 medium-2 column">
|
||||
<%= check_box_tag :allegations_phase_active, @process.active_phase?(:allegations), @process.new_record? || @process.active_phase?(:allegations), data: {disable_date: "allegations"} %>
|
||||
<%= label_tag :allegations_phase_active, t('admin.legislation.processes.form.active') %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= f.label :draft_publication_date %>
|
||||
</div>
|
||||
@@ -98,6 +108,10 @@
|
||||
class: "js-calendar-full",
|
||||
id: "draft_publication_date" %>
|
||||
</div>
|
||||
<div class="small-12 medium-2 column">
|
||||
<%= check_box_tag :draft_publication_phase_active, @process.active_phase?(:draft_publication), @process.new_record? || @process.active_phase?(:draft_publication), data: {disable_date: "draft_publication"} %>
|
||||
<%= label_tag :draft_publication_phase_active, t('admin.legislation.processes.form.active') %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
@@ -111,6 +125,10 @@
|
||||
class: "js-calendar-full",
|
||||
id: "final_publication_date" %>
|
||||
</div>
|
||||
<div class="small-12 medium-2 column">
|
||||
<%= check_box_tag :final_version_publication_phase_active, @process.active_phase?(:final_version_publication), @process.new_record? || @process.active_phase?(:final_version_publication), data: {disable_date: "final_publication"} %>
|
||||
<%= label_tag :final_version_publication_phase_active, t('admin.legislation.processes.form.active') %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
|
||||
@@ -1,32 +1,43 @@
|
||||
<nav class="legislation-process-categories">
|
||||
<nav class="legislation-process-categories">
|
||||
<div class="legislation-process-list">
|
||||
<ul>
|
||||
<%= render 'legislation/processes/key_dates_svg' %>
|
||||
|
||||
<li <%= "class=active" if phase == :debate %>>
|
||||
<%= link_to process do %>
|
||||
<h4><%= t('legislation.processes.shared.debate_dates') %></h4>
|
||||
<p><%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %></p>
|
||||
<% end %>
|
||||
</li>
|
||||
<li <%= "class=active" if phase == :draft_publication %>>
|
||||
<%= link_to legislation_process_draft_publication_path(process) do %>
|
||||
<h4><%= t('legislation.processes.shared.draft_publication_date') %></h4>
|
||||
<p><%= format_date(process.draft_publication_date) %></p>
|
||||
<% end %>
|
||||
</li>
|
||||
<li <%= "class=active" if phase == :allegations %>>
|
||||
<%= link_to legislation_process_allegations_path(process) do %>
|
||||
<h4><%= t('legislation.processes.shared.allegations_dates') %></h4>
|
||||
<p><%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %></p>
|
||||
<% end %>
|
||||
</li>
|
||||
<li <%= "class=active" if phase == :final_version_publication %>>
|
||||
<%= link_to legislation_process_final_version_publication_path(process) do %>
|
||||
<h4><%= t('legislation.processes.shared.final_publication_date') %></h4>
|
||||
<p><%= format_date(process.final_publication_date) %></p>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
<% if process.active_phase?(:debate) %>
|
||||
<li <%= "class=active" if phase == :debate %>>
|
||||
<%= link_to legislation_process_debate_path(process) do %>
|
||||
<h4><%= t('legislation.processes.shared.debate_dates') %></h4>
|
||||
<p><%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %></p>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if process.active_phase?(:draft_publication) %>
|
||||
<li <%= "class=active" if phase == :draft_publication %>>
|
||||
<%= link_to legislation_process_draft_publication_path(process) do %>
|
||||
<h4><%= t('legislation.processes.shared.draft_publication_date') %></h4>
|
||||
<p><%= format_date(process.draft_publication_date) %></p>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if process.active_phase?(:allegations) %>
|
||||
<li <%= "class=active" if phase == :allegations %>>
|
||||
<%= link_to legislation_process_allegations_path(process) do %>
|
||||
<h4><%= t('legislation.processes.shared.allegations_dates') %></h4>
|
||||
<p><%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %></p>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<% if process.active_phase?(:final_version_publication) %>
|
||||
<li <%= "class=active" if phase == :final_version_publication %>>
|
||||
<%= link_to legislation_process_final_version_publication_path(process) do %>
|
||||
<h4><%= t('legislation.processes.shared.final_publication_date') %></h4>
|
||||
<p><%= format_date(process.final_publication_date) %></p>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
25
app/views/legislation/processes/debate.html.erb
Normal file
25
app/views/legislation/processes/debate.html.erb
Normal file
@@ -0,0 +1,25 @@
|
||||
<% provide :title do %><%= @process.title %><% end %>
|
||||
|
||||
<%= render 'legislation/processes/header', process: @process, header: :full %>
|
||||
|
||||
<%= render 'key_dates', process: @process, phase: :debate %>
|
||||
|
||||
<div class="row">
|
||||
<div class="debate-chooser">
|
||||
<div class="row">
|
||||
<div class="small-12 medium-9 column">
|
||||
<div class="debate-list">
|
||||
<% if @process.questions.empty? %>
|
||||
<p><%= t('.empty_questions') %></p>
|
||||
<% else %>
|
||||
<%= render @process.questions %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-3 column">
|
||||
<div class="debate-info"><%= t('.participate') %></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -10,14 +10,9 @@
|
||||
<div class="debate-draft">
|
||||
<div class="small-12 medium-7 column">
|
||||
<h3><%= t('.not_open') %></h3>
|
||||
<p>Suscríbete al proceso para recibir un aviso en el momento en que se abra.</p>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-5 column">
|
||||
<button class="button-subscribe expanded button strong" title="Suscríbete al proceso" data-remote="true" rel="nofollow" data-method="post" href="/proposals/6-soluta-sed-sapiente-dolores/vote?value=yes">
|
||||
<h3>Suscríbete al proceso</h3>
|
||||
<p>Recibe notificaciones clave sobre el proceso</p>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
<% provide :title do %><%= @process.title %><% end %>
|
||||
|
||||
<%= render 'legislation/processes/header', process: @process, header: :full %>
|
||||
|
||||
<%= render 'key_dates', process: @process, phase: :debate %>
|
||||
|
||||
<div class="row">
|
||||
<div class="debate-chooser">
|
||||
<div class="row">
|
||||
<%= render 'debate', process: @process %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -193,6 +193,7 @@ en:
|
||||
form:
|
||||
error: Error
|
||||
form:
|
||||
active: Active
|
||||
process: Process
|
||||
debate_phase: Debate phase
|
||||
allegations_phase: Allegations phase
|
||||
|
||||
@@ -193,6 +193,7 @@ es:
|
||||
form:
|
||||
error: Error
|
||||
form:
|
||||
active: Activa
|
||||
process: Proceso
|
||||
debate_phase: Fase previa
|
||||
allegations_phase: Fase de alegaciones
|
||||
|
||||
@@ -102,6 +102,7 @@ Rails.application.routes.draw do
|
||||
|
||||
namespace :legislation do
|
||||
resources :processes, only: [:index, :show] do
|
||||
get :debate
|
||||
get :draft_publication
|
||||
get :allegations
|
||||
get :final_version_publication
|
||||
|
||||
@@ -59,4 +59,27 @@ feature 'Admin legislation processes' do
|
||||
expect(page).to have_content 'An example legislation process'
|
||||
end
|
||||
end
|
||||
|
||||
context 'Update' do
|
||||
scenario 'Deactivate debate phase', js: true do
|
||||
process = create(:legislation_process, title: 'An example legislation process')
|
||||
visit admin_root_path
|
||||
|
||||
within('#side_menu') do
|
||||
click_link "Collaborative Legislation"
|
||||
end
|
||||
|
||||
click_link "An example legislation process"
|
||||
|
||||
expect(page).to have_selector("h1", text: "An example legislation process")
|
||||
expect(find("#debate_phase_active")).to be_checked
|
||||
|
||||
uncheck "debate_phase_active"
|
||||
click_button "Save changes"
|
||||
|
||||
expect(page).to have_content "Process updated successfully"
|
||||
expect(find("#debate_start_date").value).to be_blank
|
||||
expect(find("#debate_end_date").value).to be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,32 @@ RSpec.describe Legislation::Process, type: :model do
|
||||
expect(process).to be_valid
|
||||
end
|
||||
|
||||
describe "dates validations" do
|
||||
it "is invalid if debate_start_date is present but debate_end_date is not" do
|
||||
process = build(:legislation_process, debate_start_date: Date.current, debate_end_date: "")
|
||||
expect(process).to be_invalid
|
||||
expect(process.errors.messages[:debate_end_date]).to include("can't be blank")
|
||||
end
|
||||
|
||||
it "is invalid if debate_end_date is present but debate_start_date is not" do
|
||||
process = build(:legislation_process, debate_start_date: nil, debate_end_date: Date.current)
|
||||
expect(process).to be_invalid
|
||||
expect(process.errors.messages[:debate_start_date]).to include("can't be blank")
|
||||
end
|
||||
|
||||
it "is invalid if allegations_start_date is present but debate_end_date is not" do
|
||||
process = build(:legislation_process, allegations_start_date: Date.current, allegations_end_date: "")
|
||||
expect(process).to be_invalid
|
||||
expect(process.errors.messages[:allegations_end_date]).to include("can't be blank")
|
||||
end
|
||||
|
||||
it "is invalid if debate_end_date is present but allegations_start_date is not" do
|
||||
process = build(:legislation_process, allegations_start_date: nil, allegations_end_date: Date.current)
|
||||
expect(process).to be_invalid
|
||||
expect(process.errors.messages[:allegations_start_date]).to include("can't be blank")
|
||||
end
|
||||
end
|
||||
|
||||
describe "date ranges validations" do
|
||||
it "is invalid if end_date is before start_date" do
|
||||
process = build(:legislation_process, start_date: Date.current, end_date: Date.current - 1.day)
|
||||
|
||||
Reference in New Issue
Block a user