diff --git a/app/assets/stylesheets/pages.scss b/app/assets/stylesheets/pages.scss index efde88d07..3df5ac3c1 100644 --- a/app/assets/stylesheets/pages.scss +++ b/app/assets/stylesheets/pages.scss @@ -23,11 +23,6 @@ &.light { background: #ecf0f1; } - - h1, - p { - color: $text; - } } .lead { diff --git a/app/controllers/admin/legislation/processes_controller.rb b/app/controllers/admin/legislation/processes_controller.rb index 780ee7478..1df9cdd66 100644 --- a/app/controllers/admin/legislation/processes_controller.rb +++ b/app/controllers/admin/legislation/processes_controller.rb @@ -66,8 +66,11 @@ class Admin::Legislation::ProcessesController < Admin::Legislation::BaseControll :result_publication_enabled, :published, :custom_list, + :background_color, + :font_color, translation_params(::Legislation::Process), - documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] + documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy], + image_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy] ] end diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb index 413dc3515..a39e9784d 100644 --- a/app/helpers/legislation_helper.rb +++ b/app/helpers/legislation_helper.rb @@ -37,4 +37,8 @@ module LegislationHelper "milestones" => admin_legislation_process_milestones_path(process) } end + + def banner_color? + @process.background_color.present? && @process.font_color.present? + end end diff --git a/app/models/legislation/process.rb b/app/models/legislation/process.rb index dc880552b..974546ff4 100644 --- a/app/models/legislation/process.rb +++ b/app/models/legislation/process.rb @@ -2,6 +2,7 @@ class Legislation::Process < ActiveRecord::Base include ActsAsParanoidAliases include Taggable include Milestoneable + include Imageable include Documentable documentable max_documents_allowed: 3, max_file_size: 3.megabytes, @@ -43,6 +44,8 @@ class Legislation::Process < ActiveRecord::Base validates :allegations_end_date, presence: true, if: :allegations_start_date? validates :proposals_phase_end_date, presence: true, if: :proposals_phase_start_date? validate :valid_date_ranges + validates :background_color, format: { allow_blank: true, with: /\A#?(?:[A-F0-9]{3}){1,2}\z/i } + validates :font_color, format: { allow_blank: true, with: /\A#?(?:[A-F0-9]{3}){1,2}\z/i } scope :open, -> { where("start_date <= ? and end_date >= ?", Date.current, Date.current) .order('id DESC') } diff --git a/app/views/admin/legislation/processes/_form.html.erb b/app/views/admin/legislation/processes/_form.html.erb index 1e43da6db..1cfb699ee 100644 --- a/app/views/admin/legislation/processes/_form.html.erb +++ b/app/views/admin/legislation/processes/_form.html.erb @@ -201,6 +201,35 @@
+
+ <%= render 'images/nested_image', imageable: @process, f: f %> +
+ +
+
+
+ +
+

<%= t("admin.legislation.processes.form.banner_title") %>

+
+ +
+
+ <%= f.label :sections, t("admin.legislation.processes.form.banner_background_color") %> + <%= color_field(:process, :background_color, id: 'banner_background_color_picker') %> + <%= f.text_field :background_color, label: false, id: 'banner_background_color' %> +
+
+ <%= f.label :sections, t("admin.legislation.processes.form.banner_font_color") %> + <%= color_field(:process, :font_color, id: 'banner_font_color_picker') %> + <%= f.text_field :font_color, label: false, id: 'banner_font_color' %> +
+
+ +
+
+
+ <%= f.translatable_fields do |translations_form| %>
<%= translations_form.text_field :title, diff --git a/app/views/legislation/processes/_header.html.erb b/app/views/legislation/processes/_header.html.erb index 4c6acea90..607fb9cbf 100644 --- a/app/views/legislation/processes/_header.html.erb +++ b/app/views/legislation/processes/_header.html.erb @@ -1,7 +1,17 @@ -
+
+ style="background:<%= process.background_color %>; color:<%= process.font_color %>;" + <% end %>>
- <%= back_link_to legislation_processes_path %> + + <% if banner_color? %> + <%= link_to t("shared.back"), legislation_processes_path, + class: "icon-angle-left", + style: "color:#{process.font_color};" %> + <% else %> + <%= back_link_to legislation_processes_path %> + <% end %> +

<%= @process.title %>

<% if header == :small %> @@ -35,6 +45,11 @@ description: @process.title } %> + <% if @process.image.present? %> +
+ <%= image_tag(@process.image_url(:large), alt: @process.title, id:'image') %> + <% end %> + <% if process.draft_publication.enabled? %>
- + + style="background:<%= process.font_color %>; color:<%= process.background_color %>;" + <% end %>> <%= t("legislation.processes.header.additional_info") %> <% end %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 4d3495493..819a2037e 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -438,6 +438,9 @@ en: homepage: Description homepage_description: Here you can explain the content of the process homepage_enabled: Homepage enabled + banner_title: Banner colors + banner_background_color: Background colour + banner_font_color: Font colour index: create: New process delete: Delete diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 8a1ca7315..50576eec7 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -439,6 +439,9 @@ es: homepage: Descripción homepage_description: Aquí puedes explicar el contenido del proceso homepage_enabled: Homepage activada + banner_title: Colores del banner + banner_background_color: Color de fondo + banner_font_color: Color del texto index: create: Nuevo proceso delete: Borrar diff --git a/db/migrate/20181220163447_add_header_color_settings_to_legislation_processes.rb b/db/migrate/20181220163447_add_header_color_settings_to_legislation_processes.rb new file mode 100644 index 000000000..b4c7b3ad8 --- /dev/null +++ b/db/migrate/20181220163447_add_header_color_settings_to_legislation_processes.rb @@ -0,0 +1,6 @@ +class AddHeaderColorSettingsToLegislationProcesses < ActiveRecord::Migration + def change + add_column :legislation_processes, :background_color, :text + add_column :legislation_processes, :font_color, :text + end +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 830ca56de..ab97ed08f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -666,6 +666,8 @@ ActiveRecord::Schema.define(version: 20190103132925) do t.date "draft_end_date" t.boolean "draft_phase_enabled", default: false t.boolean "homepage_enabled", default: false + t.text "background_color" + t.text "font_color" end add_index "legislation_processes", ["allegations_end_date"], name: "index_legislation_processes_on_allegations_end_date", using: :btree diff --git a/spec/features/admin/legislation/processes_spec.rb b/spec/features/admin/legislation/processes_spec.rb index af97d0e1c..e56bca81b 100644 --- a/spec/features/admin/legislation/processes_spec.rb +++ b/spec/features/admin/legislation/processes_spec.rb @@ -131,6 +131,28 @@ feature 'Admin legislation processes' do expect(page).not_to have_content 'Summary of the process' expect(page).not_to have_content 'Describing the process' end + + scenario "Create a legislation process with an image", :js do + visit new_admin_legislation_process_path() + fill_in 'Process Title', with: 'An example legislation process' + fill_in 'Summary', with: 'Summary of the process' + + base_date = Date.current + fill_in 'legislation_process[start_date]', with: base_date.strftime("%d/%m/%Y") + fill_in 'legislation_process[end_date]', with: (base_date + 5.days).strftime("%d/%m/%Y") + imageable_attach_new_file(create(:image), Rails.root.join('spec/fixtures/files/clippy.jpg')) + + click_button 'Create process' + + expect(page).to have_content 'An example legislation process' + expect(page).to have_content 'Process created successfully' + + click_link 'Click to visit' + + expect(page).to have_content 'An example legislation process' + expect(page).not_to have_content 'Summary of the process' + expect(page).to have_css("img[alt='#{Legislation::Process.last.title}']") + end end context 'Update' do diff --git a/spec/helpers/legislation_helper_spec.rb b/spec/helpers/legislation_helper_spec.rb new file mode 100644 index 000000000..9d88aa8c8 --- /dev/null +++ b/spec/helpers/legislation_helper_spec.rb @@ -0,0 +1,31 @@ +require 'rails_helper' + +describe LegislationHelper do + let(:process) { build(:legislation_process) } + + it "is valid" do + expect(process).to be_valid + end + + describe "banner colors presence" do + it "background and font color exist" do + @process = build(:legislation_process, background_color: "#944949", font_color: "#ffffff") + expect(banner_color?).to eq(true) + end + + it "background color exist and font color not exist" do + @process = build(:legislation_process, background_color: "#944949", font_color: "") + expect(banner_color?).to eq(false) + end + + it "background color not exist and font color exist" do + @process = build(:legislation_process, background_color: "", font_color: "#944949") + expect(banner_color?).to eq(false) + end + + it "background and font color not exist" do + @process = build(:legislation_process, background_color: "", font_color: "") + expect(banner_color?).to eq(false) + end + end +end diff --git a/spec/models/legislation/process_spec.rb b/spec/models/legislation/process_spec.rb index b921ffcdb..c2b1c8214 100644 --- a/spec/models/legislation/process_spec.rb +++ b/spec/models/legislation/process_spec.rb @@ -177,4 +177,24 @@ describe Legislation::Process do end end + describe "banner colors" do + it "valid banner colors" do + process1 = create(:legislation_process, background_color: "123", font_color: "#fff") + process2 = create(:legislation_process, background_color: "#fff", font_color: "123") + process3 = create(:legislation_process, background_color: "", font_color: "") + process4 = create(:legislation_process, background_color: "#abf123", font_color: "fff123") + expect(process1).to be_valid + expect(process2).to be_valid + expect(process3).to be_valid + expect(process4).to be_valid + end + + it "invalid banner colors" do + expect { + process1 = create(:legislation_process, background_color: "#123ghi", font_color: "#fff") + process2 = create(:legislation_process, background_color: "#ffffffff", font_color: "#123") + }.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Background color is invalid") + end + end + end