Newer
Older
# == Schema Information
#
# Table name: communication_blocks
#
# id :uuid not null, primary key
# about_type :string indexed => [about_id]
# data :jsonb
# position :integer default(0), not null
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid indexed => [about_type]
# university_id :uuid not null, indexed
#
# Indexes
#
# index_communication_blocks_on_university_id (university_id)
# index_communication_website_blocks_on_about (about_type,about_id)
#
# Foreign Keys
#
# fk_rails_18291ef65f (university_id => universities.id)
#
class Communication::Block < ApplicationRecord
has_many_attached :template_images
datatable: 54,
files: 55,
embed: 53,
call_to_action: 900,
organization_chart: 100,
partners: 200,
posts: 500,
pages: 600,
}
CATEGORIES = {
basic: [:chapter, :image, :video, :datatable],
storytelling: [:key_figures, :gallery, :call_to_action, :testimonials, :timeline],
references: [:pages, :posts, :organization_chart, :partners, :programs],
# When we set data from json, we pass it to the template.
# The json we save is first sanitized and prepared by the template.
# Template data is clean and sanitized, and initialized with json
end
def last_ordered_element
about.blocks.ordered.last
end
@template ||= template_class.new self, self.attributes['data']
def duplicate
block = self.dup
block.save
block
end
title.blank? ? "#{Communication::Block.model_name.human} #{position}"
protected
def check_accessibility
accessibility_merge template
end
def template_class
"Communication::Block::Template::#{template_kind.classify}".constantize
end
# FIXME @sebou
# Could not find or build blob: expected attachable, got #<ActiveStorage::Blob id: "f4c78657-5062-416b-806f-0b80fb66f9cd", key: "gri33wtop0igur8w3a646llel3sd", filename: "logo.svg", content_type: "image/svg+xml", metadata: {"identified"=>true, "width"=>709, "height"=>137, "analyzed"=>true}, service_name: "scaleway", byte_size: 4137, checksum: "aZqqTYabP5+72ZeddcZ/2Q==", created_at: "2022-05-05 12:17:33.941505000 +0200", university_id: "ebf2d273-ffc9-4d9f-a4ee-a2146913d617">