Skip to content
Snippets Groups Projects
Commit 64b020fc authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

set up action text

parent 1dc175f1
No related branches found
No related tags found
No related merge requests found
(function() {
addEventListener("trix-attachment-add", function(event) {
var file = event.attachment.file;
if (file) {
var upload = new window.ActiveStorage.DirectUpload(file,'/rails/active_storage/direct_uploads', window);
upload.create((error, attributes) => {
if (error) {
return false;
} else {
return event.attachment.setAttributes({
url: `/rails/active_storage/blobs/${attributes.signed_id}/${attributes.filename}`,
href: `/rails/active_storage/blobs/${attributes.signed_id}/${attributes.filename}`,
});
}
});
}
})
})();
......@@ -17,6 +17,9 @@
h3
font-size: 1.15rem
.attachment
text-align: initial
.attachment-gallery
> action-text-attachment,
> .attachment
......
# frozen_string_literal: true
# Creates a new blob on the server side in anticipation of a direct-to-service upload from the client side.
# When the client-side upload is completed, the signed_blob_id can be submitted as part of the form to reference
# the blob that was created up front.
class ActiveStorage::DirectUploadsController < ActiveStorage::BaseController
include ApplicationController::WithUniversity
def create
blob = ActiveStorage::Blob.create_before_direct_upload!(**blob_args)
blob.update_column(:university_id, current_university.id)
render json: direct_upload_json(blob)
end
private
def blob_args
params.require(:blob).permit(:filename, :byte_size, :checksum, :content_type, metadata: {}).to_h.symbolize_keys
end
def direct_upload_json(blob)
blob.as_json(root: false, methods: :signed_id).merge(direct_upload: {
url: blob.service_url_for_direct_upload,
headers: blob.service_headers_for_direct_upload
})
end
end
......@@ -10,7 +10,7 @@
# text :text
# title :string
# created_at :datetime not null
# updated_at :date not null
# updated_at :datetime not null
# research_journal_id :uuid not null
# research_journal_volume_id :uuid
# university_id :uuid not null
......
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
<% if blob.representable? %>
<%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
<% end %>
<figcaption class="attachment__caption">
<% if caption = blob.try(:caption) %>
<%= caption %>
<% else %>
<span class="attachment__name"><%= blob.filename %></span>
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
<% end %>
</figcaption>
</figure>
Rails.configuration.to_prepare do
ActionText::RichText.class_eval do
delegate :university, :university_id, to: :record
end
ActionText::ContentHelper.allowed_tags += Rails.application.config.action_view.sanitized_allowed_tags
ActionText::ContentHelper.allowed_attributes += Rails.application.config.action_view.sanitized_allowed_attributes
end
# This migration comes from action_text (originally 20180528164100)
class CreateActionTextTables < ActiveRecord::Migration[6.0]
def change
create_table :action_text_rich_texts, id: :uuid do |t|
t.string :name, null: false
t.text :body, size: :long
t.references :record, null: false, polymorphic: true, index: false, type: :uuid
t.timestamps
t.index [ :record_type, :record_id, :name ], name: "index_action_text_rich_texts_uniqueness", unique: true
end
end
end
......@@ -10,13 +10,23 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_10_20_090658) do
ActiveRecord::Schema.define(version: 2021_10_21_093238) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
create_table "active_storage_attachments", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "action_text_rich_texts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name", null: false
t.text "body"
t.string "record_type", null: false
t.uuid "record_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
end
create_table "active_storage_attachments", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.uuid "record_id", null: false
......@@ -26,7 +36,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end
create_table "active_storage_blobs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "active_storage_blobs", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
......@@ -40,13 +50,13 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["university_id"], name: "index_active_storage_blobs_on_university_id"
end
create_table "active_storage_variant_records", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "active_storage_variant_records", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end
create_table "administration_qualiopi_criterions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "administration_qualiopi_criterions", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.integer "number"
t.text "name"
t.text "description"
......@@ -54,7 +64,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.datetime "updated_at", precision: 6, null: false
end
create_table "administration_qualiopi_indicators", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "administration_qualiopi_indicators", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "criterion_id", null: false
t.integer "number"
t.text "name"
......@@ -68,7 +78,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id"
end
create_table "communication_website_imported_media", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "communication_website_imported_media", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.string "identifier"
t.jsonb "data"
t.text "file_url"
......@@ -83,7 +93,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["website_id"], name: "index_communication_website_imported_media_on_website_id"
end
create_table "communication_website_imported_pages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "communication_website_imported_pages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.uuid "website_id", null: false
t.uuid "page_id", null: false
......@@ -106,7 +116,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["website_id"], name: "index_communication_website_imported_pages_on_website_id"
end
create_table "communication_website_imported_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "communication_website_imported_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.uuid "website_id", null: false
t.uuid "post_id", null: false
......@@ -129,7 +139,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["website_id"], name: "index_communication_website_imported_posts_on_website_id"
end
create_table "communication_website_imported_websites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "communication_website_imported_websites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.uuid "website_id", null: false
t.integer "status", default: 0
......@@ -139,7 +149,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["website_id"], name: "index_communication_website_imported_websites_on_website_id"
end
create_table "communication_website_pages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "communication_website_pages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.uuid "communication_website_id", null: false
t.string "title"
......@@ -160,7 +170,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["university_id"], name: "index_communication_website_pages_on_university_id"
end
create_table "communication_website_posts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "communication_website_posts", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.uuid "communication_website_id", null: false
t.string "title"
......@@ -175,7 +185,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["university_id"], name: "index_communication_website_posts_on_university_id"
end
create_table "communication_websites", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "communication_websites", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.string "name"
t.string "domain"
......@@ -204,7 +214,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["priority", "run_at"], name: "delayed_jobs_priority"
end
create_table "education_programs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "education_programs", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.string "name"
t.integer "level"
......@@ -225,14 +235,14 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["university_id"], name: "index_education_programs_on_university_id"
end
create_table "languages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "languages", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.string "name"
t.string "iso_code"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "research_journal_articles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "research_journal_articles", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.string "title"
t.text "text"
t.date "published_at"
......@@ -240,7 +250,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.uuid "research_journal_id", null: false
t.uuid "research_journal_volume_id"
t.datetime "created_at", precision: 6, null: false
t.date "updated_at", null: false
t.datetime "updated_at", precision: 6, null: false
t.uuid "updated_by_id"
t.text "abstract"
t.text "references"
......@@ -258,7 +268,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["researcher_id"], name: "index_research_journal_articles_researchers_on_researcher_id"
end
create_table "research_journal_volumes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "research_journal_volumes", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.uuid "research_journal_id", null: false
t.string "title"
......@@ -272,7 +282,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["university_id"], name: "index_research_journal_volumes_on_university_id"
end
create_table "research_journals", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "research_journals", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.string "title"
t.text "description"
......@@ -284,7 +294,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["university_id"], name: "index_research_journals_on_university_id"
end
create_table "research_researchers", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "research_researchers", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.text "biography"
......@@ -294,7 +304,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.index ["user_id"], name: "index_research_researchers_on_user_id"
end
create_table "universities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "universities", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.string "name"
t.string "identifier"
t.string "address"
......@@ -309,7 +319,7 @@ ActiveRecord::Schema.define(version: 2021_10_20_090658) do
t.string "sms_sender_name"
end
create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
create_table "users", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.string "first_name"
t.string "last_name"
......
# one:
# record: name_of_fixture (ClassOfFixture)
# name: content
# body: <p>In a <i>million</i> stars!</p>
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment