diff --git a/app/assets/javascripts/legislation.js.coffee b/app/assets/javascripts/legislation.js.coffee index 8ed109482..26c0185c1 100644 --- a/app/assets/javascripts/legislation.js.coffee +++ b/app/assets/javascripts/legislation.js.coffee @@ -14,3 +14,10 @@ App.Legislation = $('form#draft_version_go_to_version select').on change: -> $('form#draft_version_go_to_version').submit() + + $('#js-toggle-legislation-process-header').on + click: -> + $('[data-target="legislation-header-small"]').toggle() + $('[data-target="legislation-header-full"]').toggle() + + diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb index f47dde361..0d84addbf 100644 --- a/app/controllers/admin/legislation/draft_versions_controller.rb +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -8,23 +8,25 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont def create if @draft_version.save - redirect_to admin_legislation_process_draft_versions_path + redirect_to admin_legislation_process_draft_versions_path, notice: t('admin.legislation.draft_versions.create.notice', link: legislation_process_draft_version_path(@process, @draft_version).html_safe) else + flash.now[:error] = t('admin.legislation.draft_versions.create.error') render :new end end def update if @draft_version.update(draft_version_params) - redirect_to admin_legislation_process_draft_versions_path + redirect_to edit_admin_legislation_process_draft_version_path(@process, @draft_version), notice: t('admin.legislation.draft_versions.update.notice', link: legislation_process_draft_version_path(@process, @draft_version).html_safe) else + flash.now[:error] = t('admin.legislation.draft_versions.update.error') render :edit end end def destroy @draft_version.destroy - redirect_to admin_legislation_process_draft_versions_path + redirect_to admin_legislation_process_draft_versions_path, notice: t('admin.legislation.draft_versions.destroy.notice') end private diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 28edb8e42..8cc678151 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -9,23 +9,25 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll def create if @process.save - redirect_to admin_legislation_processes_path + redirect_to edit_admin_legislation_process_path(@process), notice: t('admin.legislation.processes.create.notice', link: legislation_process_path(@process).html_safe) else + flash.now[:error] = t('admin.legislation.processes.create.error') render :new end end def update if @process.update(process_params) - redirect_to admin_legislation_processes_path + redirect_to edit_admin_legislation_process_path(@process), notice: t('admin.legislation.processes.update.notice', link: legislation_process_path(@process).html_safe) else + flash.now[:error] = t('admin.legislation.processes.update.error') render :edit end end def destroy @process.destroy - redirect_to admin_legislation_processes_path + redirect_to admin_legislation_processes_path, notice: t('admin.legislation.processes.destroy.notice') end private diff --git a/app/controllers/admin/legislation/questions_controller.rb b/app/controllers/admin/legislation/questions_controller.rb index e27e75ce7..c8335e6df 100644 --- a/app/controllers/admin/legislation/questions_controller.rb +++ b/app/controllers/admin/legislation/questions_controller.rb @@ -13,23 +13,25 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll def create @question.author = current_user if @question.save - redirect_to admin_legislation_process_questions_path + redirect_to admin_legislation_process_questions_path, notice: t('admin.legislation.questions.create.notice', link: legislation_process_question_path(@process, @question).html_safe) else + flash.now[:error] = t('admin.legislation.questions.create.error') render :new end end def update if @question.update(question_params) - redirect_to admin_legislation_process_questions_path + redirect_to edit_admin_legislation_process_question_path(@process, @question), notice: t('admin.legislation.questions.update.notice', link: legislation_process_question_path(@process, @question).html_safe) else + flash.now[:error] = t('admin.legislation.questions.update.error') render :edit end end def destroy @question.destroy - redirect_to admin_legislation_process_questions_path + redirect_to admin_legislation_process_questions_path, notice: t('admin.legislation.questions.destroy.notice') end private diff --git a/app/helpers/text_helper.rb b/app/helpers/text_helper.rb new file mode 100644 index 000000000..dda3ba721 --- /dev/null +++ b/app/helpers/text_helper.rb @@ -0,0 +1,9 @@ +module TextHelper + def first_paragraph(text) + if text.blank? + "" + else + text.strip.split("\n").first + end + end +end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 4a50b4b0a..291e85b5a 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -56,15 +56,27 @@ class Legislation::Process < ActiveRecord::Base end def total_comments - questions.map(&:comments_count).sum + questions.sum(:comments_count) + end + + def status + today = Date.current + + if today < start_date + :planned + elsif end_date < today + :closed + else + :open + end end private def valid_date_ranges - errors.add(:end_date, :invalid_date_range) if end_date < start_date - errors.add(:debate_end_date, :invalid_date_range) if debate_end_date < debate_start_date - errors.add(:allegations_end_date, :invalid_date_range) if allegations_end_date < allegations_start_date + errors.add(:end_date, :invalid_date_range) if end_date && start_date && end_date < start_date + errors.add(:debate_end_date, :invalid_date_range) if debate_end_date && debate_start_date && debate_end_date < debate_start_date + errors.add(:allegations_end_date, :invalid_date_range) if allegations_end_date && allegations_start_date && allegations_end_date < allegations_start_date end end diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index 7df8f67cf..c1dacd464 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -14,8 +14,14 @@ class Legislation::Question < ActiveRecord::Base validates :process, presence: true validates :title, presence: true + scope :sorted, -> { order('id ASC') } + def next_question_id - @next_question_id ||= process.questions.where("id > ?", id).order('id ASC').limit(1).pluck(:id).first + @next_question_id ||= process.questions.where("id > ?", id).sorted.limit(1).pluck(:id).first + end + + def first_question_id + @first_question_id ||= process.questions.sorted.limit(1).pluck(:id).first end def answer_for_user(user) diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index be3c5067f..8e79c0a56 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -41,7 +41,7 @@
<% ::Legislation::DraftVersion::VALID_STATUSES.each do |status| %> <%= f.radio_button :status, status, label: false %> - <%= f.label t("admin.legislation.draft_versions.statuses.#{status}") %> + <%= f.label "status_#{status}", t("admin.legislation.draft_versions.statuses.#{status}") %> <%= t("admin.legislation.draft_versions.form.hints.status.#{status}") %>
<% end %> diff --git a/app/views/admin/legislation/processes/index.html.erb b/app/views/admin/legislation/processes/index.html.erb index 7d4bd2996..a4a0a7f3e 100644 --- a/app/views/admin/legislation/processes/index.html.erb +++ b/app/views/admin/legislation/processes/index.html.erb @@ -20,6 +20,8 @@ <%= t("admin.legislation.processes.process.title") %> + <%= t("admin.legislation.processes.process.status") %> + <%= t("admin.legislation.processes.process.creation_date") %> <%= t("admin.legislation.processes.process.comments") %> @@ -30,6 +32,8 @@ <%= link_to process.title, edit_admin_legislation_process_path(process) %> + <%= t("admin.legislation.processes.process.status_#{process.status}") %> + <%= I18n.l process.created_at.to_date %> <%= process.total_comments %> <%= link_to t("admin.legislation.processes.index.delete"), admin_legislation_process_path(process), diff --git a/app/views/layouts/_flash.html.erb b/app/views/layouts/_flash.html.erb index 9f55b449a..a0f129224 100644 --- a/app/views/layouts/_flash.html.erb +++ b/app/views/layouts/_flash.html.erb @@ -5,7 +5,7 @@
- <%= flash_message %> + <%= flash_message.try(:html_safe) %>
diff --git a/app/views/legislation/draft_versions/_process_header.html.erb b/app/views/legislation/draft_versions/_process_header.html.erb deleted file mode 100644 index 3c0c94d3f..000000000 --- a/app/views/legislation/draft_versions/_process_header.html.erb +++ /dev/null @@ -1,19 +0,0 @@ -
-
-
-

<%= process.title %>

-
- -
- -
- - - -
-
diff --git a/app/views/legislation/draft_versions/changes.html.erb b/app/views/legislation/draft_versions/changes.html.erb index 0f2015cda..c158b9540 100644 --- a/app/views/legislation/draft_versions/changes.html.erb +++ b/app/views/legislation/draft_versions/changes.html.erb @@ -1,6 +1,6 @@ <% provide :title do %><%= "#{@draft_version.title} - #{t('.title')} - #{@process.title}" %><% end %> -<%= render 'process_header', process: @process %> +<%= render 'legislation/processes/header', process: @process, header: :small %>
<%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %> diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index 8ab20eea9..a1a1c15a2 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -1,6 +1,6 @@ <% provide :title do %><%= "#{@draft_version.title} - #{@process.title}" %><% end %> -<%= render 'process_header', process: @process %> +<%= render 'legislation/processes/header', process: @process, header: :small %>
<%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %> diff --git a/app/views/legislation/processes/_header.html.erb b/app/views/legislation/processes/_header.html.erb new file mode 100644 index 000000000..c73c732af --- /dev/null +++ b/app/views/legislation/processes/_header.html.erb @@ -0,0 +1,24 @@ +<% if header == :small %> +
+
+
+

<%= process.title %>

+
+ +
+
+ + + +
+
+ + <%= render 'legislation/processes/header_full', process: @process, hidden: true %> +<% else %> + <%= render 'legislation/processes/header_full', process: @process, hidden: false %> +<% end %> diff --git a/app/views/legislation/processes/_header_full.html.erb b/app/views/legislation/processes/_header_full.html.erb index d631f8de5..e3f3420cf 100644 --- a/app/views/legislation/processes/_header_full.html.erb +++ b/app/views/legislation/processes/_header_full.html.erb @@ -1,4 +1,4 @@ -
+

<%= t('.title') %>

diff --git a/app/views/legislation/processes/_process.html.erb b/app/views/legislation/processes/_process.html.erb index 9eac89a7b..87c10cc4c 100644 --- a/app/views/legislation/processes/_process.html.erb +++ b/app/views/legislation/processes/_process.html.erb @@ -3,7 +3,7 @@

<%= link_to process.title, process %>

-

<%= process.description %>

+ <%= markdown(first_paragraph(process.description)) %>
diff --git a/app/views/legislation/processes/index.html.erb b/app/views/legislation/processes/index.html.erb index 1400f7854..1d2e6caa3 100644 --- a/app/views/legislation/processes/index.html.erb +++ b/app/views/legislation/processes/index.html.erb @@ -19,8 +19,12 @@
- <%= render @processes %> - <%= paginate @processes %> + <% if @processes.any? %> + <%= render @processes %> + <%= paginate @processes %> + <% else %> + <%= t(".no_#{@current_filter}_processes") %> + <% end %>
diff --git a/app/views/legislation/processes/phase_empty.html.erb b/app/views/legislation/processes/phase_empty.html.erb index 427339b82..6fb588faf 100644 --- a/app/views/legislation/processes/phase_empty.html.erb +++ b/app/views/legislation/processes/phase_empty.html.erb @@ -1,6 +1,6 @@ <% provide :title do %><%= @process.title %><% end %> -<%= render 'legislation/processes/header_full', process: @process %> +<%= render 'legislation/processes/header', process: @process, header: :full %>
<%= render 'legislation/processes/key_dates', process: @process, phase: @phase %> diff --git a/app/views/legislation/processes/phase_not_open.html.erb b/app/views/legislation/processes/phase_not_open.html.erb index 6bd82c969..0b3b90f01 100644 --- a/app/views/legislation/processes/phase_not_open.html.erb +++ b/app/views/legislation/processes/phase_not_open.html.erb @@ -1,6 +1,6 @@ <% provide :title do %><%= @process.title %><% end %> -<%= render 'legislation/processes/header_full', process: @process %> +<%= render 'legislation/processes/header', process: @process, header: :full %>
<%= render 'legislation/processes/key_dates', process: @process, phase: @phase %> diff --git a/app/views/legislation/processes/show.html.erb b/app/views/legislation/processes/show.html.erb index b24f7668b..410068831 100644 --- a/app/views/legislation/processes/show.html.erb +++ b/app/views/legislation/processes/show.html.erb @@ -1,6 +1,6 @@ <% provide :title do %><%= @process.title %><% end %> -<%= render 'header_full', process: @process %> +<%= render 'legislation/processes/header', process: @process, header: :full %>
<%= render 'key_dates', process: @process, phase: :debate %> diff --git a/app/views/legislation/questions/_participation_not_allowed.html.erb b/app/views/legislation/questions/_participation_not_allowed.html.erb index b330f7fe0..b186c2f5b 100644 --- a/app/views/legislation/questions/_participation_not_allowed.html.erb +++ b/app/views/legislation/questions/_participation_not_allowed.html.erb @@ -17,4 +17,8 @@ signin: link_to(t("legislation.questions.participation.signin"), new_user_session_path), signup: link_to(t("legislation.questions.participation.signup"), new_user_registration_path)).html_safe %>
+<% elsif !@process.open_phase?(:debate) %> + <% end %> diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index be8e90445..808b5d331 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -16,6 +16,13 @@
@@ -32,7 +39,7 @@

<%= t('.share') %>