From 9e5a55be6862301d2a3b11c8e17d77a1932f7d6d Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 17 Nov 2016 15:00:53 +0100 Subject: [PATCH 001/197] Removes duplicated i18n keys in locale files --- config/locales/en.yml | 7 ------- config/locales/es.yml | 7 ------- 2 files changed, 14 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index db2b3b1c5..27d8bac7f 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -626,13 +626,6 @@ en: google_oauth2: sign_in: "Sign in with Google" sign_up: "Sign up with Google" - legislation: - help: - title: "How I can comment this document?" - text: "To comment this document you must %{sign_in} or %{sign_up}. Then select the text you want to comment and press the button with the pencil." - text_sign_in: "login" - text_sign_up: "sign up" - alt: "Select the text you want to comment and press the button with the pencil." invisible_captcha: sentence_for_humans: "If you are human, ignore this field" timestamp_error_message: "Sorry, that was too quick! Please resubmit." diff --git a/config/locales/es.yml b/config/locales/es.yml index fea817454..a243b759d 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -626,13 +626,6 @@ es: google_oauth2: sign_in: "Entra con Google" sign_up: "Regístrate con Google" - legislation: - help: - title: "¿Cómo puedo comentar este documento?" - text: "Para comentar este documento debes %{sign_in} o %{sign_up}. Después selecciona el texto que quieres comentar y pulsa en el botón con el lápiz." - text_sign_in: "iniciar sesión" - text_sign_up: "registrarte" - alt: "Selecciona el texto que quieres comentar y pulsa en el botón con el lápiz." invisible_captcha: sentence_for_humans: "Si eres humano, por favor ignora este campo" timestamp_error_message: "Eso ha sido demasiado rápido. Por favor, reenvía el formulario." From 9a9f1da5a0d92e522fbb19e4b7cb5c8418d2d9ba Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 17 Nov 2016 15:03:58 +0100 Subject: [PATCH 002/197] Renames Legislation model to LegacyLegislation Renames the model and related stuff from Legislation to LegacyLegislation to avoid name clashes with the future Legislation module. --- app/controllers/annotations_controller.rb | 4 +-- .../legacy_legislations_controller.rb | 8 +++++ app/controllers/legislations_controller.rb | 8 ----- app/models/abilities/everyone.rb | 2 +- app/models/annotation.rb | 2 +- app/models/legacy_legislation.rb | 3 ++ app/models/legislation.rb | 3 -- app/views/legacy_legislations/show.html.erb | 29 +++++++++++++++ app/views/legislations/show.html.erb | 29 --------------- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- config/routes.rb | 2 +- db/dev_seeds.rb | 4 --- ...ame_legislations_to_legacy_legislations.rb | 6 ++++ db/schema.rb | 10 +++--- spec/factories.rb | 6 ++-- ...ion_spec.rb => legacy_legislation_spec.rb} | 36 +++++++++---------- 17 files changed, 79 insertions(+), 77 deletions(-) create mode 100644 app/controllers/legacy_legislations_controller.rb delete mode 100644 app/controllers/legislations_controller.rb create mode 100644 app/models/legacy_legislation.rb delete mode 100644 app/models/legislation.rb create mode 100644 app/views/legacy_legislations/show.html.erb delete mode 100644 app/views/legislations/show.html.erb create mode 100644 db/migrate/20161117115841_rename_legislations_to_legacy_legislations.rb rename spec/features/{legislation_spec.rb => legacy_legislation_spec.rb} (57%) diff --git a/app/controllers/annotations_controller.rb b/app/controllers/annotations_controller.rb index d70a2e9be..8b004076c 100644 --- a/app/controllers/annotations_controller.rb +++ b/app/controllers/annotations_controller.rb @@ -24,7 +24,7 @@ class AnnotationsController < ApplicationController end def search - @annotations = Annotation.where(legislation_id: params[:legislation_id]) + @annotations = Annotation.where(legacy_legislation_id: params[:legacy_legislation_id]) annotations_hash = { total: @annotations.size, rows: @annotations } render json: annotations_hash.to_json(methods: :permissions) end @@ -35,6 +35,6 @@ class AnnotationsController < ApplicationController params .require(:annotation) .permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset]) - .merge(legislation_id: params[:legislation_id]) + .merge(legacy_legislation_id: params[:legacy_legislation_id]) end end diff --git a/app/controllers/legacy_legislations_controller.rb b/app/controllers/legacy_legislations_controller.rb new file mode 100644 index 000000000..103c81cea --- /dev/null +++ b/app/controllers/legacy_legislations_controller.rb @@ -0,0 +1,8 @@ +class LegacyLegislationsController < ApplicationController + load_and_authorize_resource + + def show + @legacy_legislation = LegacyLegislation.find(params[:id]) + end + +end diff --git a/app/controllers/legislations_controller.rb b/app/controllers/legislations_controller.rb deleted file mode 100644 index a95f95ef2..000000000 --- a/app/controllers/legislations_controller.rb +++ /dev/null @@ -1,8 +0,0 @@ -class LegislationsController < ApplicationController - load_and_authorize_resource - - def show - @legislation = Legislation.find(params[:id]) - end - -end \ No newline at end of file diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 39a7f69f5..867bc3df6 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -7,7 +7,7 @@ module Abilities can [:read, :map, :summary], Proposal can :read, Comment can :read, SpendingProposal - can :read, Legislation + can :read, LegacyLegislation can :read, User can [:search, :read], Annotation can :new, DirectMessage diff --git a/app/models/annotation.rb b/app/models/annotation.rb index 66abb2db2..295badd92 100644 --- a/app/models/annotation.rb +++ b/app/models/annotation.rb @@ -1,7 +1,7 @@ class Annotation < ActiveRecord::Base serialize :ranges, Array - belongs_to :legislation + belongs_to :legacy_legislation belongs_to :user def permissions diff --git a/app/models/legacy_legislation.rb b/app/models/legacy_legislation.rb new file mode 100644 index 000000000..ddc267e3a --- /dev/null +++ b/app/models/legacy_legislation.rb @@ -0,0 +1,3 @@ +class LegacyLegislation < ActiveRecord::Base + has_many :annotations +end diff --git a/app/models/legislation.rb b/app/models/legislation.rb deleted file mode 100644 index d918c0255..000000000 --- a/app/models/legislation.rb +++ /dev/null @@ -1,3 +0,0 @@ -class Legislation < ActiveRecord::Base - has_many :annotations -end diff --git a/app/views/legacy_legislations/show.html.erb b/app/views/legacy_legislations/show.html.erb new file mode 100644 index 000000000..ab65649bb --- /dev/null +++ b/app/views/legacy_legislations/show.html.erb @@ -0,0 +1,29 @@ +
+
+
+ +   + <%= t("legacy_legislation.help.title") %> + + + +
+
+
+ +
+
+
+

<%= @legacy_legislation.title %>

+
<%= @legacy_legislation.body %>
+
+
+
diff --git a/app/views/legislations/show.html.erb b/app/views/legislations/show.html.erb deleted file mode 100644 index 006d91bb2..000000000 --- a/app/views/legislations/show.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -
-
-
- -   - <%= t("legislation.help.title") %> - - - -
-
-
- -
-
-
-

<%= @legislation.title %>

-
<%= @legislation.body %>
-
-
-
diff --git a/config/locales/en.yml b/config/locales/en.yml index 27d8bac7f..008a1efa4 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -212,7 +212,7 @@ en: proposal_ballot: Voting see_all: See proposals spending_proposals: Spending proposals - legislation: + legacy_legislation: help: alt: Select the text you want to comment and press the button with the pencil. text: To comment this document you must %{sign_in} or %{sign_up}. Then select the text you want to comment and press the button with the pencil. diff --git a/config/locales/es.yml b/config/locales/es.yml index a243b759d..d906018ee 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -212,7 +212,7 @@ es: proposal_ballot: Votaciones see_all: Ver propuestas spending_proposals: Presupuestos ciudadanos - legislation: + legacy_legislation: help: alt: Selecciona el texto que quieres comentar y pulsa en el botón con el lápiz. text: Para comentar este documento debes %{sign_in} o %{sign_up}. Después selecciona el texto que quieres comentar y pulsa en el botón con el lápiz. diff --git a/config/routes.rb b/config/routes.rb index df1a7c6fb..037b107ae 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -79,7 +79,7 @@ Rails.application.routes.draw do resources :stats, only: [:index] - resources :legislations, only: [:show] + resources :legacy_legislations, only: [:show], path: 'legislations' resources :annotations do get :search, on: :collection diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 87dc94a2e..9f47873ce 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -316,10 +316,6 @@ puts "Creating Valuation Assignments" SpendingProposal.reorder("RANDOM()").first.valuators << valuator.valuator end -puts "Creating Legislation" - -Legislation.create!(title: 'Participatory Democracy', body: 'In order to achieve...') - puts "Ignoring flags in Debates, comments & proposals" diff --git a/db/migrate/20161117115841_rename_legislations_to_legacy_legislations.rb b/db/migrate/20161117115841_rename_legislations_to_legacy_legislations.rb new file mode 100644 index 000000000..d8eaa76c0 --- /dev/null +++ b/db/migrate/20161117115841_rename_legislations_to_legacy_legislations.rb @@ -0,0 +1,6 @@ +class RenameLegislationsToLegacyLegislations < ActiveRecord::Migration + def change + rename_table :legislations, :legacy_legislations + rename_column :annotations, :legislation_id, :legacy_legislation_id + end +end diff --git a/db/schema.rb b/db/schema.rb index a93942873..149851a2b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161102133838) do +ActiveRecord::Schema.define(version: 20161117115841) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -57,10 +57,10 @@ ActiveRecord::Schema.define(version: 20161102133838) do t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "user_id" - t.integer "legislation_id" + t.integer "legacy_legislation_id" end - add_index "annotations", ["legislation_id"], name: "index_annotations_on_legislation_id", using: :btree + add_index "annotations", ["legacy_legislation_id"], name: "index_annotations_on_legacy_legislation_id", using: :btree add_index "annotations", ["user_id"], name: "index_annotations_on_user_id", using: :btree create_table "banners", force: :cascade do |t| @@ -221,7 +221,7 @@ ActiveRecord::Schema.define(version: 20161102133838) do add_index "identities", ["user_id"], name: "index_identities_on_user_id", using: :btree - create_table "legislations", force: :cascade do |t| + create_table "legacy_legislations", force: :cascade do |t| t.string "title" t.text "body" t.datetime "created_at", null: false @@ -550,7 +550,7 @@ ActiveRecord::Schema.define(version: 20161102133838) do add_index "votes", ["voter_id", "voter_type", "vote_scope"], name: "index_votes_on_voter_id_and_voter_type_and_vote_scope", using: :btree add_foreign_key "administrators", "users" - add_foreign_key "annotations", "legislations" + add_foreign_key "annotations", "legacy_legislations" add_foreign_key "annotations", "users" add_foreign_key "failed_census_calls", "users" add_foreign_key "flags", "users" diff --git a/spec/factories.rb b/spec/factories.rb index 7b446f3a0..1445ac3c1 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -234,8 +234,8 @@ FactoryGirl.define do end end - factory :legislation do - sequence(:title) { |n| "Legislation #{n}" } + factory :legacy_legislation do + sequence(:title) { |n| "Legacy Legislation #{n}" } body "In order to achieve this..." end @@ -243,7 +243,7 @@ FactoryGirl.define do quote "ipsum" text "Loremp ipsum dolor" ranges [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}] - legislation + legacy_legislation user end diff --git a/spec/features/legislation_spec.rb b/spec/features/legacy_legislation_spec.rb similarity index 57% rename from spec/features/legislation_spec.rb rename to spec/features/legacy_legislation_spec.rb index 93a82e1e9..e2f1ba915 100644 --- a/spec/features/legislation_spec.rb +++ b/spec/features/legacy_legislation_spec.rb @@ -1,11 +1,11 @@ require 'rails_helper' -feature 'Legislation' do +feature 'Legacy Legislation' do scenario 'Show' do - legislation = create(:legislation, title: 'Change the world', body: 'To achieve this...') + legacy_legislation = create(:legacy_legislation, title: 'Change the world', body: 'To achieve this...') - visit legislation_path(legislation) + visit legacy_legislation_path(legacy_legislation) expect(page).to have_content 'Change the world' expect(page).to have_content 'To achieve this...' @@ -17,11 +17,11 @@ feature 'Legislation' do background { login_as user } scenario 'Create' do - legislation = create(:legislation) + legacy_legislation = create(:legacy_legislation) - visit legislation_path(legislation) + visit legacy_legislation_path(legacy_legislation) - page.find(:css, "#legislation_body").double_click + page.find(:css, "#legacy_legislation_body").double_click page.find(:css, ".annotator-adder button").click fill_in 'annotator-field-0', with: 'this is my annotation' page.find(:css, ".annotator-controls a[href='#save']").click @@ -30,7 +30,7 @@ feature 'Legislation' do first(:css, ".annotator-hl").click expect(page).to have_content "this is my annotation" - visit legislation_path(legislation) + visit legacy_legislation_path(legacy_legislation) expect(page).to have_css ".annotator-hl" first(:css, ".annotator-hl").click @@ -38,10 +38,10 @@ feature 'Legislation' do end scenario 'Update' do - legislation = create(:legislation) - annotation = create(:annotation, legislation: legislation, user: user, text: "my annotation") + legacy_legislation = create(:legacy_legislation) + annotation = create(:annotation, legacy_legislation: legacy_legislation, user: user, text: "my annotation") - visit legislation_path(legislation) + visit legacy_legislation_path(legacy_legislation) expect(page).to have_css ".annotator-hl" page.find(:css, ".annotator-hl").click @@ -55,17 +55,17 @@ feature 'Legislation' do page.find(:css, ".annotator-hl").click expect(page).to have_content "edited annotation" - visit legislation_path(legislation) + visit legacy_legislation_path(legacy_legislation) page.find(:css, ".annotator-hl").click expect(page).to have_content "edited annotation" end scenario 'Destroy' do - legislation = create(:legislation) - annotation = create(:annotation, legislation: legislation, user: user) + legacy_legislation = create(:legacy_legislation) + annotation = create(:annotation, legacy_legislation: legacy_legislation, user: user) - visit legislation_path(legislation) + visit legacy_legislation_path(legacy_legislation) expect(page).to have_css ".annotator-hl" @@ -76,11 +76,11 @@ feature 'Legislation' do end scenario 'Search' do - legislation = create(:legislation) - annotation1 = create(:annotation, legislation: legislation, text: "my annotation", ranges: [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}]) - annotation2 = create(:annotation, legislation: legislation, text: "my other annotation", ranges: [{"start"=>"/div[1]", "startOffset"=>12, "end"=>"/div[1]", "endOffset"=>19}]) + legacy_legislation = create(:legacy_legislation) + annotation1 = create(:annotation, legacy_legislation: legacy_legislation, text: "my annotation", ranges: [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}]) + annotation2 = create(:annotation, legacy_legislation: legacy_legislation, text: "my other annotation", ranges: [{"start"=>"/div[1]", "startOffset"=>12, "end"=>"/div[1]", "endOffset"=>19}]) - visit legislation_path(legislation) + visit legacy_legislation_path(legacy_legislation) expect(page).to have_css ".annotator-hl" first(:css, ".annotator-hl").click From 369804a2ba6094ce4011751c2413b3cbca10de25 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Mon, 5 Dec 2016 11:08:42 +0100 Subject: [PATCH 003/197] Base Legislation::Process model and admin page --- .../admin/legislation/base_controller.rb | 5 + .../admin/legislation/processes_controller.rb | 54 ++++++ .../legislation/base_controller.rb | 5 + .../legislation/processes_controller.rb | 2 + app/helpers/admin_helper.rb | 8 +- app/models/abilities/administrator.rb | 2 + app/models/legislation.rb | 5 + app/models/legislation/process.rb | 21 +++ app/views/admin/_menu.html.erb | 8 + app/views/admin/legislation/_menu.html.erb | 1 + .../legislation/processes/_form.html.erb | 155 ++++++++++++++++++ .../admin/legislation/processes/edit.html.erb | 13 ++ .../legislation/processes/index.html.erb | 33 ++++ .../admin/legislation/processes/new.html.erb | 13 ++ config/i18n-tasks.yml | 3 + config/locales/activerecord.en.yml | 19 ++- config/locales/activerecord.es.yml | 19 ++- config/locales/admin.en.yml | 1 + config/locales/admin.es.yml | 1 + config/locales/admin.legislation.en.yml | 27 +++ config/locales/admin.legislation.es.yml | 27 +++ config/locales/settings.en.yml | 1 + config/locales/settings.es.yml | 3 +- config/routes.rb | 4 + db/dev_seeds.rb | 1 + ...1117135624_create_legislation_processes.rb | 23 +++ db/schema.rb | 31 +++- db/seeds.rb | 1 + spec/factories.rb | 15 ++ .../admin/legislation/processes_spec.rb | 62 +++++++ spec/models/legislation/process_spec.rb | 41 +++++ 31 files changed, 598 insertions(+), 6 deletions(-) create mode 100644 app/controllers/admin/legislation/base_controller.rb create mode 100644 app/controllers/admin/legislation/processes_controller.rb create mode 100644 app/controllers/legislation/base_controller.rb create mode 100644 app/controllers/legislation/processes_controller.rb create mode 100644 app/models/legislation.rb create mode 100644 app/models/legislation/process.rb create mode 100644 app/views/admin/legislation/_menu.html.erb create mode 100644 app/views/admin/legislation/processes/_form.html.erb create mode 100644 app/views/admin/legislation/processes/edit.html.erb create mode 100644 app/views/admin/legislation/processes/index.html.erb create mode 100644 app/views/admin/legislation/processes/new.html.erb create mode 100644 config/locales/admin.legislation.en.yml create mode 100644 config/locales/admin.legislation.es.yml create mode 100644 db/migrate/20161117135624_create_legislation_processes.rb create mode 100644 spec/features/admin/legislation/processes_spec.rb create mode 100644 spec/models/legislation/process_spec.rb diff --git a/app/controllers/admin/legislation/base_controller.rb b/app/controllers/admin/legislation/base_controller.rb new file mode 100644 index 000000000..047180ab3 --- /dev/null +++ b/app/controllers/admin/legislation/base_controller.rb @@ -0,0 +1,5 @@ +class Admin::Legislation::BaseController < Admin::BaseController + include FeatureFlags + + feature_flag :legislation +end diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb new file mode 100644 index 000000000..83fae8812 --- /dev/null +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -0,0 +1,54 @@ +class Admin::Legislation::ProcessesController < Admin::Legislation::BaseController + has_filters %w{open next past all}, only: :index + + load_and_authorize_resource :process, class: "Legislation::Process" + + def index + @processes = ::Legislation::Process.send(@current_filter).page(params[:page]) + end + + def create + @process = ::Legislation::Process.new(process_params) + if @process.save + redirect_to admin_legislation_processes_path + else + render :new + end + end + + def update + @process.assign_attributes(process_params) + if @process.update(process_params) + redirect_to admin_legislation_processes_path + else + render :edit + end + end + + def destroy + @process.destroy + redirect_to admin_legislation_processes_path + end + + private + + def process_params + params.require(:legislation_process).permit( + :title, + :description_summary, + :target_summary, + :description, + :target, + :how_to_participate, + :additional_info, + :start_date, + :end_date, + :debate_start_date, + :debate_end_date, + :draft_publication_date, + :allegations_start_date, + :allegations_end_date, + :final_publication_date + ) + end +end diff --git a/app/controllers/legislation/base_controller.rb b/app/controllers/legislation/base_controller.rb new file mode 100644 index 000000000..ca609ecba --- /dev/null +++ b/app/controllers/legislation/base_controller.rb @@ -0,0 +1,5 @@ +class Legislation::BaseController < ApplicationController + include FeatureFlags + + feature_flag :legislation +end diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb new file mode 100644 index 000000000..75ca3f5dd --- /dev/null +++ b/app/controllers/legislation/processes_controller.rb @@ -0,0 +1,2 @@ +class Legislation::ProcessesController < Legislation::BaseController +end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 62d31cd05..f14269fb3 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -5,7 +5,7 @@ module AdminHelper end def official_level_options - options = [["", 0]] + options = [["",0]] (1..5).each do |i| options << [[t("admin.officials.level_#{i}"), setting["official_level_#{i}_name"]].compact.join(': '), i] end @@ -16,10 +16,14 @@ module AdminHelper Administrator.all.order('users.username asc').includes(:user).collect { |v| [ v.name, v.id ] } end + def admin_submit_action(resource) + resource.persisted? ? "edit" : "new" + end + private def namespace - controller.class.parent.name.downcase + controller.class.parent.name.downcase.gsub("::", "/") end end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 0dfce6d3e..b866d226e 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -43,6 +43,8 @@ module Abilities can [:read, :update, :destroy, :summary], SpendingProposal can [:search, :edit, :update, :create, :index, :destroy], Banner + + can [:manage], ::Legislation::Process end end end diff --git a/app/models/legislation.rb b/app/models/legislation.rb new file mode 100644 index 000000000..5aa217fd0 --- /dev/null +++ b/app/models/legislation.rb @@ -0,0 +1,5 @@ +module Legislation + def self.table_name_prefix + 'legislation_' + end +end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb new file mode 100644 index 000000000..487a7e70e --- /dev/null +++ b/app/models/legislation/process.rb @@ -0,0 +1,21 @@ +class Legislation::Process < ActiveRecord::Base + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases + + validates :title, presence: true + validates :description, presence: true + validates :target, presence: true + validates :how_to_participate, 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 + + 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) } +end diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 7ea48b2c6..0fb898e8e 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -35,6 +35,14 @@ <% end %> + <% if feature?(:legislation) %> +
  • > + <%= link_to admin_legislation_processes_path do %> + <%= t("admin.menu.legislation") %> + <% end %> +
  • + <% end %> +
  • > <%= link_to admin_banners_path do %> <%= t("admin.menu.banner") %> diff --git a/app/views/admin/legislation/_menu.html.erb b/app/views/admin/legislation/_menu.html.erb new file mode 100644 index 000000000..38c8bc5c4 --- /dev/null +++ b/app/views/admin/legislation/_menu.html.erb @@ -0,0 +1 @@ +<%= render "admin/menu" %> diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb new file mode 100644 index 000000000..fa1ddf54e --- /dev/null +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -0,0 +1,155 @@ +<%= form_for [:admin, @process] do |f| %> + + <% if @process.errors.any? %> + +
    + + + + <%= @process.errors.count %> + <%= t("admin.legislation.processes.errors.form.error", count: @process.errors.count) %> + +
    + +<% end %> + +
    +
    + <%= f.label :title %> +
    +
    + <%= f.text_field :title, + label: false %> +
    +
    + +
    +
    + <%= f.label :description %> +
    +
    + <%= f.text_area :description, + label: false, + rows: 5 %> +
    +
    + +
    +
    + <%= f.label :target %> +
    +
    + <%= f.text_area :target, + label: false, + rows: 5 %> +
    +
    + +
    +
    + <%= f.label :how_to_participate %> +
    +
    + <%= f.text_area :how_to_participate, + label: false, + rows: 5 %> +
    +
    + +
    +
    + <%= f.label :additional_info %> +
    +
    + <%= f.text_area :additional_info, + label: false, + rows: 10 %> +
    +
    + +
    +
    + <%= f.label :start_date %> +
    +
    + <%= f.text_field :start_date, + label: false, + class: "js-calendar-full", + id: "start_date" %> +
    +
    + <%= f.label :end_date %> +
    +
    + <%= f.text_field :end_date, + label: false, + class: "js-calendar-full", + id: "end_date" %> +
    +
    + +
    +
    + <%= f.label :debate_start_date %> +
    +
    + <%= f.text_field :debate_start_date, + label: false, + class: "js-calendar-full", + id: "debate_start_date" %> +
    +
    + <%= f.label :debate_end_date %> +
    +
    + <%= f.text_field :debate_end_date, + label: false, + class: "js-calendar-full", + id: "debate_end_date" %> +
    +
    + <%= f.label :draft_publication_date %> +
    +
    + <%= f.text_field :draft_publication_date, + label: false, + class: "js-calendar-full", + id: "draft_publication_date" %> +
    +
    + <%= f.label :allegations_start_date %> +
    +
    + <%= f.text_field :allegations_start_date, + label: false, + class: "js-calendar-full", + id: "allegations_start_date" %> +
    +
    + <%= f.label :allegations_end_date %> +
    +
    + <%= f.text_field :allegations_end_date, + label: false, + class: "js-calendar-full", + id: "allegations_end_date" %> +
    +
    + <%= f.label :final_publication_date %> +
    +
    + <%= f.text_field :final_publication_date, + label: false, + class: "js-calendar-full", + id: "final_publication_date" %> +
    +
    + +
    +
    + <%= f.submit(class: "button expanded", value: t("admin.legislation.processes.#{admin_submit_action(@process)}.submit_button")) %> +
    +
    +<% end %> diff --git a/app/views/admin/legislation/processes/edit.html.erb b/app/views/admin/legislation/processes/edit.html.erb new file mode 100644 index 000000000..013bebaa3 --- /dev/null +++ b/app/views/admin/legislation/processes/edit.html.erb @@ -0,0 +1,13 @@ +
    + +
    + <%= link_to admin_legislation_processes_path, class: "back" do %> + + <%= t("admin.legislation.processes.edit.back") %> + <% end %> + +

    <%= @process.title %>

    + + <%= render "form" %> +
    +
    diff --git a/app/views/admin/legislation/processes/index.html.erb b/app/views/admin/legislation/processes/index.html.erb new file mode 100644 index 000000000..812812856 --- /dev/null +++ b/app/views/admin/legislation/processes/index.html.erb @@ -0,0 +1,33 @@ +<%= link_to t("admin.legislation.processes.index.create"), + new_admin_legislation_process_path, class: "button success float-right" %> + +

    <%= t("admin.legislation.processes.index.title") %>

    + +<%= render 'shared/filter_subnav', i18n_namespace: "admin.legislation.processes.index" %> + +

    <%= page_entries_info @processes %>

    + + + + + + + <% @processes.each do |process| %> + + + + + + <% end %> +
    <%= t("admin.legislation.processes.process.title") %>
    + <%= link_to process.title, edit_admin_legislation_process_path(process) %> + + <%= link_to t("admin.legislation.processes.index.edit"), edit_admin_legislation_process_path(process), + class: 'edit-banner button hollow' %> + + <%= link_to t("admin.legislation.processes.index.delete"), admin_legislation_process_path(process), + method: :delete, + class: 'button hollow alert' %> +
    + +<%= paginate @processes %> diff --git a/app/views/admin/legislation/processes/new.html.erb b/app/views/admin/legislation/processes/new.html.erb new file mode 100644 index 000000000..21d5f01a7 --- /dev/null +++ b/app/views/admin/legislation/processes/new.html.erb @@ -0,0 +1,13 @@ +
    + +
    + <%= link_to admin_legislation_processes_path, class: "back" do %> + + <%= t("admin.legislation.processes.new.back") %> + <% end %> + +

    <%= t("admin.legislation.processes.new.title") %>

    + + <%= render "form" %> +
    +
    diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index edaaa0958..6aea5cec0 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -23,6 +23,7 @@ data: # - "<%#= %x[bundle show vagrant].chomp %>/templates/locales/%{locale}.yml" - config/locales/%{locale}.yml - config/locales/admin.%{locale}.yml + - config/locales/admin.legislation.%{locale}.yml - config/locales/moderation.%{locale}.yml - config/locales/valuation.%{locale}.yml - config/locales/management.%{locale}.yml @@ -117,6 +118,8 @@ ignore_unused: - 'admin.organizations.index.filter*' - 'admin.users.index.filter*' - 'admin.activity.show.filter*' + - 'admin.legislation.processes.index.filter*' + - 'admin.legislation.processes.*.submit_button' - 'admin.comments.index.hidden_*' - 'admin.settings.index.features.*' - 'moderation.comments.index.filter*' diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 7de5b340e..91d4458a4 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -34,6 +34,9 @@ en: spending_proposal: one: "Spending proposal" other: "Spending proposals" + legislation/process: + one: "Process" + other: "Processes" attributes: comment: body: "Comment" @@ -69,6 +72,20 @@ en: external_url: "Link to additional documentation" geozone_id: "Scope of operation" title: "Title" + legislation/process: + title: Process Title + description: Description + target: Target + how_to_participate: How to participate + additional_info: Additional info + start_date: Start date + end_date: End date + debate_start_date: Debate start date + debate_end_date: Debate end date + draft_publication_date: Draft publication date + allegations_start_date: Allegations start date + allegations_end_date: Allegations end date + final_publication_date: Final result publication date errors: models: user: @@ -90,4 +107,4 @@ en: proposal_notification: attributes: minimum_interval: - invalid: "You have to wait a minium of %{interval} days between notifications" \ No newline at end of file + invalid: "You have to wait a minium of %{interval} days between notifications" diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 4dae4cb56..d4a6e2800 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -34,6 +34,9 @@ es: spending_proposal: one: "Propuesta de inversión" other: "Propuestas de inversión" + legislation/process: + one: "Proceso" + other: "Procesos" attributes: comment: body: "Comentario" @@ -69,6 +72,20 @@ es: external_url: "Enlace a documentación adicional" geozone_id: "Ámbito de actuación" title: "Título" + legislation/process: + title: Título del proceso + description: En qué consiste + target: A quién afecta + how_to_participate: Cómo participar + additional_info: Información adicional + start_date: Fecha de inicio del proceso + end_date: Fecha de fin del proceso + debate_start_date: Fecha de inicio del debate + debate_end_date: Fecha de fin del debate + draft_publication_date: Fecha de publicación del borrador + allegations_start_date: Fecha de inicio de alegaciones + allegations_end_date: Fecha de fin de alegaciones + final_publication_date: Fecha de publicación del resultado final errors: models: user: @@ -90,4 +107,4 @@ es: proposal_notification: attributes: minimum_interval: - invalid: "Debes esperar un mínimo de %{interval} días entre notificaciones" \ No newline at end of file + invalid: "Debes esperar un mínimo de %{interval} días entre notificaciones" diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 2f73f64d8..4cf069adb 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -110,6 +110,7 @@ en: settings: Configuration settings spending_proposals: Spending proposals stats: Statistics + legislation: Collaborative Legislation moderators: index: title: Moderators diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 5aada1ce1..99034d3b4 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -108,6 +108,7 @@ es: settings: Configuración global spending_proposals: Propuestas de inversión stats: Estadísticas + legislation: Legislación colaborativa moderators: index: title: Moderadores diff --git a/config/locales/admin.legislation.en.yml b/config/locales/admin.legislation.en.yml new file mode 100644 index 000000000..c11957a37 --- /dev/null +++ b/config/locales/admin.legislation.en.yml @@ -0,0 +1,27 @@ +--- +en: + admin: + legislation: + processes: + edit: + back: Back + submit_button: Save changes + errors: + form: + error: Error + index: + create: New process + delete: Delete + edit: Edit + title: Legislation processess + filters: + open: Open + next: Next + past: Past + all: All + new: + back: Back + title: Create new collaborative legislation process + submit_button: Create process + process: + title: Collaborative legislation process title diff --git a/config/locales/admin.legislation.es.yml b/config/locales/admin.legislation.es.yml new file mode 100644 index 000000000..f0436476f --- /dev/null +++ b/config/locales/admin.legislation.es.yml @@ -0,0 +1,27 @@ +--- +es: + admin: + legislation: + processes: + edit: + back: Volver + submit_button: Guardar cambios + errors: + form: + error: Error + index: + create: Nuevo proceso + delete: Borrar + edit: Editar + title: Procesos de legislación colaborativa + filters: + open: Abiertos + next: Próximamente + past: Pasados + all: Todos + new: + back: Volver + title: Crear nuevo proceso de legislación colaborativa + submit_button: Crear proceso + process: + title: Título del proceso de legislación colaborativa diff --git a/config/locales/settings.en.yml b/config/locales/settings.en.yml index 0de4e5feb..f3cfe261f 100755 --- a/config/locales/settings.en.yml +++ b/config/locales/settings.en.yml @@ -30,3 +30,4 @@ en: spending_proposals: Investment projects spending_proposal_features: voting_allowed: Voting on investment projects + legislation: Legislation diff --git a/config/locales/settings.es.yml b/config/locales/settings.es.yml index 05ba6c076..78dfb8912 100644 --- a/config/locales/settings.es.yml +++ b/config/locales/settings.es.yml @@ -29,4 +29,5 @@ es: debates: Debates spending_proposals: Propuestas de inversión spending_proposal_features: - voting_allowed: Votaciones sobre propuestas de inversión. \ No newline at end of file + voting_allowed: Votaciones sobre propuestas de inversión. + legislation: Legislación diff --git a/config/routes.rb b/config/routes.rb index 037b107ae..e7043d327 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -189,6 +189,10 @@ Rails.application.routes.draw do get :direct_messages, on: :collection end + namespace :legislation do + resources :processes + end + namespace :api do resource :stats, only: :show end diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 9f47873ce..086751ac0 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -30,6 +30,7 @@ Setting.create(key: 'feature.spending_proposal_features.voting_allowed', value: Setting.create(key: 'feature.twitter_login', value: "true") Setting.create(key: 'feature.facebook_login', value: "true") Setting.create(key: 'feature.google_login', value: "true") +Setting.create(key: 'feature.legislation', value: "true") Setting.create(key: 'per_page_code', value: "") Setting.create(key: 'comments_body_max_length', value: '1000') diff --git a/db/migrate/20161117135624_create_legislation_processes.rb b/db/migrate/20161117135624_create_legislation_processes.rb new file mode 100644 index 000000000..099a84e65 --- /dev/null +++ b/db/migrate/20161117135624_create_legislation_processes.rb @@ -0,0 +1,23 @@ +class CreateLegislationProcesses < ActiveRecord::Migration + def change + create_table :legislation_processes do |t| + t.string :title + t.text :description + t.text :target + t.text :how_to_participate + t.text :additional_info + t.date :start_date, index: true + t.date :end_date, index: true + t.date :debate_start_date, index: true + t.date :debate_end_date, index: true + t.date :draft_publication_date, index: true + t.date :allegations_start_date, index: true + t.date :allegations_end_date, index: true + t.date :final_publication_date, index: true + + t.datetime :hidden_at, index: true + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 149851a2b..213ecffbc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161117115841) do +ActiveRecord::Schema.define(version: 20161117135624) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -228,6 +228,35 @@ ActiveRecord::Schema.define(version: 20161117115841) do t.datetime "updated_at", null: false end + create_table "legislation_processes", force: :cascade do |t| + t.string "title" + t.text "description" + t.text "target" + t.text "how_to_participate" + t.text "additional_info" + t.date "start_date" + t.date "end_date" + t.date "debate_start_date" + t.date "debate_end_date" + t.date "draft_publication_date" + t.date "allegations_start_date" + t.date "allegations_end_date" + t.date "final_publication_date" + t.datetime "hidden_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree + add_index "legislation_processes", ["allegations_start_date"], name: "index_legislation_processes_on_allegations_start_date", using: :btree + add_index "legislation_processes", ["debate_end_date"], name: "index_legislation_processes_on_debate_end_date", using: :btree + add_index "legislation_processes", ["debate_start_date"], name: "index_legislation_processes_on_debate_start_date", using: :btree + add_index "legislation_processes", ["draft_publication_date"], name: "index_legislation_processes_on_draft_publication_date", using: :btree + add_index "legislation_processes", ["end_date"], name: "index_legislation_processes_on_end_date", using: :btree + add_index "legislation_processes", ["final_publication_date"], name: "index_legislation_processes_on_final_publication_date", using: :btree + add_index "legislation_processes", ["hidden_at"], name: "index_legislation_processes_on_hidden_at", using: :btree + add_index "legislation_processes", ["start_date"], name: "index_legislation_processes_on_start_date", using: :btree + create_table "locks", force: :cascade do |t| t.integer "user_id" t.integer "tries", default: 0 diff --git a/db/seeds.rb b/db/seeds.rb index 1607a0aff..82d6d6cdd 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -64,6 +64,7 @@ Setting['feature.twitter_login'] = true Setting['feature.facebook_login'] = true Setting['feature.google_login'] = true Setting['feature.public_stats'] = true +Setting['feature.legislation'] = true # Spending proposals feature flags Setting['feature.spending_proposal_features.voting_allowed'] = true diff --git a/spec/factories.rb b/spec/factories.rb index 1445ac3c1..cdfede19b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,4 +1,19 @@ FactoryGirl.define do + factory :legislation_process, class: 'Legislation::Process' do + title "A collaborative legislation process" + description "Description of the process" + target "Who will affected by this law?" + how_to_participate "You can participate by answering some questions" + start_date "2016-11-16" + end_date "2016-11-16" + debate_start_date "2016-11-16" + debate_end_date "2016-11-16" + draft_publication_date "2016-11-16" + allegations_start_date "2016-11-16" + allegations_end_date "2016-11-16" + final_publication_date "2016-11-16" + end + sequence(:document_number) { |n| "#{n.to_s.rjust(8, '0')}X" } factory :user do diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb new file mode 100644 index 000000000..03aae2768 --- /dev/null +++ b/spec/features/admin/legislation/processes_spec.rb @@ -0,0 +1,62 @@ +require 'rails_helper' + +feature 'Admin legislation processes' do + + background do + admin = create(:administrator) + login_as(admin.user) + end + + context "Feature flag" do + + scenario 'Disabled with a feature flag' do + Setting['feature.legislation'] = nil + expect{ visit admin_legislation_processes_path }.to raise_exception(FeatureFlags::FeatureDisabled) + end + + end + + context "Index" do + + scenario 'Displaying legislation processes' do + process = create(:legislation_process) + visit admin_legislation_processes_path(filter: 'all') + + expect(page).to have_content(process.title) + end + end + + context 'Create' do + scenario 'Valid legislation process' do + visit admin_root_path + + within('#side_menu') do + click_link "Collaborative Legislation" + end + + expect(page).to_not have_content 'An example legislation process' + + click_link "New process" + + fill_in 'legislation_process_title', with: 'An example legislation process' + fill_in 'legislation_process_description', with: 'Describing the process' + fill_in 'legislation_process_target', with: 'This thing affects people' + fill_in 'legislation_process_how_to_participate', with: 'You can partipate in this thing by doing...' + + base_date = Date.current + fill_in 'start_date', with: base_date.strftime("%d/%m/%Y") + fill_in 'end_date', with: (base_date + 5.days).strftime("%d/%m/%Y") + + fill_in 'debate_start_date', with: base_date.strftime("%d/%m/%Y") + fill_in 'debate_end_date', with: (base_date + 2.days).strftime("%d/%m/%Y") + fill_in 'draft_publication_date', with: (base_date + 3.days).strftime("%d/%m/%Y") + fill_in 'allegations_start_date', with: (base_date + 3.days).strftime("%d/%m/%Y") + fill_in 'allegations_end_date', with: (base_date + 5.days).strftime("%d/%m/%Y") + fill_in 'final_publication_date', with: (base_date + 7.days).strftime("%d/%m/%Y") + + click_button 'Create process' + + expect(page).to have_content 'An example legislation process' + end + end +end diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb new file mode 100644 index 000000000..4302293bd --- /dev/null +++ b/spec/models/legislation/process_spec.rb @@ -0,0 +1,41 @@ +require 'rails_helper' + +RSpec.describe Legislation::Process, type: :model do + let(:legislation_process) { build(:legislation_process) } + + it "should be valid" do + expect(legislation_process).to be_valid + end + + describe "filter scopes" do + before(:each) do + @process_1 = create(:legislation_process, start_date: Date.current - 2.days, end_date: Date.current + 1.day) + @process_2 = create(:legislation_process, start_date: Date.current + 1.days, end_date: Date.current + 3.days) + @process_3 = create(:legislation_process, start_date: Date.current - 4.days, end_date: Date.current - 3.days) + end + + it "filter open" do + open_processes = ::Legislation::Process.open + + expect(open_processes).to include(@process_1) + expect(open_processes).to_not include(@process_2) + expect(open_processes).to_not include(@process_3) + end + + it "filter next" do + next_processes = ::Legislation::Process.next + + expect(next_processes).to include(@process_2) + expect(next_processes).to_not include(@process_1) + expect(next_processes).to_not include(@process_3) + end + + it "filter past" do + past_processes = ::Legislation::Process.past + + expect(past_processes).to include(@process_3) + expect(past_processes).to_not include(@process_2) + expect(past_processes).to_not include(@process_1) + end + end +end From ea799169a0ed09048abe66d6bd65a7cad5974be1 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Mon, 5 Dec 2016 11:23:01 +0100 Subject: [PATCH 004/197] Merge admin legislation locale files in general admin file --- config/i18n-tasks.yml | 1 - config/locales/admin.en.yml | 24 ++++++++++++++++++++++ config/locales/admin.es.yml | 24 ++++++++++++++++++++++ config/locales/admin.legislation.en.yml | 27 ------------------------- config/locales/admin.legislation.es.yml | 27 ------------------------- 5 files changed, 48 insertions(+), 55 deletions(-) delete mode 100644 config/locales/admin.legislation.en.yml delete mode 100644 config/locales/admin.legislation.es.yml diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index 6aea5cec0..55edc13a1 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -23,7 +23,6 @@ data: # - "<%#= %x[bundle show vagrant].chomp %>/templates/locales/%{locale}.yml" - config/locales/%{locale}.yml - config/locales/admin.%{locale}.yml - - config/locales/admin.legislation.%{locale}.yml - config/locales/moderation.%{locale}.yml - config/locales/valuation.%{locale}.yml - config/locales/management.%{locale}.yml diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 4cf069adb..3514f9bd6 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -82,6 +82,30 @@ en: with_confirmed_hide: Confirmed without_confirmed_hide: Pending title: Hidden debates + legislation: + processes: + edit: + back: Back + submit_button: Save changes + errors: + form: + error: Error + index: + create: New process + delete: Delete + edit: Edit + title: Legislation processess + filters: + open: Open + next: Next + past: Past + all: All + new: + back: Back + title: Create new collaborative legislation process + submit_button: Create process + process: + title: Collaborative legislation process title managers: index: title: Managers diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 99034d3b4..aa638f455 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -80,6 +80,30 @@ es: with_confirmed_hide: Confirmados without_confirmed_hide: Pendientes title: Debates ocultos + legislation: + processes: + edit: + back: Volver + submit_button: Guardar cambios + errors: + form: + error: Error + index: + create: Nuevo proceso + delete: Borrar + edit: Editar + title: Procesos de legislación colaborativa + filters: + open: Abiertos + next: Próximamente + past: Pasados + all: Todos + new: + back: Volver + title: Crear nuevo proceso de legislación colaborativa + submit_button: Crear proceso + process: + title: Título del proceso de legislación colaborativa managers: index: title: Gestores diff --git a/config/locales/admin.legislation.en.yml b/config/locales/admin.legislation.en.yml deleted file mode 100644 index c11957a37..000000000 --- a/config/locales/admin.legislation.en.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -en: - admin: - legislation: - processes: - edit: - back: Back - submit_button: Save changes - errors: - form: - error: Error - index: - create: New process - delete: Delete - edit: Edit - title: Legislation processess - filters: - open: Open - next: Next - past: Past - all: All - new: - back: Back - title: Create new collaborative legislation process - submit_button: Create process - process: - title: Collaborative legislation process title diff --git a/config/locales/admin.legislation.es.yml b/config/locales/admin.legislation.es.yml deleted file mode 100644 index f0436476f..000000000 --- a/config/locales/admin.legislation.es.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -es: - admin: - legislation: - processes: - edit: - back: Volver - submit_button: Guardar cambios - errors: - form: - error: Error - index: - create: Nuevo proceso - delete: Borrar - edit: Editar - title: Procesos de legislación colaborativa - filters: - open: Abiertos - next: Próximamente - past: Pasados - all: Todos - new: - back: Volver - title: Crear nuevo proceso de legislación colaborativa - submit_button: Crear proceso - process: - title: Título del proceso de legislación colaborativa From e4fe499e66aeaf17e9b4e74fea5c20ed36cce259 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 6 Dec 2016 12:10:20 +0100 Subject: [PATCH 005/197] DraftVersion base model and very basic admin pages --- .../legislation/draft_versions_controller.rb | 43 +++++++++++ .../admin/legislation/processes_controller.rb | 1 - app/models/abilities/administrator.rb | 1 + app/models/legislation/draft_version.rb | 12 ++++ app/models/legislation/process.rb | 2 + .../legislation/draft_versions/_form.html.erb | 72 +++++++++++++++++++ .../legislation/draft_versions/edit.html.erb | 21 ++++++ .../legislation/draft_versions/index.html.erb | 38 ++++++++++ .../legislation/draft_versions/new.html.erb | 17 +++++ .../legislation/processes/_subnav.html.erb | 8 +++ .../admin/legislation/processes/edit.html.erb | 2 + .../legislation/processes/index.html.erb | 3 - config/i18n-tasks.yml | 1 + config/locales/activerecord.en.yml | 9 +++ config/locales/activerecord.es.yml | 9 +++ config/locales/admin.en.yml | 27 ++++++- config/locales/admin.es.yml | 27 ++++++- config/routes.rb | 4 +- db/dev_seeds.rb | 30 ++++++++ ...10441_create_legislation_draft_versions.rb | 16 +++++ db/schema.rb | 19 ++++- spec/factories.rb | 39 ++++++---- .../admin/legislation/draft_versions_spec.rb | 66 +++++++++++++++++ spec/models/legislation/draft_version_spec.rb | 9 +++ 24 files changed, 453 insertions(+), 23 deletions(-) create mode 100644 app/controllers/admin/legislation/draft_versions_controller.rb create mode 100644 app/models/legislation/draft_version.rb create mode 100644 app/views/admin/legislation/draft_versions/_form.html.erb create mode 100644 app/views/admin/legislation/draft_versions/edit.html.erb create mode 100644 app/views/admin/legislation/draft_versions/index.html.erb create mode 100644 app/views/admin/legislation/draft_versions/new.html.erb create mode 100644 app/views/admin/legislation/processes/_subnav.html.erb create mode 100644 db/migrate/20161205110441_create_legislation_draft_versions.rb create mode 100644 spec/features/admin/legislation/draft_versions_spec.rb create mode 100644 spec/models/legislation/draft_version_spec.rb diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb new file mode 100644 index 000000000..3e0e22208 --- /dev/null +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -0,0 +1,43 @@ +class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseController + load_and_authorize_resource :process, class: "Legislation::Process" + load_and_authorize_resource :draft_version, class: "Legislation::DraftVersion", through: :process + + def index + @draft_versions = @process.draft_versions + end + + def create + @draft_version = @process.draft_versions.new(draft_version_params) + if @process.save + redirect_to admin_legislation_process_draft_versions_path + else + render :new + end + end + + def update + if @draft_version.update(draft_version_params) + redirect_to admin_legislation_process_draft_versions_path + else + render :edit + end + end + + def destroy + @draft_version.destroy + redirect_to admin_legislation_process_draft_versions_path + end + + private + + def draft_version_params + params.require(:legislation_draft_version).permit( + :legislation_process_id, + :title, + :changelog, + :status, + :final_version, + :body + ) + end +end diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 83fae8812..b2ab765dd 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -17,7 +17,6 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll end def update - @process.assign_attributes(process_params) if @process.update(process_params) redirect_to admin_legislation_processes_path else diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index b866d226e..69a5afed2 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -45,6 +45,7 @@ module Abilities can [:search, :edit, :update, :create, :index, :destroy], Banner can [:manage], ::Legislation::Process + can [:manage], ::Legislation::DraftVersion end end end diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb new file mode 100644 index 000000000..22833cf6a --- /dev/null +++ b/app/models/legislation/draft_version.rb @@ -0,0 +1,12 @@ +class Legislation::DraftVersion < ActiveRecord::Base + VALID_STATUSES = %w(draft published) + + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases + + belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' + + validates :title, presence: true + validates :body, presence: true + validates :status, presence: true, inclusion: { in: VALID_STATUSES } +end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 487a7e70e..43cca02f6 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -2,6 +2,8 @@ class Legislation::Process < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases + has_many :draft_versions, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id' + validates :title, presence: true validates :description, presence: true validates :target, presence: true diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb new file mode 100644 index 000000000..67c21ba00 --- /dev/null +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -0,0 +1,72 @@ +<%= form_for [:admin, @process, @draft_version], url: url do |f| %> + + <% if @draft_version.errors.any? %> + +
    + + + + <%= @draft_version.errors.count %> + <%= t("admin.legislation.draft_versions.errors.form.error", count: @process.errors.count) %> + +
    + +<% end %> + +
    +
    + <%= f.label :title %> +
    +
    + <%= f.text_field :title, label: false %> +
    +
    + +
    +
    + <%= f.label :changelog %> +
    +
    + <%= f.text_area :changelog, label: false, rows: 5 %> +
    +
    + +
    +
    + <%= f.label :status %> +
    +
    + <% ::Legislation::DraftVersion::VALID_STATUSES.each do |status| %> + <%= f.radio_button :status, status, label: false %> + <%= f.label t("admin.legislation.draft_versions.statuses.#{status}") %> +
    + <% end %> +
    +
    + +
    +
    + <%= f.label :final_version %> +
    +
    + <%= f.check_box :final_version, label: false %> +
    +
    + +
    +
    + <%= f.label :body %> +
    +
    + <%= f.text_area :body, label: false, rows: 15 %> +
    +
    + +
    +
    + <%= f.submit(class: "button expanded", value: t("admin.legislation.draft_versions.#{admin_submit_action(@draft_version)}.submit_button")) %> +
    +
    +<% end %> diff --git a/app/views/admin/legislation/draft_versions/edit.html.erb b/app/views/admin/legislation/draft_versions/edit.html.erb new file mode 100644 index 000000000..b48c6409b --- /dev/null +++ b/app/views/admin/legislation/draft_versions/edit.html.erb @@ -0,0 +1,21 @@ +
    +
    + <%= link_to admin_legislation_processes_path, class: "back" do %> + + <%= t("admin.legislation.draft_versions.edit.back") %> + <% end %> + +

    <%= @process.title %>

    + + <%= render 'admin/legislation/processes/subnav', process: @process, active: 'draft_versions' %> + +

    <%= @draft_version.title %>

    + + <%= render 'form', url: admin_legislation_process_draft_version_path(@process, @draft_version) %> + + <%= link_to t("admin.legislation.processes.index.delete"), admin_legislation_process_draft_version_path(@process, @draft_version), + method: :delete, + class: 'button hollow alert' %> + +
    +
    diff --git a/app/views/admin/legislation/draft_versions/index.html.erb b/app/views/admin/legislation/draft_versions/index.html.erb new file mode 100644 index 000000000..db6a459d2 --- /dev/null +++ b/app/views/admin/legislation/draft_versions/index.html.erb @@ -0,0 +1,38 @@ +
    +
    + <%= link_to admin_legislation_processes_path, class: "back" do %> + + <%= t("admin.legislation.processes.edit.back") %> + <% end %> + +

    <%= @process.title %>

    + + <%= render 'admin/legislation/processes/subnav', process: @process, active: 'draft_versions' %> + + <%= link_to t("admin.legislation.draft_versions.index.create"), + new_admin_legislation_process_draft_version_path, class: "button float-right" %> + +

    <%= t("admin.legislation.draft_versions.index.title") %>

    + + + + + + + + + + <% @process.draft_versions.each do |draft_version| %> + + + + + + + + <% end %> +
    <%= t("admin.legislation.draft_versions.table.title") %><%= t("admin.legislation.draft_versions.table.created_at") %><%= t("admin.legislation.draft_versions.table.status") %><%= t("admin.legislation.draft_versions.table.comments") %><%= t("admin.legislation.draft_versions.table.final_version") %>
    + <%= link_to draft_version.title, edit_admin_legislation_process_draft_version_path(@process, draft_version) %> + <%= draft_version.created_at.to_date %><%= draft_version.status %><%#= draft_version.comments %><%= draft_version.final_version %>
    +
    +
    diff --git a/app/views/admin/legislation/draft_versions/new.html.erb b/app/views/admin/legislation/draft_versions/new.html.erb new file mode 100644 index 000000000..c1ee1be90 --- /dev/null +++ b/app/views/admin/legislation/draft_versions/new.html.erb @@ -0,0 +1,17 @@ +
    +
    + <%= link_to admin_legislation_processes_path, class: "back" do %> + + <%= t("admin.legislation.draft_versions.new.back") %> + <% end %> + +

    <%= @process.title %>

    + + <%= render 'admin/legislation/processes/subnav', process: @process, active: 'draft_versions' %> + +

    <%= t("admin.legislation.draft_versions.new.title") %>

    + + <%= render 'form', url: admin_legislation_process_draft_versions_path(@process) %> + +
    +
    diff --git a/app/views/admin/legislation/processes/_subnav.html.erb b/app/views/admin/legislation/processes/_subnav.html.erb new file mode 100644 index 000000000..a645faef4 --- /dev/null +++ b/app/views/admin/legislation/processes/_subnav.html.erb @@ -0,0 +1,8 @@ + diff --git a/app/views/admin/legislation/processes/edit.html.erb b/app/views/admin/legislation/processes/edit.html.erb index 013bebaa3..398dc1ec6 100644 --- a/app/views/admin/legislation/processes/edit.html.erb +++ b/app/views/admin/legislation/processes/edit.html.erb @@ -8,6 +8,8 @@

    <%= @process.title %>

    + <%= render 'subnav', process: @process, active: 'info' %> + <%= render "form" %> diff --git a/app/views/admin/legislation/processes/index.html.erb b/app/views/admin/legislation/processes/index.html.erb index 812812856..c3ca87c51 100644 --- a/app/views/admin/legislation/processes/index.html.erb +++ b/app/views/admin/legislation/processes/index.html.erb @@ -19,9 +19,6 @@ - <%= link_to t("admin.legislation.processes.index.edit"), edit_admin_legislation_process_path(process), - class: 'edit-banner button hollow' %> - <%= link_to t("admin.legislation.processes.index.delete"), admin_legislation_process_path(process), method: :delete, class: 'button hollow alert' %> diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index 55edc13a1..b4476329a 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -119,6 +119,7 @@ ignore_unused: - 'admin.activity.show.filter*' - 'admin.legislation.processes.index.filter*' - 'admin.legislation.processes.*.submit_button' + - 'admin.legislation.draft_versions.*.submit_button' - 'admin.comments.index.hidden_*' - 'admin.settings.index.features.*' - 'moderation.comments.index.filter*' diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index 91d4458a4..ad7b20e8d 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -37,6 +37,9 @@ en: legislation/process: one: "Process" other: "Processes" + legislation/draft_versions: + one: "Draft version" + other: "Draft versions" attributes: comment: body: "Comment" @@ -86,6 +89,12 @@ en: allegations_start_date: Allegations start date allegations_end_date: Allegations end date final_publication_date: Final result publication date + legislation/draft_version: + title: Version title + body: Text + changelog: Changes + status: Status + final_version: Final version errors: models: user: diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index d4a6e2800..7d6147a54 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -37,6 +37,9 @@ es: legislation/process: one: "Proceso" other: "Procesos" + legislation/draft_texts: + one: "Borrador" + other: "Borradores" attributes: comment: body: "Comentario" @@ -86,6 +89,12 @@ es: allegations_start_date: Fecha de inicio de alegaciones allegations_end_date: Fecha de fin de alegaciones final_publication_date: Fecha de publicación del resultado final + legislation/draft_version: + title: Título de la version + body: Texto + changelog: Cambios + status: Estado + final_version: Versión final errors: models: user: diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 3514f9bd6..9041793da 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -93,7 +93,6 @@ en: index: create: New process delete: Delete - edit: Edit title: Legislation processess filters: open: Open @@ -106,6 +105,32 @@ en: submit_button: Create process process: title: Collaborative legislation process title + subnav: + info: Information + draft_texts: Text + draft_versions: + edit: + back: Back + submit_button: Save changes + errors: + form: + error: Error + index: + title: Draft versions + create: Create version + new: + back: Back + title: Create new version + submit_button: Create version + statuses: + draft: Draft + published: Published + table: + title: Títle + created_at: Created at + comments: Comments + final_version: Final version + status: Status managers: index: title: Managers diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index aa638f455..9308f453f 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -91,7 +91,6 @@ es: index: create: Nuevo proceso delete: Borrar - edit: Editar title: Procesos de legislación colaborativa filters: open: Abiertos @@ -104,6 +103,32 @@ es: submit_button: Crear proceso process: title: Título del proceso de legislación colaborativa + subnav: + info: Información + draft_texts: Texto + draft_versions: + edit: + back: Volver + submit_button: Guardar cambios + errors: + form: + error: Error + index: + title: Versiones del borrador + create: Crear versión + new: + back: Volver + title: Crear nueva versión + submit_button: Crear versión + statuses: + draft: Borrador + published: Publicado + table: + title: Título + created_at: Creado + comments: Comentarios + final_version: Versión final + status: Estado managers: index: title: Gestores diff --git a/config/routes.rb b/config/routes.rb index e7043d327..56dfc46d0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -190,7 +190,9 @@ Rails.application.routes.draw do end namespace :legislation do - resources :processes + resources :processes do + resources :draft_versions + end end namespace :api do diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 086751ac0..2f2a28c1c 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -355,3 +355,33 @@ Proposal.last(3).each do |proposal| created_at: rand((Time.current - 1.week) .. Time.current)) puts " #{banner.title}" end + +puts "Creating legislation processes" + +(1..5).each do |i| + process = ::Legislation::Process.create!(title: Faker::Lorem.sentence(3).truncate(60), + description: Faker::Lorem.paragraphs.join("\n\n"), + target: Faker::Lorem.paragraphs.join("\n\n"), + how_to_participate: Faker::Lorem.paragraphs.join("\n\n"), + additional_info: Faker::Lorem.paragraphs.join("\n\n"), + start_date: Date.current - 3.days, + end_date: Date.current + 3.days, + debate_start_date: Date.current - 3.days, + debate_end_date: Date.current - 1.day, + draft_publication_date: Date.current + 1.day, + allegations_start_date: Date.current + 2.days, + allegations_end_date: Date.current + 3.days, + final_publication_date: Date.current + 4.days + ) + puts " #{process.title}" +end + +::Legislation::Process.all.each do |process| + (1..3).each do |i| + version = process.draft_versions.create!(title: "Version #{i}", + body: Faker::Lorem.paragraphs.join("\n\n") + ) + puts " #{version.title}" + end +end + diff --git a/db/migrate/20161205110441_create_legislation_draft_versions.rb b/db/migrate/20161205110441_create_legislation_draft_versions.rb new file mode 100644 index 000000000..1eb15eebe --- /dev/null +++ b/db/migrate/20161205110441_create_legislation_draft_versions.rb @@ -0,0 +1,16 @@ +class CreateLegislationDraftVersions < ActiveRecord::Migration + def change + create_table :legislation_draft_versions do |t| + t.references :legislation_process, index: true, foreign_key: true + t.string :title + t.text :changelog + t.string :status, index: true, default: :draft + t.boolean :final_version, default: false + t.text :body + + t.datetime :hidden_at, index: true + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 213ecffbc..ba661579a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161117135624) do +ActiveRecord::Schema.define(version: 20161205110441) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -228,6 +228,22 @@ ActiveRecord::Schema.define(version: 20161117135624) do t.datetime "updated_at", null: false end + create_table "legislation_draft_versions", force: :cascade do |t| + t.integer "legislation_process_id" + t.string "title" + t.text "changelog" + t.string "status", default: "draft" + t.boolean "final_version", default: false + t.text "body" + t.datetime "hidden_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "legislation_draft_versions", ["hidden_at"], name: "index_legislation_draft_versions_on_hidden_at", using: :btree + add_index "legislation_draft_versions", ["legislation_process_id"], name: "index_legislation_draft_versions_on_legislation_process_id", using: :btree + add_index "legislation_draft_versions", ["status"], name: "index_legislation_draft_versions_on_status", using: :btree + create_table "legislation_processes", force: :cascade do |t| t.string "title" t.text "description" @@ -584,6 +600,7 @@ ActiveRecord::Schema.define(version: 20161117135624) do add_foreign_key "failed_census_calls", "users" add_foreign_key "flags", "users" add_foreign_key "identities", "users" + add_foreign_key "legislation_draft_versions", "legislation_processes" add_foreign_key "locks", "users" add_foreign_key "managers", "users" add_foreign_key "moderators", "users" diff --git a/spec/factories.rb b/spec/factories.rb index cdfede19b..a68d47665 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,19 +1,4 @@ FactoryGirl.define do - factory :legislation_process, class: 'Legislation::Process' do - title "A collaborative legislation process" - description "Description of the process" - target "Who will affected by this law?" - how_to_participate "You can participate by answering some questions" - start_date "2016-11-16" - end_date "2016-11-16" - debate_start_date "2016-11-16" - debate_end_date "2016-11-16" - draft_publication_date "2016-11-16" - allegations_start_date "2016-11-16" - allegations_end_date "2016-11-16" - final_publication_date "2016-11-16" - end - sequence(:document_number) { |n| "#{n.to_s.rjust(8, '0')}X" } factory :user do @@ -357,4 +342,28 @@ FactoryGirl.define do association :sender, factory: :user association :receiver, factory: :user end + + factory :legislation_process, class: 'Legislation::Process' do + title "A collaborative legislation process" + description "Description of the process" + target "Who will affected by this law?" + how_to_participate "You can participate by answering some questions" + start_date "2016-11-16" + end_date "2016-11-16" + debate_start_date "2016-11-16" + debate_end_date "2016-11-16" + draft_publication_date "2016-11-16" + allegations_start_date "2016-11-16" + allegations_end_date "2016-11-16" + final_publication_date "2016-11-16" + end + + factory :legislation_draft_version, class: 'Legislation::DraftVersion' do + process factory: :legislation_process + title "Version 1" + changelog "What changed in this version" + status "draft" + final_version false + body "Body of the legislation text" + end end diff --git a/spec/features/admin/legislation/draft_versions_spec.rb b/spec/features/admin/legislation/draft_versions_spec.rb new file mode 100644 index 000000000..3bc1c057a --- /dev/null +++ b/spec/features/admin/legislation/draft_versions_spec.rb @@ -0,0 +1,66 @@ +require 'rails_helper' + +feature 'Admin legislation draft versions' do + + background do + admin = create(:administrator) + login_as(admin.user) + end + + context "Feature flag" do + + scenario 'Disabled with a feature flag' do + Setting['feature.legislation'] = nil + process = create(:legislation_process) + expect{ visit admin_legislation_process_draft_versions_path(process) }.to raise_exception(FeatureFlags::FeatureDisabled) + end + + end + + context "Index" do + + scenario 'Displaying legislation process draft versions' do + process = create(:legislation_process, title: 'An example legislation process') + draft_version = create(:legislation_draft_version, process: process, title: 'Version 1') + + visit admin_legislation_processes_path(filter: 'all') + + click_link 'An example legislation process' + click_link 'Text' + click_link 'Version 1' + + expect(page).to have_content(draft_version.title) + expect(page).to have_content(draft_version.changelog) + end + end + + context 'Create' do + scenario 'Valid legislation draft_version' 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 "All" + + expect(page).to have_content 'An example legislation process' + + click_link 'An example legislation process' + click_link 'Text' + + click_link 'Create version' + + fill_in 'legislation_draft_version_title', with: 'Version 3' + fill_in 'legislation_draft_version_changelog', with: 'Version 3 changes' + fill_in 'legislation_draft_version_body', with: 'Version 3 body' + + click_button 'Create version' + + expect(page).to have_content 'An example legislation process' + expect(page).to have_content 'Version 3' + end + end +end diff --git a/spec/models/legislation/draft_version_spec.rb b/spec/models/legislation/draft_version_spec.rb new file mode 100644 index 000000000..a6709110a --- /dev/null +++ b/spec/models/legislation/draft_version_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe Legislation::DraftVersion, type: :model do + let(:legislation_draft_version) { build(:legislation_draft_version) } + + it "should be valid" do + expect(legislation_draft_version).to be_valid + end +end From a210914cb49c2305973c5e40069f7126d650f0bb Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 7 Dec 2016 11:35:17 +0100 Subject: [PATCH 006/197] Avoid creating two instances of DraftVersion --- app/controllers/admin/legislation/draft_versions_controller.rb | 3 +-- app/controllers/admin/legislation/processes_controller.rb | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb index 3e0e22208..921e838b3 100644 --- a/app/controllers/admin/legislation/draft_versions_controller.rb +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -7,8 +7,7 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont end def create - @draft_version = @process.draft_versions.new(draft_version_params) - if @process.save + if @draft_version.save redirect_to admin_legislation_process_draft_versions_path else render :new diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index b2ab765dd..eaa6a5716 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -8,7 +8,6 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll end def create - @process = ::Legislation::Process.new(process_params) if @process.save redirect_to admin_legislation_processes_path else From 715d9e5b8805c39f50197500d3ce5ed8aad022b3 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Mon, 12 Dec 2016 11:10:10 +0100 Subject: [PATCH 007/197] Markdown editor for DraftVersion body --- Gemfile | 2 ++ Gemfile.lock | 3 +++ app/assets/javascripts/application.js | 3 +++ .../javascripts/markdown_editor.js.coffee | 20 +++++++++++++++++++ .../legislation/draft_versions/_form.html.erb | 9 +++++++-- 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/markdown_editor.js.coffee diff --git a/Gemfile b/Gemfile index b50540b5f..d5a704569 100644 --- a/Gemfile +++ b/Gemfile @@ -65,6 +65,8 @@ gem 'browser' gem 'turnout', '~> 2.4.0' gem 'redcarpet' +gem 'rails-assets-markdown-it', source: 'https://rails-assets.org' + 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 d787b4a81..836550667 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,6 @@ GEM remote: https://rubygems.org/ + remote: https://rails-assets.org/ specs: actionmailer (4.2.7.1) actionpack (= 4.2.7.1) @@ -303,6 +304,7 @@ GEM bundler (>= 1.3.0, < 2.0) railties (= 4.2.7.1) sprockets-rails + rails-assets-markdown-it (8.2.1) rails-deprecated_sanitizer (1.0.3) activesupport (>= 4.2.0.alpha) rails-dom-testing (1.0.7) @@ -504,6 +506,7 @@ DEPENDENCIES poltergeist quiet_assets rails (= 4.2.7.1) + rails-assets-markdown-it! redcarpet responders (~> 2.3.0) rinku (~> 2.0.2) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 10339e995..a23c3ed19 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -46,6 +46,8 @@ //= require embed_video //= require banners //= require social_share +//= require markdown-it +//= require markdown_editor //= require custom var initialize_modules = function() { @@ -68,6 +70,7 @@ var initialize_modules = function() { App.EmbedVideo.initialize(); App.Banners.initialize(); App.SocialShare.initialize(); + App.MarkdownEditor.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/markdown_editor.js.coffee b/app/assets/javascripts/markdown_editor.js.coffee new file mode 100644 index 000000000..0afd8c9e9 --- /dev/null +++ b/app/assets/javascripts/markdown_editor.js.coffee @@ -0,0 +1,20 @@ +App.MarkdownEditor = + + refresh_preview: (element, md) -> + textarea_content = element.find('textarea').val() + result = md.render(textarea_content) + element.find('#markdown-preview').html(result) + + initialize: -> + $('.markdown-editor').each -> + md = window.markdownit({ + html: true, + breaks: true, + typographer: true, + }) + App.MarkdownEditor.refresh_preview($(this), md) + $(this).on 'change input paste keyup', -> + App.MarkdownEditor.refresh_preview($(this), md) + return + + diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index 67c21ba00..1363a188d 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -59,8 +59,13 @@
    <%= f.label :body %>
    -
    - <%= f.text_area :body, label: false, rows: 15 %> +
    +
    +
    + <%= f.text_area :body, label: false, rows: 25 %> +
    +
    +
    From c69f1b3e831e39327da488fbb395337371b804e4 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 13 Dec 2016 12:29:06 +0100 Subject: [PATCH 008/197] Fullscreen toggle for the markdown editor --- .../javascripts/markdown_editor.js.coffee | 9 ++++++ app/assets/stylesheets/admin.scss | 31 +++++++++++++++++++ .../legislation/draft_versions/_form.html.erb | 5 ++- config/locales/admin.en.yml | 2 ++ config/locales/admin.es.yml | 2 ++ 5 files changed, 48 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/markdown_editor.js.coffee b/app/assets/javascripts/markdown_editor.js.coffee index 0afd8c9e9..e7c982afd 100644 --- a/app/assets/javascripts/markdown_editor.js.coffee +++ b/app/assets/javascripts/markdown_editor.js.coffee @@ -12,9 +12,18 @@ App.MarkdownEditor = breaks: true, typographer: true, }) + App.MarkdownEditor.refresh_preview($(this), md) + $(this).on 'change input paste keyup', -> App.MarkdownEditor.refresh_preview($(this), md) return + $(this).find('.fullscreen-toggle').on 'click', -> + $('.markdown-editor').toggleClass('fullscreen') + + if $('.markdown-editor').hasClass('fullscreen') + $('.markdown-editor textarea').height($(window).height() - 100) + else + $('.markdown-editor textarea').height("10em") diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index 4968983f0..7512e7ef1 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -394,3 +394,34 @@ table.investment-projects-summary { white-space: nowrap; } } + + +// Markdown Editor +// --------------- + +.markdown-editor { + background-color: white; +} + +.markdown-editor #markdown-preview { + overflow-y: auto; + height: 15em; +} + +.markdown-editor textarea { + height: 15em; +} + +.markdown-editor.fullscreen { + z-index: 9999; + width: 100%; + height: 100%; + position: fixed; + top: 0; + left: 0; +} + +.markdown-editor.fullscreen #markdown-preview { + height: 99%; +} + diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index 1363a188d..edcad5993 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -61,8 +61,11 @@
    +
    + <%= link_to t("admin.legislation.draft_versions.form.fullscreen_toggle"), "#", class: 'fullscreen-toggle' %> +
    - <%= f.text_area :body, label: false, rows: 25 %> + <%= f.text_area :body, label: false %>
    diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 9041793da..814691fbc 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -115,6 +115,8 @@ en: errors: form: error: Error + form: + fullscreen_toggle: Toggle full screen index: title: Draft versions create: Create version diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 9308f453f..e5062dd7a 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -113,6 +113,8 @@ es: errors: form: error: Error + form: + fullscreen_toggle: Pantalla completa index: title: Versiones del borrador create: Crear versión From 400b510b71d9d4d7a7631d10bffa6d2973f67056 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 13 Dec 2016 17:01:50 +0100 Subject: [PATCH 009/197] Store the processed html from the markdown text body field --- .../javascripts/markdown_editor.js.coffee | 1 + .../legislation/draft_versions_controller.rb | 3 +- .../legislation/draft_versions/_form.html.erb | 3 ++ ...3144031_add_body_html_to_draft_versions.rb | 5 +++ db/schema.rb | 3 +- .../admin/legislation/draft_versions_spec.rb | 32 ++++++++++++++++++- 6 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20161213144031_add_body_html_to_draft_versions.rb diff --git a/app/assets/javascripts/markdown_editor.js.coffee b/app/assets/javascripts/markdown_editor.js.coffee index e7c982afd..1874da5aa 100644 --- a/app/assets/javascripts/markdown_editor.js.coffee +++ b/app/assets/javascripts/markdown_editor.js.coffee @@ -4,6 +4,7 @@ App.MarkdownEditor = textarea_content = element.find('textarea').val() result = md.render(textarea_content) element.find('#markdown-preview').html(result) + element.find('#markdown-result input').val(result) initialize: -> $('.markdown-editor').each -> diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb index 921e838b3..8c20374d9 100644 --- a/app/controllers/admin/legislation/draft_versions_controller.rb +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -36,7 +36,8 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont :changelog, :status, :final_version, - :body + :body, + :body_html ) end end diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index edcad5993..fb61ca3d1 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -69,6 +69,9 @@
    +
    + <%= f.hidden_field :body_html, label: false %> +
    diff --git a/db/migrate/20161213144031_add_body_html_to_draft_versions.rb b/db/migrate/20161213144031_add_body_html_to_draft_versions.rb new file mode 100644 index 000000000..c0a05c809 --- /dev/null +++ b/db/migrate/20161213144031_add_body_html_to_draft_versions.rb @@ -0,0 +1,5 @@ +class AddBodyHtmlToDraftVersions < ActiveRecord::Migration + def change + add_column :legislation_draft_versions, :body_html, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index ba661579a..7dcecb776 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161205110441) do +ActiveRecord::Schema.define(version: 20161213144031) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -238,6 +238,7 @@ ActiveRecord::Schema.define(version: 20161205110441) do t.datetime "hidden_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.text "body_html" end add_index "legislation_draft_versions", ["hidden_at"], name: "index_legislation_draft_versions_on_hidden_at", using: :btree diff --git a/spec/features/admin/legislation/draft_versions_spec.rb b/spec/features/admin/legislation/draft_versions_spec.rb index 3bc1c057a..287b119ac 100644 --- a/spec/features/admin/legislation/draft_versions_spec.rb +++ b/spec/features/admin/legislation/draft_versions_spec.rb @@ -35,7 +35,7 @@ feature 'Admin legislation draft versions' do end context 'Create' do - scenario 'Valid legislation draft_version' do + scenario 'Valid legislation draft version' do process = create(:legislation_process, title: 'An example legislation process') visit admin_root_path @@ -63,4 +63,34 @@ feature 'Admin legislation draft versions' do expect(page).to have_content 'Version 3' end end + + context 'Update' do + scenario 'Valid legislation draft version', :js do + process = create(:legislation_process, title: 'An example legislation process') + draft_version = create(:legislation_draft_version, title: 'Version 1', process: process) + + visit admin_root_path + + within('#side_menu') do + click_link "Collaborative Legislation" + end + + click_link "All" + + expect(page).to have_content 'An example legislation process' + + click_link 'An example legislation process' + click_link 'Text' + + click_link 'Version 1' + + fill_in 'legislation_draft_version_title', with: 'Version 1b' + fill_in 'legislation_draft_version_body', with: '# Version 1 body\r\nParagraph\r\n>Quote' + + click_button 'Save changes' + + expect(page).to have_content 'Version 1b' + expect(draft_version.reload.body_html).to eq("

    Version 1 body\\r\\nParagraph\\r\\n>Quote

    \r\n") + end + end end From 766f509f8ea869439c4e247ef8efdb585fed179c Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 14 Dec 2016 15:13:48 +0100 Subject: [PATCH 010/197] Base legislation processes and draft versions page structure for public site --- .../legislation/draft_versions_controller.rb | 14 ++++++++++++++ .../legislation/processes_controller.rb | 7 +++++++ app/models/abilities/everyone.rb | 2 ++ app/models/legislation/draft_version.rb | 4 ++++ .../legislation/draft_versions/changes.html.erb | 12 ++++++++++++ app/views/legislation/draft_versions/show.html.erb | 12 ++++++++++++ app/views/legislation/processes/index.html.erb | 5 +++++ app/views/legislation/processes/show.html.erb | 9 +++++++++ app/views/shared/_subnavigation.html.erb | 5 +++++ config/locales/en.yml | 7 +++++++ config/locales/es.yml | 7 +++++++ config/routes.rb | 9 +++++++++ 12 files changed, 93 insertions(+) create mode 100644 app/controllers/legislation/draft_versions_controller.rb create mode 100644 app/views/legislation/draft_versions/changes.html.erb create mode 100644 app/views/legislation/draft_versions/show.html.erb create mode 100644 app/views/legislation/processes/index.html.erb create mode 100644 app/views/legislation/processes/show.html.erb diff --git a/app/controllers/legislation/draft_versions_controller.rb b/app/controllers/legislation/draft_versions_controller.rb new file mode 100644 index 000000000..6956f11b6 --- /dev/null +++ b/app/controllers/legislation/draft_versions_controller.rb @@ -0,0 +1,14 @@ +class Legislation::DraftVersionsController < Legislation::BaseController + load_and_authorize_resource :process + load_and_authorize_resource :draft_version, through: :process + + def index + end + + def show + end + + def changes + @draft_version = @process.draft_versions.find(params[:draft_version_id]) + end +end diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 75ca3f5dd..a444f151e 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -1,2 +1,9 @@ class Legislation::ProcessesController < Legislation::BaseController + load_and_authorize_resource + + def index + end + + def show + end end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 867bc3df6..88eccd00a 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -11,6 +11,8 @@ module Abilities can :read, User can [:search, :read], Annotation can :new, DirectMessage + can [:read], Legislation::Process + can [:read], Legislation::DraftVersion end end end diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 22833cf6a..0cb0b99fc 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -9,4 +9,8 @@ class Legislation::DraftVersion < ActiveRecord::Base validates :title, presence: true validates :body, presence: true validates :status, presence: true, inclusion: { in: VALID_STATUSES } + + def body_in_html + body_html || Redcarpet::Markdown.new(Redcarpet::Render::HTML.new).render(body) + end end diff --git a/app/views/legislation/draft_versions/changes.html.erb b/app/views/legislation/draft_versions/changes.html.erb new file mode 100644 index 000000000..80d902720 --- /dev/null +++ b/app/views/legislation/draft_versions/changes.html.erb @@ -0,0 +1,12 @@ +
    +

    <%= @process.title %>

    +

    <%= @draft_version.title %>

    + +
    + <%= link_to t('.see_text'), legislation_process_draft_version_path(@process, @draft_version) %> +
    + +
    + <%= markdown @draft_version.changelog %> +
    +
    diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb new file mode 100644 index 000000000..b924870c8 --- /dev/null +++ b/app/views/legislation/draft_versions/show.html.erb @@ -0,0 +1,12 @@ +
    +

    <%= link_to @process.title, @process %>

    +

    <%= @draft_version.title %>

    + +
    + <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %> +
    + +
    + <%= @draft_version.body_in_html.html_safe %> +
    +
    diff --git a/app/views/legislation/processes/index.html.erb b/app/views/legislation/processes/index.html.erb new file mode 100644 index 000000000..fd9517c12 --- /dev/null +++ b/app/views/legislation/processes/index.html.erb @@ -0,0 +1,5 @@ +
    + <% @processes.each do |process| %> + <%= link_to process.title, process %>
    + <% end %> +
    diff --git a/app/views/legislation/processes/show.html.erb b/app/views/legislation/processes/show.html.erb new file mode 100644 index 000000000..7d11f6f25 --- /dev/null +++ b/app/views/legislation/processes/show.html.erb @@ -0,0 +1,9 @@ +
    + +

    <%= @process.title %>

    + +<% @process.draft_versions.each do |draft_version| %> + <%= link_to draft_version.title, legislation_process_draft_version_path(@process, draft_version) %> +<% end %> + +
    diff --git a/app/views/shared/_subnavigation.html.erb b/app/views/shared/_subnavigation.html.erb index 9d87a0294..899125138 100644 --- a/app/views/shared/_subnavigation.html.erb +++ b/app/views/shared/_subnavigation.html.erb @@ -11,6 +11,11 @@
  • <%= link_to t("layouts.header.proposal_ballot"), proposal_ballots_path, class: ("active" if controller_name == "proposal_ballots"), accesskey: "v" %>
  • + <% if feature?(:legislation) %> +
  • + <%= link_to t("layouts.header.collaborative_legislation"), legislation_processes_path, class: ("active" if controller.class.parent == Legislation ), accesskey: "l" %> +
  • + <% end %> <% if feature?(:spending_proposals) %>
  • <%= link_to t("layouts.header.spending_proposals"), spending_proposals_path, class: ("active" if controller_name == "spending_proposals"), accesskey: "s" %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 70556aa96..21d40f62f 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -186,6 +186,7 @@ en: header: administration: Administration available_locales: Available languages + collaborative_legislation: Legislation processes debates: Debates external_link_blog: Blog external_link_opendata: Open data @@ -220,6 +221,12 @@ en: text_sign_in: login text_sign_up: sign up title: How I can comment this document? + legislation: + draft_versions: + changes: + see_text: See text + show: + see_changes: See changes locale: English notifications: index: diff --git a/config/locales/es.yml b/config/locales/es.yml index 884255aad..226765184 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -186,6 +186,7 @@ es: header: administration: Administrar available_locales: Idiomas disponibles + collaborative_legislation: Procesos legislativos debates: Debates external_link_blog: Blog external_link_opendata: Datos abiertos @@ -220,6 +221,12 @@ es: text_sign_in: iniciar sesión text_sign_up: registrarte title: "¿Cómo puedo comentar este documento?" + legislation: + draft_versions: + changes: + see_text: Ver texto + show: + see_changes: Ver cambios locale: Español notifications: index: diff --git a/config/routes.rb b/config/routes.rb index f88755592..07200f76c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -85,6 +85,15 @@ Rails.application.routes.draw do get :search, on: :collection end + namespace :legislation do + resources :processes, only: [:index, :show] do + resources :draft_versions, only: [:show] do + resources :annotations + get :changes + end + end + end + resources :users, only: [:show] do resources :direct_messages, only: [:new, :create, :show] end From 86009bfcaca86962dc55c665410ec32cc880143e Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 14 Dec 2016 18:51:01 +0100 Subject: [PATCH 011/197] Render TOC for legislation draft versions --- app/models/legislation/draft_version.rb | 8 +++++++- .../legislation/draft_versions/show.html.erb | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 0cb0b99fc..562e48cea 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -11,6 +11,12 @@ class Legislation::DraftVersion < ActiveRecord::Base validates :status, presence: true, inclusion: { in: VALID_STATUSES } def body_in_html - body_html || Redcarpet::Markdown.new(Redcarpet::Render::HTML.new).render(body) + renderer = Redcarpet::Render::HTML.new(with_toc_data: true) + toc_renderer = Redcarpet::Render::HTML_TOC.new(with_toc_data: true) + + body_html = Redcarpet::Markdown.new(renderer).render(body) + toc = Redcarpet::Markdown.new(toc_renderer).render(body) + + return toc, body_html end end diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index b924870c8..3a1ec15cf 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -6,7 +6,20 @@ <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %> -
    - <%= @draft_version.body_in_html.html_safe %> + <% toc, body = @draft_version.body_in_html %> + +
    + <%= toc.html_safe %>
    + +
    +
    + +
    + <%= body.html_safe %> +
    +
    +
    +
    From a4055a1578f2fe989559e4b31e4cfd343ed6caa5 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Fri, 16 Dec 2016 17:52:03 +0100 Subject: [PATCH 012/197] Legislation processes home page --- .../legislation/processes_controller.rb | 3 ++ app/helpers/legislation_helper.rb | 5 +++ .../legislation/processes/_process.html.erb | 41 +++++++++++++++++++ .../legislation/processes/index.html.erb | 25 +++++++++-- config/i18n-tasks.yml | 1 + config/locales/en.yml | 16 ++++++++ config/locales/es.yml | 16 ++++++++ config/routes.rb | 2 +- spec/factories.rb | 38 +++++++++++++---- spec/features/legislation/processes_spec.rb | 38 +++++++++++++++++ 10 files changed, 172 insertions(+), 13 deletions(-) create mode 100644 app/helpers/legislation_helper.rb create mode 100644 app/views/legislation/processes/_process.html.erb create mode 100644 spec/features/legislation/processes_spec.rb diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index a444f151e..af1ab147a 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -1,7 +1,10 @@ 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 diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb new file mode 100644 index 000000000..790e21a5b --- /dev/null +++ b/app/helpers/legislation_helper.rb @@ -0,0 +1,5 @@ +module LegislationHelper + def format_date(date) + l(date, format: "%d %b %Y") + end +end diff --git a/app/views/legislation/processes/_process.html.erb b/app/views/legislation/processes/_process.html.erb new file mode 100644 index 000000000..2053cac31 --- /dev/null +++ b/app/views/legislation/processes/_process.html.erb @@ -0,0 +1,41 @@ +
    +
    +
    +
    +

    <%= link_to process.title, process %>

    +

    <%= process.description %>

    +
    +
    + +
    + <%= link_to process, class: "button button-legislation big expanded", title: t('.see_latest_comments_title') do %> +   <%= t('.see_latest_comments') %> + <% end %> +
    +
    + +
    +
    +

    <%= t('legislation.processes.common.key_dates') %>

    +
    +
    + +
    +
    +
    <%= t('legislation.processes.common.debate_dates') %>
    +

    <%= format_date(process.debate_start_date) %> - <%= format_date(process.debate_end_date) %>

    +
    +
    +
    <%= t('legislation.processes.common.draft_publication_date') %>
    +

    <%= format_date(process.draft_publication_date) %>

    +
    +
    +
    <%= t('legislation.processes.common.allegations_dates') %>
    +

    <%= format_date(process.allegations_start_date) %> - <%= format_date(process.allegations_end_date) %>

    +
    +
    +
    <%= t('legislation.processes.common.final_publication_date') %>
    +

    <%= format_date(process.final_publication_date) %>

    +
    +
    +
    diff --git a/app/views/legislation/processes/index.html.erb b/app/views/legislation/processes/index.html.erb index fd9517c12..e145896a7 100644 --- a/app/views/legislation/processes/index.html.erb +++ b/app/views/legislation/processes/index.html.erb @@ -1,5 +1,22 @@ -
    - <% @processes.each do |process| %> - <%= link_to process.title, process %>
    - <% end %> +
    +
    +
    +

    + <%= t('.hightlighted_processes') %> +

    +
    +
    +
    + +
    +
    + <%= render 'shared/filter_subnav', i18n_namespace: "legislation.processes.index" %> +
    + +
    +
    + <%= render @processes %> + <%= paginate @processes %> +
    +
    diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index b4476329a..f1e75a86e 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -141,6 +141,7 @@ ignore_unused: - 'notifications.index.comments_on*' - 'notifications.index.replies_to*' - 'notifications.index.proposal_notification*' + - 'legislation.processes.index.filter*' - 'helpers.page_entries_info.*' # kaminari - 'views.pagination.*' # kaminari - 'shared.suggest.*' diff --git a/config/locales/en.yml b/config/locales/en.yml index 21d40f62f..bbf939da4 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -227,6 +227,22 @@ en: see_text: See text 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 + index: + hightlighted_processes: HIGHLIGHTED PROCESSES + filters: + open: Open processes + next: Next + past: Past + process: + see_latest_comments: See latest comments + see_latest_comments_title: Comment on this process locale: English notifications: index: diff --git a/config/locales/es.yml b/config/locales/es.yml index 226765184..4409b7ca0 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -227,6 +227,22 @@ es: see_text: Ver texto 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 + index: + hightlighted_processes: PROCESOS DESTACADOS + filters: + open: Procesos activos + next: Próximamente + past: Terminados + process: + see_latest_comments: Ver últimas aportaciones + see_latest_comments_title: Aportar a este proceso locale: Español notifications: index: diff --git a/config/routes.rb b/config/routes.rb index 07200f76c..1f075f5b6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -88,8 +88,8 @@ Rails.application.routes.draw do namespace :legislation do resources :processes, only: [:index, :show] do resources :draft_versions, only: [:show] do - resources :annotations get :changes + resources :annotations end end end diff --git a/spec/factories.rb b/spec/factories.rb index b15676cce..5dd66b930 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -349,14 +349,36 @@ FactoryGirl.define do description "Description of the process" target "Who will affected by this law?" how_to_participate "You can participate by answering some questions" - start_date "2016-11-16" - end_date "2016-11-16" - debate_start_date "2016-11-16" - debate_end_date "2016-11-16" - draft_publication_date "2016-11-16" - allegations_start_date "2016-11-16" - allegations_end_date "2016-11-16" - final_publication_date "2016-11-16" + start_date Date.current - 5.days + end_date Date.current + 5.days + debate_start_date Date.current - 5.days + debate_end_date Date.current - 2.days + draft_publication_date Date.current - 1.day + allegations_start_date Date.current + allegations_end_date Date.current + 3.days + final_publication_date Date.current + 5.days + + trait :next do + start_date Date.current + 2.days + end_date Date.current + 8.days + debate_start_date Date.current + 2.days + debate_end_date Date.current + 4.days + draft_publication_date Date.current + 5.day + allegations_start_date Date.current + 5.days + allegations_end_date Date.current + 7.days + final_publication_date Date.current + 8.days + end + + trait :past do + start_date Date.current - 12.days + end_date Date.current - 2.days + debate_start_date Date.current - 12.days + debate_end_date Date.current - 9.days + draft_publication_date Date.current - 8.day + allegations_start_date Date.current - 8.days + allegations_end_date Date.current - 4.days + final_publication_date Date.current - 2.days + end end factory :legislation_draft_version, class: 'Legislation::DraftVersion' do diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb new file mode 100644 index 000000000..2d3d0bdb8 --- /dev/null +++ b/spec/features/legislation/processes_spec.rb @@ -0,0 +1,38 @@ +require 'rails_helper' + +feature 'Legislation' do + + context 'processes#index' do + + scenario 'Processes can be listed' do + processes = create_list(:legislation_process, 3) + + visit legislation_processes_path + + processes.each do |process| + expect(page).to have_link(process.title) + end + end + + scenario 'Filtering processes' do + create(:legislation_process, title: "Process open") + create(:legislation_process, :next, title: "Process next") + create(:legislation_process, :past, title: "Process past") + + visit legislation_processes_path + expect(page).to have_content('Process open') + expect(page).to_not have_content('Process next') + expect(page).to_not have_content('Process past') + + visit legislation_processes_path(filter: 'next') + expect(page).to_not have_content('Process open') + expect(page).to have_content('Process next') + expect(page).to_not have_content('Process past') + + visit legislation_processes_path(filter: 'past') + expect(page).to_not have_content('Process open') + expect(page).to_not have_content('Process next') + expect(page).to have_content('Process past') + end + end +end From 54f8549c43ea9c7ce10ea036ebe94ea0b371824a Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 30 Nov 2016 13:39:58 +0100 Subject: [PATCH 013/197] Set up sandbox --- app/controllers/sandbox_controller.rb | 27 +++++++++++ app/views/sandbox/index.html.erb | 13 ++++++ app/views/sandbox/test_sandbox.html.erb | 61 +++++++++++++++++++++++++ config/routes.rb | 5 ++ 4 files changed, 106 insertions(+) create mode 100644 app/controllers/sandbox_controller.rb create mode 100644 app/views/sandbox/index.html.erb create mode 100644 app/views/sandbox/test_sandbox.html.erb diff --git a/app/controllers/sandbox_controller.rb b/app/controllers/sandbox_controller.rb new file mode 100644 index 000000000..ea5a3e96b --- /dev/null +++ b/app/controllers/sandbox_controller.rb @@ -0,0 +1,27 @@ +class SandboxController < ApplicationController + skip_authorization_check + + def index + @templates = Dir.glob(Rails.root.join('app/views/sandbox/*.html.erb').to_s).map do |filename| + filename = File.basename(filename, File.extname(filename)) + filename unless filename.starts_with?('_') || filename == 'index.html' + end.compact + end + + def show + if params[:template].index('.') # CVE-2014-0130 + render :action => "index" + elsif lookup_context.exists?("sandbox/#{params[:template]}") + if params[:template] == "index" + render :action => "index" + else + render "sandbox/#{params[:template]}" + end + + elsif lookup_context.exists?("sandbox/#{params[:template]}/index") + render "sandbox/#{params[:template]}/index" + else + render :action => "index" + end + end +end diff --git a/app/views/sandbox/index.html.erb b/app/views/sandbox/index.html.erb new file mode 100644 index 000000000..9d6303698 --- /dev/null +++ b/app/views/sandbox/index.html.erb @@ -0,0 +1,13 @@ +
    +
    +
    +

    Welcome to sandbox

    + +
      + <% @templates.each do |template| %> +
    • <%= link_to template, "/sandbox/" + template %>
    • + <% end %> +
    +
    +
    +
    diff --git a/app/views/sandbox/test_sandbox.html.erb b/app/views/sandbox/test_sandbox.html.erb new file mode 100644 index 000000000..5d61aab9d --- /dev/null +++ b/app/views/sandbox/test_sandbox.html.erb @@ -0,0 +1,61 @@ + diff --git a/config/routes.rb b/config/routes.rb index 07200f76c..6d6e23686 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,10 @@ Rails.application.routes.draw do + if Rails.env.development? || Rails.env.staging? + get '/sandbox' => 'sandbox#index' + get '/sandbox/*template' => 'sandbox#show' + end + devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions', From bbacd4546bc750ea9c7255d40c6d1e78c5d38cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Thu, 1 Dec 2016 13:37:40 +0100 Subject: [PATCH 014/197] Legislation process markup and styles --- app/assets/stylesheets/application.scss | 2 + app/assets/stylesheets/legislation.scss | 131 +++++++++++ .../stylesheets/legislation_process.scss | 205 ++++++++++++++++++ app/assets/stylesheets/participation.scss | 2 +- app/views/sandbox/legislation_debate.html.erb | 159 ++++++++++++++ app/views/sandbox/legislation_draft.html.erb | 93 ++++++++ app/views/sandbox/legislation_home.html.erb | 67 ++++++ 7 files changed, 658 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/legislation.scss create mode 100644 app/assets/stylesheets/legislation_process.scss create mode 100644 app/views/sandbox/legislation_debate.html.erb create mode 100644 app/views/sandbox/legislation_draft.html.erb create mode 100644 app/views/sandbox/legislation_home.html.erb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 36e055a4e..6a773e38f 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -6,6 +6,8 @@ @import "admin"; @import "layout"; @import "participation"; +@import "legislation"; +@import "legislation_process"; @import "custom"; @import "c3"; @import "annotator.min"; diff --git a/app/assets/stylesheets/legislation.scss b/app/assets/stylesheets/legislation.scss new file mode 100644 index 000000000..389d92e03 --- /dev/null +++ b/app/assets/stylesheets/legislation.scss @@ -0,0 +1,131 @@ +// Table of Contents +// +// 01. Hero +// 02. Sidebar menu +// 03. Legislation cards +// + +// 01. Hero +// ----------------- +.legislation-hero { + margin-bottom: 4rem; +} + +.brand-heading { + background: $brand; + + .column { + padding-top: 10rem; + padding-bottom: 10rem; + + h4 { + font-weight: 400; + text-align: center; + color: white; + } + } +} + +// 02. Sidebar menu +// ----------------- +.legislation-categories { + ul { + list-style: none; + padding-left: 0; + margin-left: 0; + + li { + cursor: pointer; + + @include breakpoint(medium) { + max-width: 80%; + } + + h4 { + font-weight: 400; + color: $text-medium; + margin-bottom: 3rem; + transition: color 0.25s ease-out, color 0.25s ease-out; + } + + &:hover h4, &:active h4 { + color: $brand; + } + } + + .active h4 { + font-weight: 700; + color: $brand; + padding-bottom: 0.5rem; + border-bottom: 2px solid $brand; + } + } +} + +// 03. Legislation cards +// ----------------- +.legislation { + margin: 0 0 4rem 0; +} + +.legislation { + background: white; + border: 1px solid; + border-color: #e5e6e9 #dfe0e4 #d0d1d5; + border-radius: 0; + box-shadow: 0px 1px 3px 0 #DEE0E3; + min-height: 12rem; + padding: 2rem 0 0 0; +} + +.button-legislation { + background: white; + border: 1px solid #2C9BE5; + color: #2C9BE5; + display: inline-block; + font-weight: 700; + margin-top: rem-calc(12); + + .icon-comments { + margin-right: 0.5rem; + color: $text-medium; + transition: color 0.25s ease-out, color 0.25s ease-out; + } + + &:hover, &:active { + border: 1px solid lighten(#2C9BE5, 25%); + cursor: pointer; + } + + &:hover .icon-comments, &:active .icon-comments { + color: white; + } +} + +.legislation-text { + margin-bottom: 1rem; + + h3 a { + color: $black; + } +} + +.legislation-calendar-info p { + font-size: $small-font-size; + color: $text-medium; + margin-bottom: 0; +} + +.legislation-calendar { + background: #E5ECF2; + padding-top: 1rem; + + h5 { + margin-bottom: 0; + color: #61686E; + } + + p { + font-size: $small-font-size; + } +} diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss new file mode 100644 index 000000000..31045f649 --- /dev/null +++ b/app/assets/stylesheets/legislation_process.scss @@ -0,0 +1,205 @@ +// Table of Contents +// +// 01. Utils +// 02. Hero +// 03. Legislation process +// 04. Debate list +// 05. Legislation draft +// + +// 01. Utils +// ----------------- +.grey { + color: #878787; +} + +.grey-heading { + background: #E6E6E6; +} + +.center { + text-align: center; +} + +.right { + text-align: right; +} + +.strong { + font-weight: 700; +} + +// 02. Hero +// ----------------- +.legislation-hero { + padding-top: 1.5rem; + + @include breakpoint(medium) { + padding-top: 3.5rem; + } + + h4 { + color: #878787; + text-transform: uppercase; + font-weight: 400; + } + + ul { + list-style: none; + margin-left: 0; + + li:before { + vertical-align: text-bottom; + padding-right: 0.5rem; + content: "■"; + color: #8AA8BE; + } + } + + .half-gradient { + /* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#e6e6e6+0,e6e6e6+50,ffffff+50 */ + background: #e6e6e6; /* Old browsers */ + background: -moz-linear-gradient(top, #e6e6e6 0%, #e6e6e6 50%, #ffffff 50%); /* FF3.6-15 */ + background: -webkit-linear-gradient(top, #e6e6e6 0%,#e6e6e6 50%,#ffffff 50%); /* Chrome10-25,Safari5.1-6 */ + background: linear-gradient(to bottom, #e6e6e6 0%,#e6e6e6 50%,#ffffff 50%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */ + filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e6e6e6', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */ + } + + .center .button { + background: #004A83; + margin-bottom: 0; + } + + .headline { + margin-bottom: 1rem; + } + + .description { + margin-bottom: 1rem; + } + + .button-subscribe { + margin-top: 1.5rem; + + h3 { + margin-bottom: 0; + } + + p { + margin-bottom: 0; + font-size: $small-font-size; + } + + &:hover h3 { + color: white; + } + + @include breakpoint(medium) { + padding: 0.5em 1em; + margin-top: 3rem; + } + } + + @include breakpoint(medium) { + .headline { + margin-bottom: 4rem; + } + + .description { + margin-bottom: 0; + } + } +} + +// 03. Legislation process +// ----------------- +.legislation-process-categories { + list-style: none; + margin-left: 0; + padding-left: 0; + border-bottom: 1px solid $medium-gray; + + li { + cursor: pointer; + margin-left: 3rem; + display: inline-block; + + a, + h4 { + color: #6D6D6D; + margin-bottom: 0; + } + a:hover { + text-decoration: none; + } + } + + .active { + border-bottom: 2px solid $brand; + } + + .active h4 { + // padding-bottom: 0.4rem; + } +} + +// 04. Debate list +// ----------------- +.debate-chooser { + padding: 2rem 3rem; + + .debate-block { + margin-bottom: 2.5rem; + + .debate-type { + text-transform: uppercase; + color: #178DCC; + font-weight: 700; + font-size: $small-font-size; + + .icon-debates { + margin-left: 0.2rem; + } + } + + .debate-title a { + color: $brand; + } + + .debate-meta, + .debate-meta a { + font-size: $small-font-size; + color: #6D6D6D; + + .icon-comments { + margin-right: 0.2rem; + } + } + } + + .debate-info { + padding: 1rem; + background: #F4F4F4; + } +} + +// 05. Legislation draft +// ----------------- +.debate-draft { + padding: 10rem 2rem 15rem 2rem; + display: block; + background: #F2F2F2; + + button { + height: 90px; + + h3 { + margin-bottom: 0; + } + + p { + margin-bottom: 0; + font-size: $small-font-size; + } + } +} diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index a5e1d7df2..79702b138 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -492,7 +492,7 @@ } } -.debate, .proposal, .investment-project { +.debate, .proposal, .investment-project, .legislation { margin: $line-height/4 0; .panel { diff --git a/app/views/sandbox/legislation_debate.html.erb b/app/views/sandbox/legislation_debate.html.erb new file mode 100644 index 000000000..92d018965 --- /dev/null +++ b/app/views/sandbox/legislation_debate.html.erb @@ -0,0 +1,159 @@ +
    +
    +
    +

    Colabora en la elaboración de la normativa sobre

    +

    + Licencias urbanísticas, declaraciones responsables y comunicaciones previas +

    +
    + +
    + +
    +
    +

    En qué consiste

    +

    Se va a modificar la regulación del procedimiento para la autorización de obras y la apertura de locales comerciales o empresariales para simplificar y agilizar trámites.

    +
    +
    +

    A quién va dirigido

    +
      +
    • Ciudadanos con vivienda en propiedad
    • +
    • Profesionales de la construcción y reformas
    • +
    • Empresarios con locales comerciales
    • +
    +
    +
    +

    Cómo puedes participar

    +
      +
    • Participa en el debate previo para identificar los problemas a solucionar, la necesidad de esta normativa, sus objetivos y posibles soluciones alternativas.
    • +
    • Después del debate el Ayuntamiento presentará un borrador del texto al cual podrás realizar comentarios y alegaciones.
    • +
    +
    +
    + + +
    + +
    + + +
    +
    +
    +
    + + + + + + + + + + + + + +
    +
    +
    +
    Realiza tus aportaciones al debate previo participando en los siguientes temas.
    +
    +
    +
    +
    +
    diff --git a/app/views/sandbox/legislation_draft.html.erb b/app/views/sandbox/legislation_draft.html.erb new file mode 100644 index 000000000..29db933d3 --- /dev/null +++ b/app/views/sandbox/legislation_draft.html.erb @@ -0,0 +1,93 @@ +
    +
    +
    +

    Colabora en la elaboración de la normativa sobre

    +

    + Licencias urbanísticas, declaraciones responsables y comunicaciones previas +

    +
    + +
    + +
    +
    +

    En qué consiste

    +

    Se va a modificar la regulación del procedimiento para la autorización de obras y la apertura de locales comerciales o empresariales para simplificar y agilizar trámites.

    +
    +
    +

    A quién va dirigido

    +
      +
    • Ciudadanos con vivienda en propiedad
    • +
    • Profesionales de la construcción y reformas
    • +
    • Empresarios con locales comerciales
    • +
    +
    +
    +

    Cómo puedes participar

    +
      +
    • Participa en el debate previo para identificar los problemas a solucionar, la necesidad de esta normativa, sus objetivos y posibles soluciones alternativas.
    • +
    • Después del debate el Ayuntamiento presentará un borrador del texto al cual podrás realizar comentarios y alegaciones.
    • +
    +
    +
    + + +
    + +
    + + +
    +
    +
    + +
    +

    Esta fase del proceso todavía no está abierta

    +

    Suscríbete al proceso para recibir un aviso en el momento en que se abra.

    +
    + +
    + +
    + +
    +
    +
    +
    diff --git a/app/views/sandbox/legislation_home.html.erb b/app/views/sandbox/legislation_home.html.erb new file mode 100644 index 000000000..09ea887c1 --- /dev/null +++ b/app/views/sandbox/legislation_home.html.erb @@ -0,0 +1,67 @@ +
    +
    +
    +

    + PROCESOS DESTACADOS +

    +
    +
    +
    + +
    +
    +
      +
    • Procesos activos

    • +
    • Próximamente

    • +
    • Terminados

    • +
    +
    + +
    +
    + +
    +
    +
    +
    +

    Licencias urbanísticas, declaraciones responsables y comunicaciones previas

    +

    Se va a modificar la regulación del procedimiento para la autorización de obras y la apertura de locales comerciales o empresariales para simplificar y agilizar trámites

    +
    +
    + + +
    + +
    +
    +

    Fechas clave:

    +
    +
    + +
    +
    +
    Debate previo
    +

    15 nov 2016 - 15 dic 2016

    +
    +
    +
    Publicación borrador
    +

    1 dic 2016

    +
    +
    +
    Alegaciones
    +

    1 dic 2016 - 15 dic 2016

    +
    +
    +
    Publicación resultados
    +

    15 feb 2017

    +
    +
    +
    + +
    +
    +
    From 23211337efb701d6fab02a2d1a5e9def446cbedf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Mon, 5 Dec 2016 16:17:22 +0100 Subject: [PATCH 015/197] Legislation process debate markup --- .../stylesheets/legislation_process.scss | 186 ++++++++++++++++-- app/assets/stylesheets/participation.scss | 3 +- app/views/sandbox/legislation_debate.html.erb | 7 +- .../sandbox/legislation_debate_quiz.html.erb | 57 ++++++ app/views/sandbox/legislation_home.html.erb | 4 +- 5 files changed, 229 insertions(+), 28 deletions(-) create mode 100644 app/views/sandbox/legislation_debate_quiz.html.erb diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 31045f649..2ba1a4685 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -4,7 +4,8 @@ // 02. Hero // 03. Legislation process // 04. Debate list -// 05. Legislation draft +// 05. Debate quiz +// 06. Legislation draft // // 01. Utils @@ -33,9 +34,11 @@ // ----------------- .legislation-hero { padding-top: 1.5rem; + margin-bottom: 2rem; @include breakpoint(medium) { padding-top: 3.5rem; + margin-bottom: 4rem; } h4 { @@ -72,14 +75,23 @@ .headline { margin-bottom: 1rem; + + @include breakpoint(medium) { + margin-bottom: 4rem; + + } } .description { margin-bottom: 1rem; + + @include breakpoint(medium) { + margin-bottom: 0; + } } .button-subscribe { - margin-top: 1.5rem; + margin-top: 1rem; h3 { margin-bottom: 0; @@ -99,16 +111,6 @@ margin-top: 3rem; } } - - @include breakpoint(medium) { - .headline { - margin-bottom: 4rem; - } - - .description { - margin-bottom: 0; - } - } } // 03. Legislation process @@ -121,32 +123,51 @@ li { cursor: pointer; - margin-left: 3rem; + margin-left: 1rem; display: inline-block; + margin-bottom: 1rem; + + @include breakpoint(medium) { + margin-left: 3rem; + margin-bottom: 0; + } a, h4 { color: #6D6D6D; margin-bottom: 0; } - a:hover { - text-decoration: none; + + a { + &:hover, &:active { + text-decoration: none; + } + + p { + margin-bottom: 0; + + @include breakpoint(medium) { + margin-bottom: 1rem; + } + } } } .active { border-bottom: 2px solid $brand; } - - .active h4 { - // padding-bottom: 0.4rem; - } } // 04. Debate list // ----------------- .debate-chooser { - padding: 2rem 3rem; + padding: 2rem 1rem; + + @include breakpoint(medium) { + .debate-chooser { + padding: 2rem 3rem; + } + } .debate-block { margin-bottom: 2.5rem; @@ -183,7 +204,130 @@ } } -// 05. Legislation draft +// 05. Debate quiz +// ----------------- +.debate-quiz { + + .quiz-header { + margin-bottom: 2rem; + + .quiz-title, .quiz-next { + padding: 1rem; + height: 6rem; + } + + .quiz-title { + background: #E5ECF2; + + .quiz-header-title { + margin-bottom: 0; + text-transform: uppercase; + color: #979B9F; + font-weight: 700; + font-size: $small-font-size; + } + } + + h4 a { + color: $brand; + } + + h4 a:hover { + text-decoration: none; + } + + .quiz-next-link { + + &:hover, &:active { + text-decoration: none; + } + + .quiz-next { + background: #CCDBE5; + font-weight: 700; + color: $brand; + font-size: $small-font-size; + text-align: right; + text-transform: uppercase; + transition: background 0.25s ease-out, background 0.25s ease-out; + + .icon-angle-right { + vertical-align: sub; + } + + &:hover, &:active { + text-decoration: none; + background: $brand; + color: white; + + .icon-angle-right { + color: white; + } + } + } + } + } + + .quiz-question { + margin-bottom: 2rem; + } + + .debate-questions { + list-style: none; + + .control { + position: relative; + display: inline-block; + color: #555; + cursor: pointer; + background: #fff; + border: 1px solid $border; + border-radius: 4px; + padding: 0.75rem 2.5rem; + margin-right: 1.5rem; + } + + .active { + background: #CCDBE6; + border: none; + } + + .control input { + position: absolute; + opacity: 0; + z-index: -1; + } + + .control input:checked ~ .control-indicator { + background-color: $brand; + border: none; + } + + .radio .control-indicator { + border-radius: 50%; + } + + .control-indicator { + position: absolute; + top: 0.95rem; + left: 0.95rem; + display: block; + width: 1rem; + height: 1rem; + line-height: 1rem; + font-size: 65%; + text-align: center; + border: 2px solid #9C9C9C; + pointer-events: none; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + } + } +} + +// 06. Legislation draft // ----------------- .debate-draft { padding: 10rem 2rem 15rem 2rem; diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 79702b138..9af22d4ab 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -294,7 +294,8 @@ .debate-show, .proposal-show, -.investment-project-show { +.investment-project-show, +.debate-quiz { p { word-wrap: break-word; diff --git a/app/views/sandbox/legislation_debate.html.erb b/app/views/sandbox/legislation_debate.html.erb index 92d018965..adb5feff2 100644 --- a/app/views/sandbox/legislation_debate.html.erb +++ b/app/views/sandbox/legislation_debate.html.erb @@ -75,13 +75,12 @@ + diff --git a/app/views/sandbox/legislation_debate_quiz.html.erb b/app/views/sandbox/legislation_debate_quiz.html.erb new file mode 100644 index 000000000..d4411b3bd --- /dev/null +++ b/app/views/sandbox/legislation_debate_quiz.html.erb @@ -0,0 +1,57 @@ +
    + +
    +
    +

    ¿Considera necesario realizar una nueva regulación para facilitar y simplificar las obras en viviendas, o la modificación y apertura de locales comerciales o empresariales?

    +
    +
    + + + +
    +
    +
    + +
    + +
    + +
    + +
    +
    + COMENTARIOS +
    +
    diff --git a/app/views/sandbox/legislation_home.html.erb b/app/views/sandbox/legislation_home.html.erb index 09ea887c1..c054788b7 100644 --- a/app/views/sandbox/legislation_home.html.erb +++ b/app/views/sandbox/legislation_home.html.erb @@ -24,13 +24,13 @@
    -

    Licencias urbanísticas, declaraciones responsables y comunicaciones previas

    +

    Licencias urbanísticas, declaraciones responsables y comunicaciones previas

    Se va a modificar la regulación del procedimiento para la autorización de obras y la apertura de locales comerciales o empresariales para simplificar y agilizar trámites

    From daba4411783e7b381a6679f3c0bec2f204d31df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Mon, 12 Dec 2016 19:36:38 +0100 Subject: [PATCH 016/197] Allegations page --- app/assets/fonts/icons.eot | Bin 11104 -> 11544 bytes app/assets/fonts/icons.svg | 4 +- app/assets/fonts/icons.ttf | Bin 10948 -> 11388 bytes app/assets/fonts/icons.woff | Bin 8556 -> 8784 bytes app/assets/javascripts/allegations.js.coffee | 16 + app/assets/javascripts/application.js | 2 + app/assets/stylesheets/icons.scss | 25 +- .../stylesheets/legislation_process.scss | 553 +++++++++++++++++- .../sandbox/legislation_allegations.html.erb | 462 +++++++++++++++ app/views/sandbox/legislation_debate.html.erb | 2 +- app/views/sandbox/legislation_draft.html.erb | 2 +- 11 files changed, 1058 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/allegations.js.coffee create mode 100644 app/views/sandbox/legislation_allegations.html.erb diff --git a/app/assets/fonts/icons.eot b/app/assets/fonts/icons.eot index c3c5d6289b5c52e16a28f163f65bef1c52ae7e95..13bfbda6c98c7b2ac419afdd1908194305176968 100644 GIT binary patch delta 1152 zcmZuwU5FD`6#nkqnLFbo_>;fgjjOw^ZYFC?-DH!@>S|44wfItHw=C)k?wC#eOV*gU zvX(-MP%5YodS4X53a!u<6+!wSSj5toDIF|0V*aacfIp?YT6ShC_zu6(x_eIdlv6GqyYuZZ5I;=Vp~}J9 z;b*7LPXK+7>D^y|Q5D&}<2Rn~TCnZ~dxZyf^nI+kv{D+ORewkCg z-`%QO`g)S z$RH;_<@=c}f8iF-W^(c`epS}hNga#6T=Zway#7$VvP@dmSe+A*&Fm68gCHynk+yVO zWC;uDBEfpB*m{<+a|6L_#)?s{3tDN546(GGv*xH{#g0%g7>qWfG>1AK7>2LuGYmub zH~qTtiOLm)t3S;;b|w(+Xw=)o!C<(((Gd>3df6~d!!XT;yTv%hnHJC#&J}Wu(|37G zG=U8m1$x6C$=TVXy8JESA(kcDMAMZrKy%w10&I6@{k=-BoQ)I1JXwHP=4YAa6_p3L z>ZQFOOX__uwn@@ox`f?wx4K0VhVg!O2z`L9hav-Z zI=7nHWU&Rzis_=)&cv4MJ)(>0WRVT5En?@QQK4SYRBh>q5Nm`O?czdZ%{joIFQ{U% zpLdPutvVKBzy1$n@~E}a>OrN|lPWa)(26zq@Ovv3g#Rs@)-r1tE8V_T=TX<1kgZrl z1eaQ|AiN<1@$q>n>dqumNXu$`g_g=BQ)ziFzEwVo_s|_N`${Uyul|4G1a+CMiACElOT8Tl&< zll6cQBklF5F_Yigf=KxVI(Lnl*DhyQd@lj12dKLj$jZvg5#Y1#bL%x#Z*T#R@T*0{1+H#V{LsG zG|MQ-O*WO`RtY;0#QhSMNq@^%8_zj(#L>>nw3w*J+j*;YiV1vKtf677YGyImbdwFs zV;M6aPn4&}GU;s2n9j!2 - + + + diff --git a/app/assets/fonts/icons.ttf b/app/assets/fonts/icons.ttf index 6f938f8631bc2a37fddaaaf42cbe3b72c1316096..8051071fbec03ca8cff20ef176d82d342366959a 100644 GIT binary patch delta 1148 zcmZuwUuauZ82^3u++-K_R&Cd{xmmleO`7CZ>Rbl3qM{q^RyHfxyYz0^mSkDe zj_QLM15ud1^t>rlnGQry2EzwIk;-0@7hk4=f1b)fMDa=XGB>}QWR^nj;XCL1edm1V z{(k3t=k|&FCu<-8J8=a9$EK!^zqCAbei}G1&(ZGZCZC;x3!QO}aqrQYk<`(~tKR~2 zlJRW5_vSBvlHk~PXPs*0;X~dD2gZ5cJX?JIOm)vx6;S7a{&2x{7JLD-#&f^2 zWeWwj=BOiz#>rt0^cPA?EB@2kAB=A@UMXJ8JNjb}dI9k#5H zd-eM(lR#pLW0xuyt4n{q_rW}{|92+!a#I`&{OO&q{(i0F>3`r?I1RXSd1JjbDjVyo zbcn{~Gc-q|@_l;y)F|e-c^?aDT6c3F;A=+Sadkt*M?CsqLg5CC;uXBX(!FmKN8mJl zqlvu?@F9-NvXay?NFyt+E9c3UJB1}O>8!NH7ji=^7}#}u*X^M1)(h(Ad*!wGY)vqc z=jjHmA_NN)EHTv?eS*S>{uw1w&IKpoo70u6O^*E);8ZRiP+C{iHR}YB17OukDV6LXq9|u1N5~y}Hk5nm%9MOEIqs z(t?^Igu(*}K9@&Chj17(z(Ax)veh@K?t4Udf-+2-X?jw|xbNIXfbC_K0LV>YI9l5xz6;W^1h* z4r4!H8{z1foyv}o%@*$Ic(Txc!6QdzEe(YT6(u9R^r3-%mJ0&q_#5-jY=VkKFIrrW7?z!*%nf!RB3jxinoK6jn$XMHDA_|oD48uT zI?vh616GI^GkIP6v9VSHcrziF)fNl5iPse0Pdu2@vWaRcyaveMNlO><3&rQdUycA> zbRZY0nInU@gF|zdTnE?TTVoaMqY#;>{ejvZ zz$;>As{#=4kmfoXTboUxM5fJe7@CEs7~&#Sqr^q{C}PG6H)m9Mx3PzB;-fJbBm7Ha zoxjYtx{p^c3NPBr6+~EttwKgGWy`xe?4q|nI-vIVH8pxYcCj`*2UuT>#6wISP-9VE zmRKu`Gnq|=;(J?q#_TSi-{ssUIuuFb>~T9UO5TvL^PXoH=kE$|epU^5TE^S!n;TqS zm%GmHYid?(qU3Tr-BPRQZ&UyNVt&QP`4m44yL{fb)+LvN$XHDfV8dez+u+1o3yY+$ znhg>hq|}r3EzChegN1nUF_HRu1YVMhE17HE=s diff --git a/app/assets/fonts/icons.woff b/app/assets/fonts/icons.woff index f3c31e8043caa6659a6fb91bcc10ff8ec8783d52..2c48a6868a0c5ebe9df72483fa741bf8fc29eb8a 100644 GIT binary patch delta 8765 zcmX|{V{q8P*2bg8wr#7iZQHidIRD1B&BnHEJB{7gNs~0Xxp(G$cjouudCu%v%hVG##A)%-EIc$|^<{o}Ctn)-3vvj62@KrI-pvyPgyc(u=zie@WAg3P-q`ai zA&K6XhWsBKN+1r#_U2#SS5lD8uR)vxXMc)0Il8)iElKFhL;ivo1RMm^Gdsl_&J%w* z#iG^OeG6LvDljS-Cc!gv+@UXHic*O3us=RCtqlOb~uIuc9;4u&O?~d=t@Q|Y5-3fc1#BCJF@V+(&vbr2s?Pdr3y3Lb;PHPlS zYb!PO0hPUPKn?J%?b!vVazMg;(70ypZjQGW2764_+kOkM< zUGF1;62NX_xQXbq1oMEpg5g8DBp!?Xmu#y*)8L7LItSVAF1X(Y?K%TrERS zM@3S6A_78OZ1~0A?f1Ryey1HF6L!Mb;lYTZJ|}=L_e6R~(j*~4s>_m^FyiqE9;w(H z6`UGq>A6wjLb;NCcnC|{^AqKN&q5m>AQK(;SNR2I1S}KvY06IE_HcS z-7?V3OVj}_Gbm|QvlxMwz@me z`~y8Vv9rCV_8U+w{pQ!b7g!q}z4v6-hfF)p!>M!=ns19KQz@UWqw<;wl`}oB?H-@! zK3Bf8XUnf2CnL5Wm#>7rhO@6TZhkj=V?EB;AE%?bIIiJJThdc3eQMvA8{|H#G}YjhzEZc9K_1+8=`&Nsou zyv#znq3-q0%y|saWnn1MMRz;rdhyj8s%`V%nnr+(iZr8iaR+jSS>m!B+0In!5T@Kf6aTVJ>pI)CxMg{V z9RZ|^udN_FwCGxa9bX2%d@QC3a!9aW8OsWOmJEX#x^e<~1a$-Hcp^PrGK+XYEvici zs<^QlhCU^T5<;KgH?>1eW1#~2gBUv$hC{1ZgB1-r*~gF{x(;+nPWV9Vx+Jb7Zj|a} zd%2e-Xetan24<3LdHe4rCDStJzHO+XX)j=qfxVP6i!BDn2l0=QaQfs_vE?Y0sXSd# zDG9hTNv>?X9Vs`aVywcD%iyq-u@-J1Dtf@G!qALap7@^)?+s$O@?V=a^;KLIMTKL^ zn{H%EOFWgzgl=HC{&N8K8xaV{eCgR|-c^I0OsEO9+bF^saYKZl+-Hjto&;w{dvQE! z(u7?1TFddsi}PN5a<+n65%u!C2x{#B^$;|4W|1f_Jq;JxFva~|E*+>oXoN!VGPQ|qGF*yaaTqQASr$QJWH~lfZ+}G@NGRo8# z0iH#5$0!n*;_VQ{N>yB2=T9I}B8+qxfoJ=a%`hjiy5zV{7f zdJ#KaabEWW) zQGu8q-#ipe%F zv3@8^+K!Lam_>$~CA)!M7lv{~$|^ZCB+~Eet0eHNtH{_W)BL+`h^!Xtk4w};z4PTz zA3J&h%R7#ufO#WK?9D>Gz4C`6Gq;k48&1_qqHQQzI>g+TZ;oYQYYI-@6#zD#-6%)nc$)0)W~p+Ir=K?a5KOOH0`M!Li-1^$7UIA51!n}3_X zwR2ei^VRAd~-Be>>IC;GE<7|Q1^CcZoQapO97a9kzGO()mFCylWL0_ZRzDz zGm{fk+_f$O0|Wmj_el39gNv2F)yNRAakMp&&ntmM4k}@i)S(;6`=h;cuFRcX9L^2L zE6+3b{>}ij%l?YP3C??qViMnNkbri5aucCA#*Q z+n8^$ltfdEIz>l{D7n6wu32&9RG9a|Xr5>M=po@68p5{L7;nS~#bt`w-xXbI z!8=%qk}V~wVzX{kN<OUsNQ1*3kG};>?t^8_Bc&?y zoBq&ba~ewO>NjBdp>O;vd!8R!HYilH@)*ZPxxUvIYuE1l$M1n`2-;@~^`to#t`G|5 z?ycHqW1Z|y;K;zjjEP{x-y&l)(}tB_-k=DBd}PukYg-c7!u*1PZoR!v-&^C@9=5*d@Ih$I3|VG-biXAgK8Va^d^Ra@H#QpKA@QS46T5S{Af*vI~OEf&>S4u+Ot-y zr_*v;(Nu7}qHyHf>#MeKUCz~K;O(54q?Cccc=R$GTpd`c#!9R(LV#Jb+FAaY7R5Gp zDT#EW9vJD(Go8-c>~(z zgRr#NejWgy(0PFUSxGY`mDNNceYY`#lsi#E^T=*thV!N@ZmazbKCPMg|nku zvxP9I`QHHjEujmM3F5G85HpC!$I+JH@Ehd~JZGnpp{N1i{baZuaT(P9OyYLtVP{k~ zBdew-B0K?3s+~k?3Zu`cCLdO)!7fD%ZA<}cEf2stZ(VzPDD}n=XL`nU#IX*`6l6EM zVAhi5|7Aotnh(SJ21@jMqZ1vpe&*oVu3ZTw{IzU#@VAI~O+i7vM_q(ZwGYALJ;u(g zBy(QuBLZT`!QPO8Khi}&ck_*}r}2%{#o-=X9D$!nE)iXfNMPT`NdNF}6T9!7v8cNC z^!vcF*6`}f0>0qA*nT~D*b{Os6b20PUBSd;18qNqnM}K0EEZdvb)qAzKd-R-f|+QE z!c6ct%a)i`Idf0|+e)_MB8*w{Azn|r{+G)`*890n>JzW)SdZ($q2g)_Ja22KLxj20vqop`Qu>ZXiWsTK%N1uEO6J z=k7o;ln*Tks`g8h;wN2&+|6u^wEK*h%6Z25Sx=7!e>)Y#7{V$1pFzmwM41Xz@J+xg zGi$6Yjhv8!2@Qwh@mV$FlO%l!X*J{KLZWthj!q3hC|O-%7C~NARjEQB{gjq{*g6gE zwZauSp9W7VcdEX^Oti^9?>%(ytJ5edme@U;Lrpd3jG(ItL)JUI6#W2oR{$f;(b zVM8P9H{C5Inr&<=+hWG)0zIl>1tTCgJ3GaoNMMU^E1)3|fqSil4kQaEYDrhYPe024 zZ6T`WgGU-H8s1jh8Je>qO$@&gb^6&?hh{&zULPV_NdvJL7|ki}aJeS(T~@Q|CJA)hPQRc@q5uu$2%f09 zW!W})*?g>=y{x?|ykL^^&>m!Uw<3&#T{z@uoQI)CnE{b%n9+r&*DW56tw{;*O?|V5 zN<`LhCKk<`!q~WlF|0-xUNG}h?GdGraes+=9ska-zL3b$U?70fq{J`G>=cOUG83sV z+$`ExFBCk0|4=tTwG7TM;ROt5tKij%sQm*G>(vhDioJ4#C)^>?U`8tzH^fS9IHFVM zm++KCKW5q-ol3Rk!s1!MoW(A927bu0%|p-%DRe)-%n4xAlq8~!o1p(q3M2e?qRsS_ zne|Gy;)SxcwOPwGHttogBqFGee4BbFWAH~^u9u|rI2zv@t4GcgZVQmDR!gy&1Ci^b z9~FVpsHZg_t-?`Ha)2ziQLmN|4v<01K-}i!RSLHt>j5WrLsBMBAw9S*4IWWMqZ_jI zj}&))^T*<93W^{#oH8FGf6Vsor_~Z^SL?@91?p)vQ)m+^X*;;n8z?JdY>JE(_x5d6 znza}-?vC`hE&oi>vj7b`h@K6zeoSe>#hJ;4zvkuc=AH|{nq#CG1lR>KMW=!NC63io=|QTZ9t z8QXg!V%7QD(K*%svDuGp0M+(%n;9|zmwf(P2^D)Y!Uj{dzULszHecjQK$fgtUhqB^DRaE zMeDB-%zub*e5br#RGUQ)5|??hKUNatZ+;=sM1qh z9oPi#4f$}f!WE$i7 zOI&VU9HU~L!CDO#(j=7@uM<^8k<5I!puo8tevol%n<2-?Q6ewdF}FWFY|tKr*;5-1nq5l;ESBVVSl5x8Uu+h?Q-P1 z{fA9i!}iO%KDucFnrukB^;HR7UAUwnH3gLiPI^{k)uXEu=jXA1(e$A2tytG`s}g_b zdJV9F&|UIS1Gw)QJR|$Q;q56V9ldYvc$a2utX}(}d=SPaubxL06IQIU&UHJVnr>bQ zRU;9G=w5#|#{He;f6w+=-bBhaN6=@#CA{ew;6K>g+D@KT`cF;cU&#L=Ceo8DN_hxc*?_vFr(*Z;E1It6wFDrRIs_taeXnh-)895ep6aH}VMR3jY z_zbQjd%n1v^dNml<(YrUw>)~wZei+jK7>1tA%IDN7|6t5J&B5oS3thPhRIreTiN zCRM+DK}Q?BqA*_MUF78X#@#F5hpT$~@(99J3ZoUC@ymZrv}=$wD#Z!um^ ziHy+e@ae`t%uSAqY?SFfB>vk1hgo~c*;@$U3LqG&|CQy&2r3qe999t?k0`nWg_!q= z245+gA%iH*HLNN>UuaFa27eLo)iva_#YITPfKTzB&g6_8;EeDvAsdVFa{(?Sq2>{( zCZv5facJUjaPDqX^6JhV!e4HoxU6WJ6B*R*H84$`4bX1{Gh7~t;jGClVSe<`zQAYw zXtq25o=)ET@g3_ius{Vx+`YggI01X&kW<-_?hkBczG&-+%7iI1E?A~zK>J8d9e`7EPn5lX`p+dvk&faQm}ID9KBLvEwgY*~hS<^E`e zOuLS@KA+!1M$!))rmU_u3>TG}`2MWpsP{oXs8>jJ30cPC+Fq9{wyqqZAeIfafefs0h_q>hv?-i?A^z36 zJ-Yq%zJ`&s))=E%$!ONC#AXQz6RB9^t(>nfKG9kkGAL?5S&U)U!6MED9lddErwP+{ z%uKk&#b+z}H9BlF(rutdz5(W{!=7z>mdl=2SJ66M?H0Y2-6e_n7l#eA_)G^c7aj=- z*v}UeUUkLqBUN1giqT~}`82UZKwUT>Vr4uA%ac*+K`GS(^RA4pNMWG6%X<@HgxK|^ z;JUK=4-wS+AY53@NE0t4m=Be(tx30u<-^Lkmm{?)H{wX2Dhz>tplR>RwR)IuM6|d2 z^x{2w4`V|#FEINfTb?H{FH1uSC#rkPK6|tMrjFgqrng7i%QvbgzS*U1VlLi2ufLQ? zxpPlkcFqm@ze*gU+m0X>ih_t%kWN=q9v_9mI(D7&*_k$GD*D!cnHnq!e{OO0bT}iF z2FpmJbUYm*J@f&qFrJ#2cf*BIGA#Q@E82?ovlwMUnTxy%)T6 zDCF&o%>SBK|6%XZdu_q}O{`u^sF?m=sR*=Ql0wOZX5*uXs8vM=zzor0y!HbJO~}SS zl7XW*^so#Y*@{GU+1fs_On{uY&@c+?mz{=GB@JmKvvC~2Ihq-kIc`ysk#SfGEBmH4 zK6^axrj8-HO~$)!WFGK!$yuY7JW+` zqZ;DM6nz3#jKh;9o~iTFv5AQA6sevQ^wgsJm>)C-*`TC;lU@CyN^d^&-s8d#O}TTi zFBjO!%+1ZPo<2BlXbzkX8&26o-Ah}%H(fkfj2O4FFUF)n0>3(czv?~cB4FIU*u`z- z;2NuW&%_(DwYO(z`s1H^U;N#1l-ncZ(ZDHa)5{mws{g}tv92Cu+oV}~yuOPoOGLut z9P8Q(4sGQadf$Kl1Rlh8u?sm{Z9LMoxFs(8%HdAa6s-6ogeS#s(@4j}`)3HL{3EY4 zzt{Jr@rU;b{?Mkd*1-2yNVr3Pp5KxWjs$uo<2Y--MM_icZwIU#kC0|AYwTj5;9xOa z{Neb4z@kx9jZ(Y$3_@4!&$dRX(x*vu4Vcw7?(Wz|4+R2_7Tw2mgB2@iKkgdwG^t+K3~Rpf!U-SrIn7V z(=O4H%UJr8-bZ!waf7fY=-y#x>KPr_QBFMk(=S8iC33Mje!`e-G8c{bW{M@KU#!jK zL_$9QO&?0sy=r$0u0YRvts*N5{p><@1%Z_~>)F;8zPN9i?wP@?Pc?^gQbXU4<* zXLU#8%TG=AjkL`;=ga^n{lTBn=aiD6{vWO*Lg#E|cU!M>)F4T8E~5mMqR|C_)k7J2 z0Q$70Ap3yZoqVuTj#-jj@n-Lyns&jX*77I2+u`30WohIxyu+UBLNF3J&T&~L0=|K< z4jGo80a!KXqLa~A$CFaiX}<#h9bX8&d5*I8nPv(n(8(n3NRi)43lq5;h4miCSSXoT z9#oL2&N8vIXEgLM95v1AE(Q6hnD#+rxE#?6;+bt~WMpIp63EsPH4}6~OJ^R3G++gy zS`V!S^1q;&k3Uzy>?sCH_ zB{w*rv`pZupbzJA_2Wyd2}esi%$4`$sdP!iNFcr!pA)}Pjt~ZnKi;j;e z9=iD5kmjY{mRWpySO`JA#H#N(5N3d2DoCbx>T{0d?;%%4YR$1HlV3j>d6J>fe5T4du!I zv^pxM6Gn!eRu)gvS6_rJV^-a=DiK?mLyCUCb*W~BQ9Oey)4(Zx?e`ZP|D7mcAKNbj z&VnvJ+r*Yq(dM+r<3=;Z3^Odgx`5;~??+>dO`Vk3Vo2KNeq{L!>i_feAcuWd1bm$T z$$7^I)WNIBi0@mnDjsSscWtqDwyV{COAS*=T#7;VpOR&~rj{H=@3m3tH)ogdm#W8y{y;72$v b1@#4)npm&?dp<3MAfw^``wt`*I+}+*XVR3g^+*+)-ySuv=cP*4I(iSaz+|RuKzRaAH zIgcb)CRg$!Gl`E12&AH^sR95{I|9%E@8u&p0Or5?|1Xjt5ETFbgA4$W#{&S2g|r!K zvmlVB5&%Gv{@$D9U1Xjg47X*Zq(Sej;oXzJiwa-{fLGCA=Xz%g?_Ta*rfL_)-4;$} zt^fcf*}Lz3kK19)t+8WkWoG%#w%-}!yZBHLpHXbz;d>bPcMp6Q9XvZMoUN0m?>qZ% ztiih+QFIXcoXmXR<59hH0OJ3|qY7{~bFzA8A@6?keGZ3aJGP&$E*_rm>ot65*zckO zzyV-<^CSJxvgx!ktU+54H>U^v6wC;mYO%sa;vz3=vJo80fI1;qR8(e0j8(0T)m1Gc zy~hd}?GsuqZZ2a6V`AdRn)~kR>h5!*by>KnIsRYD^IY9=$$H|MX_7l9dtOHEA|-I9XC98FU6W5NC0 z_xxsIx#$fjMD$c&bS5c^`j6*#^MYvfEAQ`q$ur`ip7H?tH$hdV}akioBY zzABa`I$Wth3bOOdDrq7w%nhHQ-JV)IU zIP-^1*9K%wROmMGt|-ckq7DPYCj;RYcLNt2H9Z9cdy=Qh(yrotu%tHE@=B0s;3S`; z{K2%7gSJgB!6rT&kiqj=mlr`Wz-F75hi8|+rQX4n0~Z=MUQ*)3jo=fS6V^ST7`n;d z9&IbC42nLNs#GZulSo@1tpW9E)!GXjc{ZaK^v78i=) zc3ia!a5Hq=ql(Gu&u1G|eNd+$=N99@%;pNgS6mYNx>FLE$Mf8)XiL9E};f zQ_fSj)4Z9SHc2Nmujtp@P6%Z8uZ@ep*Yo8;bm!UL>tlO8^kD$A9;G?zj1G^mt!oG88&-=es%|WtX}EV8uh*&}@O3+<~w zFIS&0UG8?=mPH~VvWH8r>g02=)00fz^8lH&!I<@Z(h z!5`66?3${?kqV17Gagzl-(+-~JLyrava6KOBYLiO|L$R4CmSCO0X~yIDoI*$xe%Ln ztEjBVEvLt;;rjBm*I%DuJO&`gcQhH%QN< znstq+yeyr`3pZ(4?M(Ja*1`^K9|RsWiXecUjx1eyc?bvq7jiBLoc}~RJb8JWWaleq z$ZJm2v!OUOQ_G*9DLWhcaHRCf;u|#_CnrQ9)sc%gR~AEM#3Ovv)=ZTm1Q%a?L1kp# zvOxT#Jb@{VHHrP~dz{tksv(9_(rFo5Xc?ctmkU$ug`3E^!(hNejB)FJaMx5EeO^`N z5&=I!8YAIrL)bFN1-Se3SmUrGUESt#mdPea5r`*qyrS4dB3X?|r0$C!MXfBhB3%OH z1Xm-KV=7A%rB;t72*Vtu@GWN~q}8G((umL2)JXDRMtxa4_4P2<&rXY%S7Ql-r#D)e zwrKrr>CDA%l#8%L6mLl(9;nvz>igRu$HtUAX+7E@x;lQgvvT9dkBw7UyV*6uFQrq( zo$w0Z=9KvL(-Q5P?lz8ke5^g%gQM=|ed}))j4ij%P*XI4_ptgQ7YWv22wI!?maSOX z@QT9^uH|*Ho^vOI-d6s<+IyQ@z7{V3%%M&`x2hRNi#T7xGLV+KaigL%SvnAO8r(JY z3E?|KqFKc<(I2<81#Bk_Fq&G#ovTCfdCpI6Ra2yek717|{i4Eqw8U<7CVL9&3J(q`S#G6+lk5ESSVl~InG0{^+nvY&>cOVJyxa-wodlEr;0M*?| zN3bwZ;j=K>3xvZrhPSkUYGW6^yH!VqMEWZ0@0W@8Io^lp*s##N zabTS3(n_7Vwr5&}USFrI4b(B|nI3j))<|00=*W}zAX26KAo$w5*)Zev`FUPaw2oVk z9FS1jbSd|0K=1H3aU^{43FJ~SMx!oeAyV>k*jZRDoJjAbMxnRYDgFuBb}JsCFxMz9 z_nZI&#MOsdE>-?2fkI%@-Py|g6p1s#Mk)r12+1%y1_#$K{mB%iZM%-jkabhyOskwO z1U|o^z1eUnNt{;=daCxw#_FO%?2NwqU&jNOxp{4&Urf*~d{&3xaCJ!e{g+`GvsqZ2d;C zYVKNZ`;cDopsp=%Zak4hXn~m-=+G!@v}59z41P9R*dunpA;2mDp=tP zPGXja+*{ls}S2@ z-8w#&b17Jx&2$Riv@7?yx_c=)dR`lvo}Ld(`t$KFPS{y=du(LyXm7||U<{cKj;2w1 znC*nzzel8_5@S1#4~Tm4`GysG_7C>qQxEw*L67iri4F&lg`iR5^F5h?XPh+!JR@_l zY~PKSOLYIyq)TIxMceQx+wO3HbX%M%73Hz}XwSkyFbgYw^`E%{kNr)8aT-yP#$EGe z=Q_Q7e1ls$Mak6)66dRxr%e@-a;c)5aF#OBL?eoK`F-)(EeCUw z&C-vV4gu5>j$hyMaxw)FnmH~Nc@5Yi4B!X#vT+S^tT&0H)ef&d4`~z=6!NBO-maon zQ}xK!S#1HErU|yheac_xs4T0DtCSVTh+;^1u(IpqyRaIit4#?N)nE9w%D}R43x&sX z92olgC~#8pu>|-Dc(^}4H;uwrF~;O5elVC&ps`ZIhsXYr4(iISMV4ZoSpOPOI-#Cl z8Y3r1BaS7t0Rm(rr_AH);XxKYPNdSsMXIaeGC{)%Ii1dq85jtohuEqsOzd+m_*p8Vsy55oMc=3(Ohma{8!zD4`(geE=qtarWc-AXoL=Lv z)#7&2$2#(nX)Z+aEt=hr$rhKq0}oVNsni$rjMPBvz1z0C-4jX+Qt996LQX#XmwcK$ zg_ao!sZrfV5QUMmm*l6cw+MpTRAY7N2&CSS~2&; zP{wW#kNMMr8~^*JIGRv<8dVftZB7_kB0&#CYBV)?#YoM&n#z!Gj4?B>CKWxbdD;xc z+k)T62+0@V=lBRJ@09l$KYEEp-9^C`KO$=l7`sq8XwyrS($7btBoe1@)Xd*L^7R- zEi`!c@_-G^-%=nBFBBG4-l;f~@sFYIHIRaQiVHi*J`{o;DSU%XGNa1GflZx!FTkXl zqU`aB9|4N(Qmu_5b*p0tv!Oel^=betyG{Fn`Z$H#hGDwkJR=a_fUF^3z2f;LS1a10 zVH0bIBV8%sGzLp2NN`L!=Fttv@OJQ78K1oUuAhoRABa4uz_76hw#LyuSh;xOte}R} zWXd~flh@OcSm4uG(&hX>dTcVcaHVf|lW0tVUY8H~E!KL`2-fNuf5g+vtN5( zo-Wz@U%=&Ww|^}fj7{=sU&D99f6CIVVFkKA@9qA<%HE6kdU{59d0BBOy8WlU{pjx1 z&>TMe$te%{yI)SO0_%jI*artSYgUVi$f^_d?{TEK$m+T|>iY5OhS2(dTejOET%{M8 z9+`FXQq{RlK?9By)#t2;JK%79aSV~;l}T8{I`*|!n_)%Fi2n%GoV>Ak#kIuL(>2DY z)`vXtE`w@LhO;2){x_BsF68*L8T-%3z}5)~%f>g^m*WHOWQxE5aUdIpWa>cZSW)SN zdH`E@D4~G^>%pS#@K)qf5683b?P7TJJ#If5IZDcH(KJikhhcb2`A$RS6s`_i_XdKn zGk6g>9mPmQK{UdhP9|Y%miUL^kzPwim zN2n?^bbXjB3P~&~4u1wWi!$icza2F~NkiA88#Eca zJ)=qULwn!vC50NNyqIb3$SL zcveOEFMNlwc#&+dV_5h$80SYg1A~flV%+lM%;{so>P?awoWY_?bGoQnnf{tHqMwv`oi7`T)7+^mOdBg!G8P6w~^O zDeISp=kCsnoNtRKs|Ra$YA*TM2ybYt18V_LAqf+!^r9FQQu49iNUq;U4O!}$ngS(fTwV8L2)sya#?%m?8+;88kriYRt$g#b< zmua6(lm7)|O7a?8Sp6pjGzSP&2BoQ)0Wfiao)#K6l@Es#n*yn>YJ+K9f(h5DtdsQm z$yATREVSshE$HGfq#i1ftLG|-6=ZBO3uFlkrauw)^#$>k&qVoVI|6AWmECgM8Ddj~aleS1kG>yPbra@=Fpup6{H_O+ zzy9&42Y2=#Z4+^9&%T94=ci_&(kEyjpr{DepAv`<|0Z<@&CQs3;!H_3aQ3XoYjq-G z475ypJE5BrbgO&U=IXVco2OJ6uR5gT+wwr{?gFcoB5nC_;QH5 z$N)CkM#f~(eVF8D(_%(^4`L>1+H$o9v^L$3TGt~hCRNN@t@7zrQD&HBSCjT7o3;YW z0-d>rY})Y|0fIVndV(wpGc{k~LVw=x&X!Y^mLBWc38aw_lQJ#z;?&Yxk6UZRKMo7r zG#M|Vl!99x#6{`@RirT8PZR@bYOPul;`~bUGa0@mWV0NjMg}l3SX;IbhSo5pN4oDa zbrrK{mv(7paf)a;*c(+3F1uC*`Nr0;@@bo5*fWp$S~e3*LZ;}E?%+w^SbH{8rRfyY zIJjHj3P$snKGK3R$@6Ar8cw)K`lATzEzAX&RN^MaBf;P4Wrxr7plLqWKEnNPNuR(4 z{YMXX^U*%wdOsFnvI+9IBR9q^G^Bl1INE3R%&0pVQU{)v`c?iAVN?e}lDo_3!YrZS zuY?}VF_O?Xf^OfMAXtj<)g|{JHQlM1@-mI(;aMp*`KEUhdz`QWqJuUPDo9(O*ZIHP@B<|p8~NB{~tiw_nS?_KBMTR z6)F~q++HLiDO}qxjLDe{L80FhS@l5@NYcf6`-Ns&M#A=d9|CqI4?+ws4Xifol2EaH zd6!%dMe!-377yVmMmga{DZ8-$wP_y2DE}@r%B(zdWi6 z(5~ozF^+dwwVzFzRqfEjTlx|duYe{|M*EisN`Cz|CpzHw!{p9ny~7{w8E8)6e&%RV4+BUQZGtSi#Zr{zNe zQo7oGxH#;+F2BBUk@~Epjd}fcUSKWS<$$F(;zbZ%CG;^gefUgR2i z+kMX@sKw{C(x#W?tRGr;4lIrh?tdeAwR=P4qfchC;6P;Z*d77|B>nmb&m&k-QNj`s z2Ob)Y(@vqHzQnBJ5=E}kdjJ(7a32O9>;0y|aD!1H@BX@{^o)2y&Q_sZ>q_-w&;gaa zWjhwuGdBu;wIye^u)$&xHw7R0A>cuRm!8pO$E~r80NQxur_g`ZOYk4-&v0?`qc$1J zr#9NIK0m-O}E zs#3#Ulwg)DuN~YzI>b855VPusadV96OuDc44_Dvn>9G=8l`q~H)tL!q#6{|ZpI@{n zzN#k4d)W6L)7*QbwiQw~^qB{ce8w=*!kQ4o5Lc%gHLol@{bqJTm3rQLD(=6Iof5V@ z!M@sp@wjzy9}biTC)p*4q-Qx-S zWA=Q6f;7)+WE>6+XZmEl#jE!Wf#>1?d~c2Fdd=plkQ}>35K$ncoIZBHQ0wiE(k|=Y z7G*GpEQXsEqE*+CLS9@m*%J}U(eS08R9x&=`-l7@7_4GGw?!i+Ge zT{J35dV|wgWYcR?d(RO&XQOTUg{!(2Ob33F8A4>!UcL}AM=p}~BIhZUJV?qD<~g>% zo`hjj@R|*yLZGCt7=Ap%HeiJ@A+onMW=55Zlx`d;UYAH?%vfA>0(9$I&YL3sz zX|yhexH29~kLvP4y$%ot&W8?_+sTy~iL>|vOMBLhgWj#~e9;{Q+ShuR zQ)N-a4vhWn9O#QucuPkm$OGI3A%@C&1gD93h;GOJtIk`yw(m$!E%b1CH6;r85)v#; zZNdu99@0Y9x~?-ln0y_lsKN!dk78au3ll8*slh)Si1HYZ|G4|)E5s`_o%Ch*zK69w zjE(?pBE59K8XI>lJ+BgV)vRtsl-1Cz0dtD~KdkHC1rzdY`T}BO-y|gp9KL-zR(-TpKc7BM1;H7`z`m~ikLxYk z%~Wjo69GXVWG0m@R>SVhh7nR{7)s%tqvx)|vDq+CIH?6W z`S^q~l~E--v+*Ov&+9NJg6E#Qg@rp`y@GoC3k=@q_man-p1{64&#cht z%hx)OUFI`UDCdh`&ra*F&h4j+f0r#<-6!BTAsKcvQNN`7J~&xhm$18;$LEky9PgWd zXWuz3cCW6AN&};#@b!ln{D-clK7Zt3umERenLTgRdlug(lc^&A}H=#wFNmefzICMgHEW7wF7u`*7CmZRW3*RClv$@B6(^;Om* z@(ft*FYlx{@Fe~v1(p<|Y0mVDjqXzIvvJ!YIVa!k&0h`@nLqJj4G#{OU#n#~`|7V! zy>7i+LTW$1WD^Et>TJ$y;U+h?z%SvnpiWVQ{Ah|&3VxBxMfq`6Gq~_)0Nmbs=IA{8 zh+$&Zp04xp8x2waDEOC)=+(wxesJrfUXWi6PNcCc;dn$#whCG$5AkG!ADuu`p`1O* zV^-B9J(bT9Y96S(&vACGEDtT24QAhcGxLfnLoC6L@sBy13DH!E7>Jqyzd5od^ji8e zMHG}LxpsDrFKasb0G|v;2Q-24iuV%7_o+;}^<36oHu*=%^3(fm(;2KcoD(?oX}X|$ z`MKskXE;14dCy~-T^DNmHJJ5hv`gPc`C4$XRetc015$BA3uDS_5T8@2n^e=8M!{zD z8BziGB!lv0KV$Ao-mi~}48cGD{WKXO|CGIF`1E%}!N(A<>mqJ}FRIf)G@qG_QbY*M z+P2N_@9N#Zg|XAn@9Ns(!b3PbJvbC}{$b(j*LZv2bfd-kU*7|Kd$(;7A%912KVo*7 zog>#c!$YILn@X=%uU7o6_4R&P2Y5Z+#2Ux#9=KeR<+T1jMU|?!s@O(IX zY+zs?v$UT}maBz>gM+idoofI<3x|s=>!D=kYU*lPVIFY(1`|$!mr63WmEb~*ACiIt z*xo`@{9mlvWF6c=0Ctq9T|^8aTTBWglf3y@w}r1K29g^#ktG7d{@wbdm_M zAX1K2gpyXT(Qfu z_T5`Hj|a~g#r9ol&e}8fv-)e~-HY}r>aXAXcB;XpCx<|>5!06XF;+Wt@=G292#17{QXO_gr=H{^FcI6fb(KADLMyKLHsR;`mOra)-DGhNX zr&1w6CJ5mGAd9miMhQnpb7x+{I_3DNh0>cV)zlF8>y0q zDKyd-qgG-P>ShhqnnEFH_aIgY)0T#|WC&jh^Y}H4dx#-Z$)7MZf3qAHio2i?n?6~f ziNpt=0~9P)8Wql;wB=I)GIQA;Ny2H*8eDReT7IZTv?{&_ytnCCyZ<$U=6sJBZWaHS zfc44Xkj@SGW%+c4l)EgVvs!oT`tf+Eeb6s58oFA`3e)TU)Tez6lADw7*Dg*iaT{)Q z>uWCiDBsLyR^XXaf7?})-XUUL&1>9;Sr63m}n#R&EM2ZtxXh53JHQ4BEw M-S&OCNdScZ2Ya$P@c;k- diff --git a/app/assets/javascripts/allegations.js.coffee b/app/assets/javascripts/allegations.js.coffee new file mode 100644 index 000000000..3fac8d6f0 --- /dev/null +++ b/app/assets/javascripts/allegations.js.coffee @@ -0,0 +1,16 @@ +App.Allegations = + + toggle_comments: -> + $('.draft-allegation').toggleClass('comments-on'); + + toggle_index: -> + $('.draft-allegation').toggleClass('comments-on'); + + initialize: -> + $('#js-toggle-allegation-comments').on + click: -> + App.Allegations.toggle_comments() + + $('#js-toggle-allegation-index').on + click: -> + App.Allegations.toggle_index() diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index a23c3ed19..7188acecf 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 allegations //= require custom var initialize_modules = function() { @@ -71,6 +72,7 @@ var initialize_modules = function() { App.Banners.initialize(); App.SocialShare.initialize(); App.MarkdownEditor.initialize(); + App.Allegations.initialize(); }; $(function(){ diff --git a/app/assets/stylesheets/icons.scss b/app/assets/stylesheets/icons.scss index a4b0da4f7..015111db0 100644 --- a/app/assets/stylesheets/icons.scss +++ b/app/assets/stylesheets/icons.scss @@ -1,5 +1,4 @@ @charset "UTF-8"; - @font-face { font-family: 'icons'; src: font-url('icons.eot'); @@ -10,7 +9,6 @@ font-weight: normal; font-style: normal; } - [data-icon]:before { font-family: "icons" !important; content: attr(data-icon); @@ -23,7 +21,6 @@ -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } - [class^="icon-"]:before, [class*=" icon-"]:before { font-family: "icons" !important; @@ -36,7 +33,6 @@ -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } - .icon-angle-down:before { content: "\61"; } @@ -163,6 +159,12 @@ .icon-whatsapp:before { content: "\50"; } +.icon-zip:before { + content: "\4f"; +} +.icon-banner:before { + content: "\51"; +} .icon-arrow-down:before { content: "\52"; } @@ -172,6 +174,21 @@ .icon-arrow-right:before { content: "\55"; } +.icon-check-circle:before { + content: "\56"; +} +.icon-arrow-top:before { + content: "\57"; +} .icon-checkmark-circle:before { content: "\59"; } +.icon-minus-square:before { + content: "\58"; +} +.icon-plus-square:before { + content: "\5a"; +} +.icon-expand:before { + content: "\30"; +} diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 2ba1a4685..7e885084c 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -6,6 +6,7 @@ // 04. Debate list // 05. Debate quiz // 06. Legislation draft +// 07. Legislation allegations // // 01. Utils @@ -123,7 +124,7 @@ li { cursor: pointer; - margin-left: 1rem; + margin-left: 0; display: inline-block; margin-bottom: 1rem; @@ -347,3 +348,553 @@ } } } + +// 07. Legislation allegations +// ----------------- +.legislation-allegation { + padding-top: 1rem; + margin-bottom: 2rem; + + .headline { + margin-bottom: 0; + } + + .button-circle { + line-height: 0; + padding: 0.5em; + border-radius: 50%; + } + + .icon-checkmark-circle { + font-size: 1.5rem; + vertical-align: bottom; + color: $text-medium; + margin-right: 0.5rem; + } + + .button-subscribed { + margin-top: 1rem; + border: 1px solid #D1D1D1; + background: #F2F2F2; + + h3 { + display: inline-block; + color: $text; + margin-bottom: 0; + } + + p { + margin-bottom: 0; + font-size: $small-font-size; + } + + &:hover h3 { + color: $text; + } + + @include breakpoint(medium) { + padding: 0.5em 1em; + } + } +} + +.draft-panels { + padding: 2rem 0; + + .draft-chooser { + margin-bottom: 2rem; + + h3 { + vertical-align: top; + display: inline-block; + font-weight: 400; + margin-right: 0.5rem; + } + + span { + margin-left: 0.75rem; + font-style: italic; + font-size: $small-font-size; + color: $text-medium; + vertical-align: top; + + @include breakpoint(medium) { + margin-left: 1rem; + } + } + + .select-box { + position: relative; + + @include breakpoint(medium) { + display: inline-block; + } + + select { + margin-bottom: 0; + display: block; + } + + span { + vertical-align: inherit; + font-style: normal; + + a { + text-decoration: underline; + color: $text-medium + } + } + } + + .button { + margin-top: 1rem; + + @include breakpoint(medium) { + margin-top: 0; + } + } + } + + .draft-allegation { + @include breakpoint(medium) { + display: flex; + padding-left: 0.9375rem; + padding-right: 0.9375rem; + } + + .calc-index { + .draft-panel { + cursor: pointer; + } + + .draft-index-rotated { + display: none; + } + } + + // Panel calcs for desktop + @media screen and (min-width: 40em) { + .calc-index { + transition: all 0.25s; + width: calc(25% - 25px); + } + + .calc-text { + transition: all 0.25s; + width: calc(75% - 25px) + } + + .calc-comments { + transition: all 0.25s; + cursor: pointer; + background: #F2F2F2; + width: 50px; + + .draft-panel { + .panel-title { + display: none; + } + } + } + } + + .border-right { + @include breakpoint(medium) { + border-right: 1px solid $border; + } + } + + .draft-panel { + text-transform: uppercase; + font-weight: 700; + padding: 0.5rem 1rem; + color: #696969; + background: #F2F2F2; + font-size: $small-font-size; + + .icon-comments { + margin-right: 0.25rem; + } + + .icon-banner { + line-height: 0; + color: $text-medium; + vertical-align: sub; + margin-right: 0.25rem; + } + } + + .draft-index { + table { + tbody { + border: none; + + tr { + background: white; + + td { + padding: 0.25rem 1rem; + + .icon-plus-square, + .icon-minus-square { + color: $text-medium; + cursor: pointer; + vertical-align: sub; + } + + a { + color: $brand; + text-decoration: underline; + font-size: $small-font-size; + } + } + + .collapse-all { + padding: 1rem; + + a { + color: $text-medium; + } + + .icon-plus-square, + .icon-minus-square { + color: $text-medium; + } + } + } + + .child_group { + td { + padding: 0 1rem; + + table { + margin-bottom: 0.5rem; + } + } + } + } + } + } + + .draft-text { + position: relative; + padding: 1rem; + + @include breakpoint(medium) { + padding: 2rem 2rem 2rem 3rem; + }; + + h2 { + font-weight: 400; + margin-bottom: 2rem; + margin-top: 2rem; + } + + h3 { + font-weight: 400; + margin-bottom: 1rem; + } + + .anchor::before { + display: none; + content: "#"; + color: $text-medium; + position: absolute; + left: 1.5rem; + } + + a { + color: $text; + + &:hover, + &:active, + &:focus { + text-decoration: none; + + h3 { + color: $text; + } + + .anchor::before { + display: block; + } + } + } + } + + .calc-comments { + position: relative; + + .comment-box { + display: none; + } + + .draft-comments-rotated { + @include breakpoint(medium) { + font-size: $small-font-size; + text-transform: uppercase; + font-weight: 700; + color: #696969; + margin-top: 4rem; + -webkit-transform: rotate(-90deg); + -moz-transform: rotate(-90deg); + -ms-transform: rotate(-90deg); + -o-transform: rotate(-90deg); + filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); + } + } + + } + } + + .comments-on { + .calc-index { + width: 50px; + background: #F2F2F2; + cursor: pointer; + + .panel-title { + display: none; + } + + .draft-index { + display: none; + } + + .draft-index-rotated { + @include breakpoint(medium) { + display: block; + font-size: $small-font-size; + text-transform: uppercase; + font-weight: 700; + color: #696969; + margin-top: 1rem; + -webkit-transform: rotate(-90deg); + -moz-transform: rotate(-90deg); + -ms-transform: rotate(-90deg); + -o-transform: rotate(-90deg); + filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); + + .panel-title { + display: block; + } + } + } + } + + .calc-text { + width: calc(65% - 25px); + border-right: none; + + .show-comments { + width: 105%; + background: #FAFAFA; + padding: 0.25rem 2.5rem 0.25rem 0.25rem; + border: 1px solid $border; + margin-bottom: 1rem; + + p { + margin-bottom: 0; + } + } + + } + + .calc-comments { + background: white; + cursor: auto; + width: calc(35% - 25px); + + .draft-panel { + cursor: pointer; + } + + .draft-comments-rotated { + display: none; + } + + .comment-box { + width: 375px; + padding: 1rem; + background: #F9F9F9; + border: 1px solid $border; + display: block; + position: absolute; + top: 230px; + + .button { + font-size: $small-font-size; + padding: 0.5em 1em; + } + + .publish-comment { + float: right; + } + + .comment-header { + color: #838383; + padding-bottom: 0.5rem; + margin-bottom: 1rem; + border-bottom: 1px solid $border; + + .comment-number { + color: $text; + display: inline-block; + } + + .icon-comment { + margin-right: 0.5rem; + } + + a .icon-expand { + color: #838383; + font-size: $small-font-size; + float: right; + } + } + + .comment-input { + padding-bottom: 4rem; + margin-bottom: 1rem; + margin-top: 1rem; + border-bottom: 1px solid $border; + + .comment-advice { + border-top: 1px solid #D0D0D0; + border-right: 1px solid #D0D0D0; + border-left: 1px solid #D0D0D0; + width: 100%; + padding: 0.5rem; + display: inline-block; + font-size: $small-font-size; + background: #DFDFDF; + + .icon-proposals { + color: #838383; + } + + a { + color: #87A3B9; + text-decoration: underline; + } + } + + textarea { + border-radius: 0; + box-shadow: none; + border-top: none; + border-bottom: 1px solid #D0D0D0; + border-right: 1px solid #D0D0D0; + border-left: 1px solid #D0D0D0; + width: 100%; + height: 200px; + margin-bottom: 0.5rem; + } + + .comment-actions { + .cancel-comment { + color: #87A3B9; + text-decoration: underline; + font-size: $small-font-size; + display: inline-block; + } + } + } + + .comment { + border-bottom: 1px solid $border; + padding-bottom: 0.75rem; + margin-bottom: 1rem; + font-size: $small-font-size; + + .comment-text { + margin-bottom: 0.5rem; + + p { + line-height: 1.5; + font-size: $small-font-size; + + &:last-child { + margin-bottom: 0.5rem; + } + } + } + + .comment-meta { + + .comment-more-info { + display: inline-block; + + .comment-expand { + display: inline-block; + + &::after { + content: "|"; + color: #838383; + } + } + .comment-replies { + display: inline-block; + } + } + + .comment-votes { + color: #838383; + float: right; + display: inline-block; + + .comment-votes-number { + margin-right: 0.25rem; + display: inline-block; + + &::after { + margin-left: 0.25rem; + content: "|"; + } + } + + .icon-like, + .icon-unlike { + cursor: pointer; + color: #C7C7C7; + + &:hover, + &:active, + &:focus { + color: #838383; + } + } + + .icon-like { + margin-right: 0.25rem; + } + } + } + } + } + + .comment-box:nth-child(4) { + top: 838px; + } + + .comment-box:nth-child(5) { + top: 2035px; + } + + .draft-panel { + background: #E5E5E5; + border-left: 1px solid #D4D4D4; + + .panel-title { + display: inline-block; + } + } + + .show-for-medium { + .panel-title { + display: none; + } + } + } + } +} diff --git a/app/views/sandbox/legislation_allegations.html.erb b/app/views/sandbox/legislation_allegations.html.erb new file mode 100644 index 000000000..516b3ba56 --- /dev/null +++ b/app/views/sandbox/legislation_allegations.html.erb @@ -0,0 +1,462 @@ +
    +
    +
    +

    + Licencias urbanísticas, declaraciones responsables y comunicaciones previas +

    +
    + +
    + +
    + + + +
    +
    + +
    + + +
    +
    +
    +

    Estás viendo la revisión

    +
    + + ver resumen de cambios +
    + actualizada el 13 nov 2017 +
    + +
    + +
    + +
    +
    +
    Texto
    +
    +
    +

    TÍTULO PRELIMINAR. Objeto y definiciones

    +

    Artículo 1.

    +
    +

    1.Esta Ordenanza tiene por objeto establecer las condiciones generales que deben cumplir los distintos elementos integrados en el denominado mobiliario urbano, tanto en lo que se refiere a su emplazamiento como a las características propias de dichos elementos.

    +
    +

    2.Para determinar las condiciones relativas a la explotación del mobiliario urbano y a los requisitos que, en su caso, hayan de reunir los respectivos titulares, se estará a la normativa específica establecida para los distintos elementos y a las señaladas en el título que autorice su instalación y funcionamiento.

    +

    3.El mobiliario urbano deberá cumplir los criterios estéticos y de diseño para las distintas zonas de Madrid, aprobados por el titular del Área de Gobierno competente en materia de mobiliario urbano. En aquellos casos en los que la normativa aplicable así lo exija, deberá obtenerse dictamen de la comisión competente en materia de protección del patrimonio histórico y artístico.

    +

    (redacción dada por la Ordenanza de 30 de marzo 2011 de Adaptación al ámbito de la Ciudad de Madrid de las previsiones contenidas en la normativa estatal y autonómica de transposición de la Directiva 2006/123/CE)

    + +

    Artículo 2.

    +

    1. A los efectos de esta Ordenanza se entiende por mobiliario urbano el conjunto de instalaciones o elementos que ocupan un espacio público, y cuya finalidad sea la de atender una necesidad social o prestar un determinado servicio al vecindario.

    +
    +

    2.En el concepto indicado estarán incluidas tanto las instalaciones y elementos de titularidad pública, explotados directamente o por concesión: bancos, bolardos, marquesinas, papeleras, etcétera, como los colocados por particulares, previa autorización municipal, tales como quioscos o puestos fijos, de temporada u ocasionales.

    +
    +

    (apartado 2 del art. 2, redacción dada por la Ordenanza de 30 de marzo 2011 de Adaptación al ámbito de la Ciudad de Madrid de las previsiones contenidas en la normativa estatal y autonómica de transposición de la Directiva 2006/123/ CE)

    + +

    Artículo 3.

    +

    Constituirá criterio general para la implantación de mobiliario urbano la armonización de las finalidades asignadas al mismo con las funciones generales de los espacios públicos, la coordinación de los distintos elementos procurando, cuando fuera posible, la polivalencia de cada uno de ellos para evitar la ocupación intensiva de aquellos espacios y la adecuación, tanto por su emplazamiento como por su diseño, al entono urbano en que se localicen.

    +

    TÍTULO I. DE LOS EMPLAZAMIENTOS DE MOBILIARIO URBANO

    + +

    Artículo 4.

    +

    Cuando se trate de mobiliario urbano de titularidad pública, el número, localización y características de sus emplazamientos estará determinado en el correspondiente acuerdo de implantación o bases de concesión, si fuera municipal, y en el de autorización, si fuese promovido por otras entidades.

    + +

    Artículo 5.

    + +

    Los interesados tendrán reconocidos específicamente, además de los establecidos con carácter general en otras normas, los siguientes derechos: +

    1. Iniciar inmediatamente el ejercicio de la actividad cuando esté sometida a declaración responsable, o una vez obtenida la licencia de primera ocupación y funcionamiento.

    +

    2. Obtener la licencia de actividad y funcionamiento en el plazo establecido en cada caso, sin perjuicio de los efectos establecidos en la legislación aplicable en el ámbito del silencio administrativo.

    +

    3. No presentar documentación que obre en poder de los servicios municipales

    +

    4. Presentar quejas, reclamaciones y sugerencias sobre el funcionamiento de los servicios municipales y de las entidades colaboradoras urbanísticas.

    + +

    Artículo 6.

    +
    +

    1. Durante la realización de las obras o la implantación de la actividad y previamente al acto de comprobación, no se considerarán modificación de la licencia o de la declaración responsable las alteraciones que se hayan producido en el edificio, local o sus instalaciones cuando las mismas se ajusten a la normativa que las regula, salvo que afecten a las condiciones de volumen y forma de los edificios, a la posición y ocupación del edificio en la parcela, a la edificabilidad o superficie del local, al número de locales. Si no se ajustasen se aplicarán los mecanismos de restablecimiento de la legalidad urbanística.

    +
    + +

    Se considerará modificación el cambio de actividad, salvo que la nueva actividad o la inicial con la incorporación de alguna complementaria de ella, tenga la misma consideración y exigencias urbanísticas, ambientales, de seguridad y salubridad. Las variaciones producidas se relacionarán en el acta de comprobación, sin necesidad de tramitar licencia o declaración aparte, quedando legalizadas con la concesión de la licencia de primera ocupación y funcionamiento o el acto de comprobación posterior. Cuando las variaciones se hayan concretado en obras que requieran proyecto de obras de edificación de acuerdo con el artículo 2.2 de la Ley de Ordenación de la Edificación se incorporará el correspondiente proyecto modificado.

    +

    2. Durante el ejercicio de las actividades con licencia o declaración responsable, y con las mismas salvedades indicadas en el punto 1, no se considerará modificación de la licencia o declaración las variaciones que se hayan producido en la actividad, el local o sus instalaciones cuando no alteren las condiciones de repercusión ambiental, seguridad o salubridad por debajo de las exigencias técnicas establecidas para las mismas por la normativa vigente. Tampoco se considerará modificación el cambio de actividad o la incorporación de alguna complementaria a la misma cuando esta tenga la misma consideración y exigencias urbanísticas, ambientales, de seguridad y salubridad que la primera.

    +

    Las obras que han dado lugar a estas variaciones se legalizarán a través de licencia o declaración responsable, dependiendo de la entidad de las mismas. La licencia que se conceda o la declaración se limitarán a recoger el contenido de la modificación, haciendo referencia a la licencia del establecimiento.

    +

    3. En el caso de actividades de espectáculos públicos y recreativas también se considerará modificación de licenciao declaración responsable el cambio de actividad de las indicadas en el Catálogo, así como el incremento del aforo.

    +

    4. Cuando la modificación sea requerida de oficio, el requerimiento indicará las alteraciones existentes, motivando la necesidad de la modificación de la licencia o de la declaración responsable.

    +

    5. Durante la ejecución de las obras autorizadas no precisarán modificación de licencia las variaciones en el número de plazas de aparcamiento que no supongan disminución de la dotación obligatoria de servicio del edificio, sin perjuicio de su constancia documentada en el expediente.

    +
    +
    + +
    +
    +
    + Comentarios +
    +
    + +
    + Comentarios +
    + +
    +
    + +
    34 comentarios
    + +
    +
    +
    +
    +

    Mi comentario va encaminado a que no nos equivoquemos al pensar que esta es una opci...

    +
    +
    +
    + + +
    +
    +
    Sin votos
    + + +
    +
    +
    + +
    +
    +

    Mi comentario va encaminado a que no nos equivoquemos al pensar que esta es una opci...

    +
    +
    +
    + + +
    +
    +
    Sin votos
    + + +
    +
    +
    + +
    +
    +

    Mi comentario va encaminado a que no nos equivoquemos al pensar que esta es una opci...

    +
    +
    +
    + + +
    +
    +
    Sin votos
    + + +
    +
    +
    +
    + +
    + +
    +
    + +
    34 comentarios
    + +
    +
    +
    +
    +

    Mi comentario va encaminado a que no nos equivoquemos al pensar que esta es una opci...

    +
    +
    +
    + + +
    +
    +
    Sin votos
    + + +
    +
    +
    + +
    +
    +

    Mi comentario va encaminado a que no nos equivoquemos al pensar que esta es una opci...

    +
    +
    +
    + + +
    +
    +
    Sin votos
    + + +
    +
    +
    + +
    +
    +

    Mi comentario va encaminado a que no nos equivoquemos al pensar que esta es una opci...

    +
    +
    +
    + + +
    +
    +
    Sin votos
    + + +
    +
    +
    +
    + + + +
    + +
    +
    + +
    34 comentarios
    + +
    +
    +
    +
    +

    En la actualidad, el número de autobuses de la EMT suman 1.900 de los cuales 740 funcionan con gas natural (el 42%), con los 170 que se van a adquirir en 2016, el cómputo sube a 900, lo que significa casi el 50% del total. Con tecnología híbrida existen 23 y se prevé comprar 30 más, lo que supone 53 vehículos, y hay 20 minibuses eléctricos puros. Por último, el 80% de los autobuses de diésel están catalizados a niveles euro4 y euro5 (470), “con lo que podríamos asegurar que el 78% de nuestra flota es verde.

    +

    En la actualidad, el número de autobuses de la EMT suman 1.900 de los cuales 740 funcionan con gas natural (el 42%), con los 170 que se van a adquirir en 2016, el cómputo sube a 900, lo que significa casi el 50% del total. Con tecnología híbrida existen 23 y se prevé comprar 30 más, lo que supone 53 vehículos, y hay 20 minibuses eléctricos puros. Por último, el 80% de los autobuses de diésel están catalizados a niveles euro4 y euro5 (470), “con lo que podríamos asegurar que el 78% de nuestra flota es verde.

    +
    +
    +
    + +
    +
    +
    Sin votos
    + + +
    +
    +
    + +
    +
    +

    Mi comentario va encaminado a que no nos equivoquemos al pensar que esta es una opci...

    +
    +
    +
    + + +
    +
    +
    Sin votos
    + + +
    +
    +
    + +
    +
    +

    Mi comentario va encaminado a que no nos equivoquemos al pensar que esta es una opci...

    +
    +
    +
    + + +
    +
    +
    Sin votos
    + + +
    +
    +
    +
    + +
    + +
    + +
    +
    +
    diff --git a/app/views/sandbox/legislation_debate.html.erb b/app/views/sandbox/legislation_debate.html.erb index adb5feff2..f6852ed45 100644 --- a/app/views/sandbox/legislation_debate.html.erb +++ b/app/views/sandbox/legislation_debate.html.erb @@ -58,7 +58,7 @@
  • - +

    Fase alegaciones

    15 nov 2015 - 15 dic 2016

    diff --git a/app/views/sandbox/legislation_draft.html.erb b/app/views/sandbox/legislation_draft.html.erb index 29db933d3..7361bd54e 100644 --- a/app/views/sandbox/legislation_draft.html.erb +++ b/app/views/sandbox/legislation_draft.html.erb @@ -58,7 +58,7 @@
  • - +

    Fase alegaciones

    15 nov 2015 - 15 dic 2016

    From e8b54f375236a5b40b0fe91101de20a91e27ebd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Mon, 19 Dec 2016 15:36:28 +0100 Subject: [PATCH 017/197] Add legislation allegations draft change page --- .../stylesheets/legislation_process.scss | 49 +++++++++++ .../sandbox/legislation_allegations.html.erb | 2 +- .../legislation_draft_changes.html.erb | 83 +++++++++++++++++++ 3 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 app/views/sandbox/legislation_draft_changes.html.erb diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 7e885084c..0a32790ea 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -7,6 +7,7 @@ // 05. Debate quiz // 06. Legislation draft // 07. Legislation allegations +// 08. Legislation changes // // 01. Utils @@ -898,3 +899,51 @@ } } } + +// 08. Legislation changes +// ----------------- +.legislation-changes { + ul { + list-style: none; + margin-left: 0; + + li { + margin-bottom: 1rem; + + &::before { + margin-right: 0.25rem; + content: "—" + } + + .changes-link { + display: block; + margin-left: 1rem; + font-size: $small-font-size; + + @include breakpoint(medium) { + display: inline-block; + } + + a { + span { + text-decoration: underline; + } + + .icon-external { + text-decoration: none; + color: #999999; + line-height: 0; + vertical-align: sub; + margin-left: 0.5rem; + } + + &:active, + &:focus, + &:hover { + text-decoration: none; + } + } + } + } + } +} diff --git a/app/views/sandbox/legislation_allegations.html.erb b/app/views/sandbox/legislation_allegations.html.erb index 516b3ba56..f18cd2b96 100644 --- a/app/views/sandbox/legislation_allegations.html.erb +++ b/app/views/sandbox/legislation_allegations.html.erb @@ -58,7 +58,7 @@ - ver resumen de cambios + ver resumen de cambios actualizada el 13 nov 2017 diff --git a/app/views/sandbox/legislation_draft_changes.html.erb b/app/views/sandbox/legislation_draft_changes.html.erb new file mode 100644 index 000000000..d01cf7e26 --- /dev/null +++ b/app/views/sandbox/legislation_draft_changes.html.erb @@ -0,0 +1,83 @@ +
    +
    +
    +

    + Licencias urbanísticas, declaraciones responsables y comunicaciones previas +

    +
    + +
    + +
    + + + +
    +
    + +
    + + +
    +
    +
    +

    Estás viendo la revisión

    +
    + +
    + actualizada el 13 nov 2017 +
    + +
    + +
    +
    +

    El 12 nov 2016 se publica un nuevo borrador de la normativa sobre Licencias urbanísticas, que incorpora las aportaciones de la ciudadanía realizadas a través de la web de decide.madrid.es. A continuación se detallan los principales cambios que se han introducido en el texto:

    + +
      +
    • Se detalla el ámbito de actuación ver apartado
    • +
    • Se reescribe la introducción al Capítulo I para incorporar sugerencias ciudadanas ver apartado
    • +
    • Se detalla el ámbito de actuación ver apartado
    • +
    • Se reescribe la introducción al Capítulo I para incorporar sugerencias ciudadanas ver apartado
    • +
    • Se detalla el ámbito de actuación ver apartado
    • +
    • Se reescribe la introducción al Capítulo I para incorporar sugerencias ciudadanas ver apartado
    • +
    +
    +
    +
    From b35659086a499b62874cc7252ab5e0366af0ef68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Mon, 19 Dec 2016 16:48:03 +0100 Subject: [PATCH 018/197] Add legislation draft comments page --- .../stylesheets/legislation_process.scss | 51 ++++++++- .../legislation_draft_comments.html.erb | 108 ++++++++++++++++++ 2 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 app/views/sandbox/legislation_draft_comments.html.erb diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 0a32790ea..e78104101 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -8,6 +8,7 @@ // 06. Legislation draft // 07. Legislation allegations // 08. Legislation changes +// 09. Legislation comments // // 01. Utils @@ -924,7 +925,7 @@ display: inline-block; } - a { + a { span { text-decoration: underline; } @@ -947,3 +948,51 @@ } } } + +// 09. Legislation comments +// ----------------- +.legislation-comments { + + .pull-right { + float: right; + } + + .comment-section { + background: #FAFAFA; + padding: 1rem; + border: 1px solid #DEE0E3; + margin-top: 0.25rem; + margin-bottom: 1rem; + } + + .comment { + margin-bottom: 3rem; + + a { + span { + text-decoration: underline; + } + + .icon-expand, + .icon-comments { + text-decoration: none; + color: #999999; + line-height: 0; + } + + .icon-expand { + margin-left: 0.25rem; + } + + .icon-comments { + margin-right: 0.25rem; + } + + &:active, + &:focus, + &:hover { + text-decoration: none; + } + } + } +} diff --git a/app/views/sandbox/legislation_draft_comments.html.erb b/app/views/sandbox/legislation_draft_comments.html.erb new file mode 100644 index 000000000..984d94841 --- /dev/null +++ b/app/views/sandbox/legislation_draft_comments.html.erb @@ -0,0 +1,108 @@ +
    +
    +
    +

    + Licencias urbanísticas, declaraciones responsables y comunicaciones previas +

    +
    + +
    + +
    + + + +
    +
    + +
    + + +
    +
    +
    +

    Comentarios de la versión

    +
    + +
    + actualizada el 13 nov 2017 +
    + +
    + +
    +
    +
    + Comentarios sobre + Ver en contexto +
    + 1. Esta ordenanza tiene por objeto regular los medios de intervención administrativa para el control de la legalidad de las actuaciones urbanísticas. +
    + 34 comentarios +
    + +
    + Comentarios sobre + Ver en contexto +
    + 1. Esta ordenanza tiene por objeto regular los medios de intervención administrativa para el control de la legalidad de las actuaciones urbanísticas. +
    + 34 comentarios +
    + +
    + Comentarios sobre + Ver en contexto +
    + 1. Esta ordenanza tiene por objeto regular los medios de intervención administrativa para el control de la legalidad de las actuaciones urbanísticas. +
    + 34 comentarios +
    + +
    + Comentarios sobre + Ver en contexto +
    + 1. Esta ordenanza tiene por objeto regular los medios de intervención administrativa para el control de la legalidad de las actuaciones urbanísticas. +
    + 34 comentarios +
    +
    +
    +
    From 3c3a779f9f4bd6f0e2980d419898c3778578d4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Mon, 19 Dec 2016 17:03:59 +0100 Subject: [PATCH 019/197] Add legislation draft comment page --- .../stylesheets/legislation_process.scss | 49 ++++++++++ .../sandbox/legislation_allegations.html.erb | 2 +- .../legislation_draft_changes.html.erb | 2 +- .../legislation_draft_comment.html.erb | 93 +++++++++++++++++++ .../legislation_draft_comments.html.erb | 4 +- 5 files changed, 146 insertions(+), 4 deletions(-) create mode 100644 app/views/sandbox/legislation_draft_comment.html.erb diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index e78104101..b5e980f25 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -9,6 +9,7 @@ // 07. Legislation allegations // 08. Legislation changes // 09. Legislation comments +// 10. Legislation draft comment // // 01. Utils @@ -996,3 +997,51 @@ } } } + +// 10. Legislation draft comment +// ----------------- +.legislation-comment { + + .pull-right { + float: right; + } + + .comment-section { + background: #FAFAFA; + padding: 1rem; + border: 1px solid #DEE0E3; + margin-top: 0.25rem; + margin-bottom: 1rem; + } + + .comment { + margin-bottom: 3rem; + + a { + span { + text-decoration: underline; + } + + .icon-expand, + .icon-comments { + text-decoration: none; + color: #999999; + line-height: 0; + } + + .icon-expand { + margin-left: 0.25rem; + } + + .icon-comments { + margin-right: 0.25rem; + } + + &:active, + &:focus, + &:hover { + text-decoration: none; + } + } + } +} diff --git a/app/views/sandbox/legislation_allegations.html.erb b/app/views/sandbox/legislation_allegations.html.erb index f18cd2b96..d177d50cc 100644 --- a/app/views/sandbox/legislation_allegations.html.erb +++ b/app/views/sandbox/legislation_allegations.html.erb @@ -63,7 +63,7 @@ actualizada el 13 nov 2017
    diff --git a/app/views/sandbox/legislation_draft_changes.html.erb b/app/views/sandbox/legislation_draft_changes.html.erb index d01cf7e26..d871e842d 100644 --- a/app/views/sandbox/legislation_draft_changes.html.erb +++ b/app/views/sandbox/legislation_draft_changes.html.erb @@ -62,7 +62,7 @@ actualizada el 13 nov 2017 diff --git a/app/views/sandbox/legislation_draft_comment.html.erb b/app/views/sandbox/legislation_draft_comment.html.erb new file mode 100644 index 000000000..c0008d324 --- /dev/null +++ b/app/views/sandbox/legislation_draft_comment.html.erb @@ -0,0 +1,93 @@ +
    +
    +
    +

    + Licencias urbanísticas, declaraciones responsables y comunicaciones previas +

    +
    + +
    + +
    + + + +
    +
    + +
    + + +
    +
    +
    +

    Comentarios de la versión

    +
    + +
    + actualizada el 13 nov 2017 +
    + +
    + +
    +
    +
    + Comentarios sobre +
    +
    +
    + 1. Esta ordenanza tiene por objeto regular los medios de intervención administrativa para el control de la legalidad de las actuaciones urbanísticas. +
    + +
    +
    + +
    +
    + COMENTARIOS +
    +
    + +
    +
    +
    +
    diff --git a/app/views/sandbox/legislation_draft_comments.html.erb b/app/views/sandbox/legislation_draft_comments.html.erb index 984d94841..1a334fd12 100644 --- a/app/views/sandbox/legislation_draft_comments.html.erb +++ b/app/views/sandbox/legislation_draft_comments.html.erb @@ -62,7 +62,7 @@ actualizada el 13 nov 2017
    @@ -74,7 +74,7 @@
    1. Esta ordenanza tiene por objeto regular los medios de intervención administrativa para el control de la legalidad de las actuaciones urbanísticas.
    - 34 comentarios + 34 comentarios
    From d25d6c178c2ed84ab1a06d0026efbc7e5af5f8d2 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 20 Dec 2016 18:52:43 +0100 Subject: [PATCH 020/197] Legislation Questions model and basic admin --- Gemfile | 2 + Gemfile.lock | 2 + app/assets/javascripts/application.js | 1 + .../legislation/draft_versions_controller.rb | 1 - .../admin/legislation/questions_controller.rb | 38 ++++++++ app/models/abilities/administrator.rb | 1 + app/models/comment.rb | 2 +- app/models/legislation/process.rb | 1 + app/models/legislation/question.rb | 12 +++ app/models/legislation/question_option.rb | 8 ++ .../legislation/draft_versions/_form.html.erb | 2 +- .../legislation/draft_versions/edit.html.erb | 2 +- .../legislation/draft_versions/new.html.erb | 3 +- .../legislation/processes/_subnav.html.erb | 3 + .../legislation/questions/_form.html.erb | 46 ++++++++++ .../_question_option_fields.html.erb | 6 ++ .../admin/legislation/questions/edit.html.erb | 20 +++++ .../legislation/questions/index.html.erb | 42 +++++++++ .../admin/legislation/questions/new.html.erb | 16 ++++ config/i18n-tasks.yml | 1 + config/locales/admin.en.yml | 27 +++++- config/locales/admin.es.yml | 25 ++++++ config/routes.rb | 1 + ...1220120037_create_legislation_questions.rb | 23 +++++ db/schema.rb | 30 ++++++- spec/factories.rb | 10 +++ .../admin/legislation/questions_spec.rb | 89 +++++++++++++++++++ .../legislation/question_option_spec.rb | 18 ++++ spec/models/legislation/question_spec.rb | 9 ++ 29 files changed, 431 insertions(+), 10 deletions(-) create mode 100644 app/controllers/admin/legislation/questions_controller.rb create mode 100644 app/models/legislation/question.rb create mode 100644 app/models/legislation/question_option.rb create mode 100644 app/views/admin/legislation/questions/_form.html.erb create mode 100644 app/views/admin/legislation/questions/_question_option_fields.html.erb create mode 100644 app/views/admin/legislation/questions/edit.html.erb create mode 100644 app/views/admin/legislation/questions/index.html.erb create mode 100644 app/views/admin/legislation/questions/new.html.erb create mode 100644 db/migrate/20161220120037_create_legislation_questions.rb create mode 100644 spec/features/admin/legislation/questions_spec.rb create mode 100644 spec/models/legislation/question_option_spec.rb create mode 100644 spec/models/legislation/question_spec.rb 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 a23c3ed19..0ec556717 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 custom var initialize_modules = function() { 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..a643c39f5 --- /dev/null +++ b/app/controllers/admin/legislation/questions_controller.rb @@ -0,0 +1,38 @@ +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 + 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/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index 82035042b..3c7adb145 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -48,6 +48,7 @@ module Abilities can [:manage], ::Legislation::Process can [:manage], ::Legislation::DraftVersion + can [:manage], ::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..ac303b37d 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_many :questions, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id' validates :title, presence: true validates :description, presence: true diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb new file mode 100644 index 000000000..d139d75b2 --- /dev/null +++ b/app/models/legislation/question.rb @@ -0,0 +1,12 @@ +class Legislation::Question < ActiveRecord::Base + 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 :answers + 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 +end diff --git a/app/models/legislation/question_option.rb b/app/models/legislation/question_option.rb new file mode 100644 index 000000000..6d3654877 --- /dev/null +++ b/app/models/legislation/question_option.rb @@ -0,0 +1,8 @@ +class Legislation::QuestionOption < ActiveRecord::Base + belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options + + # has_many :answers + + 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 @@
    - <%= link_to admin_legislation_processes_path, class: "back" do %> + <%= link_to admin_legislation_process_path(@process), class: "back" do %> <%= t("admin.legislation.draft_versions.edit.back") %> <% end %> diff --git a/app/views/admin/legislation/draft_versions/new.html.erb b/app/views/admin/legislation/draft_versions/new.html.erb index c1ee1be90..7f7562339 100644 --- a/app/views/admin/legislation/draft_versions/new.html.erb +++ b/app/views/admin/legislation/draft_versions/new.html.erb @@ -1,6 +1,6 @@
    - <%= link_to admin_legislation_processes_path, class: "back" do %> + <%= link_to admin_legislation_process_path(@process), class: "back" do %> <%= t("admin.legislation.draft_versions.new.back") %> <% end %> @@ -12,6 +12,5 @@

    <%= t("admin.legislation.draft_versions.new.title") %>

    <%= render 'form', url: admin_legislation_process_draft_versions_path(@process) %> -
    diff --git a/app/views/admin/legislation/processes/_subnav.html.erb b/app/views/admin/legislation/processes/_subnav.html.erb index a645faef4..97640c4f4 100644 --- a/app/views/admin/legislation/processes/_subnav.html.erb +++ b/app/views/admin/legislation/processes/_subnav.html.erb @@ -1,6 +1,9 @@
    - + <%= render 'sandbox/legislation_process_nav' %>
    @@ -63,7 +38,7 @@ actualizada el 13 nov 2017
    diff --git a/app/views/sandbox/legislation_debate.html.erb b/app/views/sandbox/legislation_debate.html.erb index f6852ed45..d701cd918 100644 --- a/app/views/sandbox/legislation_debate.html.erb +++ b/app/views/sandbox/legislation_debate.html.erb @@ -7,7 +7,7 @@
    -
    - +
    + <%= render 'sandbox/legislation_process_nav' %>
    diff --git a/app/views/sandbox/legislation_draft.html.erb b/app/views/sandbox/legislation_draft.html.erb index 7361bd54e..8bcec8ca2 100644 --- a/app/views/sandbox/legislation_draft.html.erb +++ b/app/views/sandbox/legislation_draft.html.erb @@ -43,33 +43,8 @@
    -
    - +
    + <%= render 'sandbox/legislation_process_nav' %>
    @@ -81,7 +56,7 @@
    - diff --git a/app/views/sandbox/legislation_draft_changes.html.erb b/app/views/sandbox/legislation_draft_changes.html.erb index d871e842d..122d14b74 100644 --- a/app/views/sandbox/legislation_draft_changes.html.erb +++ b/app/views/sandbox/legislation_draft_changes.html.erb @@ -21,32 +21,7 @@
    - + <%= render 'sandbox/legislation_process_nav' %>
    @@ -62,7 +37,7 @@ actualizada el 13 nov 2017
    diff --git a/app/views/sandbox/legislation_draft_comment.html.erb b/app/views/sandbox/legislation_draft_comment.html.erb index c0008d324..0d9191e71 100644 --- a/app/views/sandbox/legislation_draft_comment.html.erb +++ b/app/views/sandbox/legislation_draft_comment.html.erb @@ -21,32 +21,7 @@
    - + <%= render 'sandbox/legislation_process_nav' %>
    @@ -62,7 +37,7 @@ actualizada el 13 nov 2017
    diff --git a/app/views/sandbox/legislation_draft_comments.html.erb b/app/views/sandbox/legislation_draft_comments.html.erb index 1a334fd12..c9ba64555 100644 --- a/app/views/sandbox/legislation_draft_comments.html.erb +++ b/app/views/sandbox/legislation_draft_comments.html.erb @@ -21,32 +21,7 @@
    - + <%= render 'sandbox/legislation_process_nav' %>
    @@ -62,7 +37,7 @@ actualizada el 13 nov 2017
    From 36399277ec5bcc30de4ebb9b45e6bb6e9e941456 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 21 Dec 2016 19:48:58 +0100 Subject: [PATCH 022/197] Legislation Process page --- .../legislation/processes_controller.rb | 20 +++ .../legislation/questions_controller.rb | 7 + app/helpers/legislation_helper.rb | 2 +- app/models/abilities/everyone.rb | 2 +- app/models/legislation/process.rb | 38 ++++- .../legislation/processes/_debate.html.erb | 14 ++ .../processes/_header_full.html.erb | 37 +++++ .../legislation/processes/_key_dates.html.erb | 29 ++++ .../processes/_key_dates_svg.html.erb | 5 + .../processes/_phase_allegations.html.erb | 9 + .../_phase_draft_publication.html.erb | 9 + .../_phase_final_version_publication.html.erb | 5 + .../processes/_phase_not_open.html.erb | 13 ++ .../legislation/processes/_process.html.erb | 10 +- .../legislation/processes/phase.html.erb | 15 ++ app/views/legislation/processes/show.html.erb | 19 ++- .../legislation/questions/_question.html.erb | 11 ++ app/views/legislation/questions/show.html.erb | 3 + config/locales/en.yml | 36 +++- config/locales/es.yml | 36 +++- config/routes.rb | 6 + spec/features/legislation/processes_spec.rb | 20 +++ spec/models/legislation/process_spec.rb | 154 +++++++++++++++++- 23 files changed, 469 insertions(+), 31 deletions(-) create mode 100644 app/controllers/legislation/questions_controller.rb create mode 100644 app/views/legislation/processes/_debate.html.erb create mode 100644 app/views/legislation/processes/_header_full.html.erb create mode 100644 app/views/legislation/processes/_key_dates.html.erb create mode 100644 app/views/legislation/processes/_key_dates_svg.html.erb create mode 100644 app/views/legislation/processes/_phase_allegations.html.erb create mode 100644 app/views/legislation/processes/_phase_draft_publication.html.erb create mode 100644 app/views/legislation/processes/_phase_final_version_publication.html.erb create mode 100644 app/views/legislation/processes/_phase_not_open.html.erb create mode 100644 app/views/legislation/processes/phase.html.erb create mode 100644 app/views/legislation/questions/_question.html.erb create mode 100644 app/views/legislation/questions/show.html.erb 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) %>

    +
    +
    + <%= link_to t('.comments', count: question.comments.count), 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 From 294d216ac1ab66adf402650d1758a0260a08e13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Thu, 22 Dec 2016 12:04:55 +0100 Subject: [PATCH 023/197] Responsive fixes --- app/assets/stylesheets/legislation_process.scss | 15 ++++++++------- .../sandbox/legislation_allegations.html.erb | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index cf2f40f6d..f837b3921 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -122,25 +122,22 @@ svg { position: absolute; - top: 0.75rem; + top: 1.5rem; left: 0; @include breakpoint(medium) { transform: rotate(-8deg); + top: 0.75rem; } } ul { - padding-top: 3rem; + padding-top: 4rem; list-style: none; margin-left: 0; padding-left: 0; border-bottom: 1px solid $medium-gray; - @include breakpoint(medium) { - padding-top: 4rem; - } - li { cursor: pointer; margin-left: 0; @@ -621,7 +618,11 @@ content: "#"; color: $text-medium; position: absolute; - left: 1.5rem; + left: 0; + + @include breakpoint(medium) { + left: 1.5rem; + } } a { diff --git a/app/views/sandbox/legislation_allegations.html.erb b/app/views/sandbox/legislation_allegations.html.erb index f7d9e7ca3..3436f0ed2 100644 --- a/app/views/sandbox/legislation_allegations.html.erb +++ b/app/views/sandbox/legislation_allegations.html.erb @@ -195,7 +195,7 @@
    34 comentarios
    - +
    From 898a10b0a59bc2d2a796ff54534837b5b15deda8 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 22 Dec 2016 13:09:17 +0100 Subject: [PATCH 024/197] Fix abilities to see the draft publication section --- app/models/abilities/everyone.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 9569ebf53..d8e6d63ef 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, :draft_version_publication, :allegations, :final_version_publication], Legislation::Process + can [:read, :draft_publication, :allegations, :final_version_publication], Legislation::Process can [:read], Legislation::DraftVersion end end From 959b36caa8b91029936bd270cf43e6ecc7c544b8 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 22 Dec 2016 13:21:44 +0100 Subject: [PATCH 025/197] Add more specs for process page (phases) --- spec/features/legislation/processes_spec.rb | 76 ++++++++++++++++++--- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index c4241698e..49e2f67ea 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -36,23 +36,77 @@ feature 'Legislation' do 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) + context 'process page' do + context 'debate phase' do + scenario 'not open' do + process = create(:legislation_process, debate_start_date: Date.current + 1.day, debate_end_date: Date.current + 2.days) - visit legislation_process_path(process) + visit legislation_process_path(process) - expect(page).to have_content("This phase is not open yet") + expect(page).to have_content("This phase is not open yet") + end + + scenario 'open' do + process = create(:legislation_process, 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 - 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) + context 'draft publication phase' do + scenario 'not open' do + process = create(:legislation_process, draft_publication_date: Date.current + 1.day) - visit legislation_process_path(process) + visit legislation_process_draft_publication_path(process) - expect(page).to have_content("Participate in the debate") + expect(page).to have_content("This phase is not open yet") + end + + scenario 'open' do + process = create(:legislation_process, draft_publication_date: Date.current) + + visit legislation_process_draft_publication_path(process) + + expect(page).to have_content("There are no drafts published") + end + end + + context 'allegations phase' do + scenario 'not open' do + process = create(:legislation_process, allegations_start_date: Date.current + 1.day, allegations_end_date: Date.current + 2.days) + + visit legislation_process_allegations_path(process) + + expect(page).to have_content("This phase is not open yet") + end + + scenario 'open' do + process = create(:legislation_process, allegations_start_date: Date.current - 1.day, allegations_end_date: Date.current + 2.days) + + visit legislation_process_allegations_path(process) + + expect(page).to have_content("There are no drafts published") + end + end + + context 'final version publication phase' do + scenario 'not open' do + process = create(:legislation_process, final_publication_date: Date.current + 1.day) + + visit legislation_process_final_version_publication_path(process) + + expect(page).to have_content("This phase is not open yet") + end + + scenario 'open' do + process = create(:legislation_process, final_publication_date: Date.current) + + visit legislation_process_final_version_publication_path(process) + + expect(page).to have_content("Results have not been published yet") + end end end end From 368430d914f3a18ddce0627d08731456d5a0bc9b Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 22 Dec 2016 12:59:58 +0100 Subject: [PATCH 026/197] Legislation Question page --- app/models/abilities/everyone.rb | 1 + app/models/legislation/question.rb | 4 ++ app/views/legislation/questions/show.html.erb | 55 ++++++++++++++++++- config/locales/en.yml | 5 ++ config/locales/es.yml | 5 ++ spec/features/legislation/debate_spec.rb | 36 ++++++++++++ spec/features/legislation/processes_spec.rb | 2 +- 7 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 spec/features/legislation/debate_spec.rb diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index d8e6d63ef..e22bcb7e0 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -13,6 +13,7 @@ module Abilities can :new, DirectMessage 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/legislation/question.rb b/app/models/legislation/question.rb index d139d75b2..1af6f8b42 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -9,4 +9,8 @@ class Legislation::Question < ActiveRecord::Base validates :process, presence: true validates :title, presence: true + + def next_question_id + @next_question_id ||= process.questions.where("id > ?", id).limit(1).pluck(:id).first + end end diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index ea3563c67..6686334a2 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -1,3 +1,56 @@ +
    +
    +
    +
    +

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

    +

    <%= link_to @process.title, @process %>

    +
    +
    +
    + <% if @question.next_question_id %> + <%= link_to legislation_process_question_path(@process, @question.next_question_id), class: "quiz-next-link" do %> + <%= content_tag :div, class: "quiz-next" do %> + <%= t('.next_question') %> +
    +
    +
    +
    +

    <%= @question.title %>

    +
    +
    + <% @question.question_options.each do |question_option| %> + + <% end %> +
    +
    +
    + +
    +
    + + +
    +
    -

    <%= @question.title %>

    +
    + <%= t('.comments') %> +
    diff --git a/config/locales/en.yml b/config/locales/en.yml index 6e71969ce..251351d44 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -266,6 +266,11 @@ en: one: "%{count} comment" other: "%{count} comments" debate: Debate + show: + comments: COMMENTS + next_question: Next question + share: Share + title: Collaborative legislation process locale: English notifications: index: diff --git a/config/locales/es.yml b/config/locales/es.yml index 41a3361cf..8a16eeb56 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -266,6 +266,11 @@ es: one: "%{count} comentario" other: "%{count} comentarios" debate: Debate + show: + comments: COMENTARIOS + next_question: Siguiente pregunta + share: Compartir + title: Proceso de legislación colaborativa locale: Español notifications: index: diff --git a/spec/features/legislation/debate_spec.rb b/spec/features/legislation/debate_spec.rb new file mode 100644 index 000000000..daba0177d --- /dev/null +++ b/spec/features/legislation/debate_spec.rb @@ -0,0 +1,36 @@ +require 'rails_helper' + +feature 'Legislation' do + + context 'process debate page' do + scenario 'shows question list' do + process = create(:legislation_process, debate_start_date: Date.current - 1.day, debate_end_date: Date.current + 2.days) + create(:legislation_question, process: process, title: "Question 1") + create(:legislation_question, process: process, title: "Question 2") + create(:legislation_question, process: process, title: "Question 3") + + visit legislation_process_path(process) + + expect(page).to have_content("Participate in the debate") + + expect(page).to have_content("Question 1") + expect(page).to have_content("Question 2") + expect(page).to have_content("Question 3") + + click_link "Question 1" + + expect(page).to have_content("Question 1") + expect(page).to have_content("Next question") + + click_link "Next question" + + expect(page).to have_content("Question 2") + expect(page).to have_content("Next question") + + click_link "Next question" + + expect(page).to have_content("Question 3") + expect(page).to_not have_content("Next question") + end + end +end diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index 49e2f67ea..818717757 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' feature 'Legislation' do - context 'processes#index' do + context 'processes home page' do scenario 'Processes can be listed' do processes = create_list(:legislation_process, 3) From 59d68264cf4846ace377693a2670bf741db3cc3d Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 22 Dec 2016 16:22:43 +0100 Subject: [PATCH 027/197] Force order in query --- app/models/legislation/question.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index 1af6f8b42..c7c123437 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -11,6 +11,6 @@ class Legislation::Question < ActiveRecord::Base validates :title, presence: true def next_question_id - @next_question_id ||= process.questions.where("id > ?", id).limit(1).pluck(:id).first + @next_question_id ||= process.questions.where("id > ?", id).order('id ASC').limit(1).pluck(:id).first end end From 8065b4d2f72318107aae60f7df81bb86abee2a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Thu, 22 Dec 2016 16:33:26 +0100 Subject: [PATCH 028/197] New approach for allegation toggle (needs review) --- app/assets/javascripts/allegations.js.coffee | 21 +++++++++++-------- .../sandbox/legislation_allegations.html.erb | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/allegations.js.coffee b/app/assets/javascripts/allegations.js.coffee index 3fac8d6f0..34b51e798 100644 --- a/app/assets/javascripts/allegations.js.coffee +++ b/app/assets/javascripts/allegations.js.coffee @@ -3,14 +3,17 @@ App.Allegations = toggle_comments: -> $('.draft-allegation').toggleClass('comments-on'); - toggle_index: -> - $('.draft-allegation').toggleClass('comments-on'); - initialize: -> - $('#js-toggle-allegation-comments').on - click: -> - App.Allegations.toggle_comments() + $('.js-toggle-allegations .draft-panel').on + click: -> + console.log("panel") + App.Allegations.toggle_comments() - $('#js-toggle-allegation-index').on - click: -> - App.Allegations.toggle_index() + $('.js-toggle-allegations').on + click: -> + console.log("column") + if $('.draft-allegation').hasClass('comments-on') + console.log("comments-on") + return false + else + App.Allegations.toggle_comments() diff --git a/app/views/sandbox/legislation_allegations.html.erb b/app/views/sandbox/legislation_allegations.html.erb index 3436f0ed2..07e3ce359 100644 --- a/app/views/sandbox/legislation_allegations.html.erb +++ b/app/views/sandbox/legislation_allegations.html.erb @@ -43,7 +43,7 @@
    -
    +
    Índice @@ -180,7 +180,7 @@
    -
    +
    Comentarios From f68b6a2f329a63a9a087addc9944fbdac3b6ef1b Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 22 Dec 2016 17:27:59 +0100 Subject: [PATCH 029/197] Question title for page and share links --- app/views/legislation/questions/show.html.erb | 10 ++++++---- config/locales/en.yml | 3 +++ config/locales/es.yml | 3 +++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index 6686334a2..3b921e207 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -1,3 +1,5 @@ +<% provide :title do %><%= @question.title %><% end %> +
    @@ -37,10 +39,10 @@

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

    diff --git a/config/locales/en.yml b/config/locales/en.yml index 7538b308c..66c95a3d1 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -271,6 +271,9 @@ en: comments: COMMENTS next_question: Next question share: Share + share_twitter: Share on Twitter + share_facebook: Share on Facebook + share_gplus: Share on Google+ title: Collaborative legislation process locale: English notifications: diff --git a/config/locales/es.yml b/config/locales/es.yml index a24fa253b..09633a60d 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -271,6 +271,9 @@ es: comments: COMENTARIOS next_question: Siguiente pregunta share: Compartir + share_twitter: Compartir en Twitter + share_facebook: Compartir en Facebook + share_gplus: Compartir en Google+ title: Proceso de legislación colaborativa locale: Español notifications: From 243429aa418ddcd9a7e42dfe2f7a8db9439a083a Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 22 Dec 2016 17:34:47 +0100 Subject: [PATCH 030/197] Set title for process and draft versions pages --- app/views/legislation/draft_versions/changes.html.erb | 2 ++ app/views/legislation/draft_versions/show.html.erb | 2 ++ app/views/legislation/processes/phase.html.erb | 2 ++ app/views/legislation/processes/show.html.erb | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + 6 files changed, 9 insertions(+) diff --git a/app/views/legislation/draft_versions/changes.html.erb b/app/views/legislation/draft_versions/changes.html.erb index 80d902720..8b97de7f4 100644 --- a/app/views/legislation/draft_versions/changes.html.erb +++ b/app/views/legislation/draft_versions/changes.html.erb @@ -1,3 +1,5 @@ +<% provide :title do %><%= "#{@draft_version.title} - #{t('.title')} - #{@process.title}" %><% end %> +

    <%= @process.title %>

    <%= @draft_version.title %>

    diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index 3a1ec15cf..0c220c03b 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -1,3 +1,5 @@ +<% provide :title do %><%= "#{@draft_version.title} - #{@process.title}" %><% end %> +

    <%= link_to @process.title, @process %>

    <%= @draft_version.title %>

    diff --git a/app/views/legislation/processes/phase.html.erb b/app/views/legislation/processes/phase.html.erb index 5ac6ceb85..04ee25523 100644 --- a/app/views/legislation/processes/phase.html.erb +++ b/app/views/legislation/processes/phase.html.erb @@ -1,3 +1,5 @@ +<% provide :title do %><%= @process.title %><% end %> + <%= render 'legislation/processes/header_full', process: @process %>
    diff --git a/app/views/legislation/processes/show.html.erb b/app/views/legislation/processes/show.html.erb index 8e31431e0..471410b58 100644 --- a/app/views/legislation/processes/show.html.erb +++ b/app/views/legislation/processes/show.html.erb @@ -1,3 +1,4 @@ +<% provide :title do %><%= @process.title %><% end %> <%= render 'header_full', process: @process %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 66c95a3d1..da1a1f6ea 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -224,6 +224,7 @@ en: legislation: draft_versions: changes: + title: Changes see_text: See text show: see_changes: See changes diff --git a/config/locales/es.yml b/config/locales/es.yml index 09633a60d..bd5c748e0 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -224,6 +224,7 @@ es: legislation: draft_versions: changes: + title: Cambios see_text: Ver texto show: see_changes: Ver cambios From 0f6ece0c3095492cef30383d4c5530d9c57779f9 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 22 Dec 2016 17:38:02 +0100 Subject: [PATCH 031/197] Toggle only works on column when the section is not visible --- app/assets/javascripts/allegations.js.coffee | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/allegations.js.coffee b/app/assets/javascripts/allegations.js.coffee index 34b51e798..d57fa30ed 100644 --- a/app/assets/javascripts/allegations.js.coffee +++ b/app/assets/javascripts/allegations.js.coffee @@ -1,19 +1,17 @@ App.Allegations = - + toggle_comments: -> $('.draft-allegation').toggleClass('comments-on'); - + initialize: -> $('.js-toggle-allegations .draft-panel').on - click: -> - console.log("panel") + click: (e) -> + e.preventDefault(); + e.stopPropagation(); App.Allegations.toggle_comments() - + $('.js-toggle-allegations').on - click: -> - console.log("column") - if $('.draft-allegation').hasClass('comments-on') - console.log("comments-on") - return false - else + click: (e) -> + # Toggle comments when the section title is visible + if $(this).find('.draft-panel .panel-title:visible').length == 0 App.Allegations.toggle_comments() From 55eb03531c015043ef4e4be48619d61f75c36c40 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 22 Dec 2016 23:00:37 +0100 Subject: [PATCH 032/197] Comments in legislation question page --- .../admin/legislation/questions_controller.rb | 1 + .../legislation/questions_controller.rb | 5 ++++ app/models/legislation/question.rb | 5 +++- app/models/legislation/question_option.rb | 5 ++-- app/views/comments/_comment.html.erb | 2 +- .../legislation/questions/_comments.html.erb | 29 +++++++++++++++++++ app/views/legislation/questions/show.html.erb | 8 +---- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- ...comments_count_to_legislation_questions.rb | 5 ++++ ...927_add_author_to_legislation_questions.rb | 5 ++++ db/schema.rb | 4 ++- 12 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 app/views/legislation/questions/_comments.html.erb create mode 100644 db/migrate/20161222171716_add_comments_count_to_legislation_questions.rb create mode 100644 db/migrate/20161222180927_add_author_to_legislation_questions.rb diff --git a/app/controllers/admin/legislation/questions_controller.rb b/app/controllers/admin/legislation/questions_controller.rb index a643c39f5..9a1c3eb5b 100644 --- a/app/controllers/admin/legislation/questions_controller.rb +++ b/app/controllers/admin/legislation/questions_controller.rb @@ -7,6 +7,7 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll end def create + @question.author = current_user if @question.save redirect_to admin_legislation_process_questions_path else diff --git a/app/controllers/legislation/questions_controller.rb b/app/controllers/legislation/questions_controller.rb index 01653fca3..7114c98cb 100644 --- a/app/controllers/legislation/questions_controller.rb +++ b/app/controllers/legislation/questions_controller.rb @@ -2,6 +2,11 @@ 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/models/legislation/question.rb b/app/models/legislation/question.rb index c7c123437..2b779d1f8 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -1,8 +1,11 @@ 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 :answers has_many :comments, as: :commentable accepts_nested_attributes_for :question_options, :reject_if => proc { |attributes| attributes[:value].blank? }, allow_destroy: true diff --git a/app/models/legislation/question_option.rb b/app/models/legislation/question_option.rb index 6d3654877..93bc20320 100644 --- a/app/models/legislation/question_option.rb +++ b/app/models/legislation/question_option.rb @@ -1,7 +1,8 @@ class Legislation::QuestionOption < ActiveRecord::Base - belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases - # has_many :answers + 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 } diff --git a/app/views/comments/_comment.html.erb b/app/views/comments/_comment.html.erb index 549b62862..deb6fa58d 100644 --- a/app/views/comments/_comment.html.erb +++ b/app/views/comments/_comment.html.erb @@ -1,6 +1,6 @@ <% cache [locale_and_user_status(comment), comment, commentable_cache_key(comment.commentable), comment.author, (@comment_flags[comment.id] if @comment_flags)] do %>
    -
      +
        <% if comment.hidden? || comment.user.hidden? %> <% if comment.children.size > 0 %> diff --git a/app/views/legislation/questions/_comments.html.erb b/app/views/legislation/questions/_comments.html.erb new file mode 100644 index 000000000..c7b9591e8 --- /dev/null +++ b/app/views/legislation/questions/_comments.html.erb @@ -0,0 +1,29 @@ +<% cache [locale_and_user_status, @current_order, commentable_cache_key(@question), @comment_tree.comments, @comment_tree.comment_authors, @question.comments_count, @comment_flags] do %> +
        +
        +

        + <%= t("legislation.questions.show.comments") %> + (<%= @question.comments_count %>) +

        + + <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> + + <% if user_signed_in? %> + <%= render 'comments/form', {commentable: @question, parent_id: nil, toggeable: false} %> + <% else %> +
        + +
        + <%= t("debates.show.login_to_comment", + signin: link_to(t("votes.signin"), new_user_session_path), + signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %> +
        + <% end %> + + <% @comment_tree.root_comments.each do |comment| %> + <%= render 'comments/comment', comment: comment %> + <% end %> + <%= paginate @comment_tree.root_comments %> +
        +
        +<% end %> diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index 3b921e207..d22289d28 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -49,10 +49,4 @@
    -
    - -
    -
    - <%= t('.comments') %> -
    -
    +<%= render 'comments' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index da1a1f6ea..cf076656f 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -269,7 +269,7 @@ en: other: "%{count} comments" debate: Debate show: - comments: COMMENTS + comments: Comments next_question: Next question share: Share share_twitter: Share on Twitter diff --git a/config/locales/es.yml b/config/locales/es.yml index bd5c748e0..0238645b6 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -269,7 +269,7 @@ es: other: "%{count} comentarios" debate: Debate show: - comments: COMENTARIOS + comments: Comentarios next_question: Siguiente pregunta share: Compartir share_twitter: Compartir en Twitter diff --git a/db/migrate/20161222171716_add_comments_count_to_legislation_questions.rb b/db/migrate/20161222171716_add_comments_count_to_legislation_questions.rb new file mode 100644 index 000000000..e71a8879b --- /dev/null +++ b/db/migrate/20161222171716_add_comments_count_to_legislation_questions.rb @@ -0,0 +1,5 @@ +class AddCommentsCountToLegislationQuestions < ActiveRecord::Migration + def change + add_column :legislation_questions, :comments_count, :integer, default: 0 + end +end diff --git a/db/migrate/20161222180927_add_author_to_legislation_questions.rb b/db/migrate/20161222180927_add_author_to_legislation_questions.rb new file mode 100644 index 000000000..a06190045 --- /dev/null +++ b/db/migrate/20161222180927_add_author_to_legislation_questions.rb @@ -0,0 +1,5 @@ +class AddAuthorToLegislationQuestions < ActiveRecord::Migration + def change + add_column :legislation_questions, :author_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index f892724a5..96001434c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161220120037) do +ActiveRecord::Schema.define(version: 20161222180927) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -293,6 +293,8 @@ ActiveRecord::Schema.define(version: 20161220120037) do t.datetime "hidden_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "comments_count", default: 0 + t.integer "author_id" end add_index "legislation_questions", ["hidden_at"], name: "index_legislation_questions_on_hidden_at", using: :btree From de5df61359dd09e3ffe5943b81d48208a2416f05 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Fri, 23 Dec 2016 15:40:52 +0100 Subject: [PATCH 033/197] Legislation question comments spec --- app/helpers/legislation_helper.rb | 4 + app/models/abilities/administrator.rb | 3 +- app/models/abilities/moderator.rb | 2 +- spec/factories.rb | 1 + .../comments/legislation_questions_spec.rb | 509 ++++++++++++++++++ spec/models/abilities/administrator_spec.rb | 4 + spec/models/abilities/moderator_spec.rb | 3 + 7 files changed, 524 insertions(+), 2 deletions(-) create mode 100644 spec/features/comments/legislation_questions_spec.rb diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb index 6b5fcbe87..59a13f9a8 100644 --- a/app/helpers/legislation_helper.rb +++ b/app/helpers/legislation_helper.rb @@ -2,4 +2,8 @@ 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 3c7adb145..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 @@ -49,6 +49,7 @@ 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/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/spec/factories.rb b/spec/factories.rb index 67cfd6add..98730380f 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -393,6 +393,7 @@ FactoryGirl.define do factory :legislation_question, class: 'Legislation::Question' do process factory: :legislation_process title "Question text" + author factory: :user end factory :legislation_question_option, class: 'Legislation::QuestionOption' do diff --git a/spec/features/comments/legislation_questions_spec.rb b/spec/features/comments/legislation_questions_spec.rb new file mode 100644 index 000000000..c8f929b9e --- /dev/null +++ b/spec/features/comments/legislation_questions_spec.rb @@ -0,0 +1,509 @@ +require 'rails_helper' +include ActionView::Helpers::DateHelper + +feature 'Commenting legislation questions' do + let(:user) { create :user } + let(:legislation_question) { create :legislation_question } + + scenario 'Index' do + 3.times { create(:comment, commentable: legislation_question) } + + visit legislation_process_question_path(legislation_question.process, legislation_question) + + expect(page).to have_css('.comment', count: 3) + + comment = Comment.last + within first('.comment') do + expect(page).to have_content comment.user.name + expect(page).to have_content I18n.l(comment.created_at, format: :datetime) + expect(page).to have_content comment.body + end + end + + scenario 'Show' do + parent_comment = create(:comment, commentable: legislation_question) + first_child = create(:comment, commentable: legislation_question, parent: parent_comment) + second_child = create(:comment, commentable: legislation_question, parent: parent_comment) + + visit comment_path(parent_comment) + + expect(page).to have_css(".comment", count: 3) + expect(page).to have_content parent_comment.body + expect(page).to have_content first_child.body + expect(page).to have_content second_child.body + + expect(page).to have_link "Go back to #{legislation_question.title}", href: legislation_process_question_path(legislation_question.process, legislation_question) + end + + scenario 'Collapsable comments', :js do + parent_comment = create(:comment, body: "Main comment", commentable: legislation_question) + child_comment = create(:comment, body: "First subcomment", commentable: legislation_question, parent: parent_comment) + grandchild_comment = create(:comment, body: "Last subcomment", commentable: legislation_question, parent: child_comment) + + visit legislation_process_question_path(legislation_question.process, legislation_question) + + expect(page).to have_css('.comment', count: 3) + + find("#comment_#{child_comment.id}_children_arrow").trigger('click') + + expect(page).to have_css('.comment', count: 2) + expect(page).to_not have_content grandchild_comment.body + + find("#comment_#{child_comment.id}_children_arrow").trigger('click') + + expect(page).to have_css('.comment', count: 3) + expect(page).to have_content grandchild_comment.body + + find("#comment_#{parent_comment.id}_children_arrow").trigger('click') + + expect(page).to have_css('.comment', count: 1) + expect(page).to_not have_content child_comment.body + expect(page).to_not have_content grandchild_comment.body + end + + scenario 'Comment order' do + c1 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.current - 2) + c2 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.current - 1) + c3 = create(:comment, :with_confidence_score, commentable: legislation_question, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current) + + visit legislation_process_question_path(legislation_question.process, legislation_question, order: :most_voted) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) + + visit legislation_process_question_path(legislation_question.process, legislation_question, order: :newest) + + expect(c3.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c1.body) + + visit legislation_process_question_path(legislation_question.process, legislation_question, order: :oldest) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) + end + + scenario 'Creation date works differently in roots and in child comments, even when sorting by confidence_score' do + old_root = create(:comment, commentable: legislation_question, created_at: Time.current - 10) + new_root = create(:comment, commentable: legislation_question, created_at: Time.current) + old_child = create(:comment, commentable: legislation_question, parent_id: new_root.id, created_at: Time.current - 10) + new_child = create(:comment, commentable: legislation_question, parent_id: new_root.id, created_at: Time.current) + + visit legislation_process_question_path(legislation_question.process, legislation_question, order: :most_voted) + + expect(new_root.body).to appear_before(old_root.body) + expect(old_child.body).to appear_before(new_child.body) + + visit legislation_process_question_path(legislation_question.process, legislation_question, order: :newest) + + expect(new_root.body).to appear_before(old_root.body) + expect(new_child.body).to appear_before(old_child.body) + + visit legislation_process_question_path(legislation_question.process, legislation_question, order: :oldest) + + expect(old_root.body).to appear_before(new_root.body) + expect(old_child.body).to appear_before(new_child.body) + end + + scenario 'Turns links into html links' do + create :comment, commentable: legislation_question, body: 'Built with http://rubyonrails.org/' + + visit legislation_process_question_path(legislation_question.process, legislation_question) + + within first('.comment') do + expect(page).to have_content 'Built with http://rubyonrails.org/' + expect(page).to have_link('http://rubyonrails.org/', href: 'http://rubyonrails.org/') + expect(find_link('http://rubyonrails.org/')[:rel]).to eq('nofollow') + expect(find_link('http://rubyonrails.org/')[:target]).to eq('_blank') + end + end + + scenario 'Sanitizes comment body for security' do + create :comment, commentable: legislation_question, body: " click me http://www.url.com" + + visit legislation_process_question_path(legislation_question.process, legislation_question) + + within first('.comment') do + expect(page).to have_content "click me http://www.url.com" + expect(page).to have_link('http://www.url.com', href: 'http://www.url.com') + expect(page).not_to have_link('click me') + end + end + + scenario 'Paginated comments' do + per_page = 10 + (per_page + 2).times { create(:comment, commentable: legislation_question)} + + visit legislation_process_question_path(legislation_question.process, legislation_question) + + expect(page).to have_css('.comment', count: per_page) + within("ul.pagination") do + expect(page).to have_content("1") + expect(page).to have_content("2") + expect(page).to_not have_content("3") + click_link "Next", exact: false + end + + expect(page).to have_css('.comment', count: 2) + end + + feature 'Not logged user' do + scenario 'can not see comments forms' do + create(:comment, commentable: legislation_question) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + expect(page).to have_content 'You must Sign in or Sign up to leave a comment' + within('#comments') do + expect(page).to_not have_content 'Write a comment' + expect(page).to_not have_content 'Reply' + end + end + end + + scenario 'Create', :js do + login_as(user) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + fill_in "comment-body-legislation_question_#{legislation_question.id}", with: 'Have you thought about...?' + click_button 'Publish comment' + + within "#comments" do + expect(page).to have_content 'Have you thought about...?' + expect(page).to have_content '(1)' + end + end + + scenario 'Errors on create', :js do + login_as(user) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + click_button 'Publish comment' + + expect(page).to have_content "Can't be blank" + end + + scenario 'Reply', :js do + citizen = create(:user, username: 'Ana') + manuela = create(:user, username: 'Manuela') + comment = create(:comment, commentable: legislation_question, user: citizen) + + login_as(manuela) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' + click_button 'Publish reply' + end + + within "#comment_#{comment.id}" do + expect(page).to have_content 'It will be done next week.' + end + + expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true) + end + + scenario 'Errors on reply', :js do + comment = create(:comment, commentable: legislation_question, user: user) + + login_as(user) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + click_button 'Publish reply' + expect(page).to have_content "Can't be blank" + end + + end + + scenario "N replies", :js do + parent = create(:comment, commentable: legislation_question) + + 7.times do + create(:comment, commentable: legislation_question, parent: parent) + parent = parent.children.first + end + + visit legislation_process_question_path(legislation_question.process, legislation_question) + expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment") + end + + scenario "Flagging as inappropriate", :js do + comment = create(:comment, commentable: legislation_question) + + login_as(user) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + within "#comment_#{comment.id}" do + page.find("#flag-expand-comment-#{comment.id}").click + page.find("#flag-comment-#{comment.id}").click + + expect(page).to have_css("#unflag-expand-comment-#{comment.id}") + end + + expect(Flag.flagged?(user, comment)).to be + end + + scenario "Undoing flagging as inappropriate", :js do + comment = create(:comment, commentable: legislation_question) + Flag.flag(user, comment) + + login_as(user) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + within "#comment_#{comment.id}" do + page.find("#unflag-expand-comment-#{comment.id}").click + page.find("#unflag-comment-#{comment.id}").click + + expect(page).to have_css("#flag-expand-comment-#{comment.id}") + end + + expect(Flag.flagged?(user, comment)).to_not be + end + + scenario "Flagging turbolinks sanity check", :js do + legislation_question = create(:legislation_question, title: "Should we change the world?") + comment = create(:comment, commentable: legislation_question) + + login_as(user) + visit legislation_process_path(legislation_question.process) + click_link "Should we change the world?" + + within "#comment_#{comment.id}" do + page.find("#flag-expand-comment-#{comment.id}").click + expect(page).to have_selector("#flag-comment-#{comment.id}") + end + end + + scenario "Erasing a comment's author" do + legislation_question = create(:legislation_question) + comment = create(:comment, commentable: legislation_question, body: 'this should be visible') + comment.user.erase + + visit legislation_process_question_path(legislation_question.process, legislation_question) + within "#comment_#{comment.id}" do + expect(page).to have_content('User deleted') + expect(page).to have_content('this should be visible') + end + end + + scenario 'Submit button is disabled after clicking', :js do + legislation_question = create(:legislation_question) + login_as(user) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + fill_in "comment-body-legislation_question_#{legislation_question.id}", with: 'Testing submit button!' + click_button 'Publish comment' + + # The button's text should now be "..." + # This should be checked before the Ajax request is finished + expect(page).to_not have_button 'Publish comment' + + expect(page).to have_content('Testing submit button!') + end + + feature "Moderators" do + scenario "can create comment as a moderator", :js do + moderator = create(:moderator) + + login_as(moderator.user) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + fill_in "comment-body-legislation_question_#{legislation_question.id}", with: "I am moderating!" + check "comment-as-moderator-legislation_question_#{legislation_question.id}" + click_button "Publish comment" + + within "#comments" do + expect(page).to have_content "I am moderating!" + expect(page).to have_content "Moderator ##{moderator.id}" + expect(page).to have_css "div.is-moderator" + expect(page).to have_css "img.moderator-avatar" + end + end + + scenario "can create reply as a moderator", :js do + citizen = create(:user, username: "Ana") + manuela = create(:user, username: "Manuela") + moderator = create(:moderator, user: manuela) + comment = create(:comment, commentable: legislation_question, user: citizen) + + login_as(manuela) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + check "comment-as-moderator-comment_#{comment.id}" + click_button 'Publish reply' + end + + within "#comment_#{comment.id}" do + expect(page).to have_content "I am moderating!" + expect(page).to have_content "Moderator ##{moderator.id}" + expect(page).to have_css "div.is-moderator" + expect(page).to have_css "img.moderator-avatar" + end + + expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true) + end + + scenario "can not comment as an administrator" do + moderator = create(:moderator) + + login_as(moderator.user) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + expect(page).to_not have_content "Comment as administrator" + end + end + + feature "Administrators" do + scenario "can create comment as an administrator", :js do + admin = create(:administrator) + + login_as(admin.user) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + fill_in "comment-body-legislation_question_#{legislation_question.id}", with: "I am your Admin!" + check "comment-as-administrator-legislation_question_#{legislation_question.id}" + click_button "Publish comment" + + within "#comments" do + expect(page).to have_content "I am your Admin!" + expect(page).to have_content "Administrator ##{admin.id}" + expect(page).to have_css "div.is-admin" + expect(page).to have_css "img.admin-avatar" + end + end + + scenario "can create reply as an administrator", :js do + citizen = create(:user, username: "Ana") + manuela = create(:user, username: "Manuela") + admin = create(:administrator, user: manuela) + comment = create(:comment, commentable: legislation_question, user: citizen) + + login_as(manuela) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + check "comment-as-administrator-comment_#{comment.id}" + click_button 'Publish reply' + end + + within "#comment_#{comment.id}" do + expect(page).to have_content "Top of the world!" + expect(page).to have_content "Administrator ##{admin.id}" + expect(page).to have_css "div.is-admin" + expect(page).to have_css "img.admin-avatar" + end + + expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true) + end + + scenario "can not comment as a moderator" do + admin = create(:administrator) + + login_as(admin.user) + visit legislation_process_question_path(legislation_question.process, legislation_question) + + expect(page).to_not have_content "Comment as moderator" + end + end + + feature 'Voting comments' do + background do + @manuela = create(:user, verified_at: Time.current) + @pablo = create(:user) + @legislation_question = create(:legislation_question) + @comment = create(:comment, commentable: @legislation_question) + + login_as(@manuela) + end + + scenario 'Show' do + create(:vote, voter: @manuela, votable: @comment, vote_flag: true) + create(:vote, voter: @pablo, votable: @comment, vote_flag: false) + + visit legislation_process_question_path(@legislation_question.process, @legislation_question) + + within("#comment_#{@comment.id}_votes") do + within(".in_favor") do + expect(page).to have_content "1" + end + + within(".against") do + expect(page).to have_content "1" + end + + expect(page).to have_content "2 votes" + end + end + + scenario 'Create', :js do + visit legislation_process_question_path(@legislation_question.process, @legislation_question) + + within("#comment_#{@comment.id}_votes") do + find(".in_favor a").click + + within(".in_favor") do + expect(page).to have_content "1" + end + + within(".against") do + expect(page).to have_content "0" + end + + expect(page).to have_content "1 vote" + end + end + + scenario 'Update', :js do + visit legislation_process_question_path(@legislation_question.process, @legislation_question) + + within("#comment_#{@comment.id}_votes") do + find('.in_favor a').click + find('.against a').click + + within('.in_favor') do + expect(page).to have_content "0" + end + + within('.against') do + expect(page).to have_content "1" + end + + expect(page).to have_content "1 vote" + end + end + + xscenario 'Trying to vote multiple times', :js do + visit legislation_process_question_path(@legislation_question.process, @legislation_question) + + within("#comment_#{@comment.id}_votes") do + find('.in_favor a').click + within('.in_favor') do + expect(page).to have_content "1" + end + + find('.in_favor a').click + within('.in_favor') do + expect(page).to_not have_content "2" + expect(page).to have_content "1" + end + + within('.against') do + expect(page).to have_content "0" + end + + expect(page).to have_content "1 vote" + end + end + end + +end diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index f9ed7a0c5..98f49a727 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -12,6 +12,7 @@ describe "Abilities::Administrator" do let(:debate) { create(:debate) } let(:comment) { create(:comment) } let(:proposal) { create(:proposal) } + let(:legislation_question) { create(:legislation_question) } let(:hidden_debate) { create(:debate, :hidden) } let(:hidden_comment) { create(:comment, :hidden) } @@ -50,6 +51,9 @@ describe "Abilities::Administrator" do it { should be_able_to(:comment_as_administrator, proposal) } it { should_not be_able_to(:comment_as_moderator, proposal) } + it { should be_able_to(:comment_as_administrator, legislation_question) } + it { should_not be_able_to(:comment_as_moderator, legislation_question) } + it { should be_able_to(:manage, Annotation) } it { should be_able_to(:read, SpendingProposal) } diff --git a/spec/models/abilities/moderator_spec.rb b/spec/models/abilities/moderator_spec.rb index c49fe572a..332f69450 100644 --- a/spec/models/abilities/moderator_spec.rb +++ b/spec/models/abilities/moderator_spec.rb @@ -11,6 +11,7 @@ describe "Abilities::Moderator" do let(:debate) { create(:debate) } let(:comment) { create(:comment) } let(:proposal) { create(:proposal) } + let(:legislation_question) { create(:legislation_question) } let(:own_debate) { create(:debate, author: user) } let(:own_comment) { create(:comment, author: user) } @@ -101,7 +102,9 @@ describe "Abilities::Moderator" do it { should be_able_to(:comment_as_moderator, debate) } it { should be_able_to(:comment_as_moderator, proposal) } + it { should be_able_to(:comment_as_moderator, legislation_question) } it { should_not be_able_to(:comment_as_administrator, debate) } it { should_not be_able_to(:comment_as_administrator, proposal) } + it { should_not be_able_to(:comment_as_administrator, legislation_question) } end end From eed8f1dd837f2d09e8d8c549d18c558367977ae8 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 27 Dec 2016 12:32:07 +0100 Subject: [PATCH 034/197] Set admin layout for admin sandbox templates --- app/controllers/sandbox_controller.rb | 18 ++++++++++++++++++ ...ox.html.erb => admin_test_sandbox.html.erb} | 0 2 files changed, 18 insertions(+) rename app/views/sandbox/{test_sandbox.html.erb => admin_test_sandbox.html.erb} (100%) diff --git a/app/controllers/sandbox_controller.rb b/app/controllers/sandbox_controller.rb index ea5a3e96b..12b5dd91e 100644 --- a/app/controllers/sandbox_controller.rb +++ b/app/controllers/sandbox_controller.rb @@ -1,6 +1,10 @@ class SandboxController < ApplicationController skip_authorization_check + layout :set_layout + + helper_method(:namespace) + def index @templates = Dir.glob(Rails.root.join('app/views/sandbox/*.html.erb').to_s).map do |filename| filename = File.basename(filename, File.extname(filename)) @@ -24,4 +28,18 @@ class SandboxController < ApplicationController render :action => "index" end end + + private + + def set_layout + if params[:template] && params[:template].split("_").first == "admin" + "admin" + else + "application" + end + end + + def namespace + "admin" + end end diff --git a/app/views/sandbox/test_sandbox.html.erb b/app/views/sandbox/admin_test_sandbox.html.erb similarity index 100% rename from app/views/sandbox/test_sandbox.html.erb rename to app/views/sandbox/admin_test_sandbox.html.erb From 5e01b380cda2245176f8d83c31d2baf66ebdad3e Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 27 Dec 2016 11:02:27 +0100 Subject: [PATCH 035/197] Legislation Answer model --- app/models/legislation/answer.rb | 9 +++++ app/models/legislation/question.rb | 1 + app/models/legislation/question_option.rb | 1 + app/models/user.rb | 1 + ...161222115744_create_legislation_answers.rb | 13 +++++++ db/schema.rb | 14 +++++++ spec/factories.rb | 6 +++ spec/models/legislation/answer_spec.rb | 39 +++++++++++++++++++ 8 files changed, 84 insertions(+) create mode 100644 app/models/legislation/answer.rb create mode 100644 db/migrate/20161222115744_create_legislation_answers.rb create mode 100644 spec/models/legislation/answer_spec.rb diff --git a/app/models/legislation/answer.rb b/app/models/legislation/answer.rb new file mode 100644 index 000000000..fd4bc90ed --- /dev/null +++ b/app/models/legislation/answer.rb @@ -0,0 +1,9 @@ +class Legislation::Answer < ActiveRecord::Base + belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :answers, counter_cache: true + belongs_to :question_option, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_option_id', dependent: :destroy, inverse_of: :answers, counter_cache: true + belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers + + validates :question, presence: true, uniqueness: { scope: :user_id} + validates :question_option, presence: true + validates :user, presence: true +end diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index 2b779d1f8..e80d169ce 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -6,6 +6,7 @@ class Legislation::Question < ActiveRecord::Base 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 :answers, class_name: 'Legislation::Answer', 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 diff --git a/app/models/legislation/question_option.rb b/app/models/legislation/question_option.rb index 93bc20320..f7927dd1a 100644 --- a/app/models/legislation/question_option.rb +++ b/app/models/legislation/question_option.rb @@ -3,6 +3,7 @@ class Legislation::QuestionOption < ActiveRecord::Base include ActsAsParanoidAliases belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :question_options + has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question validates :question, presence: true validates :value, presence: true, uniqueness: { scope: :legislation_question_id } diff --git a/app/models/user.rb b/app/models/user.rb index 03f2db27b..4ded8d99e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -25,6 +25,7 @@ class User < ActiveRecord::Base has_many :notifications has_many :direct_messages_sent, class_name: 'DirectMessage', foreign_key: :sender_id has_many :direct_messages_received, class_name: 'DirectMessage', foreign_key: :receiver_id + has_many :legislation_answers, class_name: 'Legislation::Answer', dependent: :destroy, inverse_of: :user belongs_to :geozone validates :username, presence: true, if: :username_required? diff --git a/db/migrate/20161222115744_create_legislation_answers.rb b/db/migrate/20161222115744_create_legislation_answers.rb new file mode 100644 index 000000000..0c8170d68 --- /dev/null +++ b/db/migrate/20161222115744_create_legislation_answers.rb @@ -0,0 +1,13 @@ +class CreateLegislationAnswers < ActiveRecord::Migration + def change + create_table :legislation_answers do |t| + t.references :legislation_question, index: true + t.references :legislation_question_option, index: true + t.references :user, index: true + + t.datetime :hidden_at, index: true + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0438a3328..e9e672e08 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -227,6 +227,20 @@ ActiveRecord::Schema.define(version: 20161222180927) do t.datetime "updated_at", null: false end + create_table "legislation_answers", force: :cascade do |t| + t.integer "legislation_question_id" + t.integer "legislation_question_option_id" + t.integer "user_id" + t.datetime "hidden_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "legislation_answers", ["hidden_at"], name: "index_legislation_answers_on_hidden_at", using: :btree + add_index "legislation_answers", ["legislation_question_id"], name: "index_legislation_answers_on_legislation_question_id", using: :btree + add_index "legislation_answers", ["legislation_question_option_id"], name: "index_legislation_answers_on_legislation_question_option_id", using: :btree + add_index "legislation_answers", ["user_id"], name: "index_legislation_answers_on_user_id", using: :btree + create_table "legislation_draft_versions", force: :cascade do |t| t.integer "legislation_process_id" t.string "title" diff --git a/spec/factories.rb b/spec/factories.rb index f14edf6ea..731e1fef1 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -411,4 +411,10 @@ FactoryGirl.define do question factory: :legislation_question sequence(:value) { |n| "Option #{n}" } end + + factory :legislation_answer, class: 'Legislation::Answer' do + question factory: :legislation_question + question_option factory: :legislation_question_option + user + end end diff --git a/spec/models/legislation/answer_spec.rb b/spec/models/legislation/answer_spec.rb new file mode 100644 index 000000000..9f5037081 --- /dev/null +++ b/spec/models/legislation/answer_spec.rb @@ -0,0 +1,39 @@ +require 'rails_helper' + +RSpec.describe Legislation::Answer, type: :model do + let(:legislation_answer) { build(:legislation_answer) } + + it "should be valid" do + expect(legislation_answer).to be_valid + end + + it "counts answers" do + question = create(:legislation_question) + option_1 = create(:legislation_question_option, question: question, value: 'Yes') + option_2 = create(:legislation_question_option, question: question, value: 'No') + + answer = create(:legislation_answer, question: question, question_option: option_2) + + expect(answer).to be_valid + expect(question.answers_count).to eq 1 + expect(option_2.answers_count).to eq 1 + expect(option_1.answers_count).to eq 0 + end + + it "can't answer same question more than once" do + question = create(:legislation_question) + option_1 = create(:legislation_question_option, question: question, value: 'Yes') + option_2 = create(:legislation_question_option, question: question, value: 'No') + user = create(:user) + + answer = create(:legislation_answer, question: question, question_option: option_2, user: user) + expect(answer).to be_valid + + second_answer = build(:legislation_answer, question: question, question_option: option_1, user: user) + expect(second_answer).to be_invalid + + expect(question.answers_count).to eq 1 + expect(option_2.answers_count).to eq 1 + expect(option_1.answers_count).to eq 0 + end +end From a6ceab6d73c53675b9b2093359254fb379c89869 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 27 Dec 2016 19:49:03 +0100 Subject: [PATCH 036/197] Answer legislation questions --- .../legislation/answers_controller.rb | 21 ++++++ .../legislation/questions_controller.rb | 1 + app/models/abilities/everyone.rb | 1 + app/models/legislation/process.rb | 4 +- app/models/legislation/question.rb | 6 +- app/views/admin/_menu.html.erb | 2 +- .../legislation/questions/index.html.erb | 4 +- app/views/legislation/questions/show.html.erb | 21 +++--- config/locales/activerecord.en.yml | 13 ++++ config/locales/activerecord.es.yml | 13 ++++ config/locales/en.yml | 1 + config/locales/es.yml | 1 + spec/features/legislation/debate_spec.rb | 69 +++++++++++++++++-- 13 files changed, 136 insertions(+), 21 deletions(-) create mode 100644 app/controllers/legislation/answers_controller.rb diff --git a/app/controllers/legislation/answers_controller.rb b/app/controllers/legislation/answers_controller.rb new file mode 100644 index 000000000..156cbc68b --- /dev/null +++ b/app/controllers/legislation/answers_controller.rb @@ -0,0 +1,21 @@ +class Legislation::AnswersController < Legislation::BaseController + before_action :authenticate_user! + before_action :verify_resident! + + load_and_authorize_resource :process + load_and_authorize_resource :question, through: :process + load_and_authorize_resource :answer, through: :question + + def create + @answer.user = current_user + @answer.save + redirect_to legislation_process_question_path(@process, @question) + end + + private + def answer_params + params.require(:legislation_answer).permit( + :legislation_question_option_id, + ) + end +end diff --git a/app/controllers/legislation/questions_controller.rb b/app/controllers/legislation/questions_controller.rb index 7114c98cb..d50443281 100644 --- a/app/controllers/legislation/questions_controller.rb +++ b/app/controllers/legislation/questions_controller.rb @@ -8,5 +8,6 @@ class Legislation::QuestionsController < Legislation::BaseController @commentable = @question @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) set_comment_flags(@comment_tree.comments) + @answer = @question.answer_for_user(current_user) || Legislation::Answer.new end end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index e22bcb7e0..466b6a5ba 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -14,6 +14,7 @@ module Abilities can [:read, :draft_publication, :allegations, :final_version_publication], Legislation::Process can [:read], Legislation::DraftVersion can [:read], Legislation::Question + can [:create], Legislation::Answer end end end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index dbc31c7b3..86b250b18 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -2,9 +2,9 @@ class Legislation::Process < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - has_many :draft_versions, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id' + has_many :draft_versions, -> { order(:id) }, 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' + has_many :questions, -> { order(:id) }, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id' validates :title, presence: true validates :description, presence: true diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index e80d169ce..7df8f67cf 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -5,7 +5,7 @@ class Legislation::Question < ActiveRecord::Base 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 :question_options, -> { order(:id) }, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question has_many :comments, as: :commentable @@ -17,4 +17,8 @@ class Legislation::Question < ActiveRecord::Base def next_question_id @next_question_id ||= process.questions.where("id > ?", id).order('id ASC').limit(1).pluck(:id).first end + + def answer_for_user(user) + answers.where(user: user).first + end end diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 6da3b23fd..8257b3c8a 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -44,7 +44,7 @@ <% end %> <% if feature?(:legislation) %> -
  • > +
  • > <%= link_to admin_legislation_processes_path do %> <%= t("admin.menu.legislation") %> <% end %> diff --git a/app/views/admin/legislation/questions/index.html.erb b/app/views/admin/legislation/questions/index.html.erb index 7d41f1b83..f0a4638ee 100644 --- a/app/views/admin/legislation/questions/index.html.erb +++ b/app/views/admin/legislation/questions/index.html.erb @@ -29,7 +29,9 @@ <%= content_tag :ul do %> <% question.question_options.each do |question_option| %> - <%= content_tag :li, question_option.value %> + <%= content_tag :li do %> + <%= question_option.value %> (<%= question_option.answers_count %>) + <% end %> <% end %> <% end %> diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index d22289d28..eda42d239 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -23,16 +23,19 @@

    <%= @question.title %>

    -
    - <% @question.question_options.each do |question_option| %> - + <% if @question.question_options.any? %> + <%= form_for @answer, url: legislation_process_question_answers_path(@process, @question, @answer), class: "controls-stacked" do |f| %> + <% @question.question_options.each do |question_option| %> + + <% end %> + <%= f.submit t('.answer_question'), class: "button" unless @answer.persisted? %> <% end %> -
    -
    + <% end %> +
  • <% if feature?(:legislation) %>
  • - <%= link_to t("layouts.header.collaborative_legislation"), legislation_processes_path, class: ("active" if controller.class.parent == Legislation ), accesskey: "l" %> + <%= layout_menu_link_to t("layouts.header.collaborative_legislation"), + legislation_processes_path, + controller.class.parent == Legislation, + accesskey: "l" %>
  • <% end %> <% if feature?(:spending_proposals) %> From 98b6dd75eab8ba2499b6e6c9a724d53734e1f778 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Mon, 2 Jan 2017 19:51:39 +0100 Subject: [PATCH 061/197] Fix stack level too deep bug when deleting questions with answers --- app/models/legislation/answer.rb | 4 +-- .../admin/legislation/questions_spec.rb | 18 +++++++++++ spec/models/legislation/question_spec.rb | 32 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/models/legislation/answer.rb b/app/models/legislation/answer.rb index fd4bc90ed..375bcad8c 100644 --- a/app/models/legislation/answer.rb +++ b/app/models/legislation/answer.rb @@ -1,6 +1,6 @@ class Legislation::Answer < ActiveRecord::Base - belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :answers, counter_cache: true - belongs_to :question_option, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_option_id', dependent: :destroy, inverse_of: :answers, counter_cache: true + belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :answers, counter_cache: true + belongs_to :question_option, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_option_id', inverse_of: :answers, counter_cache: true belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers validates :question, presence: true, uniqueness: { scope: :user_id} diff --git a/spec/features/admin/legislation/questions_spec.rb b/spec/features/admin/legislation/questions_spec.rb index 5b2dd0ef6..44698a25c 100644 --- a/spec/features/admin/legislation/questions_spec.rb +++ b/spec/features/admin/legislation/questions_spec.rb @@ -86,4 +86,22 @@ feature 'Admin legislation questions' do expect(page).to have_content 'Question 2b' end end + + context 'Delete' do + scenario 'Legislation question', :js do + process = create(:legislation_process, title: 'An example legislation process') + create(:legislation_question, title: 'Question 1', process: process) + question = create(:legislation_question, title: 'Question 2', process: process) + question_option = create(:legislation_question_option, question: question, value: 'Yes') + create(:legislation_answer, question: question, question_option: question_option) + + visit edit_admin_legislation_process_question_path(process, question) + + click_link 'Delete' + + expect(page).to have_content 'Questions' + expect(page).to have_content 'Question 1' + expect(page).to_not have_content 'Question 2' + end + end end diff --git a/spec/models/legislation/question_spec.rb b/spec/models/legislation/question_spec.rb index 25815cd38..660f87cd2 100644 --- a/spec/models/legislation/question_spec.rb +++ b/spec/models/legislation/question_spec.rb @@ -6,4 +6,36 @@ RSpec.describe Legislation::Question, type: :model do it "should be valid" do expect(legislation_question).to be_valid end + + context "can be deleted" do + example "when it has no options or answers" do + question = create(:legislation_question) + + expect do + question.destroy + end.to change { Legislation::Question.count }.by(-1) + end + + example "when it has options but no answers" do + question = create(:legislation_question) + create(:legislation_question_option, question: question, value: "Yes") + create(:legislation_question_option, question: question, value: "No") + + expect do + question.destroy + end.to change { Legislation::Question.count }.by(-1) + end + + example "when it has options and answers" do + question = create(:legislation_question) + option_1 = create(:legislation_question_option, question: question, value: "Yes") + option_2 = create(:legislation_question_option, question: question, value: "No") + create(:legislation_answer, question: question, question_option: option_1) + create(:legislation_answer, question: question, question_option: option_2) + + expect do + question.destroy + end.to change { Legislation::Question.count }.by(-1) + end + end end From d2b3a2118268e4f938715e6a280cc1bd353378e4 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 3 Jan 2017 17:42:27 +0100 Subject: [PATCH 062/197] Fix abilities and add specs --- app/models/abilities/everyone.rb | 2 +- .../legislation/draft_versions/show.html.erb | 4 +- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- .../legislation/draft_versions_spec.rb | 75 +++++++++++++++++++ 5 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 spec/features/legislation/draft_versions_spec.rb diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 466b6a5ba..b71e1f7d5 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -12,7 +12,7 @@ module Abilities can [:search, :read], Annotation can :new, DirectMessage can [:read, :draft_publication, :allegations, :final_version_publication], Legislation::Process - can [:read], Legislation::DraftVersion + can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer end diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index 32554cf28..14a7cc1f3 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -27,12 +27,12 @@
    - <%= t('.text_index') %> + <%= t('.text_toc') %>
    - <%= t('.text_index') %> + <%= t('.text_toc') %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index 6328a2e20..8fa1cf13f 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -235,7 +235,7 @@ en: updated_at: updated at %{date} see_changes: see changes summary see_comments: See all comments - text_index: Index + text_toc: Table of contents text_body: Text text_comments: Comments processes: diff --git a/config/locales/es.yml b/config/locales/es.yml index 8427146cc..a93d44d2e 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -235,7 +235,7 @@ es: updated_at: actualizada el %{date} see_changes: ver resumen de cambios see_comments: Ver todos los comentarios - text_index: Índice + text_toc: Índice text_body: Texto text_comments: Comentarios processes: diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb new file mode 100644 index 000000000..6414593e6 --- /dev/null +++ b/spec/features/legislation/draft_versions_spec.rb @@ -0,0 +1,75 @@ +require 'rails_helper' + +feature 'Legislation Draft Versions' do + + context "See draft text page" do + before(:each) do + @process = create(:legislation_process) + @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version") + @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version") + end + + it "shows the text body for this version" do + visit legislation_process_draft_version_path(@process, @draft_version_1) + + expect(page).to have_content("Body of the first version") + end + + it "switches to another version without js" do + visit legislation_process_draft_version_path(@process, @draft_version_1) + expect(page).to have_content("Body of the first version") + + select("Version 2") + click_button "see" + + expect(page).to_not have_content("Body of the first version") + expect(page).to have_content("Body of the second version") + end + + it "switches to another version with js", :js do + visit legislation_process_draft_version_path(@process, @draft_version_1) + expect(page).to have_content("Body of the first version") + + select("Version 2") + + expect(page).to_not have_content("Body of the first version") + expect(page).to have_content("Body of the second version") + end + end + + context "See changes page" do + before(:each) do + @process = create(:legislation_process) + @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", changelog: "Changes for first version") + @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", changelog: "Changes for second version") + end + + it "shows the text body for this version" do + visit legislation_process_draft_version_changes_path(@process, @draft_version_1) + + expect(page).to have_content("Changes for first version") + end + + it "switches to another version without js" do + visit legislation_process_draft_version_changes_path(@process, @draft_version_1) + expect(page).to have_content("Changes for first version") + + select("Version 2") + click_button "see" + + expect(page).to_not have_content("Changes for first version") + expect(page).to have_content("Changes for second version") + end + + it "switches to another version with js", :js do + visit legislation_process_draft_version_changes_path(@process, @draft_version_1) + expect(page).to have_content("Changes for first version") + + select("Version 2") + + expect(page).to_not have_content("Changes for first version") + expect(page).to have_content("Changes for second version") + end + end + +end From 3ba6b409aa6b7a842207c47ce100f6a46764e34a Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 3 Jan 2017 21:41:00 +0100 Subject: [PATCH 063/197] Make markdown helper safer to use Avoid exception if text is nil --- app/helpers/application_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1f52f0eea..313375e3f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -18,6 +18,8 @@ module ApplicationHelper end def markdown(text) + return text if text.blank? + # See https://github.com/vmg/redcarpet for options render_options = { filter_html: false, From f0407596934fc3b36fefd5f026b5bbc714de6edd Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 3 Jan 2017 22:08:54 +0100 Subject: [PATCH 064/197] Show only published draft versions to users (and also drafts to admins) --- .../legislation/draft_versions_controller.rb | 15 ++++- app/models/legislation/draft_version.rb | 2 + .../draft_versions/changes.html.erb | 2 +- .../legislation/draft_versions/show.html.erb | 2 +- .../legislation/draft_versions_spec.rb | 57 +++++++++++++++++-- 5 files changed, 69 insertions(+), 9 deletions(-) diff --git a/app/controllers/legislation/draft_versions_controller.rb b/app/controllers/legislation/draft_versions_controller.rb index bf455fa5a..705eb16bd 100644 --- a/app/controllers/legislation/draft_versions_controller.rb +++ b/app/controllers/legislation/draft_versions_controller.rb @@ -6,14 +6,15 @@ class Legislation::DraftVersionsController < Legislation::BaseController end def show + load_version(params[:id]) end def changes - @draft_version = @process.draft_versions.find(params[:draft_version_id]) + load_version(params[:draft_version_id]) end def go_to_version - version = @process.draft_versions.find(params[:draft_version_id]) + version = @process.draft_versions.published.find(params[:draft_version_id]) if params[:redirect_action] == 'changes' redirect_to legislation_process_draft_version_changes_path(@process, version) @@ -21,4 +22,14 @@ class Legislation::DraftVersionsController < Legislation::BaseController redirect_to legislation_process_draft_version_path(@process, version) end end + + private + + def load_version(id_param) + if current_user && current_user.administrator? + @draft_version = @process.draft_versions.find(id_param) + else + @draft_version = @process.draft_versions.published.find(id_param) + end + end end diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index b68903b5e..3cbbce567 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -10,6 +10,8 @@ class Legislation::DraftVersion < ActiveRecord::Base validates :body, presence: true validates :status, presence: true, inclusion: { in: VALID_STATUSES } + scope :published, -> { where(status: 'published').order('id DESC') } + before_save :render_html def render_html diff --git a/app/views/legislation/draft_versions/changes.html.erb b/app/views/legislation/draft_versions/changes.html.erb index a14a2e700..5b46c2282 100644 --- a/app/views/legislation/draft_versions/changes.html.erb +++ b/app/views/legislation/draft_versions/changes.html.erb @@ -11,7 +11,7 @@

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

    <%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %> - <%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions, 'id', 'title', @draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %> + <%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions.published, 'id', 'title', @draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %> <%= hidden_field_tag "redirect_action", "changes" %> <%= submit_tag t('legislation.draft_versions.show.select_version_submit'), class: "button" %> <% end %> diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index 14a7cc1f3..af880c10d 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -11,7 +11,7 @@

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

    <%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %> - <%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions, 'id', 'title', @draft_version.id), "aria-label": t('.select_draft_version') %> + <%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions.published, 'id', 'title', @draft_version.id), "aria-label": t('.select_draft_version') %> <%= submit_tag t('.select_version_submit'), class: "button" %> <% end %> <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %> diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index 6414593e6..8fef62213 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -1,18 +1,44 @@ require 'rails_helper' feature 'Legislation Draft Versions' do + let(:user) { create(:user) } + let(:administrator) do + create(:administrator, user: user) + user + end context "See draft text page" do before(:each) do @process = create(:legislation_process) - @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version") - @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version") + @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", status: "published") + @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", status: "published") + @draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", body: "Body of the third version", status: "draft") end it "shows the text body for this version" do visit legislation_process_draft_version_path(@process, @draft_version_1) expect(page).to have_content("Body of the first version") + + within('select#draft_version_id') do + expect(page).to have_content("Version 1") + expect(page).to have_content("Version 2") + expect(page).to_not have_content("Version 3") + end + end + + it "shows an unpublished version to admins" do + login_as(administrator) + + visit legislation_process_draft_version_path(@process, @draft_version_3) + + expect(page).to have_content("Body of the third version") + + within('select#draft_version_id') do + expect(page).to have_content("Version 1") + expect(page).to have_content("Version 2") + expect(page).to_not have_content("Version 3") + end end it "switches to another version without js" do @@ -40,14 +66,35 @@ feature 'Legislation Draft Versions' do context "See changes page" do before(:each) do @process = create(:legislation_process) - @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", changelog: "Changes for first version") - @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", changelog: "Changes for second version") + @draft_version_1 = create(:legislation_draft_version, process: @process, title: "Version 1", body: "Body of the first version", changelog: "Changes for first version", status: "published") + @draft_version_2 = create(:legislation_draft_version, process: @process, title: "Version 2", body: "Body of the second version", changelog: "Changes for second version", status: "published") + @draft_version_3 = create(:legislation_draft_version, process: @process, title: "Version 3", body: "Body of the third version", changelog: "Changes for third version", status: "draft") end - it "shows the text body for this version" do + it "shows the changes for this version" do visit legislation_process_draft_version_changes_path(@process, @draft_version_1) expect(page).to have_content("Changes for first version") + + within('select#draft_version_id') do + expect(page).to have_content("Version 1") + expect(page).to have_content("Version 2") + expect(page).to_not have_content("Version 3") + end + end + + it "shows an unpublished version to admins" do + login_as(administrator) + + visit legislation_process_draft_version_changes_path(@process, @draft_version_3) + + expect(page).to have_content("Changes for third version") + + within('select#draft_version_id') do + expect(page).to have_content("Version 1") + expect(page).to have_content("Version 2") + expect(page).to_not have_content("Version 3") + end end it "switches to another version without js" do From 6d99a24740ca252679d15cf71812d0db15a705fc Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 4 Jan 2017 10:13:55 +0100 Subject: [PATCH 065/197] Fix draft versions list --- .../legislation/draft_versions_controller.rb | 15 +++++++++------ app/models/legislation/process.rb | 2 +- .../legislation/draft_versions/changes.html.erb | 2 +- .../legislation/draft_versions/show.html.erb | 2 +- .../processes/_phase_allegations.html.erb | 2 +- .../processes/_phase_draft_publication.html.erb | 2 +- spec/features/legislation/draft_versions_spec.rb | 4 ++-- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/app/controllers/legislation/draft_versions_controller.rb b/app/controllers/legislation/draft_versions_controller.rb index 705eb16bd..0b6af46a6 100644 --- a/app/controllers/legislation/draft_versions_controller.rb +++ b/app/controllers/legislation/draft_versions_controller.rb @@ -6,15 +6,17 @@ class Legislation::DraftVersionsController < Legislation::BaseController end def show - load_version(params[:id]) + @draft_versions_list = visible_draft_versions + @draft_version = @draft_versions_list.find(params[:id]) end def changes - load_version(params[:draft_version_id]) + @draft_versions_list = visible_draft_versions + @draft_version = @draft_versions_list.find(params[:draft_version_id]) end def go_to_version - version = @process.draft_versions.published.find(params[:draft_version_id]) + version = visible_draft_versions.find(params[:draft_version_id]) if params[:redirect_action] == 'changes' redirect_to legislation_process_draft_version_changes_path(@process, version) @@ -25,11 +27,12 @@ class Legislation::DraftVersionsController < Legislation::BaseController private - def load_version(id_param) + def visible_draft_versions if current_user && current_user.administrator? - @draft_version = @process.draft_versions.find(id_param) + @process.draft_versions else - @draft_version = @process.draft_versions.published.find(id_param) + @process.draft_versions.published end end + end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 995aedb9e..566ff075e 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -3,7 +3,7 @@ class Legislation::Process < ActiveRecord::Base include ActsAsParanoidAliases has_many :draft_versions, -> { order(:id) }, 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_one :final_draft_version, -> { where final_version: true, status: 'published' }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id' has_many :questions, -> { order(:id) }, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id' validates :title, presence: true diff --git a/app/views/legislation/draft_versions/changes.html.erb b/app/views/legislation/draft_versions/changes.html.erb index 5b46c2282..0f98ad12d 100644 --- a/app/views/legislation/draft_versions/changes.html.erb +++ b/app/views/legislation/draft_versions/changes.html.erb @@ -11,7 +11,7 @@

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

    <%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %> - <%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions.published, 'id', 'title', @draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %> + <%= select_tag "draft_version_id", options_from_collection_for_select(@draft_versions_list, 'id', 'title', @draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %> <%= hidden_field_tag "redirect_action", "changes" %> <%= submit_tag t('legislation.draft_versions.show.select_version_submit'), class: "button" %> <% end %> diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index af880c10d..5635e335a 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -11,7 +11,7 @@

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

    <%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %> - <%= select_tag "draft_version_id", options_from_collection_for_select(@process.draft_versions.published, 'id', 'title', @draft_version.id), "aria-label": t('.select_draft_version') %> + <%= select_tag "draft_version_id", options_from_collection_for_select(@draft_versions_list, 'id', 'title', @draft_version.id), "aria-label": t('.select_draft_version') %> <%= submit_tag t('.select_version_submit'), class: "button" %> <% end %> <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %> diff --git a/app/views/legislation/processes/_phase_allegations.html.erb b/app/views/legislation/processes/_phase_allegations.html.erb index be31ddf43..0087b9ca5 100644 --- a/app/views/legislation/processes/_phase_allegations.html.erb +++ b/app/views/legislation/processes/_phase_allegations.html.erb @@ -1,6 +1,6 @@ <% if process.draft_versions.any? %>
      - <% process.draft_versions.each do |draft_version| %> + <% process.draft_versions.published.each do |draft_version| %>
    • <%= link_to draft_version.title, legislation_process_draft_version_path(process, draft_version) %>
    • <% end %>
    diff --git a/app/views/legislation/processes/_phase_draft_publication.html.erb b/app/views/legislation/processes/_phase_draft_publication.html.erb index be31ddf43..0087b9ca5 100644 --- a/app/views/legislation/processes/_phase_draft_publication.html.erb +++ b/app/views/legislation/processes/_phase_draft_publication.html.erb @@ -1,6 +1,6 @@ <% if process.draft_versions.any? %>
      - <% process.draft_versions.each do |draft_version| %> + <% process.draft_versions.published.each do |draft_version| %>
    • <%= link_to draft_version.title, legislation_process_draft_version_path(process, draft_version) %>
    • <% end %>
    diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index 8fef62213..a888a8427 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -37,7 +37,7 @@ feature 'Legislation Draft Versions' do within('select#draft_version_id') do expect(page).to have_content("Version 1") expect(page).to have_content("Version 2") - expect(page).to_not have_content("Version 3") + expect(page).to have_content("Version 3") end end @@ -93,7 +93,7 @@ feature 'Legislation Draft Versions' do within('select#draft_version_id') do expect(page).to have_content("Version 1") expect(page).to have_content("Version 2") - expect(page).to_not have_content("Version 3") + expect(page).to have_content("Version 3") end end From c935373c07b144ae4320f18715e654acd5795e5b Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 4 Jan 2017 10:14:58 +0100 Subject: [PATCH 066/197] Remove draft version preview buttons from edit form and add link to index --- app/views/admin/legislation/draft_versions/_form.html.erb | 4 ---- app/views/admin/legislation/draft_versions/index.html.erb | 2 +- config/locales/admin.en.yml | 1 + config/locales/admin.es.yml | 1 + 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index 4969d992a..be3c5067f 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -69,7 +69,6 @@
    Consul | Editando Versión 3 del proceso Licencias urbanísticas, declaraciones
    - Previsualizar <%= f.submit(class: "button", value: t("admin.legislation.draft_versions.#{admin_submit_action(@draft_version)}.submit_button")) %>
    @@ -89,8 +88,5 @@
    <%= f.submit(class: "button expanded", value: t("admin.legislation.draft_versions.#{admin_submit_action(@draft_version)}.submit_button")) %>
    -
    <% end %> diff --git a/app/views/admin/legislation/draft_versions/index.html.erb b/app/views/admin/legislation/draft_versions/index.html.erb index d86b61e26..6d9418c99 100644 --- a/app/views/admin/legislation/draft_versions/index.html.erb +++ b/app/views/admin/legislation/draft_versions/index.html.erb @@ -40,7 +40,7 @@ <%= link_to draft_version.title, edit_admin_legislation_process_draft_version_path(@process, draft_version) %> <%= draft_version.created_at.to_date %> - <%= draft_version.status %> + <%= draft_version.status %> <%= link_to "(#{t('.preview')})", legislation_process_draft_version_path(@process, draft_version) if draft_version.status == 'draft' %> <%#= draft_version.comments %> <%= draft_version.final_version %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index eef45e8ac..a0896d6c4 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -137,6 +137,7 @@ en: title: Draft versions create: Create version delete: Delete + preview: Preview new: back: Back title: Create new version diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index d2d8e5685..94676c9f0 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -135,6 +135,7 @@ es: title: Versiones del borrador create: Crear versión delete: Borrar + preview: Previsualizar new: back: Volver title: Crear nueva versión From 375602d29710ff1f213f405e923e725cd26cc4d7 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 4 Jan 2017 12:13:19 +0100 Subject: [PATCH 067/197] Display title with an * when status is draft in version chooser --- app/models/legislation/draft_version.rb | 4 ++++ app/views/legislation/draft_versions/changes.html.erb | 2 +- app/views/legislation/draft_versions/show.html.erb | 2 +- spec/features/legislation/draft_versions_spec.rb | 4 ++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 3cbbce567..29b22e5a6 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -21,4 +21,8 @@ class Legislation::DraftVersion < ActiveRecord::Base self.body_html = Redcarpet::Markdown.new(renderer).render(body) self.toc_html = Redcarpet::Markdown.new(toc_renderer).render(body) end + + def display_title + status == 'draft' ? "#{title} *" : title + end end diff --git a/app/views/legislation/draft_versions/changes.html.erb b/app/views/legislation/draft_versions/changes.html.erb index 0f98ad12d..0f2015cda 100644 --- a/app/views/legislation/draft_versions/changes.html.erb +++ b/app/views/legislation/draft_versions/changes.html.erb @@ -11,7 +11,7 @@

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

    <%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %> - <%= select_tag "draft_version_id", options_from_collection_for_select(@draft_versions_list, 'id', 'title', @draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %> + <%= select_tag "draft_version_id", options_from_collection_for_select(@draft_versions_list, 'id', 'display_title', @draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %> <%= hidden_field_tag "redirect_action", "changes" %> <%= submit_tag t('legislation.draft_versions.show.select_version_submit'), class: "button" %> <% end %> diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index 5635e335a..5ff3a76ba 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -11,7 +11,7 @@

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

    <%= form_tag go_to_version_legislation_process_draft_versions_path(@process), method: :get, id: "draft_version_go_to_version" do %> - <%= select_tag "draft_version_id", options_from_collection_for_select(@draft_versions_list, 'id', 'title', @draft_version.id), "aria-label": t('.select_draft_version') %> + <%= select_tag "draft_version_id", options_from_collection_for_select(@draft_versions_list, 'id', 'display_title', @draft_version.id), "aria-label": t('.select_draft_version') %> <%= submit_tag t('.select_version_submit'), class: "button" %> <% end %> <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %> diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index a888a8427..594cb8cdc 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -37,7 +37,7 @@ feature 'Legislation Draft Versions' do within('select#draft_version_id') do expect(page).to have_content("Version 1") expect(page).to have_content("Version 2") - expect(page).to have_content("Version 3") + expect(page).to have_content("Version 3 *") end end @@ -93,7 +93,7 @@ feature 'Legislation Draft Versions' do within('select#draft_version_id') do expect(page).to have_content("Version 1") expect(page).to have_content("Version 2") - expect(page).to have_content("Version 3") + expect(page).to have_content("Version 3 *") end end From 39633dce67926dee47c5dfc7652541e1b1943609 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 4 Jan 2017 12:39:09 +0100 Subject: [PATCH 068/197] Fix back links in admin --- app/views/admin/legislation/draft_versions/edit.html.erb | 2 +- app/views/admin/legislation/draft_versions/new.html.erb | 2 +- app/views/admin/legislation/questions/edit.html.erb | 2 +- app/views/admin/legislation/questions/new.html.erb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/admin/legislation/draft_versions/edit.html.erb b/app/views/admin/legislation/draft_versions/edit.html.erb index 0a27ccd97..5ad6d9501 100644 --- a/app/views/admin/legislation/draft_versions/edit.html.erb +++ b/app/views/admin/legislation/draft_versions/edit.html.erb @@ -4,7 +4,7 @@
    - <%= link_to admin_legislation_processes_path, class: "back" do %> + <%= link_to admin_legislation_process_draft_versions_path(@process), class: "back" do %> <%= t("admin.legislation.draft_versions.edit.back") %> <% end %> diff --git a/app/views/admin/legislation/draft_versions/new.html.erb b/app/views/admin/legislation/draft_versions/new.html.erb index e71bab339..b43bfc276 100644 --- a/app/views/admin/legislation/draft_versions/new.html.erb +++ b/app/views/admin/legislation/draft_versions/new.html.erb @@ -4,7 +4,7 @@
    - <%= link_to admin_legislation_process_path(@process), class: "back" do %> + <%= link_to admin_legislation_process_draft_versions_path(@process), class: "back" do %> <%= t("admin.legislation.draft_versions.new.back") %> <% end %> diff --git a/app/views/admin/legislation/questions/edit.html.erb b/app/views/admin/legislation/questions/edit.html.erb index d3f1f2df8..47b44b11a 100644 --- a/app/views/admin/legislation/questions/edit.html.erb +++ b/app/views/admin/legislation/questions/edit.html.erb @@ -4,7 +4,7 @@
    - <%= link_to admin_legislation_processes_path, class: "back" do %> + <%= link_to admin_legislation_process_questions_path(@process), class: "back" do %> <%= t("admin.legislation.questions.edit.back") %> <% end %> diff --git a/app/views/admin/legislation/questions/new.html.erb b/app/views/admin/legislation/questions/new.html.erb index 4c657f92d..243815aff 100644 --- a/app/views/admin/legislation/questions/new.html.erb +++ b/app/views/admin/legislation/questions/new.html.erb @@ -4,7 +4,7 @@
    - <%= link_to admin_legislation_process_path(@process), class: "back" do %> + <%= link_to admin_legislation_process_questions_path(@process), class: "back" do %> <%= t("admin.legislation.questions.new.back") %> <% end %> From ee9fa3db151ca18b553bc6697acd5caf48373310 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 3 Jan 2017 18:03:29 +0100 Subject: [PATCH 069/197] Base Legislation Annotations --- app/assets/javascripts/application.js | 6 ++- ...ffee => legislation_allegations.js.coffee} | 6 +-- .../legislation_annotatable.js.coffee | 38 +++++++++++++++++ .../legislation/annotations_controller.rb | 32 +++++++++++++++ app/models/abilities/everyone.rb | 1 + app/models/legislation/annotation.rb | 6 +++ .../legislation/draft_versions/show.html.erb | 7 +++- config/routes.rb | 4 +- ...03125835_create_legislation_annotations.rb | 16 ++++++++ db/schema.rb | 17 +++++++- spec/factories.rb | 12 ++++++ .../legislation/draft_versions_spec.rb | 41 +++++++++++++++++++ 12 files changed, 178 insertions(+), 8 deletions(-) rename app/assets/javascripts/{allegations.js.coffee => legislation_allegations.js.coffee} (74%) create mode 100644 app/assets/javascripts/legislation_annotatable.js.coffee create mode 100644 app/controllers/legislation/annotations_controller.rb create mode 100644 app/models/legislation/annotation.rb create mode 100644 db/migrate/20170103125835_create_legislation_annotations.rb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 01e74400a..b9d072f5a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -49,8 +49,9 @@ //= require markdown-it //= require markdown_editor //= require cocoon -//= require allegations //= require legislation +//= require legislation_allegations +//= require legislation_annotatable //= require custom var initialize_modules = function() { @@ -74,8 +75,9 @@ var initialize_modules = function() { App.Banners.initialize(); App.SocialShare.initialize(); App.MarkdownEditor.initialize(); - App.Allegations.initialize(); + App.LegislationAllegations.initialize(); App.Legislation.initialize(); + App.LegislationAnnotatable.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/allegations.js.coffee b/app/assets/javascripts/legislation_allegations.js.coffee similarity index 74% rename from app/assets/javascripts/allegations.js.coffee rename to app/assets/javascripts/legislation_allegations.js.coffee index d57fa30ed..e01a8b5d4 100644 --- a/app/assets/javascripts/allegations.js.coffee +++ b/app/assets/javascripts/legislation_allegations.js.coffee @@ -1,4 +1,4 @@ -App.Allegations = +App.LegislationAllegations = toggle_comments: -> $('.draft-allegation').toggleClass('comments-on'); @@ -8,10 +8,10 @@ App.Allegations = click: (e) -> e.preventDefault(); e.stopPropagation(); - App.Allegations.toggle_comments() + App.LegislationAllegations.toggle_comments() $('.js-toggle-allegations').on click: (e) -> # Toggle comments when the section title is visible if $(this).find('.draft-panel .panel-title:visible').length == 0 - App.Allegations.toggle_comments() + App.LegislationAllegations.toggle_comments() diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee new file mode 100644 index 000000000..fa5df598a --- /dev/null +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -0,0 +1,38 @@ +_t = (key) -> new Gettext().gettext(key) + +App.LegislationAnnotatable = + initialize: -> + current_user_id = $('html').data('current-user-id') + if current_user_id == "" + annotator.ui.editor.Editor.template = [ + '
    ', + '
    ', + ' ' + _t('Unregistered'), + '
    ', + ' ' + _t('Cancel') + '', + '
    ', + '
    ', + '
    ' + ].join('\n') + + $(".legislation-annotatable").each -> + $this = $(this) + ann_type = "legislation_draft_version" + ann_id = $this.data("legislation-draft-version-id") + base_url = $this.data("legislation-annotatable-base-url") + + app = new annotator.App() + .include -> + beforeAnnotationCreated: (ann) -> + ann["legislation_draft_version_id"] = ann_id + ann.permissions = ann.permissions || {} + ann.permissions.admin = [] + .include(annotator.ui.main, { element: this }) + .include(annotator.storage.http, { prefix: base_url, urls: { search: "/annotations/search" } }) + + app.start().then -> + app.ident.identity = current_user_id + + options = {} + options["legislation_draft_version_id"] = ann_id + app.annotations.load(options) diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb new file mode 100644 index 000000000..7e053f510 --- /dev/null +++ b/app/controllers/legislation/annotations_controller.rb @@ -0,0 +1,32 @@ +class Legislation::AnnotationsController < ApplicationController + skip_before_action :verify_authenticity_token + + before_action :authenticate_user!, only: [:create] + + load_and_authorize_resource :process + load_and_authorize_resource :draft_version, through: :process + load_and_authorize_resource + + def create + @annotation = Legislation::Annotation.new(annotation_params) + @annotation.user = current_user + if @annotation.save + render json: @annotation.to_json + end + end + + def search + @annotations = Legislation::Annotation.where(legislation_draft_version_id: params[:legislation_draft_version_id]) + annotations_hash = { total: @annotations.size, rows: @annotations } + render json: annotations_hash.to_json + end + + private + + def annotation_params + params + .require(:annotation) + .permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset]) + .merge(legislation_draft_version_id: params[:legislation_draft_version_id]) + end +end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index b71e1f7d5..e29880e95 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -15,6 +15,7 @@ module Abilities can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer + can [:search, :read, :create], Legislation::Annotation end end end diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb new file mode 100644 index 000000000..365f84ad0 --- /dev/null +++ b/app/models/legislation/annotation.rb @@ -0,0 +1,6 @@ +class Legislation::Annotation < ActiveRecord::Base + serialize :ranges, Array + + belongs_to :draft_version, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_draft_version_id' + belongs_to :user +end diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index 5ff3a76ba..8ab20eea9 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -44,7 +44,12 @@
    <%= t('.text_body') %>
    - <%= @draft_version.body_html.html_safe %> +
    + <%= @draft_version.body_html.html_safe %> +
    diff --git a/config/routes.rb b/config/routes.rb index 0ef0187f6..956b68f32 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -101,7 +101,9 @@ Rails.application.routes.draw do resources :draft_versions, only: [:show] do get :go_to_version, on: :collection get :changes - resources :annotations + resources :annotations do + get :search, on: :collection + end end end end diff --git a/db/migrate/20170103125835_create_legislation_annotations.rb b/db/migrate/20170103125835_create_legislation_annotations.rb new file mode 100644 index 000000000..723bf3813 --- /dev/null +++ b/db/migrate/20170103125835_create_legislation_annotations.rb @@ -0,0 +1,16 @@ +class CreateLegislationAnnotations < ActiveRecord::Migration + def change + create_table :legislation_annotations do |t| + t.string :quote + t.text :ranges + t.text :text + + t.references :legislation_draft_version, index: true + t.references :user, index: true + + t.datetime :hidden_at, index: true + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index d949dbb3a..39e3ec56c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20161229213217) do +ActiveRecord::Schema.define(version: 20170103125835) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -228,6 +228,21 @@ ActiveRecord::Schema.define(version: 20161229213217) do t.datetime "updated_at", null: false end + create_table "legislation_annotations", force: :cascade do |t| + t.string "quote" + t.text "ranges" + t.text "text" + t.integer "legislation_draft_version_id" + t.integer "user_id" + t.datetime "hidden_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + add_index "legislation_annotations", ["hidden_at"], name: "index_legislation_annotations_on_hidden_at", using: :btree + add_index "legislation_annotations", ["legislation_draft_version_id"], name: "index_legislation_annotations_on_legislation_draft_version_id", using: :btree + add_index "legislation_annotations", ["user_id"], name: "index_legislation_annotations_on_user_id", using: :btree + create_table "legislation_answers", force: :cascade do |t| t.integer "legislation_question_id" t.integer "legislation_question_option_id" diff --git a/spec/factories.rb b/spec/factories.rb index 731e1fef1..fe0750756 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -399,6 +399,18 @@ FactoryGirl.define do status "draft" final_version false body "Body of the legislation text" + + trait :published do + status "published" + end + end + + factory :legislation_annotation, class: 'Legislation::Annotation' do + draft_version factory: :legislation_draft_version + user + quote "ipsum" + text "Loremp ipsum dolor" + ranges [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}] end factory :legislation_question, class: 'Legislation::Question' do diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index 594cb8cdc..7df1939be 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -119,4 +119,45 @@ feature 'Legislation Draft Versions' do end end + context 'Annotations', :js do + let(:user) { create(:user) } + background { login_as user } + + scenario 'Create' do + draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) + + visit legislation_process_draft_version_path(draft_version.process, draft_version) + + page.find(:css, ".legislation-annotatable").double_click + page.find(:css, ".annotator-adder button").click + fill_in 'annotator-field-0', with: 'this is my annotation' + page.find(:css, ".annotator-controls a[href='#save']").click + + expect(page).to have_css ".annotator-hl" + first(:css, ".annotator-hl").click + expect(page).to have_content "this is my annotation" + + visit legislation_process_draft_version_path(draft_version.process, draft_version) + + expect(page).to have_css ".annotator-hl" + first(:css, ".annotator-hl").click + expect(page).to have_content "this is my annotation" + end + + scenario 'Search' do + draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) + annotation1 = create(:legislation_annotation, draft_version: draft_version, text: "my annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>5, "end"=>"/p[1]", "endOffset"=>10}]) + annotation2 = create(:legislation_annotation, draft_version: draft_version, text: "my other annotation", ranges: [{"start"=>"/p[1]", "startOffset"=>12, "end"=>"/p[1]", "endOffset"=>19}]) + + visit legislation_process_draft_version_path(draft_version.process, draft_version) + + expect(page).to have_css ".annotator-hl" + first(:css, ".annotator-hl").click + expect(page).to have_content "my annotation" + + all(".annotator-hl")[1].click + expect(page).to have_content "my other annotation" + end + end + end From 2b6df62dd74906b51a06d971841db5af5d256aae Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 4 Jan 2017 11:27:47 +0100 Subject: [PATCH 070/197] Refactor process phases pages --- .../legislation/processes_controller.rb | 36 ++++++++++++++++++- .../processes/_phase_allegations.html.erb | 9 ----- .../_phase_draft_publication.html.erb | 9 ----- .../_phase_final_version_publication.html.erb | 5 --- .../processes/_phase_not_open.html.erb | 13 ------- .../{phase.html.erb => phase_empty.html.erb} | 6 +--- .../processes/phase_not_open.html.erb | 25 +++++++++++++ app/views/legislation/processes/show.html.erb | 6 +--- config/locales/en.yml | 8 ++--- config/locales/es.yml | 8 ++--- spec/features/legislation/processes_spec.rb | 6 ++-- 11 files changed, 69 insertions(+), 62 deletions(-) delete mode 100644 app/views/legislation/processes/_phase_allegations.html.erb delete mode 100644 app/views/legislation/processes/_phase_draft_publication.html.erb delete mode 100644 app/views/legislation/processes/_phase_final_version_publication.html.erb delete mode 100644 app/views/legislation/processes/_phase_not_open.html.erb rename app/views/legislation/processes/{phase.html.erb => phase_empty.html.erb} (60%) create mode 100644 app/views/legislation/processes/phase_not_open.html.erb diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 05b7fbeae..1b51cec07 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -8,18 +8,53 @@ class Legislation::ProcessesController < Legislation::BaseController end def show + if @process.show_phase?(:debate) + render :show + else + render :phase_not_open + end end def draft_publication phase :draft_publication + + if @process.show_phase?(@phase) + if draft_version = @process.draft_versions.published.last + redirect_to legislation_process_draft_version_path(@process, draft_version) + else + render :phase_empty + end + else + render :phase_not_open + end end def allegations phase :allegations + + if @process.show_phase?(@phase) + if draft_version = @process.draft_versions.published.last + redirect_to legislation_process_draft_version_path(@process, draft_version) + else + render :phase_empty + end + else + render :phase_not_open + end end def final_version_publication phase :final_version_publication + + if @process.show_phase?(@phase) + if final_version = @process.final_draft_version + redirect_to legislation_process_draft_version_path(@process, final_version) + else + render :phase_empty + end + else + render :phase_not_open + end end private @@ -27,6 +62,5 @@ class Legislation::ProcessesController < Legislation::BaseController def phase(phase) @process = ::Legislation::Process.find(params[:process_id]) @phase = phase - render :phase end end diff --git a/app/views/legislation/processes/_phase_allegations.html.erb b/app/views/legislation/processes/_phase_allegations.html.erb deleted file mode 100644 index 0087b9ca5..000000000 --- a/app/views/legislation/processes/_phase_allegations.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<% if process.draft_versions.any? %> -
      - <% process.draft_versions.published.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 deleted file mode 100644 index 0087b9ca5..000000000 --- a/app/views/legislation/processes/_phase_draft_publication.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -<% if process.draft_versions.any? %> -
      - <% process.draft_versions.published.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 deleted file mode 100644 index 52fba50d5..000000000 --- a/app/views/legislation/processes/_phase_final_version_publication.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -<% 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 deleted file mode 100644 index 354ff5440..000000000 --- a/app/views/legislation/processes/_phase_not_open.html.erb +++ /dev/null @@ -1,13 +0,0 @@ -
    -
    -

    <%= 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/phase.html.erb b/app/views/legislation/processes/phase_empty.html.erb similarity index 60% rename from app/views/legislation/processes/phase.html.erb rename to app/views/legislation/processes/phase_empty.html.erb index 04ee25523..427339b82 100644 --- a/app/views/legislation/processes/phase.html.erb +++ b/app/views/legislation/processes/phase_empty.html.erb @@ -7,11 +7,7 @@
    - <% if @process.show_phase?(@phase) %> - <%= render "phase_#{@phase}", process: @process %> - <% else %> - <%= render 'legislation/processes/phase_not_open' %> - <% end %> +

    <%= t(".empty") %>

    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..6bd82c969 --- /dev/null +++ b/app/views/legislation/processes/phase_not_open.html.erb @@ -0,0 +1,25 @@ +<% provide :title do %><%= @process.title %><% end %> + +<%= render 'legislation/processes/header_full', process: @process %> + +
    + <%= render 'legislation/processes/key_dates', process: @process, phase: @phase %> + +
    +
    +
    +
    +

    <%= 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/show.html.erb b/app/views/legislation/processes/show.html.erb index 471410b58..b24f7668b 100644 --- a/app/views/legislation/processes/show.html.erb +++ b/app/views/legislation/processes/show.html.erb @@ -7,11 +7,7 @@
    - <% if @process.show_phase?(:debate) %> - <%= render 'debate', process: @process %> - <% else %> - <%= render 'phase_not_open' %> - <% end %> + <%= render 'debate', process: @process %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index 8fa1cf13f..0e1a2c829 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -256,12 +256,8 @@ en: 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 + phase_empty: + empty: Nothing published yet process: see_latest_comments: See latest comments see_latest_comments_title: Comment on this process diff --git a/config/locales/es.yml b/config/locales/es.yml index a93d44d2e..3459f3494 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -256,12 +256,8 @@ es: 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 + phase_empty: + empty: No hay nada publicado todavía process: see_latest_comments: Ver últimas aportaciones see_latest_comments_title: Aportar a este proceso diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index 818717757..8ae51c559 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -69,7 +69,7 @@ feature 'Legislation' do visit legislation_process_draft_publication_path(process) - expect(page).to have_content("There are no drafts published") + expect(page).to have_content("Nothing published yet") end end @@ -87,7 +87,7 @@ feature 'Legislation' do visit legislation_process_allegations_path(process) - expect(page).to have_content("There are no drafts published") + expect(page).to have_content("Nothing published yet") end end @@ -105,7 +105,7 @@ feature 'Legislation' do visit legislation_process_final_version_publication_path(process) - expect(page).to have_content("Results have not been published yet") + expect(page).to have_content("Nothing published yet") end end end From bc1905e5d9b09e5654ef128872d543c799d504dd Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 4 Jan 2017 18:13:28 +0100 Subject: [PATCH 071/197] Validate date ranges for legislation process Only validates start and end dates for the whole process or a phase, not overlap between phases, as they are permitted, at least for now. --- app/models/legislation/process.rb | 10 +++++++ config/locales/activerecord.en.yml | 8 ++++++ config/locales/activerecord.es.yml | 8 ++++++ spec/models/legislation/process_spec.rb | 35 +++++++++++++++++++++++++ 4 files changed, 61 insertions(+) diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 566ff075e..4a50b4b0a 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -18,6 +18,7 @@ class Legislation::Process < ActiveRecord::Base validates :allegations_start_date, presence: true validates :allegations_end_date, presence: true validates :final_publication_date, presence: true + validate :valid_date_ranges scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current).order('id DESC') } scope :next, -> { where("start_date > ?", Date.current).order('id DESC') } @@ -57,4 +58,13 @@ class Legislation::Process < ActiveRecord::Base def total_comments questions.map(&:comments_count).sum 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 + end + end diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index e3747d151..e99979143 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -127,6 +127,14 @@ en: attributes: max_per_day: invalid: "You have reached the maximum number of private messages per day" + legislation/process: + attributes: + end_date: + invalid_date_range: must be on or after the start date + debate_end_date: + invalid_date_range: must be on or after the debate start date + allegations_end_date: + invalid_date_range: must be on or after the allegations start date proposal: attributes: tag_list: diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index 479c3c004..3894e4b08 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -127,6 +127,14 @@ es: attributes: max_per_day: invalid: "Has llegado al número máximo de mensajes privados por día" + legislation/process: + attributes: + end_date: + invalid_date_range: tiene que ser igual o posterior a la fecha de inicio + debate_end_date: + invalid_date_range: tiene que ser igual o posterior a la fecha de inicio del debate + allegations_end_date: + invalid_date_range: tiene que ser igual o posterior a la fecha de inicio de las alegaciones proposal: attributes: tag_list: diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index 8db980327..4fbfeb587 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -7,6 +7,41 @@ RSpec.describe Legislation::Process, type: :model do expect(legislation_process).to be_valid 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) + expect(process).to be_invalid + expect(process.errors.messages[:end_date]).to include("must be on or after the start date") + end + + it "is valid if end_date is the same as start_date" do + process = build(:legislation_process, start_date: Date.current - 1.day, end_date: Date.current - 1.day) + expect(process).to be_valid + end + + it "is invalid if debate_end_date is before debate start_date" do + process = build(:legislation_process, debate_start_date: Date.current, debate_end_date: Date.current - 1.day) + expect(process).to be_invalid + expect(process.errors.messages[:debate_end_date]).to include("must be on or after the debate start date") + end + + it "is valid if debate_end_date is the same as debate_start_date" do + process = build(:legislation_process, debate_start_date: Date.current - 1.day, debate_end_date: Date.current - 1.day) + expect(process).to be_valid + end + + it "is invalid if allegations_end_date is before allegations_start_date" do + process = build(:legislation_process, allegations_start_date: Date.current, allegations_end_date: Date.current - 1.day) + expect(process).to be_invalid + expect(process.errors.messages[:allegations_end_date]).to include("must be on or after the allegations start date") + end + + it "is valid if allegations_end_date is the same as allegations_start_date" do + process = build(:legislation_process, allegations_start_date: Date.current - 1.day, allegations_end_date: Date.current - 1.day) + expect(process).to be_valid + end + end + describe "filter scopes" do before(:each) do @process_1 = create(:legislation_process, start_date: Date.current - 2.days, end_date: Date.current + 1.day) From 0c5063add9daec0402d2abcfb5aa18085da5685a Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 09:36:08 +0100 Subject: [PATCH 072/197] Show message when there aren't processes --- app/views/legislation/processes/index.html.erb | 8 ++++++-- config/locales/en.yml | 3 +++ config/locales/es.yml | 3 +++ spec/features/legislation/processes_spec.rb | 11 +++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) 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/config/locales/en.yml b/config/locales/en.yml index 0e1a2c829..f192a441c 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -254,6 +254,9 @@ en: open: Open processes next: Next past: Past + no_open_processes: There aren't open processes + no_next_processes: There aren't planned processes + no_past_processes: There aren't past processes phase_not_open: not_open: This phase is not open yet phase_empty: diff --git a/config/locales/es.yml b/config/locales/es.yml index 3459f3494..eabc14e48 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -254,6 +254,9 @@ es: open: Procesos activos next: Próximamente past: Terminados + no_open_processes: No hay procesos activos + no_next_processes: No hay procesos planeados + no_past_processes: No hay procesos terminados phase_not_open: not_open: Esta fase del proceso todavía no está abierta phase_empty: diff --git a/spec/features/legislation/processes_spec.rb b/spec/features/legislation/processes_spec.rb index 8ae51c559..66356dff8 100644 --- a/spec/features/legislation/processes_spec.rb +++ b/spec/features/legislation/processes_spec.rb @@ -4,6 +4,17 @@ feature 'Legislation' do context 'processes home page' do + scenario 'Processes can be listed' do + visit legislation_processes_path + expect(page).to have_text "There aren't open processes" + + visit legislation_processes_path(filter: 'next') + expect(page).to have_text "There aren't planned processes" + + visit legislation_processes_path(filter: 'past') + expect(page).to have_text "There aren't past processes" + end + scenario 'Processes can be listed' do processes = create_list(:legislation_process, 3) From fba4c79d2abf6c9a0f02d95e88441240ea46e6bc Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 09:43:40 +0100 Subject: [PATCH 073/197] Show the first paragraph of the description --- app/helpers/text_helper.rb | 9 +++++++++ .../legislation/processes/_process.html.erb | 2 +- spec/helpers/text_helper_spec.rb | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/helpers/text_helper.rb create mode 100644 spec/helpers/text_helper_spec.rb 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/views/legislation/processes/_process.html.erb b/app/views/legislation/processes/_process.html.erb index 9eac89a7b..a5780f792 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 %>

    + <%= simple_format(first_paragraph(process.description)) %>
    diff --git a/spec/helpers/text_helper_spec.rb b/spec/helpers/text_helper_spec.rb new file mode 100644 index 000000000..cc9300b7f --- /dev/null +++ b/spec/helpers/text_helper_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +describe TextHelper do + + describe "#first_paragraph" do + it "should return the first paragraph of a text" do + text = "\n\nThis is the first paragraph\n\nThis is the second paragraph\n" + expect(first_paragraph(text)).to eq("This is the first paragraph") + end + + it "should return blank if the text is blank" do + expect(first_paragraph("")).to eq("") + expect(first_paragraph(nil)).to eq("") + end + end + +end From 814cf9df564c9b5f8075c8fe2da04bcb3bd298f4 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 10:22:40 +0100 Subject: [PATCH 074/197] Show creation date and status in admin list --- app/models/legislation/process.rb | 12 +++++++ .../legislation/processes/index.html.erb | 4 +++ config/locales/admin.en.yml | 5 +++ config/locales/admin.es.yml | 5 +++ spec/models/legislation/process_spec.rb | 35 ++++++++++--------- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 4a50b4b0a..0a264203c 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -59,6 +59,18 @@ class Legislation::Process < ActiveRecord::Base questions.map(&:comments_count).sum 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 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/config/locales/admin.en.yml b/config/locales/admin.en.yml index a0896d6c4..efef17210 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -113,6 +113,11 @@ en: process: title: Process comments: Comments + status: Status + creation_date: Creation date + status_open: Open + status_closed: Closed + status_planned: Planned subnav: info: Information draft_texts: Text diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 94676c9f0..92503fa68 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -111,6 +111,11 @@ es: process: title: Proceso comments: Comentarios + status: Estado + creation_date: Fecha creación + status_open: Abierto + status_closed: Cerrado + status_planned: Próximamente subnav: info: Información draft_texts: Texto diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index 4fbfeb587..fd83d8989 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -1,10 +1,10 @@ require 'rails_helper' RSpec.describe Legislation::Process, type: :model do - let(:legislation_process) { build(:legislation_process) } + let(:process) { create(:legislation_process) } it "should be valid" do - expect(legislation_process).to be_valid + expect(process).to be_valid end describe "date ranges validations" do @@ -76,8 +76,6 @@ RSpec.describe Legislation::Process, type: :model do 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 @@ -96,7 +94,6 @@ RSpec.describe Legislation::Process, type: :model do 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) @@ -116,8 +113,6 @@ RSpec.describe Legislation::Process, type: :model do 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 @@ -132,8 +127,6 @@ RSpec.describe Legislation::Process, type: :model do 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 @@ -150,8 +143,6 @@ RSpec.describe Legislation::Process, type: :model do 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 @@ -170,8 +161,6 @@ RSpec.describe Legislation::Process, type: :model do 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 @@ -190,8 +179,6 @@ RSpec.describe Legislation::Process, type: :model do 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 @@ -206,8 +193,6 @@ RSpec.describe Legislation::Process, type: :model do 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 @@ -221,4 +206,20 @@ RSpec.describe Legislation::Process, type: :model do expect(process.show_phase?(:final_version_publication)).to be true end end + + describe "#status" do + it "should detect planned phase" do + process.update_attributes(start_date: Date.current + 2.days) + expect(process.status).to eq(:planned) + end + + it "should detect closed phase" do + process.update_attributes(end_date: Date.current - 2.days) + expect(process.status).to eq(:closed) + end + + it "should detect open phase" do + expect(process.status).to eq(:open) + end + end end From 48764d757c7a8c95e08333a388c33f76f3ae3b00 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 10:29:21 +0100 Subject: [PATCH 075/197] Fix label markup --- app/views/admin/legislation/draft_versions/_form.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 %> From 7100156b2849fdab5c733e8b08f81a24922fe345 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 10:55:53 +0100 Subject: [PATCH 076/197] Show full header when click on expand button --- app/assets/javascripts/legislation.js.coffee | 7 ++++++ .../draft_versions/_process_header.html.erb | 19 -------------- .../draft_versions/changes.html.erb | 2 +- .../legislation/draft_versions/show.html.erb | 2 +- .../legislation/processes/_header.html.erb | 25 +++++++++++++++++++ .../processes/_header_full.html.erb | 2 +- .../processes/phase_empty.html.erb | 2 +- .../processes/phase_not_open.html.erb | 2 +- app/views/legislation/processes/show.html.erb | 2 +- 9 files changed, 38 insertions(+), 25 deletions(-) delete mode 100644 app/views/legislation/draft_versions/_process_header.html.erb create mode 100644 app/views/legislation/processes/_header.html.erb 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/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..ecbd17dcd --- /dev/null +++ b/app/views/legislation/processes/_header.html.erb @@ -0,0 +1,25 @@ +<% 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/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 %> From ba0089ac44b6b1720d09c4f15212b8c6bcf1ce92 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 11:05:45 +0100 Subject: [PATCH 077/197] Truncate social networks text --- app/views/legislation/questions/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index be8e90445..6401359c0 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -32,7 +32,7 @@

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

    +<% elsif !@process.open_phase?(:debate) %> + <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 95cc42db4..a28c03910 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -295,6 +295,7 @@ en: unauthenticated: You must %{signin} or %{signup} to participate. verified_only: Only verified users can participate, %{verify_account}. verify_account: verify your account + debate_phase_not_open: Debate phase has finished and answers are not accepted anymore locale: English notifications: index: diff --git a/config/locales/es.yml b/config/locales/es.yml index 3a2cf0faa..9424c42f3 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -295,6 +295,7 @@ es: unauthenticated: Necesitas %{signin} o %{signup} para participar en el debate. verified_only: Solo los usuarios verificados pueden participar en el debate, %{verify_account}. verify_account: verifica tu cuenta + debate_phase_not_open: La fase de debate previo ya ha finalizado y en este momento no se aceptan respuestas locale: Español notifications: index: From dc3a917877fa3aeaa2cf5abd3ca51583911e66de Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 16:46:53 +0100 Subject: [PATCH 084/197] Add missing translation --- app/views/legislation/processes/_header.html.erb | 3 +-- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/legislation/processes/_header.html.erb b/app/views/legislation/processes/_header.html.erb index ecbd17dcd..c73c732af 100644 --- a/app/views/legislation/processes/_header.html.erb +++ b/app/views/legislation/processes/_header.html.erb @@ -11,9 +11,8 @@
    - diff --git a/config/locales/en.yml b/config/locales/en.yml index a28c03910..fdc7e4e0e 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -239,6 +239,8 @@ en: text_body: Text text_comments: Comments processes: + header: + view_process_information: View process information debate: empty_questions: There aren't any questions participate: Participate in the debate diff --git a/config/locales/es.yml b/config/locales/es.yml index 9424c42f3..f9ec8596b 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -239,6 +239,8 @@ es: text_body: Texto text_comments: Comentarios processes: + header: + view_process_information: Ver información del proceso debate: empty_questions: No hay preguntas participate: Realiza tus aportaciones al debate previo participando en los siguientes temas. From 13c49c1f75542098eacd5606a060e85bdbda116d Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 16:49:18 +0100 Subject: [PATCH 085/197] Format text with markdown --- app/views/legislation/processes/_process.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/legislation/processes/_process.html.erb b/app/views/legislation/processes/_process.html.erb index a5780f792..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 %>

    - <%= simple_format(first_paragraph(process.description)) %> + <%= markdown(first_paragraph(process.description)) %>
    From 1fbb10ff34974267da7c89792435a4f40bc9f946 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 17:03:08 +0100 Subject: [PATCH 086/197] Include link to resource in the flash message --- .../admin/legislation/draft_versions_controller.rb | 4 ++-- .../admin/legislation/processes_controller.rb | 4 ++-- .../admin/legislation/questions_controller.rb | 4 ++-- app/views/layouts/_flash.html.erb | 2 +- config/locales/admin.en.yml | 12 ++++++------ config/locales/admin.es.yml | 12 ++++++------ 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/controllers/admin/legislation/draft_versions_controller.rb b/app/controllers/admin/legislation/draft_versions_controller.rb index 6eabf7e79..0d84addbf 100644 --- a/app/controllers/admin/legislation/draft_versions_controller.rb +++ b/app/controllers/admin/legislation/draft_versions_controller.rb @@ -8,7 +8,7 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont def create if @draft_version.save - redirect_to admin_legislation_process_draft_versions_path, notice: t('admin.legislation.draft_versions.create.notice') + 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 @@ -17,7 +17,7 @@ class Admin::Legislation::DraftVersionsController < Admin::Legislation::BaseCont def update if @draft_version.update(draft_version_params) - redirect_to edit_admin_legislation_process_draft_version_path(@process, @draft_version), notice: t('admin.legislation.draft_versions.update.notice') + 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 diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 46aa0944b..8cc678151 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -9,7 +9,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll def create if @process.save - redirect_to edit_admin_legislation_process_path(@process), notice: t('admin.legislation.processes.create.notice') + 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 @@ -18,7 +18,7 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll def update if @process.update(process_params) - redirect_to edit_admin_legislation_process_path(@process), notice: t('admin.legislation.processes.update.notice') + 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 diff --git a/app/controllers/admin/legislation/questions_controller.rb b/app/controllers/admin/legislation/questions_controller.rb index 1c9c4e2ec..c8335e6df 100644 --- a/app/controllers/admin/legislation/questions_controller.rb +++ b/app/controllers/admin/legislation/questions_controller.rb @@ -13,7 +13,7 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll def create @question.author = current_user if @question.save - redirect_to admin_legislation_process_questions_path, notice: t('admin.legislation.questions.create.notice') + 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 @@ -22,7 +22,7 @@ class Admin::Legislation::QuestionsController < Admin::Legislation::BaseControll def update if @question.update(question_params) - redirect_to edit_admin_legislation_process_question_path(@process, @question), notice: t('admin.legislation.questions.update.notice') + 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 diff --git a/app/views/layouts/_flash.html.erb b/app/views/layouts/_flash.html.erb index 9f55b449a..5be4a3186 100644 --- a/app/views/layouts/_flash.html.erb +++ b/app/views/layouts/_flash.html.erb @@ -5,7 +5,7 @@
    - <%= flash_message %> + <%= flash_message.html_safe %>
    diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index 30eba7c98..6362828bd 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -85,10 +85,10 @@ en: legislation: processes: create: - notice: Process created successfully + notice: 'Process created successfully. Click to visit' error: Process couldn't be created update: - notice: Process updated successfully + notice: 'Process updated successfully. Click to visit' error: Process couldn't be updated destroy: notice: Process deleted successfully @@ -132,10 +132,10 @@ en: questions: Debate draft_versions: create: - notice: Draft created successfully + notice: 'Draft created successfully. Click to visit' error: Draft couldn't be created update: - notice: Draft updated successfully + notice: 'Draft updated successfully. Click to visit' error: Draft couldn't be updated destroy: notice: Draft deleted successfully @@ -174,10 +174,10 @@ en: status: Status questions: create: - notice: Question created successfully + notice: 'Question created successfully. Click to visit' error: Question couldn't be created update: - notice: Question updated successfully + notice: 'Question updated successfully. Click to visit' error: Question couldn't be updated destroy: notice: Question deleted successfully diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index 8e7b4dc8e..1b5bf4ffe 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -83,10 +83,10 @@ es: legislation: processes: create: - notice: Proceso creado correctamente + notice: 'Proceso creado correctamente. Haz click para verlo' error: No se ha podido crear el proceso update: - notice: Proceso actualizado correctamente + notice: 'Proceso actualizado correctamente. Haz click para verlo' error: No se ha podido actualizar el proceso destroy: notice: Proceso eliminado correctamente @@ -130,10 +130,10 @@ es: questions: Debate draft_versions: create: - notice: Borrador creado correctamente + notice: 'Borrador creado correctamente. Haz click para verlo' error: No se ha podido crear el borrador update: - notice: Borrador actualizado correctamente + notice: 'Borrador actualizado correctamente. Haz click para verlo' error: No se ha podido actualizar el borrador destroy: notice: Borrador eliminado correctamente @@ -172,10 +172,10 @@ es: status: Estado questions: create: - notice: Pregunta creada correctamente + notice: 'Pregunta creada correctamente. Haz click para verla' error: No se ha podido crear la pregunta update: - notice: Pregunta actualizada correctamente + notice: 'Pregunta actualizada correctamente. Haz click para verla' error: No se ha podido actualizar la pregunta destroy: notice: Pregunta eliminada correctamente From a5421597a4d62816207c08d9bf52524d5b695a15 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 5 Jan 2017 17:12:42 +0100 Subject: [PATCH 087/197] Safe call to flash text --- app/views/layouts/_flash.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/_flash.html.erb b/app/views/layouts/_flash.html.erb index 5be4a3186..a0f129224 100644 --- a/app/views/layouts/_flash.html.erb +++ b/app/views/layouts/_flash.html.erb @@ -5,7 +5,7 @@
    - <%= flash_message.html_safe %> + <%= flash_message.try(:html_safe) %>
    From b8f034d89687d977ef41f0ce70fa996cc48f0a54 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Thu, 5 Jan 2017 22:59:35 +0100 Subject: [PATCH 088/197] Legislation annotations/comments page --- .../legislation/annotations_controller.rb | 26 +- app/helpers/legislation_helper.rb | 4 + app/models/abilities/administrator.rb | 4 +- app/models/abilities/moderator.rb | 2 +- app/models/comment.rb | 2 +- app/models/legislation/annotation.rb | 15 +- app/models/legislation/answer.rb | 3 + app/models/legislation/draft_version.rb | 1 + .../annotations/_comments.html.erb | 29 + .../annotations/_version_chooser.html.erb | 16 + .../legislation/annotations/index.html.erb | 35 ++ .../legislation/annotations/show.html.erb | 42 ++ .../legislation/draft_versions/show.html.erb | 3 - config/locales/en.yml | 14 + config/locales/es.yml | 14 + ...omments_count_to_legislation_annotation.rb | 5 + ...er_to_author_in_legislation_annotations.rb | 5 + db/schema.rb | 11 +- spec/factories.rb | 2 +- .../comments/legislation_annotations_spec.rb | 508 ++++++++++++++++++ .../legislation/draft_versions_spec.rb | 23 + 21 files changed, 743 insertions(+), 21 deletions(-) create mode 100644 app/views/legislation/annotations/_comments.html.erb create mode 100644 app/views/legislation/annotations/_version_chooser.html.erb create mode 100644 app/views/legislation/annotations/index.html.erb create mode 100644 app/views/legislation/annotations/show.html.erb create mode 100644 db/migrate/20170105120836_add_comments_count_to_legislation_annotation.rb create mode 100644 db/migrate/20170105212047_rename_user_to_author_in_legislation_annotations.rb create mode 100644 spec/features/comments/legislation_annotations_spec.rb diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index 7e053f510..bd6006909 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -7,9 +7,20 @@ class Legislation::AnnotationsController < ApplicationController load_and_authorize_resource :draft_version, through: :process load_and_authorize_resource + has_orders %w{most_voted newest oldest}, only: :show + + def index + end + + def show + @commentable = @annotation + @comment_tree = CommentTree.new(@commentable, params[:page], @current_order) + set_comment_flags(@comment_tree.comments) + end + def create @annotation = Legislation::Annotation.new(annotation_params) - @annotation.user = current_user + @annotation.author = current_user if @annotation.save render json: @annotation.to_json end @@ -23,10 +34,11 @@ class Legislation::AnnotationsController < ApplicationController private - def annotation_params - params - .require(:annotation) - .permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset]) - .merge(legislation_draft_version_id: params[:legislation_draft_version_id]) - end + def annotation_params + params + .require(:annotation) + .permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset]) + .merge(legislation_draft_version_id: params[:legislation_draft_version_id]) + end + end diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb index 1692cf326..a49bb1e8e 100644 --- a/app/helpers/legislation_helper.rb +++ b/app/helpers/legislation_helper.rb @@ -10,4 +10,8 @@ module LegislationHelper def legislation_question_path(question) legislation_process_question_path(question.process, question) end + + def legislation_annotation_path(annotation) + legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) + end end diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index f8362f87b..5a660e059 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, Legislation::Question] + can :comment_as_administrator, [Debate, Comment, Proposal, Legislation::Question, Legislation::Annotation] can [:search, :create, :index, :destroy], ::Moderator can [:search, :create, :index, :summary], ::Valuator @@ -49,7 +49,7 @@ module Abilities can [:manage], ::Legislation::Process can [:manage], ::Legislation::DraftVersion can [:manage], ::Legislation::Question - cannot :comment_as_moderator, ::Legislation::Question + cannot :comment_as_moderator, [::Legislation::Question, Legislation::Annotation] end end end diff --git a/app/models/abilities/moderator.rb b/app/models/abilities/moderator.rb index c8aed38fe..23b11b2e5 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, Legislation::Question] + can :comment_as_moderator, [Debate, Comment, Proposal, Legislation::Question, Legislation::Annotation] end end end diff --git a/app/models/comment.rb b/app/models/comment.rb index 025f50e71..b850d63eb 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", "Legislation::Question"] + validates_inclusion_of :commentable_type, in: ["Debate", "Proposal", "Legislation::Question", "Legislation::Annotation"] validate :validate_body_length diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index 365f84ad0..0313b7e36 100644 --- a/app/models/legislation/annotation.rb +++ b/app/models/legislation/annotation.rb @@ -1,6 +1,19 @@ class Legislation::Annotation < ActiveRecord::Base + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases + serialize :ranges, Array belongs_to :draft_version, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_draft_version_id' - belongs_to :user + belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' + has_many :comments, as: :commentable + + validates :text, presence: true + validates :quote, presence: true + validates :draft_version, presence: true + validates :author, presence: true + + def title + text[0..50] + end end diff --git a/app/models/legislation/answer.rb b/app/models/legislation/answer.rb index 375bcad8c..cd415d0d4 100644 --- a/app/models/legislation/answer.rb +++ b/app/models/legislation/answer.rb @@ -1,4 +1,7 @@ class Legislation::Answer < ActiveRecord::Base + acts_as_paranoid column: :hidden_at + include ActsAsParanoidAliases + belongs_to :question, class_name: 'Legislation::Question', foreign_key: 'legislation_question_id', inverse_of: :answers, counter_cache: true belongs_to :question_option, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_option_id', inverse_of: :answers, counter_cache: true belongs_to :user, dependent: :destroy, inverse_of: :legislation_answers diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index 29b22e5a6..d0150f1ff 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -5,6 +5,7 @@ class Legislation::DraftVersion < ActiveRecord::Base include ActsAsParanoidAliases belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' + has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id' validates :title, presence: true validates :body, presence: true diff --git a/app/views/legislation/annotations/_comments.html.erb b/app/views/legislation/annotations/_comments.html.erb new file mode 100644 index 000000000..158c2f789 --- /dev/null +++ b/app/views/legislation/annotations/_comments.html.erb @@ -0,0 +1,29 @@ +<% cache [locale_and_user_status, @current_order, commentable_cache_key(commentable), @comment_tree.comments, @comment_tree.comment_authors, commentable.comments_count, @comment_flags] do %> +
    +
    +

    + <%= t("legislation.annotations.show.comments") %> + (<%= commentable.comments_count %>) +

    + + <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> + + <% if user_signed_in? %> + <%= render 'comments/form', {commentable: commentable, parent_id: nil, toggeable: false} %> + <% else %> +
    + +
    + <%= t("debates.show.login_to_comment", + signin: link_to(t("votes.signin"), new_user_session_path), + signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %> +
    + <% end %> + + <% @comment_tree.root_comments.each do |comment| %> + <%= render 'comments/comment', comment: comment %> + <% end %> + <%= paginate @comment_tree.root_comments %> +
    +
    +<% end %> diff --git a/app/views/legislation/annotations/_version_chooser.html.erb b/app/views/legislation/annotations/_version_chooser.html.erb new file mode 100644 index 000000000..8cf4f5fc4 --- /dev/null +++ b/app/views/legislation/annotations/_version_chooser.html.erb @@ -0,0 +1,16 @@ +
    +
    +

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

    +
    + <%= form_tag go_to_version_legislation_process_draft_versions_path(process), method: :get, id: "draft_version_go_to_version" do %> + <%= select_tag "draft_version_id", options_from_collection_for_select(process.draft_versions.published, 'id', 'display_title', draft_version.id), "aria-label": t('legislation.draft_versions.show.select_draft_version') %> + <%= hidden_field_tag "redirect_action", "annotations" %> + <%= submit_tag t('legislation.draft_versions.show.select_version_submit'), class: "button" %> + <% end %> +
    + <%= t('legislation.draft_versions.show.updated_at', date: format_date(@draft_version.updated_at)) %> +
    +
    + <%= link_to t('.see_text'), legislation_process_draft_version_annotations_path(process, draft_version), title: t('.see_text'), class: "button strong" %> +
    +
    diff --git a/app/views/legislation/annotations/index.html.erb b/app/views/legislation/annotations/index.html.erb new file mode 100644 index 000000000..ad9d0a52a --- /dev/null +++ b/app/views/legislation/annotations/index.html.erb @@ -0,0 +1,35 @@ +<% provide :title do %><%= "#{t('.title')} - #{@draft_version.title} - #{@process.title}" %><% end %> + +<%= render 'legislation/processes/header', process: @process, header: :small %> + +
    + <%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %> + +
    + <%= render 'version_chooser', process: @process, draft_version: @draft_version %> + +
    +
    + + <% @annotations.each do |annotation| %> +
    + <%= t('.comments_about') %> + + <%= link_to legislation_process_draft_version_path(@process, @draft_version, anchor: "annotation-id-#{annotation.id}") do %> + <%= t('.see_in_context') %> + <% end %> + +
    + <%= annotation.quote %> +
    + <%= link_to legislation_process_draft_version_annotation_path(@process, @draft_version, annotation) do %> + <%= t('.comments_count', count: annotation.comments_count + 1) %> + <% end %> +
    + <% end %> + +
    +
    + +
    +
    diff --git a/app/views/legislation/annotations/show.html.erb b/app/views/legislation/annotations/show.html.erb new file mode 100644 index 000000000..05caf8ef6 --- /dev/null +++ b/app/views/legislation/annotations/show.html.erb @@ -0,0 +1,42 @@ +<% provide :title do %><%= "#{t('.title')} - #{@draft_version.title} - #{@process.title}" %><% end %> + +<%= render 'legislation/processes/header', process: @process, header: :small %> + +
    + <%= render 'legislation/processes/key_dates', process: @process, phase: :allegations %> + +
    + <%= render 'version_chooser', process: @process, draft_version: @draft_version %> + +
    +
    +
    + <%= t('legislation.annotations.index.comments_about') %> +
    +
    +
    + <%= @annotation.quote %> +
    +
    + + <%= link_to legislation_process_draft_version_path(@process, @draft_version, anchor: "annotation-id-#{@annotation.id}") do %> + <%= t('legislation.annotations.index.see_in_context') %> + <% end %> + +
    +
    +
    + +
    +
    + <%= @annotation.text %> +
    +
    + + <%= render 'comments', commentable: @annotation %> + +
    +
    + +
    +
    diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index a1a1c15a2..7a0af08a4 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -68,7 +68,4 @@
    - -
    -
    diff --git a/config/locales/en.yml b/config/locales/en.yml index fdc7e4e0e..3830e2b78 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -223,6 +223,20 @@ en: text_sign_up: sign up title: How I can comment this document? legislation: + annotations: + index: + title: Comments + comments_about: Comments about + see_in_context: See in context + comments_count: + one: "%{count} comment" + other: "%{count} comments" + show: + title: Comment + comments: Replies + version_chooser: + seeing_version: Commments for version + see_text: See text draft draft_versions: changes: title: Changes diff --git a/config/locales/es.yml b/config/locales/es.yml index f9ec8596b..de031d959 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -223,6 +223,20 @@ es: text_sign_up: registrarte title: "¿Cómo puedo comentar este documento?" legislation: + annotations: + index: + title: Comentarios + see_in_context: Ver en contexto + comments_about: Comentarios sobre + comments_count: + one: "%{count} comentario" + other: "%{count} comentarios" + show: + title: Comentario + comments: Respuestas + version_chooser: + seeing_version: Comentarios para la versión + see_text: Ver borrador del texto draft_versions: changes: title: Cambios diff --git a/db/migrate/20170105120836_add_comments_count_to_legislation_annotation.rb b/db/migrate/20170105120836_add_comments_count_to_legislation_annotation.rb new file mode 100644 index 000000000..39b2e6387 --- /dev/null +++ b/db/migrate/20170105120836_add_comments_count_to_legislation_annotation.rb @@ -0,0 +1,5 @@ +class AddCommentsCountToLegislationAnnotation < ActiveRecord::Migration + def change + add_column :legislation_annotations, :comments_count, :integer, default: 0 + end +end diff --git a/db/migrate/20170105212047_rename_user_to_author_in_legislation_annotations.rb b/db/migrate/20170105212047_rename_user_to_author_in_legislation_annotations.rb new file mode 100644 index 000000000..55b70395b --- /dev/null +++ b/db/migrate/20170105212047_rename_user_to_author_in_legislation_annotations.rb @@ -0,0 +1,5 @@ +class RenameUserToAuthorInLegislationAnnotations < ActiveRecord::Migration + def change + rename_column :legislation_annotations, :user_id, :author_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 39e3ec56c..3953ffc2d 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170103125835) do +ActiveRecord::Schema.define(version: 20170105212047) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -233,15 +233,16 @@ ActiveRecord::Schema.define(version: 20170103125835) do t.text "ranges" t.text "text" t.integer "legislation_draft_version_id" - t.integer "user_id" + t.integer "author_id" t.datetime "hidden_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "comments_count", default: 0 end + add_index "legislation_annotations", ["author_id"], name: "index_legislation_annotations_on_author_id", using: :btree add_index "legislation_annotations", ["hidden_at"], name: "index_legislation_annotations_on_hidden_at", using: :btree add_index "legislation_annotations", ["legislation_draft_version_id"], name: "index_legislation_annotations_on_legislation_draft_version_id", using: :btree - add_index "legislation_annotations", ["user_id"], name: "index_legislation_annotations_on_user_id", using: :btree create_table "legislation_answers", force: :cascade do |t| t.integer "legislation_question_id" diff --git a/spec/factories.rb b/spec/factories.rb index fe0750756..7dee7e9ea 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -407,7 +407,7 @@ FactoryGirl.define do factory :legislation_annotation, class: 'Legislation::Annotation' do draft_version factory: :legislation_draft_version - user + author factory: :user quote "ipsum" text "Loremp ipsum dolor" ranges [{"start"=>"/div[1]", "startOffset"=>5, "end"=>"/div[1]", "endOffset"=>10}] diff --git a/spec/features/comments/legislation_annotations_spec.rb b/spec/features/comments/legislation_annotations_spec.rb new file mode 100644 index 000000000..6e86d97d3 --- /dev/null +++ b/spec/features/comments/legislation_annotations_spec.rb @@ -0,0 +1,508 @@ +require 'rails_helper' +include ActionView::Helpers::DateHelper + +feature 'Commenting legislation questions' do + let(:user) { create :user } + let(:legislation_annotation) { create :legislation_annotation } + + scenario 'Index' do + 3.times { create(:comment, commentable: legislation_annotation) } + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + expect(page).to have_css('.comment', count: 3) + + comment = Comment.last + within first('.comment') do + expect(page).to have_content comment.user.name + expect(page).to have_content I18n.l(comment.created_at, format: :datetime) + expect(page).to have_content comment.body + end + end + + scenario 'Show' do + parent_comment = create(:comment, commentable: legislation_annotation) + first_child = create(:comment, commentable: legislation_annotation, parent: parent_comment) + second_child = create(:comment, commentable: legislation_annotation, parent: parent_comment) + + visit comment_path(parent_comment) + + expect(page).to have_css(".comment", count: 3) + expect(page).to have_content parent_comment.body + expect(page).to have_content first_child.body + expect(page).to have_content second_child.body + + expect(page).to have_link "Go back to #{legislation_annotation.title}", href: legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + end + + scenario 'Collapsable comments', :js do + parent_comment = create(:comment, body: "Main comment", commentable: legislation_annotation) + child_comment = create(:comment, body: "First subcomment", commentable: legislation_annotation, parent: parent_comment) + grandchild_comment = create(:comment, body: "Last subcomment", commentable: legislation_annotation, parent: child_comment) + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + expect(page).to have_css('.comment', count: 3) + + find("#comment_#{child_comment.id}_children_arrow").trigger('click') + + expect(page).to have_css('.comment', count: 2) + expect(page).to_not have_content grandchild_comment.body + + find("#comment_#{child_comment.id}_children_arrow").trigger('click') + + expect(page).to have_css('.comment', count: 3) + expect(page).to have_content grandchild_comment.body + + find("#comment_#{parent_comment.id}_children_arrow").trigger('click') + + expect(page).to have_css('.comment', count: 1) + expect(page).to_not have_content child_comment.body + expect(page).to_not have_content grandchild_comment.body + end + + scenario 'Comment order' do + c1 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 100, cached_votes_total: 120, created_at: Time.current - 2) + c2 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 10, cached_votes_total: 12, created_at: Time.current - 1) + c3 = create(:comment, :with_confidence_score, commentable: legislation_annotation, cached_votes_up: 1, cached_votes_total: 2, created_at: Time.current) + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :most_voted) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :newest) + + expect(c3.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c1.body) + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :oldest) + + expect(c1.body).to appear_before(c2.body) + expect(c2.body).to appear_before(c3.body) + end + + scenario 'Creation date works differently in roots and in child comments, even when sorting by confidence_score' do + old_root = create(:comment, commentable: legislation_annotation, created_at: Time.current - 10) + new_root = create(:comment, commentable: legislation_annotation, created_at: Time.current) + old_child = create(:comment, commentable: legislation_annotation, parent_id: new_root.id, created_at: Time.current - 10) + new_child = create(:comment, commentable: legislation_annotation, parent_id: new_root.id, created_at: Time.current) + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :most_voted) + + expect(new_root.body).to appear_before(old_root.body) + expect(old_child.body).to appear_before(new_child.body) + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :newest) + + expect(new_root.body).to appear_before(old_root.body) + expect(new_child.body).to appear_before(old_child.body) + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation, order: :oldest) + + expect(old_root.body).to appear_before(new_root.body) + expect(old_child.body).to appear_before(new_child.body) + end + + scenario 'Turns links into html links' do + create :comment, commentable: legislation_annotation, body: 'Built with http://rubyonrails.org/' + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + within first('.comment') do + expect(page).to have_content 'Built with http://rubyonrails.org/' + expect(page).to have_link('http://rubyonrails.org/', href: 'http://rubyonrails.org/') + expect(find_link('http://rubyonrails.org/')[:rel]).to eq('nofollow') + expect(find_link('http://rubyonrails.org/')[:target]).to eq('_blank') + end + end + + scenario 'Sanitizes comment body for security' do + create :comment, commentable: legislation_annotation, body: " click me http://www.url.com" + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + within first('.comment') do + expect(page).to have_content "click me http://www.url.com" + expect(page).to have_link('http://www.url.com', href: 'http://www.url.com') + expect(page).not_to have_link('click me') + end + end + + scenario 'Paginated comments' do + per_page = 10 + (per_page + 2).times { create(:comment, commentable: legislation_annotation)} + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + expect(page).to have_css('.comment', count: per_page) + within("ul.pagination") do + expect(page).to have_content("1") + expect(page).to have_content("2") + expect(page).to_not have_content("3") + click_link "Next", exact: false + end + + expect(page).to have_css('.comment', count: 2) + end + + feature 'Not logged user' do + scenario 'can not see comments forms' do + create(:comment, commentable: legislation_annotation) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + expect(page).to have_content 'You must Sign in or Sign up to leave a comment' + within('#comments') do + expect(page).to_not have_content 'Write a comment' + expect(page).to_not have_content 'Reply' + end + end + end + + scenario 'Create', :js do + login_as(user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: 'Have you thought about...?' + click_button 'Publish comment' + + within "#comments" do + expect(page).to have_content 'Have you thought about...?' + expect(page).to have_content '(1)' + end + end + + scenario 'Errors on create', :js do + login_as(user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + click_button 'Publish comment' + + expect(page).to have_content "Can't be blank" + end + + scenario 'Reply', :js do + citizen = create(:user, username: 'Ana') + manuela = create(:user, username: 'Manuela') + comment = create(:comment, commentable: legislation_annotation, user: citizen) + + login_as(manuela) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: 'It will be done next week.' + click_button 'Publish reply' + end + + within "#comment_#{comment.id}" do + expect(page).to have_content 'It will be done next week.' + end + + expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true) + end + + scenario 'Errors on reply', :js do + comment = create(:comment, commentable: legislation_annotation, user: user) + + login_as(user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + click_button 'Publish reply' + expect(page).to have_content "Can't be blank" + end + + end + + scenario "N replies", :js do + parent = create(:comment, commentable: legislation_annotation) + + 7.times do + create(:comment, commentable: legislation_annotation, parent: parent) + parent = parent.children.first + end + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + expect(page).to have_css(".comment.comment.comment.comment.comment.comment.comment.comment") + end + + scenario "Flagging as inappropriate", :js do + comment = create(:comment, commentable: legislation_annotation) + + login_as(user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + within "#comment_#{comment.id}" do + page.find("#flag-expand-comment-#{comment.id}").click + page.find("#flag-comment-#{comment.id}").click + + expect(page).to have_css("#unflag-expand-comment-#{comment.id}") + end + + expect(Flag.flagged?(user, comment)).to be + end + + scenario "Undoing flagging as inappropriate", :js do + comment = create(:comment, commentable: legislation_annotation) + Flag.flag(user, comment) + + login_as(user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + within "#comment_#{comment.id}" do + page.find("#unflag-expand-comment-#{comment.id}").click + page.find("#unflag-comment-#{comment.id}").click + + expect(page).to have_css("#flag-expand-comment-#{comment.id}") + end + + expect(Flag.flagged?(user, comment)).to_not be + end + + scenario "Flagging turbolinks sanity check", :js do + legislation_annotation = create(:legislation_annotation, text: "Should we change the world?") + comment = create(:comment, commentable: legislation_annotation) + + login_as(user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + within "#comment_#{comment.id}" do + page.find("#flag-expand-comment-#{comment.id}").click + expect(page).to have_selector("#flag-comment-#{comment.id}") + end + end + + scenario "Erasing a comment's author" do + legislation_annotation = create(:legislation_annotation) + comment = create(:comment, commentable: legislation_annotation, body: 'this should be visible') + comment.user.erase + + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + within "#comment_#{comment.id}" do + expect(page).to have_content('User deleted') + expect(page).to have_content('this should be visible') + end + end + + scenario 'Submit button is disabled after clicking', :js do + legislation_annotation = create(:legislation_annotation) + login_as(user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: 'Testing submit button!' + click_button 'Publish comment' + + # The button's text should now be "..." + # This should be checked before the Ajax request is finished + expect(page).to_not have_button 'Publish comment' + + expect(page).to have_content('Testing submit button!') + end + + feature "Moderators" do + scenario "can create comment as a moderator", :js do + moderator = create(:moderator) + + login_as(moderator.user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: "I am moderating!" + check "comment-as-moderator-legislation_annotation_#{legislation_annotation.id}" + click_button "Publish comment" + + within "#comments" do + expect(page).to have_content "I am moderating!" + expect(page).to have_content "Moderator ##{moderator.id}" + expect(page).to have_css "div.is-moderator" + expect(page).to have_css "img.moderator-avatar" + end + end + + scenario "can create reply as a moderator", :js do + citizen = create(:user, username: "Ana") + manuela = create(:user, username: "Manuela") + moderator = create(:moderator, user: manuela) + comment = create(:comment, commentable: legislation_annotation, user: citizen) + + login_as(manuela) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: "I am moderating!" + check "comment-as-moderator-comment_#{comment.id}" + click_button 'Publish reply' + end + + within "#comment_#{comment.id}" do + expect(page).to have_content "I am moderating!" + expect(page).to have_content "Moderator ##{moderator.id}" + expect(page).to have_css "div.is-moderator" + expect(page).to have_css "img.moderator-avatar" + end + + expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true) + end + + scenario "can not comment as an administrator" do + moderator = create(:moderator) + + login_as(moderator.user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + expect(page).to_not have_content "Comment as administrator" + end + end + + feature "Administrators" do + scenario "can create comment as an administrator", :js do + admin = create(:administrator) + + login_as(admin.user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + fill_in "comment-body-legislation_annotation_#{legislation_annotation.id}", with: "I am your Admin!" + check "comment-as-administrator-legislation_annotation_#{legislation_annotation.id}" + click_button "Publish comment" + + within "#comments" do + expect(page).to have_content "I am your Admin!" + expect(page).to have_content "Administrator ##{admin.id}" + expect(page).to have_css "div.is-admin" + expect(page).to have_css "img.admin-avatar" + end + end + + scenario "can create reply as an administrator", :js do + citizen = create(:user, username: "Ana") + manuela = create(:user, username: "Manuela") + admin = create(:administrator, user: manuela) + comment = create(:comment, commentable: legislation_annotation, user: citizen) + + login_as(manuela) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + click_link "Reply" + + within "#js-comment-form-comment_#{comment.id}" do + fill_in "comment-body-comment_#{comment.id}", with: "Top of the world!" + check "comment-as-administrator-comment_#{comment.id}" + click_button 'Publish reply' + end + + within "#comment_#{comment.id}" do + expect(page).to have_content "Top of the world!" + expect(page).to have_content "Administrator ##{admin.id}" + expect(page).to have_css "div.is-admin" + expect(page).to have_css "img.admin-avatar" + end + + expect(page).to_not have_selector("#js-comment-form-comment_#{comment.id}", visible: true) + end + + scenario "can not comment as a moderator" do + admin = create(:administrator) + + login_as(admin.user) + visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) + + expect(page).to_not have_content "Comment as moderator" + end + end + + feature 'Voting comments' do + background do + @manuela = create(:user, verified_at: Time.current) + @pablo = create(:user) + @legislation_annotation = create(:legislation_annotation) + @comment = create(:comment, commentable: @legislation_annotation) + + login_as(@manuela) + end + + scenario 'Show' do + create(:vote, voter: @manuela, votable: @comment, vote_flag: true) + create(:vote, voter: @pablo, votable: @comment, vote_flag: false) + + visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation) + + within("#comment_#{@comment.id}_votes") do + within(".in_favor") do + expect(page).to have_content "1" + end + + within(".against") do + expect(page).to have_content "1" + end + + expect(page).to have_content "2 votes" + end + end + + scenario 'Create', :js do + visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation) + + within("#comment_#{@comment.id}_votes") do + find(".in_favor a").click + + within(".in_favor") do + expect(page).to have_content "1" + end + + within(".against") do + expect(page).to have_content "0" + end + + expect(page).to have_content "1 vote" + end + end + + scenario 'Update', :js do + visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation) + + within("#comment_#{@comment.id}_votes") do + find('.in_favor a').click + find('.against a').click + + within('.in_favor') do + expect(page).to have_content "0" + end + + within('.against') do + expect(page).to have_content "1" + end + + expect(page).to have_content "1 vote" + end + end + + xscenario 'Trying to vote multiple times', :js do + visit legislation_process_draft_version_annotation_path(@legislation_annotation.draft_version.process, @legislation_annotation.draft_version, @legislation_annotation) + + within("#comment_#{@comment.id}_votes") do + find('.in_favor a').click + within('.in_favor') do + expect(page).to have_content "1" + end + + find('.in_favor a').click + within('.in_favor') do + expect(page).to_not have_content "2" + expect(page).to have_content "1" + end + + within('.against') do + expect(page).to have_content "0" + end + + expect(page).to have_content "1 vote" + end + end + end + +end diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index 7df1939be..a817a8b2c 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -160,4 +160,27 @@ feature 'Legislation Draft Versions' do end end + context "Annotations page" do + background do + @draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) + @annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "first quote") + @annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "second quote") + end + scenario "See all annotations for a draft version" do + visit legislation_process_draft_version_annotations_path(@draft_version.process, @draft_version) + + expect(page).to have_content "first quote" + expect(page).to have_content "second quote" + end + + scenario "See one annotation with replies for a draft version" do + visit legislation_process_draft_version_annotation_path(@draft_version.process, @draft_version, @annotation_2) + + expect(page).to_not have_content "first quote" + expect(page).to have_content "second quote" + expect(page).to_not have_content "my annotation" + expect(page).to have_content "my other annotation" + end + end + end From f43f13e82687f756eb009efd7514506612a4ebe2 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Mon, 9 Jan 2017 17:03:00 +0100 Subject: [PATCH 089/197] Create first comment automatically from the annotation --- app/models/legislation/annotation.rb | 6 ++++++ .../legislation/annotations/index.html.erb | 2 +- .../legislation/annotations/show.html.erb | 6 ------ config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- .../comments/legislation_annotations_spec.rb | 21 +++++++++++-------- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index 0313b7e36..d62363946 100644 --- a/app/models/legislation/annotation.rb +++ b/app/models/legislation/annotation.rb @@ -13,6 +13,12 @@ class Legislation::Annotation < ActiveRecord::Base validates :draft_version, presence: true validates :author, presence: true + after_create :create_first_comment + + def create_first_comment + comments.create(body: self.text, user: self.author) + end + def title text[0..50] end diff --git a/app/views/legislation/annotations/index.html.erb b/app/views/legislation/annotations/index.html.erb index ad9d0a52a..ead25ae3b 100644 --- a/app/views/legislation/annotations/index.html.erb +++ b/app/views/legislation/annotations/index.html.erb @@ -23,7 +23,7 @@ <%= annotation.quote %>
    <%= link_to legislation_process_draft_version_annotation_path(@process, @draft_version, annotation) do %> - <%= t('.comments_count', count: annotation.comments_count + 1) %> + <%= t('.comments_count', count: annotation.comments_count) %> <% end %>
    <% end %> diff --git a/app/views/legislation/annotations/show.html.erb b/app/views/legislation/annotations/show.html.erb index 05caf8ef6..6bf499f52 100644 --- a/app/views/legislation/annotations/show.html.erb +++ b/app/views/legislation/annotations/show.html.erb @@ -27,12 +27,6 @@
    -
    -
    - <%= @annotation.text %> -
    -
    - <%= render 'comments', commentable: @annotation %>
    diff --git a/config/locales/en.yml b/config/locales/en.yml index 3830e2b78..1556c4403 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -233,7 +233,7 @@ en: other: "%{count} comments" show: title: Comment - comments: Replies + comments: Comments version_chooser: seeing_version: Commments for version see_text: See text draft diff --git a/config/locales/es.yml b/config/locales/es.yml index de031d959..bf79276c4 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -233,7 +233,7 @@ es: other: "%{count} comentarios" show: title: Comentario - comments: Respuestas + comments: Comentarios version_chooser: seeing_version: Comentarios para la versión see_text: Ver borrador del texto diff --git a/spec/features/comments/legislation_annotations_spec.rb b/spec/features/comments/legislation_annotations_spec.rb index 6e86d97d3..eb72036e2 100644 --- a/spec/features/comments/legislation_annotations_spec.rb +++ b/spec/features/comments/legislation_annotations_spec.rb @@ -3,14 +3,14 @@ include ActionView::Helpers::DateHelper feature 'Commenting legislation questions' do let(:user) { create :user } - let(:legislation_annotation) { create :legislation_annotation } + let(:legislation_annotation) { create :legislation_annotation, author: user } scenario 'Index' do 3.times { create(:comment, commentable: legislation_annotation) } visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) - expect(page).to have_css('.comment', count: 3) + expect(page).to have_css('.comment', count: 4) comment = Comment.last within first('.comment') do @@ -36,7 +36,7 @@ feature 'Commenting legislation questions' do end scenario 'Collapsable comments', :js do - parent_comment = create(:comment, body: "Main comment", commentable: legislation_annotation) + parent_comment = legislation_annotation.comments.first child_comment = create(:comment, body: "First subcomment", commentable: legislation_annotation, parent: parent_comment) grandchild_comment = create(:comment, body: "Last subcomment", commentable: legislation_annotation, parent: child_comment) @@ -143,7 +143,7 @@ feature 'Commenting legislation questions' do click_link "Next", exact: false end - expect(page).to have_css('.comment', count: 2) + expect(page).to have_css('.comment', count: 3) end feature 'Not logged user' do @@ -168,7 +168,7 @@ feature 'Commenting legislation questions' do within "#comments" do expect(page).to have_content 'Have you thought about...?' - expect(page).to have_content '(1)' + expect(page).to have_content '(2)' end end @@ -184,7 +184,8 @@ feature 'Commenting legislation questions' do scenario 'Reply', :js do citizen = create(:user, username: 'Ana') manuela = create(:user, username: 'Manuela') - comment = create(:comment, commentable: legislation_annotation, user: citizen) + legislation_annotation = create(:legislation_annotation, author: citizen) + comment = legislation_annotation.comments.first login_as(manuela) visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) @@ -204,7 +205,7 @@ feature 'Commenting legislation questions' do end scenario 'Errors on reply', :js do - comment = create(:comment, commentable: legislation_annotation, user: user) + comment = legislation_annotation.comments.first login_as(user) visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) @@ -326,7 +327,8 @@ feature 'Commenting legislation questions' do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") moderator = create(:moderator, user: manuela) - comment = create(:comment, commentable: legislation_annotation, user: citizen) + legislation_annotation = create(:legislation_annotation, author: citizen) + comment = legislation_annotation.comments.first login_as(manuela) visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) @@ -382,7 +384,8 @@ feature 'Commenting legislation questions' do citizen = create(:user, username: "Ana") manuela = create(:user, username: "Manuela") admin = create(:administrator, user: manuela) - comment = create(:comment, commentable: legislation_annotation, user: citizen) + legislation_annotation = create(:legislation_annotation, author: citizen) + comment = legislation_annotation.comments.first login_as(manuela) visit legislation_process_draft_version_annotation_path(legislation_annotation.draft_version.process, legislation_annotation.draft_version, legislation_annotation) From 4f539b374f8b3cb45a436bc4638516be252406f3 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 10 Jan 2017 17:25:02 +0100 Subject: [PATCH 090/197] View comments for draft text --- app/assets/javascripts/application.js | 3 +- .../legislation_allegations.js.coffee | 3 ++ .../legislation_annotatable.js.coffee | 31 +++++++++++++- .../legislation/annotations_controller.rb | 4 ++ app/models/abilities/everyone.rb | 2 +- .../annotations/_comments_for.html.erb | 42 +++++++++++++++++++ .../legislation/annotations/comments.js.erb | 2 + .../legislation/draft_versions/show.html.erb | 7 ++++ config/locales/en.yml | 10 +++++ config/locales/es.yml | 10 +++++ config/routes.rb | 1 + 11 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 app/views/legislation/annotations/_comments_for.html.erb create mode 100644 app/views/legislation/annotations/comments.js.erb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index b9d072f5a..e196c94c3 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -77,7 +77,8 @@ var initialize_modules = function() { App.MarkdownEditor.initialize(); App.LegislationAllegations.initialize(); App.Legislation.initialize(); - App.LegislationAnnotatable.initialize(); + if ( $(".legislation-annotatable").length ) + App.LegislationAnnotatable.initialize(); }; $(function(){ diff --git a/app/assets/javascripts/legislation_allegations.js.coffee b/app/assets/javascripts/legislation_allegations.js.coffee index e01a8b5d4..14d274243 100644 --- a/app/assets/javascripts/legislation_allegations.js.coffee +++ b/app/assets/javascripts/legislation_allegations.js.coffee @@ -3,6 +3,9 @@ App.LegislationAllegations = toggle_comments: -> $('.draft-allegation').toggleClass('comments-on'); + show_comments: -> + $('.draft-allegation').addClass('comments-on'); + initialize: -> $('.js-toggle-allegations .draft-panel').on click: (e) -> diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index fa5df598a..33803ab43 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -1,7 +1,35 @@ _t = (key) -> new Gettext().gettext(key) App.LegislationAnnotatable = + + renderAnnotationComments: (event) -> + $('.comment-box').offset(top: event.offset) + $.ajax + method: "GET" + url: event.annotation_url + "/annotations/" + event.annotation_id + "/comments" + dataType: 'script' + + viewerExtension: (viewer) -> + viewer._onHighlightMouseover = (event) -> + App.LegislationAllegations.show_comments() + $.event.trigger + type: "renderLegislationAnnotation" + annotation_id: $(event.target).data("annotation-id") + annotation_url: $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url") + offset: $(event.target).offset()["top"] + + + + scrollToAnchor: -> + annotationsLoaded: (annotations) -> + anchor = $(location).attr('hash') + ann_id = anchor.split("-")[-1..] + el = $("span[data-annotation-id='" + ann_id + "']") + $('html,body').animate({scrollTop: el.offset().top}) + initialize: -> + $(document).on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments) + current_user_id = $('html').data('current-user-id') if current_user_id == "" annotator.ui.editor.Editor.template = [ @@ -27,7 +55,8 @@ App.LegislationAnnotatable = ann["legislation_draft_version_id"] = ann_id ann.permissions = ann.permissions || {} ann.permissions.admin = [] - .include(annotator.ui.main, { element: this }) + .include(annotator.ui.main, { element: this, viewerExtensions: [App.LegislationAnnotatable.viewerExtension] }) + .include(App.LegislationAnnotatable.scrollToAnchor) .include(annotator.storage.http, { prefix: base_url, urls: { search: "/annotations/search" } }) app.start().then -> diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index bd6006909..ee63574f5 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -32,6 +32,10 @@ class Legislation::AnnotationsController < ApplicationController render json: annotations_hash.to_json end + def comments + @annotation = Legislation::Annotation.find(params[:annotation_id]) + end + private def annotation_params diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index e29880e95..179c67350 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -15,7 +15,7 @@ module Abilities can [:read, :changes, :go_to_version], Legislation::DraftVersion can [:read], Legislation::Question can [:create], Legislation::Answer - can [:search, :read, :create], Legislation::Annotation + can [:search, :comments, :read, :create], Legislation::Annotation end end end diff --git a/app/views/legislation/annotations/_comments_for.html.erb b/app/views/legislation/annotations/_comments_for.html.erb new file mode 100644 index 000000000..caea782af --- /dev/null +++ b/app/views/legislation/annotations/_comments_for.html.erb @@ -0,0 +1,42 @@ +
    + +
    <%= t('legislation.annotations.comments.comments_count', count: annotation.comments_count) %>
    + <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> + + <% end %> +
    +
    + <% annotation.comments.each do |comment| %> +
    +
    +

    <%= comment.body %>

    +
    +
    +
    +
    + <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> + <%= t('legislation.annotations.comments.see_complete') %> + <% end %> +
    +
    + <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> + <%= t('legislation.annotations.comments.replies_count', count: comment.children.size) %> + <% end %> +
    +
    +
    +
    + <%= render 'comments/votes', comment: comment %> +
    +
    +
    +
    + <% end %> + +
    + diff --git a/app/views/legislation/annotations/comments.js.erb b/app/views/legislation/annotations/comments.js.erb new file mode 100644 index 000000000..a058b00da --- /dev/null +++ b/app/views/legislation/annotations/comments.js.erb @@ -0,0 +1,2 @@ +$("#comments-box").html("<%= j render('comments_for', annotation: @annotation) %>"); + diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index 7a0af08a4..6bee874c4 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -64,6 +64,13 @@ <%= t('.text_comments') %>
    +
    +
    + +
    <%= t('.loading_comments') %>
    +
    +
    +
    diff --git a/config/locales/en.yml b/config/locales/en.yml index 1556c4403..a7fe21a91 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -224,6 +224,15 @@ en: title: How I can comment this document? legislation: annotations: + comments: + see_all: See all + see_complete: See complete + comments_count: + one: "%{count} comment" + other: "%{count} comments" + replies_count: + one: "%{count} reply" + other: "%{count} replies" index: title: Comments comments_about: Comments about @@ -243,6 +252,7 @@ en: seeing_changelog_version: Revision changes summary see_text: See text draft show: + loading_comments: Loading comments seeing_version: You're seeing draft version select_draft_version: Select draft select_version_submit: see diff --git a/config/locales/es.yml b/config/locales/es.yml index bf79276c4..823115d12 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -224,6 +224,15 @@ es: title: "¿Cómo puedo comentar este documento?" legislation: annotations: + comments: + see_all: Ver todos + see_complete: Ver completo + comments_count: + one: "%{count} comentario" + other: "%{count} comentarios" + replies_count: + one: "%{count} respuesta" + other: "%{count} respuestas" index: title: Comentarios see_in_context: Ver en contexto @@ -243,6 +252,7 @@ es: seeing_changelog_version: Resumen de cambios de la revisión see_text: Ver borrador del texto show: + loading_comments: Cargando comentarios seeing_version: Estás viendo la revisión select_draft_version: Seleccionar borrador select_version_submit: ver diff --git a/config/routes.rb b/config/routes.rb index 956b68f32..315ab1d6b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -103,6 +103,7 @@ Rails.application.routes.draw do get :changes resources :annotations do get :search, on: :collection + get :comments end end end From 329b288c018357a2a8a679731847430cc08a5f47 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 10 Jan 2017 17:56:35 +0100 Subject: [PATCH 091/197] Try to fix poltergeist error in spec --- spec/features/legislation/draft_versions_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index a817a8b2c..bdf83e088 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -155,7 +155,7 @@ feature 'Legislation Draft Versions' do first(:css, ".annotator-hl").click expect(page).to have_content "my annotation" - all(".annotator-hl")[1].click + all(".annotator-hl")[1].trigger('click') expect(page).to have_content "my other annotation" end end From f3daf2aca29a11bf123ceefd591fd44174df32d1 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 10 Jan 2017 18:21:16 +0100 Subject: [PATCH 092/197] Show comments box when scrolling to annotation --- app/assets/javascripts/legislation_annotatable.js.coffee | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index 33803ab43..01bd42bf5 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -25,7 +25,13 @@ App.LegislationAnnotatable = anchor = $(location).attr('hash') ann_id = anchor.split("-")[-1..] el = $("span[data-annotation-id='" + ann_id + "']") + App.LegislationAllegations.show_comments() $('html,body').animate({scrollTop: el.offset().top}) + $.event.trigger + type: "renderLegislationAnnotation" + annotation_id: ann_id + annotation_url: el.closest(".legislation-annotatable").data("legislation-annotatable-base-url") + offset: el.offset()["top"] initialize: -> $(document).on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments) From 87a548a2980c5a0c069724d25b656c1309b52e56 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 10 Jan 2017 18:23:02 +0100 Subject: [PATCH 093/197] Adjust panel widths to maintain the same width for the center text --- .../stylesheets/legislation_process.scss | 364 +++++++++--------- 1 file changed, 182 insertions(+), 182 deletions(-) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 245ea0a7f..d5ab74130 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -38,21 +38,21 @@ // ----------------- .legislation-hero { padding-top: 1.5rem; - + @include breakpoint(medium) { padding-top: 3.5rem; } - + h4 { color: #878787; text-transform: uppercase; font-weight: 400; } - + ul { list-style: none; margin-left: 0; - + li:before { vertical-align: text-bottom; padding-right: 0.5rem; @@ -60,25 +60,25 @@ color: #8AA8BE; } } - + #debate-info { display: none; margin-top: 1rem; - + @include breakpoint(medium) { margin-bottom: 2rem; } - + .debate-info-wrapper { h2 { font-size: $lead-font-size; - + @include breakpoint(medium) { float: left; } } - + p { @include breakpoint(medium) { margin-left: 25%; @@ -86,7 +86,7 @@ } } } - + .half-gradient { /* Permalink - use to edit and share this gradient: http://colorzilla.com/gradient-editor/#e6e6e6+0,e6e6e6+50,ffffff+50 */ background: #e6e6e6; /* Old browsers */ @@ -95,45 +95,45 @@ background: linear-gradient(to bottom, #e6e6e6 0%,#e6e6e6 50%,#ffffff 50%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */ filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e6e6e6', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */ } - + .center .button { background: #004A83; margin-bottom: 0; } - + .headline { margin-bottom: 1rem; - + @include breakpoint(medium) { margin-bottom: 4rem; - + } } - + .description { margin-bottom: 1rem; - + @include breakpoint(medium) { margin-bottom: 0; } } - + .button-subscribe { margin-top: 1rem; - + h3 { margin-bottom: 0; } - + p { margin-bottom: 0; font-size: $small-font-size; } - + &:hover h3 { color: white; } - + @include breakpoint(medium) { padding: 0.5em 1em; margin-top: 3rem; @@ -145,59 +145,59 @@ // ----------------- .legislation-process-categories { position: relative; - + svg { position: absolute; top: 1.5rem; left: 0; - + @include breakpoint(medium) { transform: rotate(-8deg); top: 0.75rem; } } - + ul { padding-top: 4rem; list-style: none; margin-left: 0; padding-left: 0; border-bottom: 1px solid $medium-gray; - + li { cursor: pointer; margin-left: 0; display: inline-block; margin-bottom: 1rem; margin-right: 1rem; - + @media (min-width: 950px) { margin-right: 0; margin-left: 3rem; margin-bottom: 0; } - + a, h4 { color: #6D6D6D; margin-bottom: 0; } - + a { &:hover, &:active { text-decoration: none; } - + p { margin-bottom: 0; - + @include breakpoint(medium) { margin-bottom: 1rem; } } } } - + .active { border-bottom: 2px solid $brand; } @@ -208,42 +208,42 @@ // ----------------- .debate-chooser { padding: 2rem 1rem; - + @include breakpoint(medium) { .debate-chooser { padding: 2rem 3rem; } } - + .debate-block { margin-bottom: 2.5rem; - + .debate-type { text-transform: uppercase; color: #178DCC; font-weight: 700; font-size: $small-font-size; - + .icon-debates { margin-left: 0.2rem; } } - + .debate-title a { color: $brand; } - + .debate-meta, .debate-meta a { font-size: $small-font-size; color: #6D6D6D; - + .icon-comments { margin-right: 0.2rem; } } } - + .debate-info { padding: 1rem; background: #F4F4F4; @@ -253,18 +253,18 @@ // 05. Debate quiz // ----------------- .debate-quiz { - + .quiz-header { margin-bottom: 2rem; - + .quiz-title, .quiz-next { padding: 1rem; height: 6rem; } - + .quiz-title { background: #E5ECF2; - + .quiz-header-title { margin-bottom: 0; text-transform: uppercase; @@ -273,21 +273,21 @@ font-size: $small-font-size; } } - + h4 a { color: $brand; } - + h4 a:hover { text-decoration: none; } - + .quiz-next-link { - + &:hover, &:active { text-decoration: none; } - + .quiz-next { background: #CCDBE5; font-weight: 700; @@ -296,16 +296,16 @@ text-align: right; text-transform: uppercase; transition: background 0.25s ease-out, background 0.25s ease-out; - + .icon-angle-right { vertical-align: sub; } - + &:hover, &:active { text-decoration: none; background: $brand; color: white; - + .icon-angle-right { color: white; } @@ -313,15 +313,15 @@ } } } - + .quiz-question { margin-bottom: 2rem; } - + .debate-questions { position: relative; list-style: none; - + .control { position: relative; display: inline-block; @@ -333,27 +333,27 @@ padding: 0.75rem 2.5rem; margin-right: 1.5rem; } - + .active { background: #CCDBE6; border: none; } - + .control input { position: absolute; opacity: 0; z-index: -1; } - + .control input:checked ~ .control-indicator { background-color: $brand; border: none; } - + .radio .control-indicator { border-radius: 50%; } - + .control-indicator { position: absolute; top: 0.95rem; @@ -380,14 +380,14 @@ padding: 10rem 2rem 15rem 2rem; display: block; background: #F2F2F2; - + button { height: 90px; - + h3 { margin-bottom: 0; } - + p { margin-bottom: 0; font-size: $small-font-size; @@ -399,44 +399,44 @@ // ----------------- .legislation-allegation { padding-top: 1rem; - + .headline { margin-bottom: 0; } - + .button-circle { line-height: 0; padding: 0.5em; border-radius: 50%; } - + .icon-checkmark-circle { font-size: 1.5rem; vertical-align: bottom; color: $text-medium; margin-right: 0.5rem; } - + .button-subscribed { margin-top: 1rem; border: 1px solid #D1D1D1; background: #F2F2F2; - + h3 { display: inline-block; color: $text; margin-bottom: 0; } - + p { margin-bottom: 0; font-size: $small-font-size; } - + &:hover h3 { color: $text; } - + @include breakpoint(medium) { padding: 0.5em 1em; } @@ -445,96 +445,96 @@ .draft-panels { padding: 2rem 0; - + .draft-chooser { margin-bottom: 2rem; - + h3 { vertical-align: top; display: inline-block; font-weight: 400; margin-right: 0.5rem; } - + span { margin-left: 0.75rem; font-style: italic; font-size: $small-font-size; color: $text-medium; vertical-align: top; - + @include breakpoint(medium) { margin-left: 1rem; } } - + .select-box { position: relative; - + @include breakpoint(medium) { display: inline-block; } - + select { margin-bottom: 0; display: block; } - + span { vertical-align: inherit; font-style: normal; - + a { text-decoration: underline; color: $text-medium } } } - + .button { margin-top: 1rem; - + @include breakpoint(medium) { margin-top: 0; } } } - + .draft-allegation { @include breakpoint(medium) { display: flex; padding-left: 0.9375rem; padding-right: 0.9375rem; } - + .calc-index { .draft-panel { cursor: pointer; } - + .draft-index-rotated { display: none; } } - + // Panel calcs for desktop @media screen and (min-width: 40em) { .calc-index { transition: all 0.25s; - width: calc(25% - 25px); + width: calc(35% - 25px); } - + .calc-text { transition: all 0.25s; - width: calc(75% - 25px) + width: calc(65% - 25px) } - + .calc-comments { transition: all 0.25s; cursor: pointer; background: #F2F2F2; width: 50px; - + .draft-panel { .panel-title { display: none; @@ -542,13 +542,13 @@ } } } - + .border-right { @include breakpoint(medium) { border-right: 1px solid $border; } } - + .draft-panel { text-transform: uppercase; font-weight: 700; @@ -556,11 +556,11 @@ color: #696969; background: #F2F2F2; font-size: $small-font-size; - + .icon-comments { margin-right: 0.25rem; } - + .icon-banner { line-height: 0; color: $text-medium; @@ -568,50 +568,50 @@ margin-right: 0.25rem; } } - + .draft-index { table { tbody { border: none; - + tr { background: white; - + td { padding: 0.25rem 1rem; - + .icon-plus-square, .icon-minus-square { color: $text-medium; cursor: pointer; vertical-align: sub; } - + a { color: $brand; text-decoration: underline; font-size: $small-font-size; } } - + .collapse-all { padding: 1rem; - + a { color: $text-medium; } - + .icon-plus-square, .icon-minus-square { color: $text-medium; } } } - + .child_group { td { padding: 0 1rem; - + table { margin-bottom: 0.5rem; } @@ -620,64 +620,64 @@ } } } - + .draft-text { position: relative; padding: 1rem; - + @include breakpoint(medium) { padding: 2rem 2rem 2rem 3rem; }; - + h2 { font-weight: 400; margin-bottom: 2rem; margin-top: 2rem; } - + h3 { font-weight: 400; margin-bottom: 1rem; } - + .anchor::before { display: none; content: "#"; color: $text-medium; position: absolute; left: 0; - + @include breakpoint(medium) { left: 1.5rem; } } - + a { color: $text; - + &:hover, &:active, &:focus { text-decoration: none; - + h3 { color: $text; } - + .anchor::before { display: block; } } } } - + .calc-comments { position: relative; - + .comment-box { display: none; } - + .draft-comments-rotated { @include breakpoint(medium) { font-size: $small-font-size; @@ -692,16 +692,16 @@ filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); } } - + } } - + .comments-on { .calc-index { width: 50px; background: #F2F2F2; cursor: pointer; - + .panel-title { display: none; } @@ -709,7 +709,7 @@ .draft-index { display: none; } - + .draft-index-rotated { @include breakpoint(medium) { display: block; @@ -723,18 +723,18 @@ -ms-transform: rotate(-90deg); -o-transform: rotate(-90deg); filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); - + .panel-title { display: block; } } } } - + .calc-text { width: calc(65% - 25px); border-right: none; - + .show-comments { width: 105%; background: #FAFAFA; @@ -746,22 +746,22 @@ margin-bottom: 0; } } - + } - + .calc-comments { background: white; cursor: auto; width: calc(35% - 25px); - + .draft-panel { cursor: pointer; } - + .draft-comments-rotated { display: none; } - + .comment-box { width: 375px; padding: 1rem; @@ -770,44 +770,44 @@ display: block; position: absolute; top: 230px; - + .button { font-size: $small-font-size; padding: 0.5em 1em; } - + .publish-comment { float: right; } - + .comment-header { color: #838383; padding-bottom: 0.5rem; margin-bottom: 1rem; border-bottom: 1px solid $border; - + .comment-number { color: $text; display: inline-block; } - + .icon-comment { margin-right: 0.5rem; } - + a .icon-expand { color: #838383; font-size: $small-font-size; float: right; } } - + .comment-input { padding-bottom: 4rem; margin-bottom: 1rem; margin-top: 1rem; border-bottom: 1px solid $border; - + .comment-advice { border-top: 1px solid #D0D0D0; border-right: 1px solid #D0D0D0; @@ -817,17 +817,17 @@ display: inline-block; font-size: $small-font-size; background: #DFDFDF; - + .icon-proposals { color: #838383; } - + a { color: #87A3B9; text-decoration: underline; } } - + textarea { border-radius: 0; box-shadow: none; @@ -839,7 +839,7 @@ height: 200px; margin-bottom: 0.5rem; } - + .comment-actions { .cancel-comment { color: #87A3B9; @@ -849,7 +849,7 @@ } } } - + .comment { border-bottom: 1px solid $border; padding-bottom: 0.75rem; @@ -858,25 +858,25 @@ .comment-text { margin-bottom: 0.5rem; - + p { line-height: 1.5; font-size: $small-font-size; - + &:last-child { margin-bottom: 0.5rem; } } } - + .comment-meta { - + .comment-more-info { display: inline-block; - + .comment-expand { display: inline-block; - + &::after { content: "|"; color: #838383; @@ -884,36 +884,36 @@ } .comment-replies { display: inline-block; - } + } } - + .comment-votes { color: #838383; float: right; display: inline-block; - + .comment-votes-number { margin-right: 0.25rem; display: inline-block; - + &::after { margin-left: 0.25rem; content: "|"; } } - + .icon-like, .icon-unlike { cursor: pointer; color: #C7C7C7; - + &:hover, &:active, &:focus { color: #838383; } } - + .icon-like { margin-right: 0.25rem; } @@ -921,11 +921,11 @@ } } } - + .comment-box:nth-child(4) { top: 838px; } - + .comment-box:nth-child(5) { top: 2035px; } @@ -933,12 +933,12 @@ .draft-panel { background: #E5E5E5; border-left: 1px solid #D4D4D4; - + .panel-title { display: inline-block; } } - + .show-for-medium { .panel-title { display: none; @@ -954,29 +954,29 @@ ul { list-style: none; margin-left: 0; - + li { margin-bottom: 1rem; - + &::before { margin-right: 0.25rem; content: "—" } - + .changes-link { display: block; margin-left: 1rem; font-size: $small-font-size; - + @include breakpoint(medium) { display: inline-block; } - + a { span { text-decoration: underline; } - + .icon-external { text-decoration: none; color: #999999; @@ -984,7 +984,7 @@ vertical-align: sub; margin-left: 0.5rem; } - + &:active, &:focus, &:hover { @@ -999,11 +999,11 @@ // 09. Legislation comments // ----------------- .legislation-comments { - + .pull-right { float: right; } - + .comment-section { background: #FAFAFA; padding: 1rem; @@ -1011,30 +1011,30 @@ margin-top: 0.25rem; margin-bottom: 1rem; } - + .comment { margin-bottom: 3rem; - + a { span { text-decoration: underline; } - + .icon-expand, .icon-comments { text-decoration: none; color: #999999; line-height: 0; } - + .icon-expand { margin-left: 0.25rem; } - + .icon-comments { margin-right: 0.25rem; } - + &:active, &:focus, &:hover { @@ -1047,11 +1047,11 @@ // 10. Legislation draft comment // ----------------- .legislation-comment { - + .pull-right { float: right; } - + .comment-section { background: #FAFAFA; padding: 1rem; @@ -1059,30 +1059,30 @@ margin-top: 0.25rem; margin-bottom: 1rem; } - + .comment { margin-bottom: 3rem; - + a { span { text-decoration: underline; } - + .icon-expand, .icon-comments { text-decoration: none; color: #999999; line-height: 0; } - + .icon-expand { margin-left: 0.25rem; } - + .icon-comments { margin-right: 0.25rem; } - + &:active, &:focus, &:hover { From 1966c5b8fd12e2338a0712b2b4222e097a892b45 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 10 Jan 2017 18:30:30 +0100 Subject: [PATCH 094/197] Use mouse over event in spec --- spec/features/legislation/draft_versions_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index bdf83e088..c7f761669 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -155,7 +155,7 @@ feature 'Legislation Draft Versions' do first(:css, ".annotator-hl").click expect(page).to have_content "my annotation" - all(".annotator-hl")[1].trigger('click') + all(".annotator-hl")[1].trigger('mouseover') expect(page).to have_content "my other annotation" end end From 174fe5ee049e321f7ef8612990211143bed0e725 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 10 Jan 2017 18:59:18 +0100 Subject: [PATCH 095/197] =?UTF-8?q?Don=E2=80=99t=20scroll=20and=20show=20c?= =?UTF-8?q?omments=20when=20there=20isn=E2=80=99t=20an=20anchor=20in=20the?= =?UTF-8?q?=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legislation_annotatable.js.coffee | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index 01bd42bf5..ce9e9b8d7 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -22,16 +22,16 @@ App.LegislationAnnotatable = scrollToAnchor: -> annotationsLoaded: (annotations) -> - anchor = $(location).attr('hash') - ann_id = anchor.split("-")[-1..] - el = $("span[data-annotation-id='" + ann_id + "']") - App.LegislationAllegations.show_comments() - $('html,body').animate({scrollTop: el.offset().top}) - $.event.trigger - type: "renderLegislationAnnotation" - annotation_id: ann_id - annotation_url: el.closest(".legislation-annotatable").data("legislation-annotatable-base-url") - offset: el.offset()["top"] + if anchor = $(location).attr('hash') + ann_id = anchor.split("-")[-1..] + el = $("span[data-annotation-id='" + ann_id + "']") + App.LegislationAllegations.show_comments() + $('html,body').animate({scrollTop: el.offset().top}) + $.event.trigger + type: "renderLegislationAnnotation" + annotation_id: ann_id + annotation_url: el.closest(".legislation-annotatable").data("legislation-annotatable-base-url") + offset: el.offset()["top"] initialize: -> $(document).on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments) From 4a5276f0898fbb2ec449b1ccd00f6ac77ec0fb3a Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 11 Jan 2017 15:34:41 +0100 Subject: [PATCH 096/197] Revert change in admin namespace helper and redefine it in the controller --- app/controllers/admin/legislation/base_controller.rb | 9 +++++++++ app/helpers/admin_helper.rb | 4 ++-- app/views/admin/legislation/_menu.html.erb | 1 - 3 files changed, 11 insertions(+), 3 deletions(-) delete mode 100644 app/views/admin/legislation/_menu.html.erb diff --git a/app/controllers/admin/legislation/base_controller.rb b/app/controllers/admin/legislation/base_controller.rb index 047180ab3..b6c62f426 100644 --- a/app/controllers/admin/legislation/base_controller.rb +++ b/app/controllers/admin/legislation/base_controller.rb @@ -2,4 +2,13 @@ class Admin::Legislation::BaseController < Admin::BaseController include FeatureFlags feature_flag :legislation + + helper_method :namespace + + private + + def namespace + "admin" + end + end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index f14269fb3..b38b0acf9 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -5,7 +5,7 @@ module AdminHelper end def official_level_options - options = [["",0]] + options = [["", 0]] (1..5).each do |i| options << [[t("admin.officials.level_#{i}"), setting["official_level_#{i}_name"]].compact.join(': '), i] end @@ -23,7 +23,7 @@ module AdminHelper private def namespace - controller.class.parent.name.downcase.gsub("::", "/") + controller.class.parent.name.downcase end end diff --git a/app/views/admin/legislation/_menu.html.erb b/app/views/admin/legislation/_menu.html.erb deleted file mode 100644 index 38c8bc5c4..000000000 --- a/app/views/admin/legislation/_menu.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render "admin/menu" %> From f974883556b3b3dc99161c124d1e7938a938b31a Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 11 Jan 2017 16:07:39 +0100 Subject: [PATCH 097/197] Refactor legislation comments partials --- ...ts_for.html.erb => _comments_box.html.erb} | 0 .../legislation/annotations/comments.js.erb | 2 +- .../legislation/annotations/show.html.erb | 2 +- .../legislation/questions/_comments.html.erb | 29 ------------------- app/views/legislation/questions/show.html.erb | 2 +- .../_comments.html.erb | 2 +- config/locales/en.yml | 4 +-- config/locales/es.yml | 4 +-- 8 files changed, 8 insertions(+), 37 deletions(-) rename app/views/legislation/annotations/{_comments_for.html.erb => _comments_box.html.erb} (100%) delete mode 100644 app/views/legislation/questions/_comments.html.erb rename app/views/legislation/{annotations => shared}/_comments.html.erb (95%) diff --git a/app/views/legislation/annotations/_comments_for.html.erb b/app/views/legislation/annotations/_comments_box.html.erb similarity index 100% rename from app/views/legislation/annotations/_comments_for.html.erb rename to app/views/legislation/annotations/_comments_box.html.erb diff --git a/app/views/legislation/annotations/comments.js.erb b/app/views/legislation/annotations/comments.js.erb index a058b00da..6ee83560e 100644 --- a/app/views/legislation/annotations/comments.js.erb +++ b/app/views/legislation/annotations/comments.js.erb @@ -1,2 +1,2 @@ -$("#comments-box").html("<%= j render('comments_for', annotation: @annotation) %>"); +$("#comments-box").html("<%= j render('comments_box', annotation: @annotation) %>"); diff --git a/app/views/legislation/annotations/show.html.erb b/app/views/legislation/annotations/show.html.erb index 6bf499f52..cdfa04447 100644 --- a/app/views/legislation/annotations/show.html.erb +++ b/app/views/legislation/annotations/show.html.erb @@ -27,7 +27,7 @@
    - <%= render 'comments', commentable: @annotation %> + <%= render 'legislation/shared/comments', commentable: @annotation %> diff --git a/app/views/legislation/questions/_comments.html.erb b/app/views/legislation/questions/_comments.html.erb deleted file mode 100644 index c7b9591e8..000000000 --- a/app/views/legislation/questions/_comments.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(@question), @comment_tree.comments, @comment_tree.comment_authors, @question.comments_count, @comment_flags] do %> -
    -
    -

    - <%= t("legislation.questions.show.comments") %> - (<%= @question.comments_count %>) -

    - - <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> - - <% if user_signed_in? %> - <%= render 'comments/form', {commentable: @question, parent_id: nil, toggeable: false} %> - <% else %> -
    - -
    - <%= t("debates.show.login_to_comment", - signin: link_to(t("votes.signin"), new_user_session_path), - signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %> -
    - <% end %> - - <% @comment_tree.root_comments.each do |comment| %> - <%= render 'comments/comment', comment: comment %> - <% end %> - <%= paginate @comment_tree.root_comments %> -
    -
    -<% end %> diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index 808b5d331..4ad67a546 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -49,4 +49,4 @@ -<%= render 'comments' %> +<%= render 'legislation/shared/comments', commentable: @question %> diff --git a/app/views/legislation/annotations/_comments.html.erb b/app/views/legislation/shared/_comments.html.erb similarity index 95% rename from app/views/legislation/annotations/_comments.html.erb rename to app/views/legislation/shared/_comments.html.erb index 158c2f789..25b4ce18d 100644 --- a/app/views/legislation/annotations/_comments.html.erb +++ b/app/views/legislation/shared/_comments.html.erb @@ -2,7 +2,7 @@

    - <%= t("legislation.annotations.show.comments") %> + <%= t("legislation.shared.comments") %> (<%= commentable.comments_count %>)

    diff --git a/config/locales/en.yml b/config/locales/en.yml index a7fe21a91..0e6831657 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -242,7 +242,6 @@ en: other: "%{count} comments" show: title: Comment - comments: Comments version_chooser: seeing_version: Commments for version see_text: See text draft @@ -305,7 +304,6 @@ en: debate: Debate show: answer_question: Submit answer - comments: Comments next_question: Next question first_question: First question share: Share @@ -322,6 +320,8 @@ en: verified_only: Only verified users can participate, %{verify_account}. verify_account: verify your account debate_phase_not_open: Debate phase has finished and answers are not accepted anymore + shared: + comments: Comments locale: English notifications: index: diff --git a/config/locales/es.yml b/config/locales/es.yml index 823115d12..6afbc6820 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -242,7 +242,6 @@ es: other: "%{count} comentarios" show: title: Comentario - comments: Comentarios version_chooser: seeing_version: Comentarios para la versión see_text: Ver borrador del texto @@ -305,7 +304,6 @@ es: debate: Debate show: answer_question: Enviar respuesta - comments: Comentarios next_question: Siguiente pregunta first_question: Primera pregunta share: Compartir @@ -322,6 +320,8 @@ es: verified_only: Solo los usuarios verificados pueden participar en el debate, %{verify_account}. verify_account: verifica tu cuenta debate_phase_not_open: La fase de debate previo ya ha finalizado y en este momento no se aceptan respuestas + shared: + comments: Comentarios locale: Español notifications: index: From 306e3fa59f94558a3262a592f434b147586d29a4 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 11 Jan 2017 19:44:41 +0100 Subject: [PATCH 098/197] =?UTF-8?q?Don=E2=80=99t=20show=20comments=20panel?= =?UTF-8?q?=20if=20seeing=20final=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legislation_annotatable.js.coffee | 1 + .../draft_versions/_comments_panel.html.erb | 18 +++++++++ .../legislation/draft_versions/show.html.erb | 39 ++++++++----------- .../legislation/draft_versions_spec.rb | 12 ++++++ 4 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 app/views/legislation/draft_versions/_comments_panel.html.erb diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index ce9e9b8d7..f1df2927a 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -12,6 +12,7 @@ App.LegislationAnnotatable = viewerExtension: (viewer) -> viewer._onHighlightMouseover = (event) -> App.LegislationAllegations.show_comments() + $("#comments-box").show() $.event.trigger type: "renderLegislationAnnotation" annotation_id: $(event.target).data("annotation-id") diff --git a/app/views/legislation/draft_versions/_comments_panel.html.erb b/app/views/legislation/draft_versions/_comments_panel.html.erb new file mode 100644 index 000000000..94523b557 --- /dev/null +++ b/app/views/legislation/draft_versions/_comments_panel.html.erb @@ -0,0 +1,18 @@ +
    +
    +
    + <%= t('legislation.draft_versions.show.text_comments') %> +
    +
    + +
    + <%= t('legislation.draft_versions.show.text_comments') %> +
    + + +
    diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index 6bee874c4..d89926929 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -18,13 +18,17 @@
    <%= t('.updated_at', date: format_date(@draft_version.updated_at)) %>
    -
    - <%= link_to t('.see_comments'), legislation_process_draft_version_annotations_path(@process, @draft_version), title: t('.see_comments'), class: "button strong" %> -
    + + <% unless @draft_version.final_version? %> +
    + <%= link_to t('.see_comments'), legislation_process_draft_version_annotations_path(@process, @draft_version), title: t('.see_comments'), class: "button strong" %> +
    + <% end %> +
    -
    +
    ">
    <%= t('.text_toc') %> @@ -44,34 +48,25 @@
    <%= t('.text_body') %>
    + <% if @draft_version.final_version? %> +
    + <% else %>
    + <% end %> <%= @draft_version.body_html.html_safe %>
    -
    -
    -
    - <%= t('.text_comments') %> -
    -
    + <% if @draft_version.final_version? %> +
    + <% else %> + <%= render 'comments_panel', draft_version: @draft_version %> + <% end %> -
    - <%= t('.text_comments') %> -
    - -
    -
    - -
    <%= t('.loading_comments') %>
    -
    -
    - -
    diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index c7f761669..cd655ae4a 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -61,6 +61,18 @@ feature 'Legislation Draft Versions' do expect(page).to_not have_content("Body of the first version") expect(page).to have_content("Body of the second version") end + + context "for final versions" do + it "does not show the comments panel" do + final_version = create(:legislation_draft_version, process: @process, title: "Final version", body: "Final body", status: "published", final_version: true) + + visit legislation_process_draft_version_path(@process, final_version) + + expect(page).to have_content("Final body") + expect(page).to_not have_content("See all comments") + expect(page).to_not have_content("Comments") + end + end end context "See changes page" do From a56898fed7423e18b5347b8ee164718de1bdf447 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Wed, 11 Jan 2017 20:14:20 +0100 Subject: [PATCH 099/197] Fix version chooser for annotations page --- .../legislation/annotations_controller.rb | 1 + .../legislation/draft_versions_controller.rb | 2 + .../legislation/draft_versions_spec.rb | 40 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index ee63574f5..ff4ecf813 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -10,6 +10,7 @@ class Legislation::AnnotationsController < ApplicationController has_orders %w{most_voted newest oldest}, only: :show def index + @annotations = @draft_version.annotations end def show diff --git a/app/controllers/legislation/draft_versions_controller.rb b/app/controllers/legislation/draft_versions_controller.rb index 0b6af46a6..cdac2c9d5 100644 --- a/app/controllers/legislation/draft_versions_controller.rb +++ b/app/controllers/legislation/draft_versions_controller.rb @@ -20,6 +20,8 @@ class Legislation::DraftVersionsController < Legislation::BaseController if params[:redirect_action] == 'changes' redirect_to legislation_process_draft_version_changes_path(@process, version) + elsif params[:redirect_action] == 'annotations' + redirect_to legislation_process_draft_version_annotations_path(@process, version) else redirect_to legislation_process_draft_version_path(@process, version) end diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index cd655ae4a..6c39d11ce 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -178,6 +178,7 @@ feature 'Legislation Draft Versions' do @annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "first quote") @annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "second quote") end + scenario "See all annotations for a draft version" do visit legislation_process_draft_version_annotations_path(@draft_version.process, @draft_version) @@ -185,6 +186,45 @@ feature 'Legislation Draft Versions' do expect(page).to have_content "second quote" end + context "switching versions" do + background do + @process = create(:legislation_process) + @draft_version_1 = create(:legislation_draft_version, :published, process: @process, title: "Version 1", body: Faker::Lorem.paragraph) + @annotation_1 = create(:legislation_annotation, draft_version: @draft_version_1, text: "annotation for version 1", quote: "quote for version 1") + @draft_version_2 = create(:legislation_draft_version, :published, process: @process, title: "Version 2", body: Faker::Lorem.paragraph) + @annotation_1 = create(:legislation_annotation, draft_version: @draft_version_2, text: "annotation for version 2", quote: "quote for version 2") + end + + scenario "without js" do + visit legislation_process_draft_version_annotations_path(@process, @draft_version_1) + expect(page).to have_content("quote for version 1") + + select("Version 2") + click_button "see" + + expect(page).to_not have_content("quote for version 1") + expect(page).to have_content("quote for version 2") + end + + scenario "with js", :js do + visit legislation_process_draft_version_annotations_path(@process, @draft_version_1) + expect(page).to have_content("quote for version 1") + + select("Version 2") + + expect(page).to_not have_content("quote for version 1") + expect(page).to have_content("quote for version 2") + end + end + end + + context "Annotation comments page" do + background do + @draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) + @annotation_1 = create(:legislation_annotation, draft_version: @draft_version, text: "my annotation", quote: "first quote") + @annotation_2 = create(:legislation_annotation, draft_version: @draft_version, text: "my other annotation", quote: "second quote") + end + scenario "See one annotation with replies for a draft version" do visit legislation_process_draft_version_annotation_path(@draft_version.process, @draft_version, @annotation_2) From 203bc740ac4bc423c5af2c07b07d2e252ea6a826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Thu, 12 Jan 2017 10:54:39 +0100 Subject: [PATCH 100/197] Adjust home and process index styles --- app/assets/stylesheets/legislation.scss | 4 +- .../stylesheets/legislation_process.scss | 117 +++++++++++------- .../legislation/processes/_key_dates.html.erb | 59 ++++----- .../legislation/processes/_process.html.erb | 5 +- .../processes/phase_empty.html.erb | 4 +- .../processes/phase_not_open.html.erb | 4 +- app/views/legislation/processes/show.html.erb | 4 +- 7 files changed, 115 insertions(+), 82 deletions(-) diff --git a/app/assets/stylesheets/legislation.scss b/app/assets/stylesheets/legislation.scss index c53216dd9..950f9ce23 100644 --- a/app/assets/stylesheets/legislation.scss +++ b/app/assets/stylesheets/legislation.scss @@ -9,7 +9,7 @@ // ----------------- .brand-heading { background: $brand; - margin-bottom: 2rem; + margin-bottom: 5rem; .column { padding-top: 10rem; @@ -58,7 +58,7 @@ // 03. Legislation cards // ----------------- .legislation { - margin: 0 0 4rem 0; + margin: 0 0 5rem 0; background: white; border: 1px solid; border-color: #e5e6e9 #dfe0e4 #d0d1d5; diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index d5ab74130..db6c9718e 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -34,6 +34,8 @@ font-weight: 700; } +$epigraph-font-size: rem-calc(15); + // 02. Hero // ----------------- .legislation-hero { @@ -63,7 +65,9 @@ #debate-info { display: none; - margin-top: 1rem; + margin-top: 3rem; + padding-top: 4rem; + border-top: 1px solid darken($border, 10%); @include breakpoint(medium) { margin-bottom: 2rem; @@ -80,6 +84,7 @@ } p { + font-size: $base-font-size; @include breakpoint(medium) { margin-left: 25%; } @@ -97,7 +102,7 @@ } .center .button { - background: #004A83; + background: $brand; margin-bottom: 0; } @@ -112,6 +117,14 @@ .description { margin-bottom: 1rem; + + p { + font-size: $epigraph-font-size; + } + + h4 { + font-size: $base-font-size; + } @include breakpoint(medium) { margin-bottom: 0; @@ -145,61 +158,75 @@ // ----------------- .legislation-process-categories { position: relative; - - svg { - position: absolute; - top: 1.5rem; - left: 0; - - @include breakpoint(medium) { - transform: rotate(-8deg); - top: 0.75rem; - } - } - - ul { - padding-top: 4rem; - list-style: none; - margin-left: 0; - padding-left: 0; + + .legislation-process-list { border-bottom: 1px solid $medium-gray; - - li { - cursor: pointer; + margin: 0 1rem 1rem 1rem; + + @include breakpoint(medium) { margin-left: 0; - display: inline-block; - margin-bottom: 1rem; - margin-right: 1rem; + } + + ul { + max-width: 75rem; + margin-left: auto; + margin-right: auto; + list-style: none; + padding-top: 4rem; + padding-left: 0; + margin-bottom: 0; + + @include breakpoint(medium) { + padding-left: 1rem; + } + + svg { + position: absolute; + top: 1.5rem; - @media (min-width: 950px) { - margin-right: 0; - margin-left: 3rem; - margin-bottom: 0; + @include breakpoint(medium) { + transform: rotate(-8deg); + top: 0.75rem; + } } - a, - h4 { - color: #6D6D6D; - margin-bottom: 0; - } - - a { - &:hover, &:active { - text-decoration: none; + li { + cursor: pointer; + display: inline-block; + margin: 0 1rem 1rem 0; + + &:first-of-type { + margin-left: 0; } - p { - margin-bottom: 0; + @media (min-width: 950px) { + margin: 0 0 0 3rem; + } - @include breakpoint(medium) { - margin-bottom: 1rem; + a, + h4 { + color: #6D6D6D; + margin-bottom: 0; + } + + a { + &:hover, &:active { + text-decoration: none; + } + + p { + margin-bottom: 0; + + @include breakpoint(medium) { + margin-bottom: 1rem; + } } } } - } - .active { - border-bottom: 2px solid $brand; + .active { + border-bottom: 2px solid $brand; + } } } } diff --git a/app/views/legislation/processes/_key_dates.html.erb b/app/views/legislation/processes/_key_dates.html.erb index a6d921c35..e64d99f08 100644 --- a/app/views/legislation/processes/_key_dates.html.erb +++ b/app/views/legislation/processes/_key_dates.html.erb @@ -1,29 +1,32 @@ -
    + +
    + <%= markdown(first_paragraph(process.description)) %> +
    diff --git a/app/views/legislation/processes/phase_empty.html.erb b/app/views/legislation/processes/phase_empty.html.erb index 6fb588faf..d0534d59c 100644 --- a/app/views/legislation/processes/phase_empty.html.erb +++ b/app/views/legislation/processes/phase_empty.html.erb @@ -2,9 +2,9 @@ <%= render 'legislation/processes/header', process: @process, header: :full %> -
    - <%= render 'legislation/processes/key_dates', process: @process, phase: @phase %> +<%= render 'legislation/processes/key_dates', process: @process, phase: @phase %> +

    <%= t(".empty") %>

    diff --git a/app/views/legislation/processes/phase_not_open.html.erb b/app/views/legislation/processes/phase_not_open.html.erb index 0b3b90f01..0b20c83f8 100644 --- a/app/views/legislation/processes/phase_not_open.html.erb +++ b/app/views/legislation/processes/phase_not_open.html.erb @@ -2,9 +2,9 @@ <%= render 'legislation/processes/header', process: @process, header: :full %> -
    - <%= render 'legislation/processes/key_dates', process: @process, phase: @phase %> +<%= 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 410068831..5b29dc292 100644 --- a/app/views/legislation/processes/show.html.erb +++ b/app/views/legislation/processes/show.html.erb @@ -2,9 +2,9 @@ <%= render 'legislation/processes/header', process: @process, header: :full %> -
    - <%= render 'key_dates', process: @process, phase: :debate %> +<%= render 'key_dates', process: @process, phase: :debate %> +
    <%= render 'debate', process: @process %> From be024f0fe133ecda1bee4fc5918f0bcae34f48f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Thu, 12 Jan 2017 11:19:30 +0100 Subject: [PATCH 101/197] Push legislation comments style fixes --- app/assets/stylesheets/legislation_process.scss | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index db6c9718e..1e3fc8bb1 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -310,6 +310,7 @@ $epigraph-font-size: rem-calc(15); } .quiz-next-link { + display: block; &:hover, &:active { text-decoration: none; @@ -484,15 +485,12 @@ $epigraph-font-size: rem-calc(15); } span { - margin-left: 0.75rem; + margin-left: 0.25rem; font-style: italic; font-size: $small-font-size; color: $text-medium; vertical-align: top; - - @include breakpoint(medium) { - margin-left: 1rem; - } + line-height: 2.35rem; } .select-box { @@ -547,17 +545,14 @@ $epigraph-font-size: rem-calc(15); // Panel calcs for desktop @media screen and (min-width: 40em) { .calc-index { - transition: all 0.25s; width: calc(35% - 25px); } .calc-text { - transition: all 0.25s; width: calc(65% - 25px) } .calc-comments { - transition: all 0.25s; cursor: pointer; background: #F2F2F2; width: 50px; From a0011b7c5c8ce3283acf9fefd0f787f31fa11139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Thu, 12 Jan 2017 11:55:12 +0100 Subject: [PATCH 102/197] More css fixes --- app/assets/stylesheets/legislation_process.scss | 11 +++++++++++ app/views/legislation/processes/_header.html.erb | 2 +- app/views/legislation/questions/show.html.erb | 5 +++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 1e3fc8bb1..2c0dfc672 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -280,6 +280,9 @@ $epigraph-font-size: rem-calc(15); // 05. Debate quiz // ----------------- .debate-quiz { + .comments { + margin-top: 4rem; + } .quiz-header { margin-bottom: 2rem; @@ -349,6 +352,10 @@ $epigraph-font-size: rem-calc(15); .debate-questions { position: relative; list-style: none; + + .participation-not-allowed { + padding-bottom: 3rem; + } .control { position: relative; @@ -430,6 +437,10 @@ $epigraph-font-size: rem-calc(15); .headline { margin-bottom: 0; + + .headline-small { + padding-top: 0.75rem; + } } .button-circle { diff --git a/app/views/legislation/processes/_header.html.erb b/app/views/legislation/processes/_header.html.erb index c73c732af..5d18217bc 100644 --- a/app/views/legislation/processes/_header.html.erb +++ b/app/views/legislation/processes/_header.html.erb @@ -2,7 +2,7 @@ + + <%= render 'legislation/shared/comments', commentable: @question %> + - -<%= render 'legislation/shared/comments', commentable: @question %> From 495c7e8099b1f211a929d001c9badf5068d5f1a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Thu, 12 Jan 2017 12:16:45 +0100 Subject: [PATCH 103/197] Key dates SVG fix --- app/assets/stylesheets/legislation_process.scss | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 2c0dfc672..201d83fcb 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -168,6 +168,7 @@ $epigraph-font-size: rem-calc(15); } ul { + position: relative; max-width: 75rem; margin-left: auto; margin-right: auto; @@ -182,10 +183,11 @@ $epigraph-font-size: rem-calc(15); svg { position: absolute; - top: 1.5rem; + top: 1.25rem; + left: -1rem; @include breakpoint(medium) { - transform: rotate(-8deg); + transform: rotate(-6deg); top: 0.75rem; } } From 046bcbfb0f74704c647095443ffaaade758f2dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Thu, 12 Jan 2017 12:48:14 +0100 Subject: [PATCH 104/197] Fix small header toggle --- app/assets/javascripts/legislation.js.coffee | 8 +++++--- app/assets/stylesheets/legislation_process.scss | 12 +++++++++++- app/views/legislation/processes/_header.html.erb | 11 ++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/legislation.js.coffee b/app/assets/javascripts/legislation.js.coffee index 26c0185c1..cf2dfabd1 100644 --- a/app/assets/javascripts/legislation.js.coffee +++ b/app/assets/javascripts/legislation.js.coffee @@ -4,6 +4,11 @@ App.Legislation = $('#js-toggle-debate').on click: -> $('#debate-info').toggle() + + $('#js-toggle-small-debate').on + click: -> + $('#debate-info').toggle() + $('span').toggleClass('icon-angle-up') $('form#new_legislation_answer input.button').hide() $('form#new_legislation_answer input[type=radio]').on @@ -17,7 +22,4 @@ App.Legislation = $('#js-toggle-legislation-process-header').on click: -> - $('[data-target="legislation-header-small"]').toggle() $('[data-target="legislation-header-full"]').toggle() - - diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 201d83fcb..ba506dc37 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -447,8 +447,18 @@ $epigraph-font-size: rem-calc(15); .button-circle { line-height: 0; - padding: 0.5em; + padding: 0em; + width: 30px; + height: 30px; border-radius: 50%; + + span { + padding-left: 1px; + + &:before { + line-height: 1.55; + } + } } .icon-checkmark-circle { diff --git a/app/views/legislation/processes/_header.html.erb b/app/views/legislation/processes/_header.html.erb index 5d18217bc..b59969b81 100644 --- a/app/views/legislation/processes/_header.html.erb +++ b/app/views/legislation/processes/_header.html.erb @@ -11,8 +11,17 @@
    + +
    + +
    + From 1cf074a297e4ef7d2aa74656c866ccf9fd37ec2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Fri, 13 Jan 2017 15:41:23 +0100 Subject: [PATCH 105/197] Fix identation and markup issue on the legislation question page --- app/views/legislation/questions/show.html.erb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index 2e79136b3..8ba698899 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -39,13 +39,13 @@

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

    +
    +
    <%= render 'legislation/shared/comments', commentable: @question %> From 3f956294ed8c87aa8521d04e905d220c52bed215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Fri, 13 Jan 2017 15:51:12 +0100 Subject: [PATCH 106/197] Fix legislation question comments markup --- app/views/legislation/questions/show.html.erb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index 2e79136b3..b2e83fc3c 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -39,14 +39,13 @@

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

    -
    +
    + <%= render 'legislation/shared/comments', commentable: @question %> From 02d49266e0af210a6a9ea5b6df0a5a42b0d3d510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Fri, 13 Jan 2017 16:14:44 +0100 Subject: [PATCH 107/197] Increase margin on questions to fix a cosmetic issue --- app/assets/stylesheets/legislation_process.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index ba506dc37..b2cb4e527 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -369,6 +369,7 @@ $epigraph-font-size: rem-calc(15); border-radius: 4px; padding: 0.75rem 2.5rem; margin-right: 1.5rem; + margin-bottom: 0.5rem; } .active { From 5a5fed975a5e49d60331cc744cd7f73e08be3014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Fri, 13 Jan 2017 16:19:57 +0100 Subject: [PATCH 108/197] Push changes --- app/views/legislation/questions/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index 8ba698899..d12296a2f 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -49,5 +49,5 @@
    <%= render 'legislation/shared/comments', commentable: @question %> - + From eadf933c22a4bc594f508ca6110f56bb5400a19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Fri, 13 Jan 2017 16:42:59 +0100 Subject: [PATCH 109/197] Change debate questions class to avoid colliding with other CSS --- app/assets/stylesheets/legislation_process.scss | 2 +- app/views/legislation/questions/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index b2cb4e527..6de923542 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -281,7 +281,7 @@ $epigraph-font-size: rem-calc(15); // 05. Debate quiz // ----------------- -.debate-quiz { +.debate-questions { .comments { margin-top: 4rem; } diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index d12296a2f..c74bd9efa 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -1,6 +1,6 @@ <% provide :title do %><%= @question.title %><% end %> -
    +
    From 49e66a431c12560b76418f8779a67967e429b461 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Fri, 13 Jan 2017 17:57:03 +0100 Subject: [PATCH 110/197] Check phase dates and that draft version is not final before creating annotations --- .../legislation/annotations_controller.rb | 18 ++++- .../legislation/answers_controller.rb | 2 +- .../annotations_controller_spec.rb | 70 +++++++++++++++++++ .../legislation/answers_controller_spec.rb | 5 -- spec/factories.rb | 4 ++ 5 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 spec/controllers/legislation/annotations_controller_spec.rb diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index ff4ecf813..f1c4e4401 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -20,15 +20,22 @@ class Legislation::AnnotationsController < ApplicationController end def create - @annotation = Legislation::Annotation.new(annotation_params) + if !@process.open_phase?(:allegations) || @draft_version.final_version? + render json: {}, status: :not_found and return + end + + @annotation = @draft_version.annotations.new(annotation_params) @annotation.author = current_user if @annotation.save + track_event render json: @annotation.to_json + else + render json: {}, status: :unprocessable_entity end end def search - @annotations = Legislation::Annotation.where(legislation_draft_version_id: params[:legislation_draft_version_id]) + @annotations = @draft_version.annotations annotations_hash = { total: @annotations.size, rows: @annotations } render json: annotations_hash.to_json end @@ -43,7 +50,12 @@ class Legislation::AnnotationsController < ApplicationController params .require(:annotation) .permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset]) - .merge(legislation_draft_version_id: params[:legislation_draft_version_id]) + end + + def track_event + ahoy.track "legislation_annotation_created".to_sym, + "legislation_annotation_id": @annotation.id, + "legislation_draft_version_id": @draft_version.id end end diff --git a/app/controllers/legislation/answers_controller.rb b/app/controllers/legislation/answers_controller.rb index ac77ea5f1..372398e41 100644 --- a/app/controllers/legislation/answers_controller.rb +++ b/app/controllers/legislation/answers_controller.rb @@ -19,7 +19,7 @@ class Legislation::AnswersController < Legislation::BaseController end else respond_to do |format| - format.js + format.js { render json: {} , status: :not_found } format.html { redirect_to legislation_process_question_path(@process, @question), alert: t('legislation.questions.participation.phase_not_open') } end end diff --git a/spec/controllers/legislation/annotations_controller_spec.rb b/spec/controllers/legislation/annotations_controller_spec.rb new file mode 100644 index 000000000..2713fc273 --- /dev/null +++ b/spec/controllers/legislation/annotations_controller_spec.rb @@ -0,0 +1,70 @@ +require 'rails_helper' + +describe Legislation::AnnotationsController do + + describe 'POST create' do + before(:each) do + @process = create(:legislation_process, allegations_start_date: Date.current - 3.day, allegations_end_date: Date.current + 2.days) + @draft_version = create(:legislation_draft_version, :published, process: @process, title: "Version 1") + @final_version = create(:legislation_draft_version, :published, :final_version, process: @process, title: "Final version") + @user = create(:user, :level_two) + end + + it 'should create an ahoy event' do + sign_in @user + + post :create, process_id: @process.id, + draft_version_id: @draft_version.id, + annotation: { + "quote"=>"Ordenación Territorial", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], + "text": "una anotacion" + } + expect(Ahoy::Event.where(name: :legislation_annotation_created).count).to eq 1 + expect(Ahoy::Event.last.properties['legislation_annotation_id']).to eq Legislation::Annotation.last.id + end + + it 'should not create an annotation if the draft version is a final version' do + sign_in @user + + post :create, process_id: @process.id, + draft_version_id: @final_version.id, + annotation: { + "quote"=>"Ordenación Territorial", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], + "text": "una anotacion" + } + + expect(response).to have_http_status(:not_found) + end + + it 'should create an annotation if the process allegations phase is open' do + sign_in @user + + expect do + xhr :post, :create, process_id: @process.id, + draft_version_id: @draft_version.id, + annotation: { + "quote"=>"Ordenación Territorial", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], + "text": "una anotacion" + } + end.to change { @draft_version.annotations.count }.by(1) + end + + it 'should not create an annotation if the process allegations phase is not open' do + sign_in @user + @process.update_attribute(:allegations_end_date, Date.current - 1.day) + + expect do + xhr :post, :create, process_id: @process.id, + draft_version_id: @draft_version.id, + annotation: { + "quote"=>"Ordenación Territorial", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], + "text": "una anotacion" + } + end.to_not change { @draft_version.annotations.count } + end + end +end diff --git a/spec/controllers/legislation/answers_controller_spec.rb b/spec/controllers/legislation/answers_controller_spec.rb index 99efcef67..77d037478 100644 --- a/spec/controllers/legislation/answers_controller_spec.rb +++ b/spec/controllers/legislation/answers_controller_spec.rb @@ -4,17 +4,12 @@ describe Legislation::AnswersController do describe 'POST create' do before(:each) do - InvisibleCaptcha.timestamp_enabled = false @process = create(:legislation_process, debate_start_date: Date.current - 3.day, debate_end_date: Date.current + 2.days) @question = create(:legislation_question, process: @process, title: "Question 1") @question_option = create(:legislation_question_option, question: @question, value: "Yes") @user = create(:user, :level_two) end - after(:each) do - InvisibleCaptcha.timestamp_enabled = true - end - it 'should create an ahoy event' do sign_in @user diff --git a/spec/factories.rb b/spec/factories.rb index a7ee19610..5ed16fc30 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -499,6 +499,10 @@ FactoryGirl.define do trait :published do status "published" end + + trait :final_version do + final_version true + end end factory :legislation_annotation, class: 'Legislation::Annotation' do From 49f4bf5bc568027760d103da1ce2c1f0c039863a Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Fri, 13 Jan 2017 19:34:17 +0100 Subject: [PATCH 111/197] Destroy object when their parent object is destroyed --- app/models/legislation/annotation.rb | 2 +- app/models/legislation/draft_version.rb | 2 +- app/models/legislation/process.rb | 4 ++-- app/models/legislation/question.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index d62363946..2bdfb3fca 100644 --- a/app/models/legislation/annotation.rb +++ b/app/models/legislation/annotation.rb @@ -6,7 +6,7 @@ class Legislation::Annotation < ActiveRecord::Base belongs_to :draft_version, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_draft_version_id' belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id' - has_many :comments, as: :commentable + has_many :comments, as: :commentable, dependent: :destroy validates :text, presence: true validates :quote, presence: true diff --git a/app/models/legislation/draft_version.rb b/app/models/legislation/draft_version.rb index d0150f1ff..297cef236 100644 --- a/app/models/legislation/draft_version.rb +++ b/app/models/legislation/draft_version.rb @@ -5,7 +5,7 @@ class Legislation::DraftVersion < ActiveRecord::Base include ActsAsParanoidAliases belongs_to :process, class_name: 'Legislation::Process', foreign_key: 'legislation_process_id' - has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id' + has_many :annotations, class_name: 'Legislation::Annotation', foreign_key: 'legislation_draft_version_id', dependent: :destroy validates :title, presence: true validates :body, presence: true diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index 291e85b5a..5c4fc391b 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -2,9 +2,9 @@ class Legislation::Process < ActiveRecord::Base acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases - has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id' + has_many :draft_versions, -> { order(:id) }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id', dependent: :destroy has_one :final_draft_version, -> { where final_version: true, status: 'published' }, class_name: 'Legislation::DraftVersion', foreign_key: 'legislation_process_id' - has_many :questions, -> { order(:id) }, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id' + has_many :questions, -> { order(:id) }, class_name: 'Legislation::Question', foreign_key: 'legislation_process_id', dependent: :destroy validates :title, presence: true validates :description, presence: true diff --git a/app/models/legislation/question.rb b/app/models/legislation/question.rb index c1dacd464..5ab0ea355 100644 --- a/app/models/legislation/question.rb +++ b/app/models/legislation/question.rb @@ -7,7 +7,7 @@ class Legislation::Question < ActiveRecord::Base has_many :question_options, -> { order(:id) }, class_name: 'Legislation::QuestionOption', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question has_many :answers, class_name: 'Legislation::Answer', foreign_key: 'legislation_question_id', dependent: :destroy, inverse_of: :question - has_many :comments, as: :commentable + has_many :comments, as: :commentable, dependent: :destroy accepts_nested_attributes_for :question_options, :reject_if => proc { |attributes| attributes[:value].blank? }, allow_destroy: true From 4431d95d31c5facf343bc09d34a802a32f442f94 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Tue, 10 Jan 2017 18:21:37 +0100 Subject: [PATCH 112/197] Basic annotation creation --- app/assets/javascripts/application.js | 2 +- app/assets/javascripts/custom.js | 3 +- .../legislation_annotatable.js.coffee | 22 ++++++++++++- .../legislation/annotations_controller.rb | 15 +++++++++ .../legislation/annotations/_form.html.erb | 31 +++++++++++++++++++ app/views/legislation/annotations/new.js.erb | 2 ++ config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 8 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 app/views/legislation/annotations/_form.html.erb create mode 100644 app/views/legislation/annotations/new.js.erb diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 939705c51..19c081b54 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -53,8 +53,8 @@ //= require cocoon //= require legislation //= require legislation_allegations -//= require legislation_annotatable //= require custom +//= require legislation_annotatable var initialize_modules = function() { App.Comments.initialize(); diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index 6c880b3a9..50903021a 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -1,7 +1,6 @@ // Overrides and adds customized javascripts in this file -// Read more on documentation: +// Read more on documentation: // * English: https://github.com/consul/consul/blob/master/CUSTOMIZE_EN.md#javascript // * Spanish: https://github.com/consul/consul/blob/master/CUSTOMIZE_ES.md#javascript // -// diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index f1df2927a..dd861c6ef 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -19,7 +19,23 @@ App.LegislationAnnotatable = annotation_url: $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url") offset: $(event.target).offset()["top"] + customShow: (position) -> + $(@element).html '' + # Clean comments section and open it + $('#comments-box').html '' + App.LegislationAllegations.show_comments() + annotation_url = $('[data-legislation-annotatable-base-url]').data('legislation-annotatable-base-url') + $.ajax( + method: 'GET' + url: annotation_url + '/annotations/new' + dataType: 'script').done (-> + $('#new_annotation #annotation_quote').val(@annotation.quote) + $('#new_annotation #annotation_ranges').val(JSON.stringify(@annotation.ranges)) + ).bind(this) + + editorExtension: (editor) -> + editor.show = App.LegislationAnnotatable.customShow scrollToAnchor: -> annotationsLoaded: (annotations) -> @@ -62,7 +78,11 @@ App.LegislationAnnotatable = ann["legislation_draft_version_id"] = ann_id ann.permissions = ann.permissions || {} ann.permissions.admin = [] - .include(annotator.ui.main, { element: this, viewerExtensions: [App.LegislationAnnotatable.viewerExtension] }) + .include(annotator.ui.main, { + element: this, + viewerExtensions: [App.LegislationAnnotatable.viewerExtension], + editorExtensions: [App.LegislationAnnotatable.editorExtension] + }) .include(App.LegislationAnnotatable.scrollToAnchor) .include(annotator.storage.http, { prefix: base_url, urls: { search: "/annotations/search" } }) diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index f1c4e4401..861eb9d14 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -2,6 +2,7 @@ class Legislation::AnnotationsController < ApplicationController skip_before_action :verify_authenticity_token before_action :authenticate_user!, only: [:create] + before_action :convert_ranges_parameters, only: [:create] load_and_authorize_resource :process load_and_authorize_resource :draft_version, through: :process @@ -44,6 +45,13 @@ class Legislation::AnnotationsController < ApplicationController @annotation = Legislation::Annotation.find(params[:annotation_id]) end + def new + respond_to do |format| + format.js + end + end + + private def annotation_params @@ -58,4 +66,11 @@ class Legislation::AnnotationsController < ApplicationController "legislation_draft_version_id": @draft_version.id end + def convert_ranges_parameters + if params[:annotation] && params[:annotation][:ranges] + params[:annotation][:ranges] = JSON.parse(params[:annotation][:ranges]) + end + rescue JSON::ParserError + end + end diff --git a/app/views/legislation/annotations/_form.html.erb b/app/views/legislation/annotations/_form.html.erb new file mode 100644 index 000000000..81605e648 --- /dev/null +++ b/app/views/legislation/annotations/_form.html.erb @@ -0,0 +1,31 @@ +
    + +
    <%= t('legislation.annotations.comments.comments_count', count: 0) %>
    + <%= link_to '#' do %> + + <% end %> +
    + +
    +
    + <%= form_for [@process, @draft_version, Annotation.new], url: legislation_process_draft_version_annotations_path(@process, @draft_version), remote: true do |f| %> + <%= f.text_area :text, autofocus: true %> + +
    + <%= t('legislation.annotations.comments.cancel') %> + <%= f.submit t('legislation.annotations.comments.publish_comment'), class: 'button strong publish-comment' %> + <% if false %> + <%= t('legislation.annotations.comments.publish_comment') %> + <% end %> +
    + + <%= f.hidden_field :quote %> + <%= f.hidden_field :ranges %> + <% end %> +
    + + +
    + diff --git a/app/views/legislation/annotations/new.js.erb b/app/views/legislation/annotations/new.js.erb new file mode 100644 index 000000000..9b719814c --- /dev/null +++ b/app/views/legislation/annotations/new.js.erb @@ -0,0 +1,2 @@ +$("#comments-box").html("<%= j render('form') %>"); + diff --git a/config/locales/en.yml b/config/locales/en.yml index 760fa67c8..09eac149c 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -235,6 +235,8 @@ en: replies_count: one: "%{count} reply" other: "%{count} replies" + cancel: Cancel + publish_comment: Publish Comment index: title: Comments comments_about: Comments about diff --git a/config/locales/es.yml b/config/locales/es.yml index 81716214b..1a9626cc6 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -235,6 +235,8 @@ es: replies_count: one: "%{count} respuesta" other: "%{count} respuestas" + cancel: Cancelar + publish_comment: Publicar Comentario index: title: Comentarios see_in_context: Ver en contexto From 17a68f5c14233cae3a6b52a1273e46d69d84d924 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Wed, 11 Jan 2017 17:20:00 +0100 Subject: [PATCH 113/197] Load annotations on click event --- .../legislation_annotatable.js.coffee | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index dd861c6ef..343c638ad 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -9,15 +9,21 @@ App.LegislationAnnotatable = url: event.annotation_url + "/annotations/" + event.annotation_id + "/comments" dataType: 'script' + onClick: (event) -> + event.preventDefault() + event.stopPropagation() + + App.LegislationAllegations.show_comments() + $("#comments-box").show() + $.event.trigger + type: "renderLegislationAnnotation" + annotation_id: $(event.target).data("annotation-id") + annotation_url: $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url") + offset: $(event.target).offset()["top"] + viewerExtension: (viewer) -> viewer._onHighlightMouseover = (event) -> - App.LegislationAllegations.show_comments() - $("#comments-box").show() - $.event.trigger - type: "renderLegislationAnnotation" - annotation_id: $(event.target).data("annotation-id") - annotation_url: $(event.target).closest(".legislation-annotatable").data("legislation-annotatable-base-url") - offset: $(event.target).offset()["top"] + return customShow: (position) -> $(@element).html '' @@ -52,6 +58,7 @@ App.LegislationAnnotatable = initialize: -> $(document).on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments) + $(document).on('click', '[data-annotation-id]', App.LegislationAnnotatable.onClick) current_user_id = $('html').data('current-user-id') if current_user_id == "" From 72ff1de2ab62e93a1cab97580030dae15514a34d Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 12 Jan 2017 19:36:16 +0100 Subject: [PATCH 114/197] CSS fix --- app/assets/stylesheets/legislation_process.scss | 1 - 1 file changed, 1 deletion(-) diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index d5ab74130..e7fc4dcc1 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -831,7 +831,6 @@ textarea { border-radius: 0; box-shadow: none; - border-top: none; border-bottom: 1px solid #D0D0D0; border-right: 1px solid #D0D0D0; border-left: 1px solid #D0D0D0; From 755ddab2cb434f170446023c0a2abfc637afc6f6 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Thu, 12 Jan 2017 19:36:24 +0100 Subject: [PATCH 115/197] Amend translations --- app/views/legislation/annotations/_form.html.erb | 11 ++--------- config/locales/activerecord.en.yml | 6 ++++-- config/locales/activerecord.es.yml | 6 ++++-- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/views/legislation/annotations/_form.html.erb b/app/views/legislation/annotations/_form.html.erb index 81605e648..5662cafe2 100644 --- a/app/views/legislation/annotations/_form.html.erb +++ b/app/views/legislation/annotations/_form.html.erb @@ -8,24 +8,17 @@
    - <%= form_for [@process, @draft_version, Annotation.new], url: legislation_process_draft_version_annotations_path(@process, @draft_version), remote: true do |f| %> + <%= form_for Legislation::Annotation.new, url: legislation_process_draft_version_annotations_path(@process, @draft_version), remote: true do |f| %> <%= f.text_area :text, autofocus: true %>
    - <%= t('legislation.annotations.comments.cancel') %> + <%= t('legislation.annotations.comments.cancel') %> <%= f.submit t('legislation.annotations.comments.publish_comment'), class: 'button strong publish-comment' %> - <% if false %> - <%= t('legislation.annotations.comments.publish_comment') %> - <% end %>
    <%= f.hidden_field :quote %> <%= f.hidden_field :ranges %> <% end %>
    - -
    diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml index e873abc26..51ee2190b 100644 --- a/config/locales/activerecord.en.yml +++ b/config/locales/activerecord.en.yml @@ -139,10 +139,12 @@ en: status: Status final_version: Final version legislation/question: - title: "Title" + title: Title question_options: Options legislation/question_option: - value: "Value" + value: Value + legislation/annotation: + text: Comment errors: models: user: diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml index e8f2a42eb..aa7e05875 100644 --- a/config/locales/activerecord.es.yml +++ b/config/locales/activerecord.es.yml @@ -134,10 +134,12 @@ es: status: Estado final_version: Versión final legislation/question: - title: "Título" + title: Título question_options: Respuestas legislation/question_option: - value: "Valor" + value: Valor + legislation/annotation: + text: Comentario errors: models: user: From d253c4c09ffbf8ec81ca9feae2953a980a5a329f Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Sat, 14 Jan 2017 10:17:21 +0100 Subject: [PATCH 116/197] Restore custom position --- app/assets/javascripts/application.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 19c081b54..939705c51 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -53,8 +53,8 @@ //= require cocoon //= require legislation //= require legislation_allegations -//= require custom //= require legislation_annotatable +//= require custom var initialize_modules = function() { App.Comments.initialize(); From f47cef5a93d8be448774d3da5dadbfa829c4008d Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Sat, 14 Jan 2017 12:52:14 +0100 Subject: [PATCH 117/197] Highlight text when creating a comment --- .../legislation_annotatable.js.coffee | 62 ++++++++++++++++++- .../legislation/annotations_controller.rb | 9 ++- .../legislation/annotations/_form.html.erb | 2 +- 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index 343c638ad..f1e2d50d2 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -2,6 +2,42 @@ _t = (key) -> new Gettext().gettext(key) App.LegislationAnnotatable = + makeEditableAndHighlight: (colour) -> + sel = window.getSelection() + if sel.rangeCount and sel.getRangeAt + range = sel.getRangeAt(0) + document.designMode = 'on' + if range + sel.removeAllRanges() + sel.addRange range + # Use HiliteColor since some browsers apply BackColor to the whole block + if !document.execCommand('HiliteColor', false, colour) + document.execCommand 'BackColor', false, colour + document.designMode = 'off' + return + + highlight: (colour) -> + range = undefined + sel = undefined + if window.getSelection + # IE9 and non-IE + try + if !document.execCommand('BackColor', false, colour) + App.LegislationAnnotatable.makeEditableAndHighlight colour + catch ex + App.LegislationAnnotatable.makeEditableAndHighlight colour + else if document.selection and document.selection.createRange + # IE <= 8 case + range = document.selection.createRange() + range.execCommand 'BackColor', false, colour + return + + remove_highlight: -> + $('[data-legislation-draft-version-id] span[style]').replaceWith(-> + return $(this).contents() + ) + return + renderAnnotationComments: (event) -> $('.comment-box').offset(top: event.offset) $.ajax @@ -30,14 +66,29 @@ App.LegislationAnnotatable = # Clean comments section and open it $('#comments-box').html '' App.LegislationAllegations.show_comments() + $('#comments-box').show() annotation_url = $('[data-legislation-annotatable-base-url]').data('legislation-annotatable-base-url') $.ajax( method: 'GET' url: annotation_url + '/annotations/new' dataType: 'script').done (-> - $('#new_annotation #annotation_quote').val(@annotation.quote) - $('#new_annotation #annotation_ranges').val(JSON.stringify(@annotation.ranges)) + $('#new_legislation_annotation #legislation_annotation_quote').val(@annotation.quote) + $('#new_legislation_annotation #legislation_annotation_ranges').val(JSON.stringify(@annotation.ranges)) + $('#comments-box').css({top: $('.annotator-adder').position().top}) + + App.LegislationAnnotatable.highlight('#7fff9a') + $('#comments-box textarea').focus() + + $("#new_legislation_annotation").on("ajax:complete", (e, data, status, xhr) -> + App.LegislationAnnotatable.remove_highlight() + $("#comments-box").html("").hide(); + return true + ).on("ajax:error", (e, data, status, xhr) -> + console.log(data) + return false + ) + return ).bind(this) editorExtension: (editor) -> @@ -59,6 +110,13 @@ App.LegislationAnnotatable = initialize: -> $(document).on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments) $(document).on('click', '[data-annotation-id]', App.LegislationAnnotatable.onClick) + $(document).on('click', '[data-cancel-annotation]', (e) -> + e.preventDefault() + $('#comments-box').html('') + $('#comments-box').hide() + App.LegislationAnnotatable.remove_highlight() + return + ) current_user_id = $('html').data('current-user-id') if current_user_id == "" diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index 861eb9d14..664cd6252 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -31,7 +31,7 @@ class Legislation::AnnotationsController < ApplicationController track_event render json: @annotation.to_json else - render json: {}, status: :unprocessable_entity + render json: @annotation.errors.full_messages, status: :unprocessable_entity end end @@ -51,12 +51,11 @@ class Legislation::AnnotationsController < ApplicationController end end - private def annotation_params params - .require(:annotation) + .require(:legislation_annotation) .permit(:quote, :text, ranges: [:start, :startOffset, :end, :endOffset]) end @@ -67,8 +66,8 @@ class Legislation::AnnotationsController < ApplicationController end def convert_ranges_parameters - if params[:annotation] && params[:annotation][:ranges] - params[:annotation][:ranges] = JSON.parse(params[:annotation][:ranges]) + if params[:legislation_annotation] && params[:legislation_annotation][:ranges] + params[:legislation_annotation][:ranges] = JSON.parse(params[:legislation_annotation][:ranges]) end rescue JSON::ParserError end diff --git a/app/views/legislation/annotations/_form.html.erb b/app/views/legislation/annotations/_form.html.erb index 5662cafe2..7fa52cd5a 100644 --- a/app/views/legislation/annotations/_form.html.erb +++ b/app/views/legislation/annotations/_form.html.erb @@ -9,7 +9,7 @@
    <%= form_for Legislation::Annotation.new, url: legislation_process_draft_version_annotations_path(@process, @draft_version), remote: true do |f| %> - <%= f.text_area :text, autofocus: true %> + <%= f.text_area :text %>
    <%= t('legislation.annotations.comments.cancel') %> From 046c021c0c40b489b2afaff72fa629dc8b3dfbfd Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Sat, 14 Jan 2017 16:06:45 +0100 Subject: [PATCH 118/197] Complete create comment details --- .../legislation_annotatable.js.coffee | 27 ++++++++++--------- .../legislation/annotations/_form.html.erb | 24 +++++++++++------ .../legislation/annotations/comments.js.erb | 2 +- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index f1e2d50d2..4baa1a725 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -17,8 +17,6 @@ App.LegislationAnnotatable = return highlight: (colour) -> - range = undefined - sel = undefined if window.getSelection # IE9 and non-IE try @@ -39,7 +37,7 @@ App.LegislationAnnotatable = return renderAnnotationComments: (event) -> - $('.comment-box').offset(top: event.offset) + $('#comments-box').css({top: event.offset - $('.calc-comments').offset().top}) $.ajax method: "GET" url: event.annotation_url + "/annotations/" + event.annotation_id + "/comments" @@ -75,18 +73,23 @@ App.LegislationAnnotatable = dataType: 'script').done (-> $('#new_legislation_annotation #legislation_annotation_quote').val(@annotation.quote) $('#new_legislation_annotation #legislation_annotation_ranges').val(JSON.stringify(@annotation.ranges)) - $('#comments-box').css({top: $('.annotator-adder').position().top}) + $('#comments-box').css({top: position.top - $('.calc-comments').offset().top}) App.LegislationAnnotatable.highlight('#7fff9a') $('#comments-box textarea').focus() $("#new_legislation_annotation").on("ajax:complete", (e, data, status, xhr) -> - App.LegislationAnnotatable.remove_highlight() - $("#comments-box").html("").hide(); + if data.status == 200 + App.LegislationAnnotatable.remove_highlight() + $("#comments-box").html("").hide() + $.ajax + method: "GET" + url: annotation_url + "/annotations/" + data.responseJSON.id + "/comments" + dataType: 'script' + else + $(e.target).find('label').addClass('error') + $('' + data.responseJSON[0] + '').insertAfter($(e.target).find('textarea')) return true - ).on("ajax:error", (e, data, status, xhr) -> - console.log(data) - return false ) return ).bind(this) @@ -108,9 +111,9 @@ App.LegislationAnnotatable = offset: el.offset()["top"] initialize: -> - $(document).on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments) - $(document).on('click', '[data-annotation-id]', App.LegislationAnnotatable.onClick) - $(document).on('click', '[data-cancel-annotation]', (e) -> + $(document).off("renderLegislationAnnotation").on("renderLegislationAnnotation", App.LegislationAnnotatable.renderAnnotationComments) + $(document).off('click', '[data-annotation-id]').on('click', '[data-annotation-id]', App.LegislationAnnotatable.onClick) + $(document).off('click', '[data-cancel-annotation]').on('click', '[data-cancel-annotation]', (e) -> e.preventDefault() $('#comments-box').html('') $('#comments-box').hide() diff --git a/app/views/legislation/annotations/_form.html.erb b/app/views/legislation/annotations/_form.html.erb index 7fa52cd5a..317a712c8 100644 --- a/app/views/legislation/annotations/_form.html.erb +++ b/app/views/legislation/annotations/_form.html.erb @@ -8,16 +8,24 @@
    - <%= form_for Legislation::Annotation.new, url: legislation_process_draft_version_annotations_path(@process, @draft_version), remote: true do |f| %> - <%= f.text_area :text %> + <% if user_signed_in? %> + <%= form_for Legislation::Annotation.new, url: legislation_process_draft_version_annotations_path(@process, @draft_version), remote: true do |f| %> + <%= f.text_area :text %> -
    - <%= t('legislation.annotations.comments.cancel') %> - <%= f.submit t('legislation.annotations.comments.publish_comment'), class: 'button strong publish-comment' %> -
    +
    + <%= t('legislation.annotations.comments.cancel') %> + <%= f.submit t('legislation.annotations.comments.publish_comment'), class: 'button strong publish-comment' %> +
    - <%= f.hidden_field :quote %> - <%= f.hidden_field :ranges %> + <%= f.hidden_field :quote %> + <%= f.hidden_field :ranges %> + <% end %> + <% else %> +
    + <%= t("debates.show.login_to_comment", + signin: link_to(t("votes.signin"), new_user_session_path), + signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %> +
    <% end %>
    diff --git a/app/views/legislation/annotations/comments.js.erb b/app/views/legislation/annotations/comments.js.erb index 6ee83560e..75d8f35a0 100644 --- a/app/views/legislation/annotations/comments.js.erb +++ b/app/views/legislation/annotations/comments.js.erb @@ -1,2 +1,2 @@ -$("#comments-box").html("<%= j render('comments_box', annotation: @annotation) %>"); +$("#comments-box").html("<%= j render('comments_box', annotation: @annotation) %>").show(); From f1be212eeb052b5431c6abab53d4d4b9a1a3ead9 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Sat, 14 Jan 2017 16:56:55 +0100 Subject: [PATCH 119/197] Fix and complete controller specs --- .../legislation/annotations_controller.rb | 2 +- .../annotations_controller_spec.rb | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/app/controllers/legislation/annotations_controller.rb b/app/controllers/legislation/annotations_controller.rb index 664cd6252..6f5069763 100644 --- a/app/controllers/legislation/annotations_controller.rb +++ b/app/controllers/legislation/annotations_controller.rb @@ -66,7 +66,7 @@ class Legislation::AnnotationsController < ApplicationController end def convert_ranges_parameters - if params[:legislation_annotation] && params[:legislation_annotation][:ranges] + if params[:legislation_annotation] && params[:legislation_annotation][:ranges] && params[:legislation_annotation][:ranges].is_a?(String) params[:legislation_annotation][:ranges] = JSON.parse(params[:legislation_annotation][:ranges]) end rescue JSON::ParserError diff --git a/spec/controllers/legislation/annotations_controller_spec.rb b/spec/controllers/legislation/annotations_controller_spec.rb index 2713fc273..4ffd91357 100644 --- a/spec/controllers/legislation/annotations_controller_spec.rb +++ b/spec/controllers/legislation/annotations_controller_spec.rb @@ -15,7 +15,7 @@ describe Legislation::AnnotationsController do post :create, process_id: @process.id, draft_version_id: @draft_version.id, - annotation: { + legislation_annotation: { "quote"=>"Ordenación Territorial", "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], "text": "una anotacion" @@ -29,7 +29,7 @@ describe Legislation::AnnotationsController do post :create, process_id: @process.id, draft_version_id: @final_version.id, - annotation: { + legislation_annotation: { "quote"=>"Ordenación Territorial", "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], "text": "una anotacion" @@ -44,7 +44,7 @@ describe Legislation::AnnotationsController do expect do xhr :post, :create, process_id: @process.id, draft_version_id: @draft_version.id, - annotation: { + legislation_annotation: { "quote"=>"Ordenación Territorial", "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], "text": "una anotacion" @@ -59,12 +59,27 @@ describe Legislation::AnnotationsController do expect do xhr :post, :create, process_id: @process.id, draft_version_id: @draft_version.id, - annotation: { + legislation_annotation: { "quote"=>"Ordenación Territorial", "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}], "text": "una anotacion" } end.to_not change { @draft_version.annotations.count } end + + it 'should create an annotation by parsing parameters in JSON' do + sign_in @user + + expect do + xhr :post, :create, process_id: @process.id, + draft_version_id: @draft_version.id, + legislation_annotation: { + "quote"=>"Ordenación Territorial", + "ranges"=>[{"start"=>"/p[1]", "startOffset"=>1, "end"=>"/p[1]", "endOffset"=>3}].to_json, + "text": "una anotacion" + } + end.to change { @draft_version.annotations.count }.by(1) + end + end end From 819c9efcc3b15dc999ab2b10a3dd78c6c800d9bf Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Sat, 14 Jan 2017 17:19:27 +0100 Subject: [PATCH 120/197] Fix and complete feature specs --- .../legislation/draft_versions_spec.rb | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/spec/features/legislation/draft_versions_spec.rb b/spec/features/legislation/draft_versions_spec.rb index 6c39d11ce..d0f303743 100644 --- a/spec/features/legislation/draft_versions_spec.rb +++ b/spec/features/legislation/draft_versions_spec.rb @@ -135,6 +135,18 @@ feature 'Legislation Draft Versions' do let(:user) { create(:user) } background { login_as user } + scenario 'Visit as anonymous' do + logout + draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) + + visit legislation_process_draft_version_path(draft_version.process, draft_version) + + page.find(:css, ".legislation-annotatable").double_click + page.find(:css, ".annotator-adder button").click + expect(page).to_not have_css('#legislation_annotation_text') + expect(page).to have_content "ou must Sign in or Sign up to leave a comment." + end + scenario 'Create' do draft_version = create(:legislation_draft_version, :published, body: Faker::Lorem.paragraph) @@ -142,8 +154,11 @@ feature 'Legislation Draft Versions' do page.find(:css, ".legislation-annotatable").double_click page.find(:css, ".annotator-adder button").click - fill_in 'annotator-field-0', with: 'this is my annotation' - page.find(:css, ".annotator-controls a[href='#save']").click + page.click_button "Publish Comment" + expect(page).to have_content "Comment can't be blank" + + fill_in 'legislation_annotation_text', with: 'this is my annotation' + page.click_button "Publish Comment" expect(page).to have_css ".annotator-hl" first(:css, ".annotator-hl").click @@ -167,7 +182,7 @@ feature 'Legislation Draft Versions' do first(:css, ".annotator-hl").click expect(page).to have_content "my annotation" - all(".annotator-hl")[1].trigger('mouseover') + all(".annotator-hl")[1].trigger('click') expect(page).to have_content "my other annotation" end end From 65fcd83ee59f17da8da9f97407f0ee4dcaa7073b Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Mon, 16 Jan 2017 17:42:32 +0100 Subject: [PATCH 121/197] =?UTF-8?q?Don=E2=80=99t=20show=20new=20annotation?= =?UTF-8?q?/comment=20form=20if=20allegations=20phase=20is=20not=20open?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/custom.js | 3 ++- .../javascripts/legislation_annotatable.js.coffee | 15 ++------------- app/views/legislation/annotations/_form.html.erb | 14 +++++++++----- .../legislation/draft_versions/show.html.erb | 1 + config/locales/en.yml | 5 +++++ config/locales/es.yml | 5 +++++ 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index 50903021a..6c880b3a9 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -1,6 +1,7 @@ // Overrides and adds customized javascripts in this file -// Read more on documentation: +// Read more on documentation: // * English: https://github.com/consul/consul/blob/master/CUSTOMIZE_EN.md#javascript // * Spanish: https://github.com/consul/consul/blob/master/CUSTOMIZE_ES.md#javascript // +// diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index 4baa1a725..cc238835e 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -122,17 +122,6 @@ App.LegislationAnnotatable = ) current_user_id = $('html').data('current-user-id') - if current_user_id == "" - annotator.ui.editor.Editor.template = [ - '
    ', - '
    ', - ' ' + _t('Unregistered'), - '
    ', - ' ' + _t('Cancel') + '', - '
    ', - '
    ', - '
    ' - ].join('\n') $(".legislation-annotatable").each -> $this = $(this) @@ -146,8 +135,8 @@ App.LegislationAnnotatable = ann["legislation_draft_version_id"] = ann_id ann.permissions = ann.permissions || {} ann.permissions.admin = [] - .include(annotator.ui.main, { - element: this, + .include(annotator.ui.main, { + element: this, viewerExtensions: [App.LegislationAnnotatable.viewerExtension], editorExtensions: [App.LegislationAnnotatable.editorExtension] }) diff --git a/app/views/legislation/annotations/_form.html.erb b/app/views/legislation/annotations/_form.html.erb index 317a712c8..a757b4612 100644 --- a/app/views/legislation/annotations/_form.html.erb +++ b/app/views/legislation/annotations/_form.html.erb @@ -8,7 +8,11 @@
    - <% if user_signed_in? %> + <% if !@process.open_phase?(:allegations) %> +
    + <%= t("legislation.annotations.form.phase_not_open") %> +
    + <% elsif user_signed_in? %> <%= form_for Legislation::Annotation.new, url: legislation_process_draft_version_annotations_path(@process, @draft_version), remote: true do |f| %> <%= f.text_area :text %> @@ -22,10 +26,10 @@ <% end %> <% else %>
    - <%= t("debates.show.login_to_comment", - signin: link_to(t("votes.signin"), new_user_session_path), - signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %> -
    + <%= t("legislation.annotations.form.login_to_comment", + signin: link_to(t("legislation.annotations.form.signin"), new_user_session_path), + signup: link_to(t("legislation.annotations.form.signup"), new_user_registration_path)).html_safe %> +
    <% end %>
    diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index d89926929..615a86fc8 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -54,6 +54,7 @@
    <% end %> <%= @draft_version.body_html.html_safe %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 09eac149c..d65c3b007 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -237,6 +237,11 @@ en: other: "%{count} replies" cancel: Cancel publish_comment: Publish Comment + form: + phase_not_open: This phase is not open + login_to_comment: You must %{signin} or %{signup} to leave a comment. + signin: Sign in + signup: Sign up index: title: Comments comments_about: Comments about diff --git a/config/locales/es.yml b/config/locales/es.yml index 1a9626cc6..708a74ed2 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -237,6 +237,11 @@ es: other: "%{count} respuestas" cancel: Cancelar publish_comment: Publicar Comentario + form: + phase_not_open: Esta fase del proceso no está abierta + login_to_comment: Necesitas %{signin} o %{signup} para comentar. + signin: iniciar sesión + signup: registrarte index: title: Comentarios see_in_context: Ver en contexto From 7be2901535662f86a14e9d4c359191664d06de69 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Mon, 16 Jan 2017 22:23:30 +0100 Subject: [PATCH 122/197] Only highlight text and send request if phase is open --- .../legislation_annotatable.js.coffee | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/legislation_annotatable.js.coffee b/app/assets/javascripts/legislation_annotatable.js.coffee index cc238835e..5a9481e64 100644 --- a/app/assets/javascripts/legislation_annotatable.js.coffee +++ b/app/assets/javascripts/legislation_annotatable.js.coffee @@ -75,22 +75,23 @@ App.LegislationAnnotatable = $('#new_legislation_annotation #legislation_annotation_ranges').val(JSON.stringify(@annotation.ranges)) $('#comments-box').css({top: position.top - $('.calc-comments').offset().top}) - App.LegislationAnnotatable.highlight('#7fff9a') - $('#comments-box textarea').focus() + unless $('[data-legislation-open-phase]').data('legislation-open-phase') == false + App.LegislationAnnotatable.highlight('#7fff9a') + $('#comments-box textarea').focus() - $("#new_legislation_annotation").on("ajax:complete", (e, data, status, xhr) -> - if data.status == 200 - App.LegislationAnnotatable.remove_highlight() - $("#comments-box").html("").hide() - $.ajax - method: "GET" - url: annotation_url + "/annotations/" + data.responseJSON.id + "/comments" - dataType: 'script' - else - $(e.target).find('label').addClass('error') - $('' + data.responseJSON[0] + '').insertAfter($(e.target).find('textarea')) - return true - ) + $("#new_legislation_annotation").on("ajax:complete", (e, data, status, xhr) -> + if data.status == 200 + App.LegislationAnnotatable.remove_highlight() + $("#comments-box").html("").hide() + $.ajax + method: "GET" + url: annotation_url + "/annotations/" + data.responseJSON.id + "/comments" + dataType: 'script' + else + $(e.target).find('label').addClass('error') + $('' + data.responseJSON[0] + '').insertAfter($(e.target).find('textarea')) + return true + ) return ).bind(this) From 30cb7fe7b40467282fc50323795ec09539740844 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Mon, 16 Jan 2017 22:53:27 +0100 Subject: [PATCH 123/197] Fix link --- app/views/legislation/annotations/_version_chooser.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/legislation/annotations/_version_chooser.html.erb b/app/views/legislation/annotations/_version_chooser.html.erb index 8cf4f5fc4..2b98cd90a 100644 --- a/app/views/legislation/annotations/_version_chooser.html.erb +++ b/app/views/legislation/annotations/_version_chooser.html.erb @@ -11,6 +11,6 @@ <%= t('legislation.draft_versions.show.updated_at', date: format_date(@draft_version.updated_at)) %>
    - <%= link_to t('.see_text'), legislation_process_draft_version_annotations_path(process, draft_version), title: t('.see_text'), class: "button strong" %> + <%= link_to t('.see_text'), legislation_process_draft_version_path(process, draft_version), title: t('.see_text'), class: "button strong" %>
    From 327fa6bce59d7b3ef8c1d921e1482356c826a51f Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Mon, 16 Jan 2017 23:34:41 +0100 Subject: [PATCH 124/197] Remove link to non existing comments --- app/views/legislation/annotations/_form.html.erb | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/legislation/annotations/_form.html.erb b/app/views/legislation/annotations/_form.html.erb index a757b4612..f0a64e7ac 100644 --- a/app/views/legislation/annotations/_form.html.erb +++ b/app/views/legislation/annotations/_form.html.erb @@ -1,9 +1,6 @@
    <%= t('legislation.annotations.comments.comments_count', count: 0) %>
    - <%= link_to '#' do %> - - <% end %>
    From 108d7889856295ae3816cca9b06953c8c0ffaece Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 17 Jan 2017 10:58:33 +0100 Subject: [PATCH 125/197] Extract legislation translations to another yml file --- config/i18n-tasks.yml | 1 + config/locales/en.yml | 107 ----------------------------- config/locales/es.yml | 107 ----------------------------- config/locales/legislation.en.yml | 109 ++++++++++++++++++++++++++++++ config/locales/legislation.es.yml | 109 ++++++++++++++++++++++++++++++ 5 files changed, 219 insertions(+), 214 deletions(-) create mode 100644 config/locales/legislation.en.yml create mode 100644 config/locales/legislation.es.yml diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index 1ddf4f67c..65051fbf4 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -33,6 +33,7 @@ data: - config/locales/responders.%{locale}.yml - config/locales/kaminari.%{locale}.yml - config/locales/budgets.%{locale}.yml + - config/locales/legislation.%{locale}.yml # Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom: # `i18n-tasks normalize -p` will force move the keys according to these rules diff --git a/config/locales/en.yml b/config/locales/en.yml index 5fa5d6727..30cdbcb69 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -224,113 +224,6 @@ en: text_sign_in: login text_sign_up: sign up title: How I can comment this document? - legislation: - annotations: - comments: - see_all: See all - see_complete: See complete - comments_count: - one: "%{count} comment" - other: "%{count} comments" - replies_count: - one: "%{count} reply" - other: "%{count} replies" - cancel: Cancel - publish_comment: Publish Comment - form: - phase_not_open: This phase is not open - login_to_comment: You must %{signin} or %{signup} to leave a comment. - signin: Sign in - signup: Sign up - index: - title: Comments - comments_about: Comments about - see_in_context: See in context - comments_count: - one: "%{count} comment" - other: "%{count} comments" - show: - title: Comment - version_chooser: - seeing_version: Commments for version - see_text: See text draft - draft_versions: - changes: - title: Changes - seeing_changelog_version: Revision changes summary - see_text: See text draft - show: - loading_comments: Loading comments - seeing_version: You're seeing draft version - select_draft_version: Select draft - select_version_submit: see - updated_at: updated at %{date} - see_changes: see changes summary - see_comments: See all comments - text_toc: Table of contents - text_body: Text - text_comments: Comments - processes: - header: - view_process_information: View process information - 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 - no_open_processes: There aren't open processes - no_next_processes: There aren't planned processes - no_past_processes: There aren't past processes - phase_not_open: - not_open: This phase is not open yet - phase_empty: - empty: Nothing 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 - show: - answer_question: Submit answer - next_question: Next question - first_question: First question - share: Share - share_twitter: Share on Twitter - share_facebook: Share on Facebook - share_gplus: Share on Google+ - title: Collaborative legislation process - participation: - phase_not_open: This phase is not open - organizations: Organisations are not permitted to participate in the debate - signin: Sign in - signup: Sign up - unauthenticated: You must %{signin} or %{signup} to participate. - verified_only: Only verified users can participate, %{verify_account}. - verify_account: verify your account - debate_phase_not_open: Debate phase has finished and answers are not accepted anymore - shared: - comments: Comments locale: English notifications: index: diff --git a/config/locales/es.yml b/config/locales/es.yml index 2732af08f..17832f708 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -224,113 +224,6 @@ es: text_sign_in: iniciar sesión text_sign_up: registrarte title: "¿Cómo puedo comentar este documento?" - legislation: - annotations: - comments: - see_all: Ver todos - see_complete: Ver completo - comments_count: - one: "%{count} comentario" - other: "%{count} comentarios" - replies_count: - one: "%{count} respuesta" - other: "%{count} respuestas" - cancel: Cancelar - publish_comment: Publicar Comentario - form: - phase_not_open: Esta fase del proceso no está abierta - login_to_comment: Necesitas %{signin} o %{signup} para comentar. - signin: iniciar sesión - signup: registrarte - index: - title: Comentarios - see_in_context: Ver en contexto - comments_about: Comentarios sobre - comments_count: - one: "%{count} comentario" - other: "%{count} comentarios" - show: - title: Comentario - version_chooser: - seeing_version: Comentarios para la versión - see_text: Ver borrador del texto - draft_versions: - changes: - title: Cambios - seeing_changelog_version: Resumen de cambios de la revisión - see_text: Ver borrador del texto - show: - loading_comments: Cargando comentarios - seeing_version: Estás viendo la revisión - select_draft_version: Seleccionar borrador - select_version_submit: ver - updated_at: actualizada el %{date} - see_changes: ver resumen de cambios - see_comments: Ver todos los comentarios - text_toc: Índice - text_body: Texto - text_comments: Comentarios - processes: - header: - view_process_information: Ver información del proceso - 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 - no_open_processes: No hay procesos activos - no_next_processes: No hay procesos planeados - no_past_processes: No hay procesos terminados - phase_not_open: - not_open: Esta fase del proceso todavía no está abierta - phase_empty: - empty: No hay nada publicado 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 - show: - answer_question: Enviar respuesta - next_question: Siguiente pregunta - first_question: Primera pregunta - share: Compartir - share_twitter: Compartir en Twitter - share_facebook: Compartir en Facebook - share_gplus: Compartir en Google+ - title: Proceso de legislación colaborativa - participation: - phase_not_open: Esta fase no está abierta - organizations: Las organizaciones no pueden participar en el debate - signin: iniciar sesión - signup: registrarte - unauthenticated: Necesitas %{signin} o %{signup} para participar en el debate. - verified_only: Solo los usuarios verificados pueden participar en el debate, %{verify_account}. - verify_account: verifica tu cuenta - debate_phase_not_open: La fase de debate previo ya ha finalizado y en este momento no se aceptan respuestas - shared: - comments: Comentarios locale: Español notifications: index: diff --git a/config/locales/legislation.en.yml b/config/locales/legislation.en.yml new file mode 100644 index 000000000..8185377bf --- /dev/null +++ b/config/locales/legislation.en.yml @@ -0,0 +1,109 @@ +--- +en: + legislation: + annotations: + comments: + see_all: See all + see_complete: See complete + comments_count: + one: "%{count} comment" + other: "%{count} comments" + replies_count: + one: "%{count} reply" + other: "%{count} replies" + cancel: Cancel + publish_comment: Publish Comment + form: + phase_not_open: This phase is not open + login_to_comment: You must %{signin} or %{signup} to leave a comment. + signin: Sign in + signup: Sign up + index: + title: Comments + comments_about: Comments about + see_in_context: See in context + comments_count: + one: "%{count} comment" + other: "%{count} comments" + show: + title: Comment + version_chooser: + seeing_version: Commments for version + see_text: See text draft + draft_versions: + changes: + title: Changes + seeing_changelog_version: Revision changes summary + see_text: See text draft + show: + loading_comments: Loading comments + seeing_version: You're seeing draft version + select_draft_version: Select draft + select_version_submit: see + updated_at: updated at %{date} + see_changes: see changes summary + see_comments: See all comments + text_toc: Table of contents + text_body: Text + text_comments: Comments + processes: + header: + view_process_information: View process information + 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 + no_open_processes: There aren't open processes + no_next_processes: There aren't planned processes + no_past_processes: There aren't past processes + phase_not_open: + not_open: This phase is not open yet + phase_empty: + empty: Nothing 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 + show: + answer_question: Submit answer + next_question: Next question + first_question: First question + share: Share + share_twitter: Share on Twitter + share_facebook: Share on Facebook + share_gplus: Share on Google+ + title: Collaborative legislation process + participation: + phase_not_open: This phase is not open + organizations: Organisations are not permitted to participate in the debate + signin: Sign in + signup: Sign up + unauthenticated: You must %{signin} or %{signup} to participate. + verified_only: Only verified users can participate, %{verify_account}. + verify_account: verify your account + debate_phase_not_open: Debate phase has finished and answers are not accepted anymore + shared: + comments: Comments diff --git a/config/locales/legislation.es.yml b/config/locales/legislation.es.yml new file mode 100644 index 000000000..c84607c3d --- /dev/null +++ b/config/locales/legislation.es.yml @@ -0,0 +1,109 @@ +--- +es: + legislation: + annotations: + comments: + see_all: Ver todos + see_complete: Ver completo + comments_count: + one: "%{count} comentario" + other: "%{count} comentarios" + replies_count: + one: "%{count} respuesta" + other: "%{count} respuestas" + cancel: Cancelar + publish_comment: Publicar Comentario + form: + phase_not_open: Esta fase del proceso no está abierta + login_to_comment: Necesitas %{signin} o %{signup} para comentar. + signin: iniciar sesión + signup: registrarte + index: + title: Comentarios + see_in_context: Ver en contexto + comments_about: Comentarios sobre + comments_count: + one: "%{count} comentario" + other: "%{count} comentarios" + show: + title: Comentario + version_chooser: + seeing_version: Comentarios para la versión + see_text: Ver borrador del texto + draft_versions: + changes: + title: Cambios + seeing_changelog_version: Resumen de cambios de la revisión + see_text: Ver borrador del texto + show: + loading_comments: Cargando comentarios + seeing_version: Estás viendo la revisión + select_draft_version: Seleccionar borrador + select_version_submit: ver + updated_at: actualizada el %{date} + see_changes: ver resumen de cambios + see_comments: Ver todos los comentarios + text_toc: Índice + text_body: Texto + text_comments: Comentarios + processes: + header: + view_process_information: Ver información del proceso + 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 + no_open_processes: No hay procesos activos + no_next_processes: No hay procesos planeados + no_past_processes: No hay procesos terminados + phase_not_open: + not_open: Esta fase del proceso todavía no está abierta + phase_empty: + empty: No hay nada publicado 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 + show: + answer_question: Enviar respuesta + next_question: Siguiente pregunta + first_question: Primera pregunta + share: Compartir + share_twitter: Compartir en Twitter + share_facebook: Compartir en Facebook + share_gplus: Compartir en Google+ + title: Proceso de legislación colaborativa + participation: + phase_not_open: Esta fase no está abierta + organizations: Las organizaciones no pueden participar en el debate + signin: iniciar sesión + signup: registrarte + unauthenticated: Necesitas %{signin} o %{signup} para participar en el debate. + verified_only: Solo los usuarios verificados pueden participar en el debate, %{verify_account}. + verify_account: verifica tu cuenta + debate_phase_not_open: La fase de debate previo ya ha finalizado y en este momento no se aceptan respuestas + shared: + comments: Comentarios From 53e9837db387084b895a4f69b2c8c1175fe33366 Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 17 Jan 2017 15:03:48 +0100 Subject: [PATCH 126/197] Change texts for legislation questions comments --- app/helpers/comments_helper.rb | 26 +++++++++++++++-- app/views/comments/_comment_tree.html.erb | 2 +- app/views/comments/_form.html.erb | 4 +-- .../legislation/annotations/show.html.erb | 2 +- app/views/legislation/questions/show.html.erb | 4 +-- .../legislation/shared/_comments.html.erb | 29 ------------------- config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/legislation.en.yml | 7 +++-- config/locales/legislation.es.yml | 7 +++-- .../comments/legislation_questions_spec.rb | 12 ++++---- spec/features/legislation/questions_spec.rb | 2 +- 12 files changed, 48 insertions(+), 49 deletions(-) delete mode 100644 app/views/legislation/shared/_comments.html.erb diff --git a/app/helpers/comments_helper.rb b/app/helpers/comments_helper.rb index b9e69ddf9..491944c03 100644 --- a/app/helpers/comments_helper.rb +++ b/app/helpers/comments_helper.rb @@ -1,11 +1,31 @@ module CommentsHelper + def comment_tree_title_text(commentable) + if commentable.class == Legislation::Question + t("legislation.questions.comments.comments_title") + else + t("comments_helper.comments_title") + end + end + + def leave_comment_text(commentable) + if commentable.class == Legislation::Question + t("legislation.questions.comments.form.leave_comment") + else + t("comments.form.leave_comment") + end + end + def comment_link_text(parent_id) parent_id.present? ? t("comments_helper.reply_link") : t("comments_helper.comment_link") end - def comment_button_text(parent_id) - parent_id.present? ? t("comments_helper.reply_button") : t("comments_helper.comment_button") + def comment_button_text(parent_id, commentable) + if commentable.class == Legislation::Question + parent_id.present? ? t("comments_helper.reply_button") : t("legislation.questions.comments.comment_button") + else + parent_id.present? ? t("comments_helper.reply_button") : t("comments_helper.comment_button") + end end def parent_or_commentable_dom_id(parent_id, commentable) @@ -48,4 +68,4 @@ module CommentsHelper end end -end \ No newline at end of file +end diff --git a/app/views/comments/_comment_tree.html.erb b/app/views/comments/_comment_tree.html.erb index 0581809fb..746ab9225 100644 --- a/app/views/comments/_comment_tree.html.erb +++ b/app/views/comments/_comment_tree.html.erb @@ -6,7 +6,7 @@

    - <%= t("debates.show.comments_title") %> + <%= comment_tree_title_text(commentable) %> (<%= commentable.comments_count %>)

    diff --git a/app/views/comments/_form.html.erb b/app/views/comments/_form.html.erb index e3399c383..9d9767e73 100644 --- a/app/views/comments/_form.html.erb +++ b/app/views/comments/_form.html.erb @@ -2,13 +2,13 @@ <% css_id = parent_or_commentable_dom_id(parent_id, commentable) %>
    class="comment-form"> <%= form_for Comment.new, remote: true do |f| %> - <%= label_tag "comment-body-#{css_id}", t("comments.form.leave_comment") %> + <%= label_tag "comment-body-#{css_id}", leave_comment_text(commentable) %> <%= f.text_area :body, id: "comment-body-#{css_id}", maxlength: Comment.body_max_length, label: false %> <%= f.hidden_field :commentable_type, value: commentable.class.name %> <%= f.hidden_field :commentable_id, value: commentable.id %> <%= f.hidden_field :parent_id, value: parent_id %> - <%= f.submit comment_button_text(parent_id), class: "button" %> + <%= f.submit comment_button_text(parent_id, commentable), class: "button" %> <% if can? :comment_as_moderator, commentable %>
    diff --git a/app/views/legislation/annotations/show.html.erb b/app/views/legislation/annotations/show.html.erb index cdfa04447..e03304e59 100644 --- a/app/views/legislation/annotations/show.html.erb +++ b/app/views/legislation/annotations/show.html.erb @@ -27,7 +27,7 @@
    - <%= render 'legislation/shared/comments', commentable: @annotation %> + <%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree, comment_flags: @comment_flags } %>
    diff --git a/app/views/legislation/questions/show.html.erb b/app/views/legislation/questions/show.html.erb index c74bd9efa..b99e7b17f 100644 --- a/app/views/legislation/questions/show.html.erb +++ b/app/views/legislation/questions/show.html.erb @@ -47,7 +47,7 @@
    - - <%= render 'legislation/shared/comments', commentable: @question %> + + <%= render partial: '/comments/comment_tree', locals: { comment_tree: @comment_tree, comment_flags: @comment_flags } %>
    diff --git a/app/views/legislation/shared/_comments.html.erb b/app/views/legislation/shared/_comments.html.erb deleted file mode 100644 index 25b4ce18d..000000000 --- a/app/views/legislation/shared/_comments.html.erb +++ /dev/null @@ -1,29 +0,0 @@ -<% cache [locale_and_user_status, @current_order, commentable_cache_key(commentable), @comment_tree.comments, @comment_tree.comment_authors, commentable.comments_count, @comment_flags] do %> -
    -
    -

    - <%= t("legislation.shared.comments") %> - (<%= commentable.comments_count %>) -

    - - <%= render 'shared/wide_order_selector', i18n_namespace: "comments" %> - - <% if user_signed_in? %> - <%= render 'comments/form', {commentable: commentable, parent_id: nil, toggeable: false} %> - <% else %> -
    - -
    - <%= t("debates.show.login_to_comment", - signin: link_to(t("votes.signin"), new_user_session_path), - signup: link_to(t("votes.signup"), new_user_registration_path)).html_safe %> -
    - <% end %> - - <% @comment_tree.root_comments.each do |comment| %> - <%= render 'comments/comment', comment: comment %> - <% end %> - <%= paginate @comment_tree.root_comments %> -
    -
    -<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 30cdbcb69..2f192cb0c 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -62,6 +62,7 @@ en: comments_helper: comment_button: Publish comment comment_link: Comment + comments_title: Comments reply_button: Publish reply reply_link: Reply debates: diff --git a/config/locales/es.yml b/config/locales/es.yml index 17832f708..7c418521f 100755 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -62,6 +62,7 @@ es: comments_helper: comment_button: Publicar comentario comment_link: Comentar + comments_title: Comentarios reply_button: Publicar respuesta reply_link: Responder debates: diff --git a/config/locales/legislation.en.yml b/config/locales/legislation.en.yml index 8185377bf..294d35104 100644 --- a/config/locales/legislation.en.yml +++ b/config/locales/legislation.en.yml @@ -81,6 +81,11 @@ en: allegations_dates: Allegations final_publication_date: Final result publication questions: + comments: + comment_button: Publish answer + comments_title: Open answers + form: + leave_comment: Leave your answer question: comments: zero: No comments @@ -105,5 +110,3 @@ en: verified_only: Only verified users can participate, %{verify_account}. verify_account: verify your account debate_phase_not_open: Debate phase has finished and answers are not accepted anymore - shared: - comments: Comments diff --git a/config/locales/legislation.es.yml b/config/locales/legislation.es.yml index c84607c3d..6f0d5d5e7 100644 --- a/config/locales/legislation.es.yml +++ b/config/locales/legislation.es.yml @@ -81,6 +81,11 @@ es: allegations_dates: Alegaciones final_publication_date: Publicación resultados questions: + comments: + comment_button: Publicar respuesta + comments_title: Respuestas abiertas + form: + leave_comment: Deja tu respuesta question: comments: zero: Sin comentarios @@ -105,5 +110,3 @@ es: verified_only: Solo los usuarios verificados pueden participar en el debate, %{verify_account}. verify_account: verifica tu cuenta debate_phase_not_open: La fase de debate previo ya ha finalizado y en este momento no se aceptan respuestas - shared: - comments: Comentarios diff --git a/spec/features/comments/legislation_questions_spec.rb b/spec/features/comments/legislation_questions_spec.rb index c8f929b9e..253c25b99 100644 --- a/spec/features/comments/legislation_questions_spec.rb +++ b/spec/features/comments/legislation_questions_spec.rb @@ -164,7 +164,7 @@ feature 'Commenting legislation questions' do visit legislation_process_question_path(legislation_question.process, legislation_question) fill_in "comment-body-legislation_question_#{legislation_question.id}", with: 'Have you thought about...?' - click_button 'Publish comment' + click_button 'Publish answer' within "#comments" do expect(page).to have_content 'Have you thought about...?' @@ -176,7 +176,7 @@ feature 'Commenting legislation questions' do login_as(user) visit legislation_process_question_path(legislation_question.process, legislation_question) - click_button 'Publish comment' + click_button 'Publish answer' expect(page).to have_content "Can't be blank" end @@ -295,11 +295,11 @@ feature 'Commenting legislation questions' do visit legislation_process_question_path(legislation_question.process, legislation_question) fill_in "comment-body-legislation_question_#{legislation_question.id}", with: 'Testing submit button!' - click_button 'Publish comment' + click_button 'Publish answer' # The button's text should now be "..." # This should be checked before the Ajax request is finished - expect(page).to_not have_button 'Publish comment' + expect(page).to_not have_button 'Publish answer' expect(page).to have_content('Testing submit button!') end @@ -313,7 +313,7 @@ feature 'Commenting legislation questions' do fill_in "comment-body-legislation_question_#{legislation_question.id}", with: "I am moderating!" check "comment-as-moderator-legislation_question_#{legislation_question.id}" - click_button "Publish comment" + click_button "Publish answer" within "#comments" do expect(page).to have_content "I am moderating!" @@ -369,7 +369,7 @@ feature 'Commenting legislation questions' do fill_in "comment-body-legislation_question_#{legislation_question.id}", with: "I am your Admin!" check "comment-as-administrator-legislation_question_#{legislation_question.id}" - click_button "Publish comment" + click_button "Publish answer" within "#comments" do expect(page).to have_content "I am your Admin!" diff --git a/spec/features/legislation/questions_spec.rb b/spec/features/legislation/questions_spec.rb index c9513e9de..77503b5a9 100644 --- a/spec/features/legislation/questions_spec.rb +++ b/spec/features/legislation/questions_spec.rb @@ -38,7 +38,7 @@ feature 'Legislation' do visit legislation_process_question_path(@process, @process.questions.first) expect(page).to have_content("Question 1") - expect(page).to have_content("Comments (0)") + expect(page).to have_content("Open answers (0)") end scenario 'shows next question link in question page' do From 4b04b93f50f8e90aaa13288a40173b30ff38efcc Mon Sep 17 00:00:00 2001 From: Amaia Castro Date: Tue, 17 Jan 2017 17:40:04 +0100 Subject: [PATCH 127/197] Show only first level comments in comments box for annotations --- app/views/legislation/annotations/_comments_box.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/legislation/annotations/_comments_box.html.erb b/app/views/legislation/annotations/_comments_box.html.erb index caea782af..24e87b141 100644 --- a/app/views/legislation/annotations/_comments_box.html.erb +++ b/app/views/legislation/annotations/_comments_box.html.erb @@ -6,7 +6,7 @@ <% end %>
    - <% annotation.comments.each do |comment| %> + <% annotation.comments.roots.each do |comment| %>

    <%= comment.body %>

    From 2f5e180069918e15c35345901f4c8fdae1ffa872 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Tue, 17 Jan 2017 15:46:44 +0100 Subject: [PATCH 128/197] View changelog link only if present --- app/views/legislation/draft_versions/show.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/legislation/draft_versions/show.html.erb b/app/views/legislation/draft_versions/show.html.erb index 615a86fc8..f094ae38c 100644 --- a/app/views/legislation/draft_versions/show.html.erb +++ b/app/views/legislation/draft_versions/show.html.erb @@ -14,7 +14,9 @@ <%= select_tag "draft_version_id", options_from_collection_for_select(@draft_versions_list, 'id', 'display_title', @draft_version.id), "aria-label": t('.select_draft_version') %> <%= submit_tag t('.select_version_submit'), class: "button" %> <% end %> - <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %> + <% if @draft_version.changelog.present? %> + <%= link_to t('.see_changes'), legislation_process_draft_version_changes_path(@process, @draft_version) %> + <% end %>
    <%= t('.updated_at', date: format_date(@draft_version.updated_at)) %>
    From e7c754a875df4fa28e15f3b56a4f2f4770531856 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Tue, 17 Jan 2017 16:00:24 +0100 Subject: [PATCH 129/197] Limit to 5 the number of comments. Strip comments length --- app/models/legislation/annotation.rb | 1 + .../annotations/_comments_box.html.erb | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/models/legislation/annotation.rb b/app/models/legislation/annotation.rb index 2bdfb3fca..b038b5e51 100644 --- a/app/models/legislation/annotation.rb +++ b/app/models/legislation/annotation.rb @@ -1,4 +1,5 @@ class Legislation::Annotation < ActiveRecord::Base + COMMENTS_PAGE_SIZE = 5 acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases diff --git a/app/views/legislation/annotations/_comments_box.html.erb b/app/views/legislation/annotations/_comments_box.html.erb index 24e87b141..79f702fa0 100644 --- a/app/views/legislation/annotations/_comments_box.html.erb +++ b/app/views/legislation/annotations/_comments_box.html.erb @@ -6,18 +6,20 @@ <% end %>
    - <% annotation.comments.roots.each do |comment| %> + <% annotation.comments.roots.limit(5).each do |comment| %>
    -

    <%= comment.body %>

    +

    <%= truncate comment.body, length: 250 %>

    -
    - <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> - <%= t('legislation.annotations.comments.see_complete') %> - <% end %> -
    + <% if comment.body.length > 250 %> +
    + <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> + <%= t('legislation.annotations.comments.see_complete') %> + <% end %> +
    + <% end %>
    <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> <%= t('legislation.annotations.comments.replies_count', count: comment.children.size) %> @@ -35,8 +37,10 @@
    From dbbbf34b60eb665209b948517e79df4ac11ce266 Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Wed, 18 Jan 2017 11:26:38 +0100 Subject: [PATCH 130/197] Link to the comment using an anchor --- app/views/legislation/annotations/_comments_box.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/legislation/annotations/_comments_box.html.erb b/app/views/legislation/annotations/_comments_box.html.erb index 79f702fa0..4f33d45ef 100644 --- a/app/views/legislation/annotations/_comments_box.html.erb +++ b/app/views/legislation/annotations/_comments_box.html.erb @@ -21,7 +21,7 @@
    <% end %>
    - <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation) do %> + <%= link_to legislation_process_draft_version_annotation_path(annotation.draft_version.process, annotation.draft_version, annotation, anchor: "comment_#{comment.id}") do %> <%= t('legislation.annotations.comments.replies_count', count: comment.children.size) %> <% end %>
    From 1537dd41dafdb582026932d63bd9e4785d238b7e Mon Sep 17 00:00:00 2001 From: Fernando Blat Date: Wed, 18 Jan 2017 11:46:19 +0100 Subject: [PATCH 131/197] Add forms placeholders --- .../legislation/draft_versions/_form.html.erb | 6 +++--- .../admin/legislation/processes/_form.html.erb | 15 ++++++++++----- .../admin/legislation/questions/_form.html.erb | 2 +- .../questions/_question_option_fields.html.erb | 2 +- config/locales/admin.en.yml | 10 ++++++++++ config/locales/admin.es.yml | 10 ++++++++++ 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/app/views/admin/legislation/draft_versions/_form.html.erb b/app/views/admin/legislation/draft_versions/_form.html.erb index 8e79c0a56..25bfd2942 100644 --- a/app/views/admin/legislation/draft_versions/_form.html.erb +++ b/app/views/admin/legislation/draft_versions/_form.html.erb @@ -20,7 +20,7 @@ <%= f.label :title %>
    - <%= f.text_field :title, label: false %> + <%= f.text_field :title, label: false, placeholder: t('admin.legislation.draft_versions.form.title_placeholder') %>
    @@ -30,7 +30,7 @@ <%= t('admin.legislation.draft_versions.form.use_markdown') %>
    - <%= f.text_area :changelog, label: false, rows: 5 %> + <%= f.text_area :changelog, label: false, rows: 5, placeholder: t('admin.legislation.draft_versions.form.changelog_placeholder') %>
    @@ -77,7 +77,7 @@ <% end %>
    - <%= f.text_area :body, label: false %> + <%= f.text_area :body, label: false, placeholder: t('admin.legislation.draft_versions.form.body_placeholder') %>
    diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index 06bcfd43c..2e2464e71 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -119,7 +119,8 @@
    <%= f.text_field :title, - label: false %> + label: false, + placeholder: t('admin.legislation.processes.form.title_placeholder') %>
    @@ -131,7 +132,8 @@
    <%= f.text_area :description, label: false, - rows: 5 %> + rows: 5, + placeholder: t('admin.legislation.processes.form.description_placeholder') %>
    @@ -143,7 +145,8 @@
    <%= f.text_area :target, label: false, - rows: 5 %> + rows: 5, + placeholder: t('admin.legislation.processes.form.target_placeholder') %>
    @@ -155,7 +158,8 @@
    <%= f.text_area :how_to_participate, label: false, - rows: 5 %> + rows: 5, + placeholder: t('admin.legislation.processes.form.how_to_participate_placeholder') %>
    @@ -167,7 +171,8 @@
    <%= f.text_area :additional_info, label: false, - rows: 10 %> + rows: 10, + placeholder: t('admin.legislation.processes.form.additional_info_placeholder') %>
    diff --git a/app/views/admin/legislation/questions/_form.html.erb b/app/views/admin/legislation/questions/_form.html.erb index cca5ca430..5b8ae1286 100644 --- a/app/views/admin/legislation/questions/_form.html.erb +++ b/app/views/admin/legislation/questions/_form.html.erb @@ -20,7 +20,7 @@ <%= f.label :title %>
    - <%= f.text_area :title, rows: 5, label: false %> + <%= f.text_area :title, rows: 5, label: false, placeholder: t('admin.legislation.questions.form.title_placeholder') %>
    diff --git a/app/views/admin/legislation/questions/_question_option_fields.html.erb b/app/views/admin/legislation/questions/_question_option_fields.html.erb index 0578e65ae..ef77872fa 100644 --- a/app/views/admin/legislation/questions/_question_option_fields.html.erb +++ b/app/views/admin/legislation/questions/_question_option_fields.html.erb @@ -2,7 +2,7 @@
    - <%= f.text_field :value, label: false %> + <%= f.text_field :value, label: false, placeholder: t('admin.legislation.questions.form.value_placeholder') %>
    <%= link_to_remove_association " #{t('.remove_option')}".html_safe, f %> diff --git a/config/locales/admin.en.yml b/config/locales/admin.en.yml index f259cd0f7..1392aa75e 100755 --- a/config/locales/admin.en.yml +++ b/config/locales/admin.en.yml @@ -198,6 +198,11 @@ en: start: Start end: End use_markdown: Use Markdown to format the text + title_placeholder: The title of the process + description_placeholder: Add a description of the process + target_placeholder: Describe who is the target of the process + how_to_participate_placeholder: Describe how to participate + additional_info_placeholder: Add an additional information you consider useful index: create: New process delete: Delete @@ -247,6 +252,9 @@ en: status: draft: You can preview as admin, no one else can see it published: Visible for everybody + title_placeholder: Write the title of the draft version + changelog_placeholder: Add the main changes from the previous version + body_placeholder: Write down the draft text index: title: Draft versions create: Create version @@ -283,6 +291,8 @@ en: error: Error form: add_option: Add option + title_placeholder: Add a title + value_placeholder: Add a closed answer index: back: Back title: Questions associated to this process diff --git a/config/locales/admin.es.yml b/config/locales/admin.es.yml index de228e0c6..368b32c2a 100644 --- a/config/locales/admin.es.yml +++ b/config/locales/admin.es.yml @@ -198,6 +198,11 @@ es: start: Inicio end: Fin use_markdown: Usa Markdown para formatear el texto + title_placeholder: Escribe el título del proceso + description_placeholder: Añade una descripción del proceso + target_placeholder: Describe a quién va dirigido + how_to_participate_placeholder: Describe cómo participar + additional_info_placeholder: Añade cualquier información adicional que pueda ser de interés index: create: Nuevo proceso delete: Borrar @@ -247,6 +252,9 @@ es: status: draft: Podrás previsualizarlo como logueado, nadie más lo podrá ver published: Será visible para todo el mundo + title_placeholder: Escribe el título de esta versión del borrador + changelog_placeholder: Describe cualquier cambio relevante con la versión anterior + body_placeholder: Escribe el texto del borrador index: title: Versiones del borrador create: Crear versión @@ -283,6 +291,8 @@ es: error: Error form: add_option: +Añadir respuesta cerrada + title_placeholder: Escribe un título a la pregunta + value_placeholder: Escribe una respuesta cerrada index: back: Volver title: Preguntas asociadas a este proceso From 146db24d5847dd1b2a671549c9221613173b9132 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Gonz=C3=A1lez?= Date: Wed, 18 Jan 2017 12:26:45 +0100 Subject: [PATCH 132/197] Refactor header toggle and show additional info on the small header --- app/assets/javascripts/legislation.js.coffee | 4 ++-- app/assets/stylesheets/legislation_process.scss | 11 +++++++++-- app/views/legislation/processes/_header.html.erb | 16 ++++++++++++++-- .../legislation/processes/_header_full.html.erb | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/legislation.js.coffee b/app/assets/javascripts/legislation.js.coffee index cf2dfabd1..cd4e90bc3 100644 --- a/app/assets/javascripts/legislation.js.coffee +++ b/app/assets/javascripts/legislation.js.coffee @@ -3,11 +3,11 @@ App.Legislation = initialize: -> $('#js-toggle-debate').on click: -> - $('#debate-info').toggle() + $('#debate-show').toggle() $('#js-toggle-small-debate').on click: -> - $('#debate-info').toggle() + $('#debate-show').toggle() $('span').toggleClass('icon-angle-up') $('form#new_legislation_answer input.button').hide() diff --git a/app/assets/stylesheets/legislation_process.scss b/app/assets/stylesheets/legislation_process.scss index 50dfe7161..052c86727 100644 --- a/app/assets/stylesheets/legislation_process.scss +++ b/app/assets/stylesheets/legislation_process.scss @@ -62,9 +62,12 @@ $epigraph-font-size: rem-calc(15); color: #8AA8BE; } } - - #debate-info { + + #debate-show { display: none; + } + + .debate-add-info { margin-top: 3rem; padding-top: 4rem; border-top: 1px solid darken($border, 10%); @@ -437,6 +440,10 @@ $epigraph-font-size: rem-calc(15); // ----------------- .legislation-allegation { padding-top: 1rem; + + #debate-show { + margin-top: 2rem; + } .headline { margin-bottom: 0; diff --git a/app/views/legislation/processes/_header.html.erb b/app/views/legislation/processes/_header.html.erb index b59969b81..945d1c59f 100644 --- a/app/views/legislation/processes/_header.html.erb +++ b/app/views/legislation/processes/_header.html.erb @@ -12,8 +12,20 @@
    -
    -