Site customization: images uploads
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -65,6 +65,8 @@ gem 'browser'
|
|||||||
gem 'turnout', '~> 2.4.0'
|
gem 'turnout', '~> 2.4.0'
|
||||||
gem 'redcarpet', '~> 3.4.0'
|
gem 'redcarpet', '~> 3.4.0'
|
||||||
|
|
||||||
|
gem 'paperclip'
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||||
gem 'byebug'
|
gem 'byebug'
|
||||||
|
|||||||
10
Gemfile.lock
10
Gemfile.lock
@@ -238,6 +238,7 @@ GEM
|
|||||||
mime-types (3.1)
|
mime-types (3.1)
|
||||||
mime-types-data (~> 3.2015)
|
mime-types-data (~> 3.2015)
|
||||||
mime-types-data (3.2016.0521)
|
mime-types-data (3.2016.0521)
|
||||||
|
mimemagic (0.3.2)
|
||||||
mini_portile2 (2.1.0)
|
mini_portile2 (2.1.0)
|
||||||
minitest (5.10.1)
|
minitest (5.10.1)
|
||||||
multi_json (1.12.1)
|
multi_json (1.12.1)
|
||||||
@@ -277,6 +278,12 @@ GEM
|
|||||||
omniauth-oauth (~> 1.1)
|
omniauth-oauth (~> 1.1)
|
||||||
rack
|
rack
|
||||||
orm_adapter (0.5.0)
|
orm_adapter (0.5.0)
|
||||||
|
paperclip (5.1.0)
|
||||||
|
activemodel (>= 4.2.0)
|
||||||
|
activesupport (>= 4.2.0)
|
||||||
|
cocaine (~> 0.5.5)
|
||||||
|
mime-types
|
||||||
|
mimemagic (~> 0.3.0)
|
||||||
paranoia (2.2.1)
|
paranoia (2.2.1)
|
||||||
activerecord (>= 4.0, < 5.1)
|
activerecord (>= 4.0, < 5.1)
|
||||||
parser (2.4.0.0)
|
parser (2.4.0.0)
|
||||||
@@ -504,6 +511,7 @@ DEPENDENCIES
|
|||||||
omniauth-facebook (~> 4.0.0)
|
omniauth-facebook (~> 4.0.0)
|
||||||
omniauth-google-oauth2 (~> 0.4.0)
|
omniauth-google-oauth2 (~> 0.4.0)
|
||||||
omniauth-twitter
|
omniauth-twitter
|
||||||
|
paperclip
|
||||||
paranoia (~> 2.2.1)
|
paranoia (~> 2.2.1)
|
||||||
pg (~> 0.20.0)
|
pg (~> 0.20.0)
|
||||||
pg_search
|
pg_search
|
||||||
@@ -533,4 +541,4 @@ DEPENDENCIES
|
|||||||
whenever
|
whenever
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.13.7
|
1.14.6
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
class Admin::SiteCustomization::ImagesController < Admin::SiteCustomization::BaseController
|
||||||
|
load_and_authorize_resource :image, class: "SiteCustomization::Image"
|
||||||
|
|
||||||
|
def index
|
||||||
|
@images = SiteCustomization::Image.all_images
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if params[:site_customization_image].nil?
|
||||||
|
redirect_to admin_site_customization_images_path
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if @image.update(image_params)
|
||||||
|
redirect_to admin_site_customization_images_path, notice: t('admin.site_customization.images.update.notice')
|
||||||
|
else
|
||||||
|
flash.now[:error] = t('admin.site_customization.images.update.error')
|
||||||
|
|
||||||
|
@images = SiteCustomization::Image.all_images
|
||||||
|
idx = @images.index {|e| e.name == @image.name }
|
||||||
|
@images[idx] = @image
|
||||||
|
|
||||||
|
render :index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@image.image = nil
|
||||||
|
if @image.save
|
||||||
|
redirect_to admin_site_customization_images_path, notice: t('admin.site_customization.images.destroy.notice')
|
||||||
|
else
|
||||||
|
redirect_to admin_site_customization_images_path, notice: t('admin.site_customization.images.destroy.error')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def image_params
|
||||||
|
params.require(:site_customization_image).permit(
|
||||||
|
:image
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -7,7 +7,7 @@ class Admin::SiteCustomization::PagesController < Admin::SiteCustomization::Base
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
if @page.save
|
if @page.save
|
||||||
redirect_to admin_site_customization_pages_path, notice: t('admin.site_customization.pages.create.notice', link: @page.slug.html_safe)
|
redirect_to admin_site_customization_pages_path, notice: t('admin.site_customization.pages.create.notice')
|
||||||
else
|
else
|
||||||
flash.now[:error] = t('admin.site_customization.pages.create.error')
|
flash.now[:error] = t('admin.site_customization.pages.create.error')
|
||||||
render :new
|
render :new
|
||||||
@@ -16,7 +16,7 @@ class Admin::SiteCustomization::PagesController < Admin::SiteCustomization::Base
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
if @page.update(page_params)
|
if @page.update(page_params)
|
||||||
redirect_to admin_site_customization_pages_path, notice: t('admin.site_customization.pages.update.notice', link: @page.slug.html_safe)
|
redirect_to admin_site_customization_pages_path, notice: t('admin.site_customization.pages.update.notice')
|
||||||
else
|
else
|
||||||
flash.now[:error] = t('admin.site_customization.pages.update.error')
|
flash.now[:error] = t('admin.site_customization.pages.update.error')
|
||||||
render :edit
|
render :edit
|
||||||
|
|||||||
@@ -47,4 +47,8 @@ module ApplicationHelper
|
|||||||
"<span class='icon-angle-left'></span>".html_safe + t("shared.back")
|
"<span class='icon-angle-left'></span>".html_safe + t("shared.back")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def image_path_for(filename)
|
||||||
|
SiteCustomization::Image.image_path_for(filename) || filename
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ module Abilities
|
|||||||
can [:index, :create, :edit, :update, :destroy], Geozone
|
can [:index, :create, :edit, :update, :destroy], Geozone
|
||||||
|
|
||||||
can :manage, SiteCustomization::Page
|
can :manage, SiteCustomization::Page
|
||||||
|
can :manage, SiteCustomization::Image
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
48
app/models/site_customization/image.rb
Normal file
48
app/models/site_customization/image.rb
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
class SiteCustomization::Image < ActiveRecord::Base
|
||||||
|
VALID_IMAGES = {
|
||||||
|
"icon_home" => [330, 240],
|
||||||
|
"logo_header" => [80, 80],
|
||||||
|
"social-media-icon" => [200, 200],
|
||||||
|
"apple-touch-icon-200" => [200, 200]
|
||||||
|
}
|
||||||
|
|
||||||
|
has_attached_file :image
|
||||||
|
|
||||||
|
validates :name, presence: true, uniqueness: true, inclusion: { in: VALID_IMAGES.keys }
|
||||||
|
validates_attachment_content_type :image, :content_type => ["image/png"]
|
||||||
|
validate :check_image
|
||||||
|
|
||||||
|
def self.all_images
|
||||||
|
VALID_IMAGES.keys.map do |image_name|
|
||||||
|
find_by(name: image_name) || create!(name: image_name.to_s)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.image_path_for(filename)
|
||||||
|
image_name = filename.split(".").first
|
||||||
|
|
||||||
|
if i = find_by(name: image_name)
|
||||||
|
i.image.exists? ? i.image.url : nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def required_width
|
||||||
|
VALID_IMAGES[name].try(:first)
|
||||||
|
end
|
||||||
|
|
||||||
|
def required_height
|
||||||
|
VALID_IMAGES[name].try(:second)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def check_image
|
||||||
|
return unless image?
|
||||||
|
|
||||||
|
dimensions = Paperclip::Geometry.from_file(image.queued_for_write[:original].path)
|
||||||
|
|
||||||
|
errors.add(:image, :image_width, required_width: required_width) unless dimensions.width == required_width
|
||||||
|
errors.add(:image, :image_height, required_height: required_height) unless dimensions.height == required_height
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -128,5 +128,11 @@
|
|||||||
<span class="icon-settings"></span><%= t("admin.menu.site_customization.pages") %>
|
<span class="icon-settings"></span><%= t("admin.menu.site_customization.pages") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li <%= "class=active" if controller_name == "images" %>>
|
||||||
|
<%= link_to admin_site_customization_images_path do %>
|
||||||
|
<span class="icon-settings"></span><%= t("admin.menu.site_customization.images") %>
|
||||||
|
<% end %>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|||||||
25
app/views/admin/site_customization/images/index.html.erb
Normal file
25
app/views/admin/site_customization/images/index.html.erb
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<h2><%= t("admin.site_customization.images.index.title") %></h2>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<% @images.each do |image| %>
|
||||||
|
<tr class="<%= image.name %>">
|
||||||
|
<td class="small-12 medium-4">
|
||||||
|
<strong><%= image.name %></strong> (<%= image.required_width %>x<%= image.required_height %>)
|
||||||
|
</td>
|
||||||
|
<td class="small-12 medium-8">
|
||||||
|
<%= form_for([:admin, image], html: { id: "edit_#{dom_id(image)}"}) do |f| %>
|
||||||
|
<div class="small-12 medium-6 large-6 column">
|
||||||
|
<%= image_tag image.image.url if image.image.exists? %>
|
||||||
|
<%= f.file_field :image, label: false %>
|
||||||
|
</div>
|
||||||
|
<div class="small-12 medium-6 large-6 column">
|
||||||
|
<%= f.submit(t('admin.site_customization.images.index.update'), class: "button hollow") %>
|
||||||
|
<%= link_to t('admin.site_customization.images.index.delete'), admin_site_customization_image_path(image), method: :delete, class: "button hollow alert" if image.image.exists? %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
<div id="responsive-menu">
|
<div id="responsive-menu">
|
||||||
<div class="top-bar-title">
|
<div class="top-bar-title">
|
||||||
<%= link_to admin_root_path, class: "hide-for-small-only" do %>
|
<%= link_to admin_root_path, class: "hide-for-small-only" do %>
|
||||||
<%= image_tag('logo_header.png', class: 'hide-for-small-only float-left', size: '80x80', alt: t("layouts.header.logo")) %>
|
<%= image_tag(image_path_for('logo_header.png'), class: 'hide-for-small-only float-left', size: '80x80', alt: t("layouts.header.logo")) %>
|
||||||
<%= setting['org_name'] %>
|
<%= setting['org_name'] %>
|
||||||
| <%= t("admin.dashboard.index.title") %>
|
| <%= t("admin.dashboard.index.title") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -34,4 +34,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
<div id="responsive-menu">
|
<div id="responsive-menu">
|
||||||
<div class="top-bar-title">
|
<div class="top-bar-title">
|
||||||
<%= link_to root_path, class: "hide-for-small-only", accesskey: "0" do %>
|
<%= link_to root_path, class: "hide-for-small-only", accesskey: "0" do %>
|
||||||
<%= image_tag('logo_header.png', class: 'hide-for-small-only float-left', size: '80x80', alt: t("layouts.header.logo")) %>
|
<%= image_tag(image_path_for('logo_header.png'), class: 'hide-for-small-only float-left', size: '80x80', alt: t("layouts.header.logo")) %>
|
||||||
<%= setting['org_name'] %>
|
<%= setting['org_name'] %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
|
<%= javascript_include_tag "application", 'data-turbolinks-track' => true %>
|
||||||
<%= csrf_meta_tags %>
|
<%= csrf_meta_tags %>
|
||||||
<%= favicon_link_tag "favicon.ico" %>
|
<%= favicon_link_tag "favicon.ico" %>
|
||||||
<%= favicon_link_tag "apple-touch-icon-200.png",
|
<%= favicon_link_tag image_path_for("apple-touch-icon-200.png"),
|
||||||
rel: "icon apple-touch-icon",
|
rel: "icon apple-touch-icon",
|
||||||
sizes: "200x200",
|
sizes: "200x200",
|
||||||
type: "image/png" %>
|
type: "image/png" %>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<div class="auth-image small-12 medium-3 column">
|
<div class="auth-image small-12 medium-3 column">
|
||||||
<h1 class="logo margin">
|
<h1 class="logo margin">
|
||||||
<%= link_to root_path do %>
|
<%= link_to root_path do %>
|
||||||
<%= image_tag('logo_header.png', class: 'float-left', alt: t("layouts.header.logo")) %>
|
<%= image_tag(image_path_for('logo_header.png'), class: 'float-left', alt: t("layouts.header.logo")) %>
|
||||||
<%= setting['org_name'] %>
|
<%= setting['org_name'] %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</h1>
|
</h1>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
<div id="responsive-menu">
|
<div id="responsive-menu">
|
||||||
<div class="top-bar-title">
|
<div class="top-bar-title">
|
||||||
<%= link_to management_root_path, class: "hide-for-small-only" do %>
|
<%= link_to management_root_path, class: "hide-for-small-only" do %>
|
||||||
<%= image_tag('logo_header.png', class: 'hide-for-small-only float-left', size: '80x80', alt: t("layouts.header.logo")) %>
|
<%= image_tag(image_path_for('logo_header.png'), class: 'hide-for-small-only float-left', size: '80x80', alt: t("layouts.header.logo")) %>
|
||||||
<%= setting['org_name'] %>
|
<%= setting['org_name'] %>
|
||||||
| <%= t("management.dashboard.index.title") %>
|
| <%= t("management.dashboard.index.title") %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<meta name="twitter:site" content="@consul_dev" />
|
<meta name="twitter:site" content="@consul_dev" />
|
||||||
<meta name="twitter:title" content="<%= social_title %>" />
|
<meta name="twitter:title" content="<%= social_title %>" />
|
||||||
<meta name="twitter:description" content="<%= social_description %>" />
|
<meta name="twitter:description" content="<%= social_description %>" />
|
||||||
<meta name="twitter:image" content="<%= image_url '/social-media-icon.png' %>" />
|
<meta name="twitter:image" content="<%= image_url image_path_for('social-media-icon.png') %>" />
|
||||||
<!-- Facebook OG -->
|
<!-- Facebook OG -->
|
||||||
<meta id="ogtitle" property="og:title" content="<%= social_title %>"/>
|
<meta id="ogtitle" property="og:title" content="<%= social_title %>"/>
|
||||||
<% if setting['url'] %>
|
<% if setting['url'] %>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<meta property="og:type" content="article"/>
|
<meta property="og:type" content="article"/>
|
||||||
<meta id="ogurl" property="og:url" content="<%= social_url %>"/>
|
<meta id="ogurl" property="og:url" content="<%= social_url %>"/>
|
||||||
<meta id="ogimage" property="og:image" content="<%= image_url '/social-media-icon.png' %>"/>
|
<meta id="ogimage" property="og:image" content="<%= image_url image_path_for('social-media-icon.png') %>"/>
|
||||||
<meta property="og:site_name" content="<%= setting['org_name'] %>"/>
|
<meta property="og:site_name" content="<%= setting['org_name'] %>"/>
|
||||||
<meta id="ogdescription" property="og:description" content="<%= social_description %>"/>
|
<meta id="ogdescription" property="og:description" content="<%= social_description %>"/>
|
||||||
<meta property="fb:app_id" content="<%= Rails.application.secrets.facebook_key %>"/>
|
<meta property="fb:app_id" content="<%= Rails.application.secrets.facebook_key %>"/>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="hide-for-small-only small-12 medium-5 column text-center">
|
<div class="hide-for-small-only small-12 medium-5 column text-center">
|
||||||
<%= image_tag("icon_home.png", size: "330x240", alt:"") %>
|
<%= image_tag(image_path_for("icon_home.png"), size: "330x240", alt:"") %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ en:
|
|||||||
site_customization/page:
|
site_customization/page:
|
||||||
one: Custom page
|
one: Custom page
|
||||||
other: Custom pages
|
other: Custom pages
|
||||||
|
site_customization/image:
|
||||||
|
one: Custom image
|
||||||
|
other: Custom images
|
||||||
attributes:
|
attributes:
|
||||||
budget:
|
budget:
|
||||||
name: "Name"
|
name: "Name"
|
||||||
@@ -151,3 +154,8 @@ en:
|
|||||||
attributes:
|
attributes:
|
||||||
slug:
|
slug:
|
||||||
slug_format: "must be letters, numbers, _ and -"
|
slug_format: "must be letters, numbers, _ and -"
|
||||||
|
site_customization/image:
|
||||||
|
attributes:
|
||||||
|
image:
|
||||||
|
image_width: "Width must be %{required_width}px"
|
||||||
|
image_height: "Height must be %{required_height}px"
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ es:
|
|||||||
site_customization/page:
|
site_customization/page:
|
||||||
one: Página
|
one: Página
|
||||||
other: Páginas
|
other: Páginas
|
||||||
|
site_customization/image:
|
||||||
|
one: Imagen
|
||||||
|
other: Imágenes
|
||||||
attributes:
|
attributes:
|
||||||
budget:
|
budget:
|
||||||
name: "Nombre"
|
name: "Nombre"
|
||||||
@@ -146,3 +149,8 @@ es:
|
|||||||
attributes:
|
attributes:
|
||||||
slug:
|
slug:
|
||||||
slug_format: "deber ser letras, números, _ y -"
|
slug_format: "deber ser letras, números, _ y -"
|
||||||
|
site_customization/image:
|
||||||
|
attributes:
|
||||||
|
image:
|
||||||
|
image_width: "Debe tener %{required_width}px de ancho"
|
||||||
|
image_height: "Debe tener %{required_height}px de alto"
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ en:
|
|||||||
signature_sheets: Signature Sheets
|
signature_sheets: Signature Sheets
|
||||||
site_customization:
|
site_customization:
|
||||||
pages: Custom Pages
|
pages: Custom Pages
|
||||||
|
images: Custom Images
|
||||||
moderators:
|
moderators:
|
||||||
index:
|
index:
|
||||||
title: Moderators
|
title: Moderators
|
||||||
@@ -478,12 +479,23 @@ en:
|
|||||||
sms_code_not_confirmed: Has not confirmed the sms code
|
sms_code_not_confirmed: Has not confirmed the sms code
|
||||||
title: Incomplete verifications
|
title: Incomplete verifications
|
||||||
site_customization:
|
site_customization:
|
||||||
|
images:
|
||||||
|
index:
|
||||||
|
title: Custom images
|
||||||
|
update: Update
|
||||||
|
delete: Delete
|
||||||
|
update:
|
||||||
|
notice: Image updated successfully
|
||||||
|
error: Image couldn't be updated
|
||||||
|
destroy:
|
||||||
|
notice: Image deleted successfully
|
||||||
|
error: Image couldn't be deleted
|
||||||
pages:
|
pages:
|
||||||
create:
|
create:
|
||||||
notice: 'Page created successfully.'
|
notice: Page created successfully
|
||||||
error: Process couldn't be created
|
error: Process couldn't be created
|
||||||
update:
|
update:
|
||||||
notice: 'Page updated successfully.'
|
notice: Page updated successfully
|
||||||
error: Page couldn't be updated
|
error: Page couldn't be updated
|
||||||
destroy:
|
destroy:
|
||||||
notice: Page deleted successfully
|
notice: Page deleted successfully
|
||||||
|
|||||||
@@ -208,7 +208,8 @@ es:
|
|||||||
stats: Estadísticas
|
stats: Estadísticas
|
||||||
signature_sheets: Hojas de firmas
|
signature_sheets: Hojas de firmas
|
||||||
site_customization:
|
site_customization:
|
||||||
pages: Páginas
|
pages: Personalizar páginas
|
||||||
|
images: Personalizar imágenes
|
||||||
moderators:
|
moderators:
|
||||||
index:
|
index:
|
||||||
title: Moderadores
|
title: Moderadores
|
||||||
@@ -478,12 +479,23 @@ es:
|
|||||||
sms_code_not_confirmed: No ha introducido su código de seguridad
|
sms_code_not_confirmed: No ha introducido su código de seguridad
|
||||||
title: Verificaciones incompletas
|
title: Verificaciones incompletas
|
||||||
site_customization:
|
site_customization:
|
||||||
|
images:
|
||||||
|
index:
|
||||||
|
title: Personalizar imágenes
|
||||||
|
update: Actualizar
|
||||||
|
delete: Borrar
|
||||||
|
update:
|
||||||
|
notice: Imagen actualizada correctamente
|
||||||
|
error: No se ha podido actualizar la imagen
|
||||||
|
destroy:
|
||||||
|
notice: Imagen borrada correctamente
|
||||||
|
error: No se ha podido borrar la imagen
|
||||||
pages:
|
pages:
|
||||||
create:
|
create:
|
||||||
notice: 'Página creada correctamente.'
|
notice: Página creada correctamente
|
||||||
error: No se ha podido crear la página
|
error: No se ha podido crear la página
|
||||||
update:
|
update:
|
||||||
notice: 'Página actualizada correctamente.s'
|
notice: Página actualizada correctamente
|
||||||
error: No se ha podido actualizar la página
|
error: No se ha podido actualizar la página
|
||||||
destroy:
|
destroy:
|
||||||
notice: Página eliminada correctamente
|
notice: Página eliminada correctamente
|
||||||
|
|||||||
@@ -225,6 +225,7 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
namespace :site_customization do
|
namespace :site_customization do
|
||||||
resources :pages, except: [:show]
|
resources :pages, except: [:show]
|
||||||
|
resources :images, only: [:index, :update, :destroy]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
class CreateSiteCustomizationImages < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :site_customization_images do |t|
|
||||||
|
t.string :name, null: false
|
||||||
|
t.attachment :image
|
||||||
|
t.timestamps null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index :site_customization_images, :name, unique: true
|
||||||
|
end
|
||||||
|
end
|
||||||
14
db/schema.rb
14
db/schema.rb
@@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20170316174351) do
|
ActiveRecord::Schema.define(version: 20170322145702) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -439,6 +439,18 @@ ActiveRecord::Schema.define(version: 20170316174351) do
|
|||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "site_customization_images", force: :cascade do |t|
|
||||||
|
t.string "name", null: false
|
||||||
|
t.string "image_file_name"
|
||||||
|
t.string "image_content_type"
|
||||||
|
t.integer "image_file_size"
|
||||||
|
t.datetime "image_updated_at"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
|
add_index "site_customization_images", ["name"], name: "index_site_customization_images_on_name", unique: true, using: :btree
|
||||||
|
|
||||||
create_table "site_customization_pages", force: :cascade do |t|
|
create_table "site_customization_pages", force: :cascade do |t|
|
||||||
t.string "slug", null: false
|
t.string "slug", null: false
|
||||||
t.string "title", null: false
|
t.string "title", null: false
|
||||||
|
|||||||
62
spec/features/admin/site_customization/images_spec.rb
Normal file
62
spec/features/admin/site_customization/images_spec.rb
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature "Admin custom images" do
|
||||||
|
|
||||||
|
background do
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Upload valid image" do
|
||||||
|
visit admin_root_path
|
||||||
|
|
||||||
|
within("#side_menu") do
|
||||||
|
click_link "Custom Images"
|
||||||
|
end
|
||||||
|
|
||||||
|
within("tr.logo_header") do
|
||||||
|
attach_file "site_customization_image_image", "spec/fixtures/files/logo_header.png"
|
||||||
|
click_button "Update"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_css("tr.logo_header img[src*='logo_header.png']")
|
||||||
|
expect(page).to have_css("img[src*='logo_header.png']", count: 2) # one in the admin form an one in the page header
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Upload invalid image" do
|
||||||
|
visit admin_root_path
|
||||||
|
|
||||||
|
within("#side_menu") do
|
||||||
|
click_link "Custom Images"
|
||||||
|
end
|
||||||
|
|
||||||
|
within("tr.icon_home") do
|
||||||
|
attach_file "site_customization_image_image", "spec/fixtures/files/logo_header.png"
|
||||||
|
click_button "Update"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_content("Width must be 330px")
|
||||||
|
expect(page).to have_content("Height must be 240px")
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "Delete image" do
|
||||||
|
visit admin_root_path
|
||||||
|
|
||||||
|
within("#side_menu") do
|
||||||
|
click_link "Custom Images"
|
||||||
|
end
|
||||||
|
|
||||||
|
within("tr.social-media-icon") do
|
||||||
|
attach_file "site_customization_image_image", "spec/fixtures/files/social-media-icon.png"
|
||||||
|
click_button "Update"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to have_css("img[src*='social-media-icon.png']")
|
||||||
|
|
||||||
|
within("tr.social-media-icon") do
|
||||||
|
click_link "Delete"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).to_not have_css("img[src*='social-media-icon.png']")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -39,7 +39,7 @@ feature "Admin custom pages" do
|
|||||||
|
|
||||||
context "Update" do
|
context "Update" do
|
||||||
scenario "Valid custom page" do
|
scenario "Valid custom page" do
|
||||||
custom_page = create(:site_customization_page, title: "An example custom page")
|
create(:site_customization_page, title: "An example custom page")
|
||||||
visit admin_root_path
|
visit admin_root_path
|
||||||
|
|
||||||
within("#side_menu") do
|
within("#side_menu") do
|
||||||
@@ -58,7 +58,7 @@ feature "Admin custom pages" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Index" do
|
scenario "Delete" do
|
||||||
custom_page = create(:site_customization_page, title: "An example custom page")
|
custom_page = create(:site_customization_page, title: "An example custom page")
|
||||||
visit edit_admin_site_customization_page_path(custom_page)
|
visit edit_admin_site_customization_page_path(custom_page)
|
||||||
|
|
||||||
|
|||||||
BIN
spec/fixtures/files/logo_header.png
vendored
Normal file
BIN
spec/fixtures/files/logo_header.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 463 B |
BIN
spec/fixtures/files/social-media-icon.png
vendored
Normal file
BIN
spec/fixtures/files/social-media-icon.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
Reference in New Issue
Block a user