Skip to content
Snippets Groups Projects
Unverified Commit 6477cc9b authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

Merge branch 'master' of github.com:noesya/osuny

parents 45da1377 0c137567
No related branches found
No related tags found
No related merge requests found
Showing
with 147 additions and 36 deletions
(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}`,
});
}
});
}
})
})();
# 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
......@@ -27,10 +27,16 @@ class TrixEditorInput < SimpleForm::Inputs::Base
end
def id
"#{@builder.object.class.to_s.downcase}_#{attribute_name}"
"#{object_name}_#{attribute_name}"
end
def name
"#{@builder.object.class.to_s.downcase}[#{attribute_name}]"
"#{object_name}[#{attribute_name}]"
end
private
def object_name
@builder.object.class.to_s.downcase.gsub('::', '_')
end
end
......@@ -33,6 +33,8 @@
#
class Communication::Website::Page < ApplicationRecord
include WithSlug
belongs_to :university
belongs_to :website,
foreign_key: :communication_website_id
......@@ -45,7 +47,7 @@ class Communication::Website::Page < ApplicationRecord
has_one :imported_page,
class_name: 'Communication::Website::Imported::Page',
foreign_key: :page_id,
dependent: :nullify
dependent: :destroy
validates :title, presence: true
......
......@@ -25,13 +25,15 @@
# fk_rails_... (university_id => universities.id)
#
class Communication::Website::Post < ApplicationRecord
include WithSlug
belongs_to :university
belongs_to :website,
foreign_key: :communication_website_id
has_one :imported_post,
class_name: 'Communication::Website::Imported::Post',
foreign_key: :post_id,
dependent: :nullify
dependent: :destroy
scope :ordered, -> { order(published_at: :desc, created_at: :desc) }
scope :recent, -> { order(published_at: :desc).limit(5) }
......
module WithSlug
extend ActiveSupport::Concern
included do
before_validation :generate_slug, if: Proc.new { |o| o.slug.blank? }
end
protected
def generate_slug
n = nil
loop do
self.slug = [to_s.parameterize, n].compact.join('-')
break if slug_available?
n = n.to_i + 1
end
end
def slug_available?
self.class.unscoped.where.not(id: self.id).where(university_id: self.university_id, slug: self.slug).none?
end
end
......@@ -14,14 +14,16 @@
<td><%= page.path %></td>
<td><%= link_to page.parent, admin_communication_website_page_path(website_id: page.website.id, id: page.parent.id) if page.parent %></td>
<td class="text-end">
<%= link_to t('edit'),
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_admin_communication_website_page_path(website_id: page.website.id, id: page.id),
class: button_classes %>
<%= link_to t('delete'),
<%= link_to t('delete'),
admin_communication_website_page_path(website_id: page.website.id, id: page.id),
method: :delete,
data: { confirm: t('please-confirm') },
class: button_classes_danger %>
</div>
</td>
</tr>
<% end %>
......
......@@ -3,7 +3,7 @@
<div class="col-md-8">
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0">Content</h5>
<h5 class="card-title mb-0"><%= t('communication.website.content') %></h5>
</div>
<div class="card-body">
<%= f.input :title %>
......@@ -15,7 +15,7 @@
<div class="col-md-4">
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0">Metadata</h5>
<h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5>
</div>
<div class="card-body">
<%= f.input :published %>
......
......@@ -3,7 +3,7 @@
<tr>
<th><%= Communication::Website::Post.human_attribute_name('title') %></th>
<th><%= Communication::Website::Post.human_attribute_name('published_at') %></th>
<th width="150"></th>
<th></th>
</tr>
</thead>
<tbody>
......@@ -12,14 +12,16 @@
<td><%= link_to post, admin_communication_website_post_path(website_id: post.website.id, id: post.id) %></td>
<td><%= l post.published_at, format: :long if post.published_at %></td>
<td class="text-end">
<%= link_to t('edit'),
edit_admin_communication_website_post_path(website_id: post.website.id, id: post.id),
class: button_classes %>
<%= link_to t('delete'),
admin_communication_website_post_path(website_id: post.website.id, id: post.id),
method: :delete,
data: { confirm: t('please-confirm') },
class: button_classes_danger %>
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_admin_communication_website_post_path(website_id: post.website.id, id: post.id),
class: button_classes %>
<%= link_to t('delete'),
admin_communication_website_post_path(website_id: post.website.id, id: post.id),
method: :delete,
data: { confirm: t('please-confirm') },
class: button_classes_danger %>
</div>
</td>
</tr>
<% end %>
......
......@@ -4,25 +4,25 @@
<div class="col-md-8">
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0">Content</h5>
<h5 class="card-title mb-0"><%= t('communication.website.content') %></h5>
</div>
<div class="card-body">
<p>
<strong>Description</strong>
<%= @post.description %>
<strong><%= Communication::Website::Post.human_attribute_name('description') %></strong>
<%= sanitize @post.description %>
</p>
<p>
<strong>Text</strong>
<strong><%= Communication::Website::Post.human_attribute_name('text') %></strong>
</p>
<%= raw @post.text %>
<%= sanitize @post.text %>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0">Metadata</h5>
<h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5>
</div>
<table class="<%= table_classes %>">
<tbody>
......@@ -32,12 +32,12 @@
</tr>
<tr>
<td><%= Communication::Website::Page.human_attribute_name('published') %></td>
<td><%= @post.published %></td>
<td><%= t @post.published %></td>
</tr>
<% if @post.imported_post %>
<tr>
<td>Imported from</td>
<td><a href="<%= @post.imported_post.url %>" target="_blank">Original URL</a></td>
<td><%= t('communication.website.imported.from') %></td>
<td><a href="<%= @post.imported_post.url %>" target="_blank"><%= @post.imported_post.url %></a></td>
</tr>
<% end %>
</tbody>
......
......@@ -18,8 +18,10 @@
<td><%= I18n.t("activerecord.attributes.communication/website.about_#{website.about_type}") %></td>
<td><%= website.about %></td>
<td class="text-end">
<%= edit_link website %>
<%= destroy_link website %>
<div class="btn-group" role="group">
<%= edit_link website %>
<%= destroy_link website %>
</div>
</td>
</tr>
<% end %>
......
......@@ -20,8 +20,10 @@
<td><%= user.role.humanize %></td>
<td><%= user.language %></td>
<td class="text-end">
<%= edit_link user %>
<%= destroy_link user %>
<div class="btn-group" role="group">
<%= edit_link user %>
<%= destroy_link user %>
</div>
</td>
</tr>
<% end %>
......
......@@ -15,14 +15,16 @@
<td><%= link_to language, [:server, language] %></td>
<td><%= language.iso_code %></td>
<td class="text-end">
<%= link_to t('edit'),
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_server_language_path(language),
class: button_classes %>
<%= link_to t('delete'),
<%= link_to t('delete'),
server_language_path(language),
method: :delete,
data: { confirm: t('please-confirm') },
class: button_classes_danger %>
</div>
</td>
</tr>
<% end %>
......
......@@ -16,14 +16,16 @@
<td><%= link_to university.url, university.url, target: :_blank %></td>
<td><%= university.private ? University.human_attribute_name('private') : University.human_attribute_name('public') %></td>
<td class="text-end">
<%= link_to t('edit'),
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_server_university_path(university),
class: button_classes %>
<%= link_to t('delete'),
<%= link_to t('delete'),
server_university_path(university),
method: :delete,
data: { confirm: t('please-confirm') },
class: button_classes_danger %>
</div>
</td>
</tr>
<% end %>
......
en:
communication:
website:
content: Content
imported:
from: Imported from
launch: Launch import
media:
file_size: File size
......@@ -9,6 +11,7 @@ en:
refresh: Refresh import
show: Show import
pending: Import in progress
metadata: Metadata
activemodel:
models:
communication: Communication
......@@ -45,6 +48,13 @@ en:
published: Published ?
parent: Parent page
website: Website
communication/website/post:
title: Title
description: Description (SEO)
text: Text
published: Published ?
published_at: Publication date
website: Website
simple_form:
hints:
communication_website_page:
......
fr:
communication:
website:
content: Contenu
imported:
from: Importé depuis
launch: Importer le site
media:
file_size: Taille du fichier
......@@ -9,6 +11,7 @@ fr:
refresh: Relancer l'import
show: Voir l'import
pending: Import en cours
metadata: Informations
activemodel:
models:
communication: Communication
......@@ -39,11 +42,18 @@ fr:
communication/website/imported/medium:
filename: Nom du fichier
communication/website/page:
description: Description (SEO)
parent: Page parente
published: Publié ?
text: Texte
title: Titre
website: Site Web
communication/website/post:
description: Description (SEO)
text: Text
published: Publié ?
parent: Page parente
published_at: Date de publication
text: Texte
title: Titre
website: Site Web
simple_form:
hints:
......
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