diff --git a/Gemfile b/Gemfile index 6eb34093c..9ac7e06a9 100644 --- a/Gemfile +++ b/Gemfile @@ -67,6 +67,8 @@ gem 'redcarpet' gem 'rails-assets-markdown-it', source: 'https://rails-assets.org' +gem 'cocoon' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock index fb6eeb62f..28f67e75d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -104,6 +104,7 @@ GEM cliver (0.3.2) cocaine (0.5.8) climate_control (>= 0.0.3, < 1.0) + cocoon (1.2.9) coffee-rails (4.2.1) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.2.x) @@ -467,6 +468,7 @@ DEPENDENCIES capistrano3-delayed-job (~> 1.0) capybara ckeditor (~> 4.2.0) + cocoon coffee-rails (~> 4.2.1) coveralls daemons diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 7188acecf..e81e74f34 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -48,6 +48,7 @@ //= require social_share //= require markdown-it //= require markdown_editor +//= require cocoon //= require allegations //= require custom diff --git a/app/assets/stylesheets/foundation_and_overrides.scss b/app/assets/stylesheets/foundation_and_overrides.scss index 403d5566d..cd33ac92d 100644 --- a/app/assets/stylesheets/foundation_and_overrides.scss +++ b/app/assets/stylesheets/foundation_and_overrides.scss @@ -34,3 +34,4 @@ @include foundation-thumbnail; @include foundation-title-bar; @include foundation-top-bar; +@include foundation-menu-icon; diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 8c4549ffd..e5e6562d3 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -246,7 +246,7 @@ a { } } - h2 { + h2, h3 { font-size: $base-font-size; } } diff --git a/app/controllers/admin/banners_controller.rb b/app/controllers/admin/banners_controller.rb index c96c7c72b..b919e0861 100644 --- a/app/controllers/admin/banners_controller.rb +++ b/app/controllers/admin/banners_controller.rb @@ -2,7 +2,6 @@ class Admin::BannersController < Admin::BaseController has_filters %w{all with_active with_inactive}, only: :index - before_action :find_banner, only: [:edit, :update, :destroy] before_action :banner_styles, only: [:edit, :new, :create, :update] before_action :banner_imgs, only: [:edit, :new, :create, :update] @@ -24,7 +23,6 @@ class Admin::BannersController < Admin::BaseController end def update - @banner.assign_attributes(banner_params) if @banner.update(banner_params) redirect_to admin_banners_path else @@ -43,10 +41,6 @@ class Admin::BannersController < Admin::BaseController params.require(:banner).permit(:title, :description, :target_url, :style, :image, :post_started_at, :post_ended_at) end - def find_banner - @banner = Banner.find(params[:id]) - end - def banner_styles @banner_styles = Setting.all.banner_style.map { |banner_style| [banner_style.value, banner_style.key.split('.')[1]] } end diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb index 8c20374d9..f47dde361 100644 --- a/app/controllers/admin/legislation/draft_versions_controller.rb +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -31,7 +31,6 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont def draft_version_params params.require(:legislation_draft_version).permit( - :legislation_process_id, :title, :changelog, :status, diff --git a/app/controllers/admin/legislation/questions_controller.rb b/app/controllers/admin/legislation/questions_controller.rb new file mode 100644 index 000000000..9a1c3eb5b --- /dev/null +++ b/app/controllers/admin/legislation/questions_controller.rb @@ -0,0 +1,39 @@ +class Admin::Legislation::QuestionsController < Admin::Legislation::BaseController + load_and_authorize_resource :process, class: "Legislation::Process" + load_and_authorize_resource :question, class: "Legislation::Question", through: :process + + def index + @questions = @process.questions + end + + def create + @question.author = current_user + if @question.save + redirect_to admin_legislation_process_questions_path + else + render :new + end + end + + def update + if @question.update(question_params) + redirect_to admin_legislation_process_questions_path + else + render :edit + end + end + + def destroy + @question.destroy + redirect_to admin_legislation_process_questions_path + end + + private + + def question_params + params.require(:legislation_question).permit( + :title, + question_options_attributes: [:id, :value, :_destroy] + ) + end +end diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index a444f151e..05b7fbeae 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -1,9 +1,32 @@ class Legislation::ProcessesController < Legislation::BaseController + has_filters %w{open next past}, only: :index load_and_authorize_resource def index + @current_filter ||= 'open' + @processes = ::Legislation::Process.send(@current_filter).page(params[:page]) end 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..7114c98cb --- /dev/null +++ b/app/controllers/legislation/questions_controller.rb @@ -0,0 +1,12 @@ +class Legislation::QuestionsController < Legislation::BaseController + load_and_authorize_resource :process + load_and_authorize_resource :question, through: :process + + has_orders %w{most_voted newest oldest}, only: :show + + def show + @commentable = @question + @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) + set_comment_flags(@comment_tree.comments) + end +end diff --git a/app/helpers/layouts_helper.rb b/app/helpers/layouts_helper.rb new file mode 100644 index 000000000..c92f57898 --- /dev/null +++ b/app/helpers/layouts_helper.rb @@ -0,0 +1,12 @@ +module LayoutsHelper + + def layout_menu_link_to(text, path, is_active, options) + if is_active + content_tag(:span, t('shared.you_are_in'), class: 'sr-only') + ' ' + + link_to(text, path, options.merge(class: "active")) + else + link_to(text, path, options) + end + end + +end diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb new file mode 100644 index 000000000..59a13f9a8 --- /dev/null +++ b/app/helpers/legislation_helper.rb @@ -0,0 +1,9 @@ +module LegislationHelper + def format_date(date) + l(date, format: "%d %b %Y") if date + end + + def legislation_question_path(question) + legislation_process_question_path(question.process, question) + end +end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 82035042b..f8362f87b 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -33,7 +33,7 @@ module Abilities can :mark_featured, Debate can :unmark_featured, Debate - can :comment_as_administrator, [Debate, Comment, Proposal] + can :comment_as_administrator, [Debate, Comment, Proposal, Legislation::Question] can [:search, :create, :index, :destroy], ::Moderator can [:search, :create, :index, :summary], ::Valuator @@ -48,6 +48,8 @@ module Abilities can [:manage], ::Legislation::Process can [:manage], ::Legislation::DraftVersion + can [:manage], ::Legislation::Question + cannot :comment_as_moderator, ::Legislation::Question end end end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 88eccd00a..e22bcb7e0 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -11,8 +11,9 @@ module Abilities can :read, User can [:search, :read], Annotation can :new, DirectMessage - can [:read], Legislation::Process + can [:read, :draft_publication, :allegations, :final_version_publication], Legislation::Process can [:read], Legislation::DraftVersion + can [:read], Legislation::Question end end end diff --git a/app/models/abilities/moderator.rb b/app/models/abilities/moderator.rb index f6c5c5004..c8aed38fe 100644 --- a/app/models/abilities/moderator.rb +++ b/app/models/abilities/moderator.rb @@ -5,7 +5,7 @@ module Abilities def initialize(user) self.merge Abilities::Moderation.new(user) - can :comment_as_moderator, [Debate, Comment, Proposal] + can :comment_as_moderator, [Debate, Comment, Proposal, Legislation::Question] end end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 0bfb6a320..025f50e71 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -10,7 +10,7 @@ class Comment < ActiveRecord::Base validates :body, presence: true validates :user, presence: true - validates_inclusion_of :commentable_type, in: ["Debate", "Proposal"] + validates_inclusion_of :commentable_type, in: ["Debate", "Proposal", "Legislation::Question"] validate :validate_body_length diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 43cca02f6..dbc31c7b3 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -3,6 +3,8 @@ 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 validates :description, presence: true @@ -17,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/models/legislation/question.rb b/app/models/legislation/question.rb new file mode 100644 index 000000000..2b779d1f8 --- /dev/null +++ b/app/models/legislation/question.rb @@ -0,0 +1,19 @@ +class Legislation::Question < ActiveRecord::Base + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases + + belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' + + has_many :question_options, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question + has_many :comments, as: :commentable + + accepts_nested_attributes_for :question_options, :reject_if => proc { |attributes| attributes[:value].blank? }, allow_destroy: true + + validates :process, presence: true + validates :title, presence: true + + def next_question_id + @next_question_id ||= process.questions.where("id > ?", id).order('id ASC').limit(1).pluck(:id).first + end +end diff --git a/app/models/legislation/question_option.rb b/app/models/legislation/question_option.rb new file mode 100644 index 000000000..93bc20320 --- /dev/null +++ b/app/models/legislation/question_option.rb @@ -0,0 +1,9 @@ +class Legislation::QuestionOption < ActiveRecord::Base + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases + + belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options + + validates :question, presence: true + validates :value, presence: true, uniqueness: { scope: :legislation_question_id } +end diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index fb61ca3d1..a55bddc66 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -9,7 +9,7 @@ <%= @draft_version.errors.count %> - <%= t("admin.legislation.draft_versions.errors.form.error", count: @process.errors.count) %> + <%= t("admin.legislation.draft_versions.errors.form.error", count: @draft_version.errors.count) %> diff --git a/app/views/admin/legislation/draft_versions/edit.html.erb b/app/views/admin/legislation/draft_versions/edit.html.erb index b48c6409b..f347101cf 100644 --- a/app/views/admin/legislation/draft_versions/edit.html.erb +++ b/app/views/admin/legislation/draft_versions/edit.html.erb @@ -1,6 +1,6 @@
<%= t('.empty_questions') %>
+ <% else %> + <%= render process.questions %> + <% end %> +<%= t('.title') %>
+<%= 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? %> +<%= 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 @@ +Suscríbete al proceso para recibir un aviso en el momento en que se abra.
+<%= process.description %>
+<%= t('legislation.processes.shared.key_dates') %>
+<%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %>
+<%= format_date(process.draft_publication_date) %>
+<%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %>
+<%= format_date(process.final_publication_date) %>
+<%= t('.title') %>
+
<% if comment.hidden? || comment.user.hidden? %> <% if comment.children.size > 0 %> @@ -23,7 +23,7 @@ <% end %> <% end %> -
+ -
<% if comment.as_administrator? %>
@@ -92,14 +92,13 @@
<%= render 'comments/form', {commentable: comment.commentable, parent_id: comment.id, toggeable: true} %>
<% end %>
-
+
<% end %>
-
-
+
-
<% child_comments_of(comment).each do |child| %> <%= render 'comments/comment', comment: child %> <% end %> -