Commit 99124ecf by Mykhailo Makohin

add all nested attributes to project and some progress in localization activeadmin projects

parent 934e72d2
......@@ -77,6 +77,8 @@ GEM
image_processing (~> 1.1)
mimemagic (>= 0.3.0)
mini_mime (>= 0.1.3)
ckeditor (5.0.0)
orm_adapter (~> 0.5.0)
cocoon (1.2.14)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
......@@ -292,6 +294,7 @@ DEPENDENCIES
byebug
cancancan
carrierwave
ckeditor
cocoon
coffee-rails (~> 4.2)
devise
......@@ -300,6 +303,7 @@ DEPENDENCIES
jbuilder (~> 2.5)
jquery-rails
listen (~> 3.0.5)
mini_magick
mysql2 (>= 0.3.18, < 0.6.0)
omniauth
omniauth-facebook
......
......@@ -14,12 +14,12 @@ ActiveAdmin.register Project do
end
def project_params
params.require(:project).permit(:photo, :photo_preview, :photo_before, :photo_after, :types,
:status, :individual_type_uk, :individual_type_en,
params.require(:project).permit(:photo, :photo_preview, :photo_before, :remove_photo_before,
:photo_after, :remove_photo_after, :types, :status, :individual_type_uk, :individual_type_en,
:title_uk, :title_en, :heading_uk, :heading_en, :slug, :short_description_uk,
:short_description_en, :description_uk,:description_en, :site,
:link_to_facebook, :required_amount, :related_links_uk, :related_links_en,
:footer_photo,
:footer_photo, :remove_footer_photo,
project_photos_attributes: [:id, :project_id, :photo, :title_uk,
:title_en, :_destroy],
project_galeries_attributes: [:id, :project_id, :photo, :name_uk,
......@@ -29,17 +29,25 @@ ActiveAdmin.register Project do
:text_quote, :text_below_quote_uk, :text_below_quote, :_destroy],
project_links_attributes: [:id, :project_id, :site, :title_uk,
:title_en, :_destroy],
project_vidos_attributes: [:id, :project_id, :video_fiel, :video_link, :short_description_uk,
:short_description_en, :description_uk, :description_en, :_destroy],
project_documents_attributes: [:id, :project_id, :document_uk, :document_en,
:document_name_uk, :document_name_en, :_destroy])
end
end
form do |f|
form html: { multipart: true } do |f|
f.inputs do
f.input :photo, label: "Photo"
f.input :photo_preview, label: "Preview for main page"
f.input :photo_before, label: "Before photo"
f.input :photo_after, label: "After photo"
f.input :photo, label: "Photo",
hint: f.object.photo.present? ? image_tag(f.object.photo.url(:thumb_small)) : content_tag(:span, "no file yet")
f.input :photo_preview, label: "Preview for main page",
hint: f.object.photo_preview.present? ? image_tag(f.object.photo_preview.url(:thumb_small)) : content_tag(:span, "no file yet")
f.input :photo_before, label: "Before photo",
hint: f.object.photo_before.present? ? image_tag(f.object.photo_before.url(:thumb_small)) : content_tag(:span, "no file yet")
f.input :remove_photo_before, as: :boolean
f.input :photo_after, label: "After photo",
hint: f.object.photo_after.present? ? image_tag(f.object.photo_after.url(:thumb_small)) : content_tag(:span, "no file yet")
f.input :remove_photo_after, as: :boolean
f.input :types, label: "Type"
f.input :status, label: "Status"
f.input :individual_type_uk, label: "Individual type uk"
......@@ -58,7 +66,9 @@ ActiveAdmin.register Project do
f.input :required_amount, label: "Required amount"
f.input :related_links_uk, label: "Related links uk"
f.input :related_links_en, label: "Related links en"
f.input :footer_photo, label: "Footer photo"
f.input :footer_photo, label: "Footer photo",
hint: f.object.footer_photo.present? ? image_tag(f.object.footer_photo.url(:thumb_small)) : content_tag(:span, "no file yet")
f.input :remove_footer_photo, as: :boolean
f.has_many :project_galeries, heading: false, new_record: true do |project_galaries_form|
project_galaries_form.input :photo
project_galaries_form.input :name_uk
......@@ -95,8 +105,130 @@ ActiveAdmin.register Project do
project_documents_form.input :document_name_en
project_documents_form.input :_destroy, as: :boolean
end
f.has_many :project_videos, heading: false, new_record: true do |project_videos_form|
project_videos_form.input :short_description_uk
project_videos_form.input :short_description_en
project_videos_form.input :video_file
project_videos_form.input :video_link
project_videos_form.input :description_uk
project_videos_form.input :description_en
project_videos_form.input :_destroy, as: :boolean
end
end
f.actions
end
index title: "Projects" do
selectable_column
id_column
column "Photo" do |p|
if p.photo?
image_tag p.photo_url, height: '50'
end
end
column "Type" do |p|
p.types
end
column "Status" do |p|
p.status
end
column "Individual type" do |p|
p.individual_type_uk
end
column "Individual type en" do |p|
p.individual_type_en
end
column "Title" do |p|
p.title_uk
end
column "Title en" do |p|
p.title_en
end
column "Site" do |p|
p.site
end
column "Facebook link" do |p|
p.link_to_facebook
end
column "Required amount" do |p|
p.required_amount
end
column "Related links uk" do |p|
p.related_links_uk
end
column "Related links en" do |p|
p.related_links_en
end
column "Footer photo" do |p|
p.footer_photo
end
column "Created" do |p|
p.created_at
end
column "Updated" do |p|
p.updated_at
end
actions
end
show do
attributes_table do
row :id
row I18n.t "active_admin.attributes.project.photo" do |p|
p.photo? ? image_tag(p.photo_url(:thumb_small)) : image_tag("default_img.png")
end
row I18n.t "active_admin.attributes.project.photo_preview" do |p|
p.photo_preview? ? image_tag(p.photo_preview_url(:thumb_small)) : image_tag("default_img.png")
end
row I18n.t "active_admin.attributes.project.photo_before" do |p|
p.photo_before? ? image_tag(p.photo_before_url(:thumb_small)) : image_tag("default_img.png")
end
row I18n.t "active_admin.attributes.project.photo_after" do |p|
p.photo_after? ? image_tag(p.photo_after_url(:thumb_small)) : image_tag("default_img.png")
end
row I18n.t "active_admin.attributes.project.types" do |p|
t "#{p.types}"
end
row I18n.t "active_admin.attributes.project.status" do |p|
t "#{p.status}"
end
row I18n.t "active_admin.attributes.project.individual_type_uk" do |p|
p.individual_type_uk
end
row I18n.t "active_admin.attributes.project.individual_type_en" do |p|
p.individual_type_en
end
row I18n.t "active_admin.attributes.project.title_uk" do |p|
p.title_uk
end
row I18n.t "active_admin.attributes.project.title_en" do |p|
p.title_en
end
row I18n.t "active_admin.attributes.project.site" do |p|
p.site
end
row I18n.t "active_admin.attributes.project.link_to_facebook" do |p|
p.link_to_facebook
end
row I18n.t "active_admin.attributes.project.required_amount" do |p|
p.required_amount
end
row I18n.t "active_admin.attributes.project.related_links_uk" do |p|
p.related_links_uk
end
row I18n.t "active_admin.attributes.project.related_links_en" do |p|
p.related_links_en
end
row I18n.t "active_admin.attributes.project.footer_photo" do |p|
p.footer_photo? ? image_tag(p.footer_photo_url(:thumb_small)) : image_tag("default_img.png")
end
row I18n.t "active_admin.attributes.project.created_at" do |p|
p.created_at
end
row I18n.t "active_admin.attributes.project.updated_at" do |p|
p.updated_at
end
end
end
end
......@@ -13,13 +13,15 @@ class Project < ApplicationRecord
has_many :project_photos, inverse_of: :project, dependent: :destroy
has_many :project_links, inverse_of: :project, dependent: :destroy
has_many :project_documents, inverse_of: :project, dependent: :destroy
has_many :project_videos, inverse_of: :project, dependent: :destroy
accepts_nested_attributes_for :project_galeries, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :project_qoutes, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :project_photos, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :project_links, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :project_documents, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :project_videos, reject_if: :all_blank, allow_destroy: true
validates :types, :status, :title_uk, :short_description_uk,
validates :photo, :photo_preview, :types, :status, :title_uk, :short_description_uk,
:description_uk, :required_amount, presence: true
validates_length_of :individual_type_uk, :individual_type_en, :title_uk, :title_en,
:heading_uk, :heading_en, :site, :link_to_facebook, :related_links_uk,
......
class ProjectDocument < ApplicationRecord
mount_uploader :document_uk, AvatarUploader
mount_uploader :document_en, AvatarUploader
mount_uploader :document_uk, DocumentUploader
mount_uploader :document_en, DocumentUploader
belongs_to :project
end
class ProjectVideo < ApplicationRecord
mount_uploader :video_file, VideoUploader
belongs_to :project
end
......@@ -3,6 +3,10 @@ class AvatarUploader < CarrierWave::Uploader::Base
process :resize_to_fit => [1280, 1024]
version :thumb_small do
process resize_to_fill: [320,200]
end
storage :file
def extension_whitelist
......
class DocumentUploader < CarrierWave::Uploader::Base
storage :file
def extension_whitelist
%w(pdf doc)
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
class VideoUploader < CarrierWave::Uploader::Base
storage :file
def extension_whitelist
%w(mp4 wbmv flv avi)
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
......@@ -6,6 +6,16 @@ ActiveAdmin.setup do |config|
#
config.site_title = "Warm City"
config.namespace :admin do |admin|
admin.build_menu :utility_navigation do |menu|
menu.add :label => "Languages" do |lang|
lang.add :label => "English",:url => proc { url_for(:locale => 'en') }, id: 'i18n-en', :priority => 1
lang.add :label => "Ukrainian",:url => proc { url_for(:locale => 'uk') }, id: 'i18n-es', :priority => 2
end
admin.add_logout_button_to_menu menu
end
end
# config.authorization_adapter = ActiveAdmin::CanCanAdapter
# config.on_unauthorized_access = :access_denied
......
en:
active_admin:
project/types:
program: "Program"
project: "Project"
project/status:
in_progress: "In progress"
implemented: "Implemented"
models:
project:
one: "Project"
other: "Projects"
attributes:
project:
photo: "Photo"
photo_preview: "Preview for main page"
photo_before: "Photo for blinds (before)"
photo_after: "Photo for blinds (after)"
types: "Type"
status: "Status"
individual_type_uk: "Individual type"
individual_type_en: "Individual type (en)"
title_uk: "Title"
title_en: "Title(en)"
heading_uk: "Heading"
heading_en: "Heading (en)"
slug: "Slug"
short_description_uk: "Short description"
short_description_en0: "Short description (en)"
description_uk: "Description"
description_en: "Description (en)"
site: "Site"
link_to_facebook: "Link to Facebook"
required_amount: "Required amount"
related_links_uk: "Related links"
related_links_en: "Related links (en)"
footer_photo: "Footer photo"
created_at: "Created"
updated_at: "Updated"
uk:
program: "Програма"
time:
formats:
long: "%Y-%m-%d %H:%M:%S"
active_admin:
project:
one: "Проект"
other: "Проекти"
project/types:
program: "Програма"
project: "Проект"
project/status:
in_progress: "Триває"
implemented: "Реалізовано"
models:
attributes:
project:
photo: "Фото"
photo_preview: "Прев'ю для головної"
photo_before: "Фото для шторки (до)"
photo_after: "Фото для шторки (після)"
types: "Тип"
status: "Статус"
individual_type_uk: "Індивідуальний тип"
individual_type_en: "Індивідуальний тип (анг)"
title_uk: "Назва"
title_en: "Назва (анг)"
heading_uk: "Заголовок"
heading_en: "Заголовок (анг)"
slug: "Slug"
short_description_uk: "Короткий опис"
short_description_en0: "Короткий опис (анг)"
description_uk: "Опис"
description_en: "Опис (анг)"
site: "Сайт"
link_to_facebook: "Посилання Facebook"
required_amount: "Необхідна сума"
related_links_uk: "Корисні лінки"
related_links_en: "Корисні лінки (анг)"
footer_photo: "Фото для футера"
created_at: "Створено"
updated_at: "Оновлено"
class CreateProjectVideos < ActiveRecord::Migration[5.0]
def change
create_table :project_videos do |t|
t.string :title_uk
t.string :title_en
t.string :short_description_uk
t.string :short_description_en
t.string :video_file
t.string :video_link
t.string :description_uk
t.string :description_en
t.references :project
t.timestamps
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20190926130127) do
ActiveRecord::Schema.define(version: 20190927094153) do
create_table "active_admin_comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "namespace"
......@@ -82,6 +82,21 @@ ActiveRecord::Schema.define(version: 20190926130127) do
t.index ["project_id"], name: "index_project_qoutes_on_project_id", using: :btree
end
create_table "project_videos", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "title_uk"
t.string "title_en"
t.string "short_description_uk"
t.string "short_description_en"
t.string "video_file"
t.string "video_link"
t.string "description_uk"
t.string "description_en"
t.integer "project_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["project_id"], name: "index_project_videos_on_project_id", using: :btree
end
create_table "projects", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "photo"
t.string "photo_preview"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment