Add more images to admin site customization

This commit is contained in:
decabeza
2022-05-19 20:34:09 +02:00
committed by Javi Martín
parent 11bed74678
commit 10cd182774
12 changed files with 81 additions and 12 deletions

View File

@@ -998,7 +998,7 @@ footer {
} }
.auth-image { .auth-image {
background: $brand image-url("auth_bg.jpg"); background-color: $brand;
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: cover; background-size: cover;
color: $white; color: $white;

View File

@@ -2,7 +2,7 @@
<% if investment.image.present? %> <% if investment.image.present? %>
<%= image_tag investment.image.variant(:large), alt: investment.image.title.unicode_normalize %> <%= image_tag investment.image.variant(:large), alt: investment.image.title.unicode_normalize %>
<% else %> <% else %>
<%= image_tag "budget_investment_no_image.jpg", alt: investment.title %> <%= image_tag(image_path_for("budget_investment_no_image.jpg"), alt: investment.title) %>
<% end %> <% end %>
<% if investment.should_show_vote_count? || investment.should_show_price? %> <% if investment.should_show_vote_count? || investment.should_show_price? %>

View File

@@ -1,5 +1,5 @@
class Budgets::InvestmentComponent < ApplicationComponent class Budgets::InvestmentComponent < ApplicationComponent
delegate :locale_and_user_status, :namespaced_budget_investment_path, to: :helpers delegate :locale_and_user_status, :namespaced_budget_investment_path, :image_path_for, to: :helpers
attr_reader :investment attr_reader :investment
def initialize(investment) def initialize(investment)

View File

@@ -1,7 +1,7 @@
<div class="legislation-process card"> <div class="legislation-process card">
<%= link_to url_for(process) do %> <%= link_to url_for(process) do %>
<figure class="figure-card"> <figure class="figure-card">
<%= image_tag("welcome_process.png", alt: "") %> <%= image_tag(image_path_for("welcome_process.png"), alt: "") %>
<figcaption> <figcaption>
<span><%= t("welcome.feed.process_label") %></span><br> <span><%= t("welcome.feed.process_label") %></span><br>
<h3><%= process.title %></h3> <h3><%= process.title %></h3>

View File

@@ -1,4 +1,5 @@
class Widget::Feeds::ProcessComponent < ApplicationComponent class Widget::Feeds::ProcessComponent < ApplicationComponent
delegate :image_path_for, to: :helpers
attr_reader :process attr_reader :process
def initialize(process) def initialize(process)

View File

@@ -6,12 +6,21 @@ class SiteCustomization::Image < ApplicationRecord
"social_media_icon" => [470, 246], "social_media_icon" => [470, 246],
"social_media_icon_twitter" => [246, 246], "social_media_icon_twitter" => [246, 246],
"apple-touch-icon-200" => [200, 200], "apple-touch-icon-200" => [200, 200],
"auth_bg" => [1280, 1500],
"budget_execution_no_image" => [800, 600], "budget_execution_no_image" => [800, 600],
"budget_investment_no_image" => [800, 600],
"favicon" => [16, 16],
"map" => [420, 500], "map" => [420, 500],
"logo_email" => [400, 80] "logo_email" => [400, 80],
"welcome_process" => [370, 185]
}.freeze }.freeze
VALID_MIME_TYPES = %w[image/jpeg image/png].freeze VALID_MIME_TYPES = %w[
image/jpeg
image/png
image/vnd.microsoft.icon
image/x-icon
].freeze
has_attachment :image has_attachment :image

View File

@@ -10,4 +10,4 @@
<% end %> <% end %>
<%= javascript_include_tag "application", "data-turbolinks-track" => "reload" %> <%= javascript_include_tag "application", "data-turbolinks-track" => "reload" %>
<%= csrf_meta_tags %> <%= csrf_meta_tags %>
<%= favicon_link_tag "favicon.ico" %> <%= favicon_link_tag image_path_for("favicon.ico") %>

View File

@@ -9,7 +9,8 @@
<body class="auth-page"> <body class="auth-page">
<%= raw setting["html.per_page_code_body"] %> <%= raw setting["html.per_page_code_body"] %>
<div class="wrapper"> <div class="wrapper">
<div class="auth-image small-12 medium-3 column"> <div class="auth-image small-12 medium-3 column"
style="background-image: url(<%= asset_url(image_path_for("auth_bg.jpg")) %>)">
<h1 class="logo margin"> <h1 class="logo margin">
<%= link_to root_path do %> <%= link_to root_path do %>
<%= image_tag(image_path_for("logo_header.png"), class: "float-left", alt: setting["org_name"]) %> <%= image_tag(image_path_for("logo_header.png"), class: "float-left", alt: setting["org_name"]) %>

View File

@@ -11,11 +11,26 @@ describe Budgets::InvestmentComponent do
expect(page).to have_css "img[alt='#{investment.image.title}']" expect(page).to have_css "img[alt='#{investment.image.title}']"
end end
it "shows the default image when investment has not an image defined" do context "investment without an image" do
investment = create(:budget_investment) let(:component) { Budgets::InvestmentComponent.new(create(:budget_investment)) }
render_inline Budgets::InvestmentComponent.new(investment)
expect(page).to have_css "img[src*='budget_investment_no_image']" it "shows the default image" do
render_inline component
expect(page).to have_css "img[src*='budget_investment_no_image']"
end
it "shows a custom default image when available" do
stub_const("#{SiteCustomization::Image}::VALID_IMAGES", { "budget_investment_no_image" => [260, 80] })
create(:site_customization_image,
name: "budget_investment_no_image",
image: fixture_file_upload("logo_header-260x80.png"))
render_inline component
expect(page).to have_css "img[src$='logo_header-260x80.png']"
expect(page).not_to have_css "img[src*='budget_investment_no_image']"
end
end end
it "shows supports count when budget is valuating" do it "shows supports count when budget is valuating" do

View File

@@ -20,4 +20,24 @@ describe Widget::Feeds::ProcessComponent do
expect(page).to have_css("img[alt='1. No Poverty']") expect(page).to have_css("img[alt='1. No Poverty']")
end end
describe "image" do
it "shows the default image" do
render_inline component
expect(page).to have_css "img[src*='welcome_process']"
end
it "shows a custom default image when available" do
stub_const("#{SiteCustomization::Image}::VALID_IMAGES", { "welcome_process" => [260, 80] })
create(:site_customization_image,
name: "welcome_process",
image: fixture_file_upload("logo_header-260x80.png"))
render_inline component
expect(page).to have_css "img[src$='logo_header-260x80.png']"
expect(page).not_to have_css "img[src*='welcome_process']"
end
end
end end

BIN
spec/fixtures/files/favicon_custom.ico vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,23 @@
require "rails_helper"
describe "Site customization images" do
scenario "Custom favicon" do
create(:site_customization_image, name: "favicon", image: fixture_file_upload("favicon_custom.ico"))
visit root_path
expect(page).to have_css("link[rel='shortcut icon'][href$='favicon_custom.ico']", visible: :hidden)
end
scenario "Custom auth background" do
stub_const("#{SiteCustomization::Image}::VALID_IMAGES", { "auth_bg" => [260, 80] })
create(:site_customization_image,
name: "auth_bg",
image: fixture_file_upload("logo_header-260x80.png"))
visit new_user_session_path
expect(page).to have_css "[style*='background-image:'][style*='logo_header-260x80.png']"
expect(page).not_to have_css "[style*='auth_bg']"
end
end