diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index 89abd5760d54801511f0052c5bb84110f90cd0b9..a08b351fed9a55337efc660582fd0b61e213b3d6 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -77,6 +77,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web params.require(:communication_website_page) .permit(:university_id, :communication_website_id, :title, :description, :text, :about_type, :about_id, :slug, :published, + :featured_image, :featured_image_delete, :featured_image_infos, :parent_id) end end diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb index 72126a1cf3e067e0d950a1deea0ced0a8948a183..14abbb9696e8ea2d92e8ecf91a8052e3b9bfed28 100644 --- a/app/controllers/admin/communication/website/posts_controller.rb +++ b/app/controllers/admin/communication/website/posts_controller.rb @@ -57,6 +57,6 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web def post_params params.require(:communication_website_post) - .permit(:university_id, :website_id, :title, :description, :text, :published, :published_at, :featured_image, :featured_image_delete, :slug) + .permit(:university_id, :website_id, :title, :description, :text, :published, :published_at, :featured_image, :featured_image_delete, :featured_image_infos, :slug) end end diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index b8b94fb271e0043684cedbab620d2e0b3db81059..a438514beab1a2f59cf36b620ff82f4d71f0aea5 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -6,11 +6,11 @@ # about_type :string # description :text # github_path :text +# old_text :text # path :text # position :integer default(0), not null # published :boolean default(FALSE) # slug :string -# text :text # title :string # created_at :datetime not null # updated_at :datetime not null @@ -37,6 +37,9 @@ class Communication::Website::Page < ApplicationRecord include WithSlug include WithGithub + has_rich_text :text + has_one_attached_deletable :featured_image + belongs_to :university belongs_to :website, foreign_key: :communication_website_id diff --git a/app/views/admin/communication/website/pages/_form.html.erb b/app/views/admin/communication/website/pages/_form.html.erb index 1e658226c49b66da37c2d2f21b047b26fbc0325f..d2c2ca65f4d3f0a37201d99dc0508fd796bc92f4 100644 --- a/app/views/admin/communication/website/pages/_form.html.erb +++ b/app/views/admin/communication/website/pages/_form.html.erb @@ -3,26 +3,40 @@ <div class="col-md-8"> <div class="card flex-fill w-100"> <div class="card-header"> - <h5 class="card-title">Content</h5> + <h5 class="card-title mb-0"><%= t('communication.website.content') %></h5> </div> <div class="card-body"> <%= f.input :title %> <%= f.input :description %> - <%= f.input :text, input_html: { rows: 20 } %> + <%= f.input :text, as: :rich_text_area %> </div> </div> </div> <div class="col-md-4"> <div class="card flex-fill w-100"> <div class="card-header"> - <h5 class="card-title">Metadata</h5> + <h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5> </div> <div class="card-body"> - <%= f.input :slug %> + <%= f.input :slug, as: :string %> <%= f.input :published %> <%= f.association :parent, collection: page.website.pages.where.not(id: page) %> </div> </div> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/page.featured_image') %></h5> + </div> + <div class="card-body"> + <%= f.input :featured_image, + as: :single_deletable_file, + direct_upload: true, + label: false, + input_html: { accept: '.jpg,.jpeg,.png' }, + preview: true + %> + </div> + </div> </div> </div> <% content_for :action_bar_right do %> diff --git a/app/views/admin/communication/website/pages/show.html.erb b/app/views/admin/communication/website/pages/show.html.erb index a989bb177b51b90bd5fcdcda932d9897450d595b..78f3592f29c90310b9707c140bce7ded325a290f 100644 --- a/app/views/admin/communication/website/pages/show.html.erb +++ b/app/views/admin/communication/website/pages/show.html.erb @@ -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> + <strong><%= Communication::Website::Page.human_attribute_name('description') %></strong> </p> <%= sanitize @page.description %> <p> - <strong>Text</strong> + <strong><%= Communication::Website::Page.human_attribute_name('text') %></strong> </p> - <%= sanitize @page.text %> + <%= @page.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> @@ -34,16 +34,23 @@ <td><%= Communication::Website::Page.human_attribute_name('path') %></td> <td><%= @page.path %></td> </tr> + <tr> + <td><%= Communication::Website::Page.human_attribute_name('published') %></td> + <td> + <%= t @page.published %> + </td> + </tr> <% if @page.imported_page %> <tr> - <td>Imported from</td> - <td><a href="<%= @page.imported_page.url %>" target="_blank">Original URL</a></td> + <td><%= t('communication.website.imported.from') %></td> + <td><a href="<%= @page.imported_page.url %>" target="_blank"><%= t('communication.website.imported.original_url') %></a></td> </tr> <% end %> <% if @page.parent %> <tr> <td><%= Communication::Website::Page.human_attribute_name('parent') %></td> - <td><%= link_to @page.parent, + <td><%= link_to_if can?(:read, @page.parent), + @page.parent, admin_communication_website_page_path( website_id: @website.id, id: @page.parent.id @@ -56,7 +63,8 @@ <td> <ul class="list-unstyled mb-0"> <% @page.children.each do |child| %> - <li><%= link_to child, + <li><%= link_to_if can?(:read, child), + child, admin_communication_website_page_path( website_id: @website.id, id: child.id @@ -69,6 +77,16 @@ </tbody> </table> </div> + <% if @page.featured_image.attached? %> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/page.featured_image') %></h5> + </div> + <div class="card-body"> + <%= image_tag @page.featured_image.variant(resize: '600'), class: 'img-fluid mb-3' %><br> + </div> + </div> + <% end %> </div> </div> diff --git a/app/views/admin/communication/website/posts/show.html.erb b/app/views/admin/communication/website/posts/show.html.erb index 4623d0abc2f0e7908c6af246f341816ca0d6df53..95856f9e1a0dd2e27faeb37ea15bad8df2bb5358 100644 --- a/app/views/admin/communication/website/posts/show.html.erb +++ b/app/views/admin/communication/website/posts/show.html.erb @@ -41,7 +41,7 @@ <% if @post.imported_post %> <tr> <td><%= t('communication.website.imported.from') %></td> - <td><a href="<%= @post.imported_post.url %>" target="_blank">Original URL</a></td> + <td><a href="<%= @post.imported_post.url %>" target="_blank"><%= t('communication.website.imported.original_url') %></a></td> </tr> <% end %> </tbody> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index e9d5e749ce9789e0c4e605a6a7ad4e72a420478b..1484428fb5382715dc9073b078be803d202e159f 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -6,6 +6,7 @@ en: from: Imported from launch: Launch import launched: Import in progress + original_url: Original URL media: file_size: File size not_imported_yet: Not imported yet @@ -45,6 +46,7 @@ en: communication/website/page: title: Title description: Description (SEO) + featured_image: Featured image text: Text published: Published ? parent: Parent page diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 6b73c1ed7dee99d47db7c36cf46a2582b527ae9f..8bc2e040fb782c6485defc8277b14bb0138a5d9f 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -6,6 +6,7 @@ fr: from: Importé depuis launch: Importer le site launched: Importation en cours + original_url: URL originale media: file_size: Taille du fichier not_imported_yet: Non importé pour le moment @@ -44,6 +45,7 @@ fr: filename: Nom du fichier communication/website/page: description: Description (SEO) + featured_image: Image à la une parent: Page parente published: Publié ? text: Texte diff --git a/db/migrate/20211025102046_rename_text_for_website_pages.rb b/db/migrate/20211025102046_rename_text_for_website_pages.rb new file mode 100644 index 0000000000000000000000000000000000000000..0a6ad3ff6a05b263d575ec77cbcea2bc158e1071 --- /dev/null +++ b/db/migrate/20211025102046_rename_text_for_website_pages.rb @@ -0,0 +1,6 @@ +class RenameTextForWebsitePages < ActiveRecord::Migration[6.1] + def change + rename_column :communication_website_pages, :text, :old_text + + end +end diff --git a/db/schema.rb b/db/schema.rb index 3ac5ad0ad2ef8773307a6115336a156c4e314603..963a4246c73a26a8ae5452fd6240155553e9462e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_10_25_062028) do +ActiveRecord::Schema.define(version: 2021_10_25_102046) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -177,7 +177,7 @@ ActiveRecord::Schema.define(version: 2021_10_25_062028) do t.uuid "about_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false - t.text "text" + t.text "old_text" t.boolean "published", default: false t.text "github_path" t.index ["about_type", "about_id"], name: "index_communication_website_pages_on_about" diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index 4ec8f8748672906191b67a6f99e0ce9dd31f6287..1da5718b4a666a4aa5f8e4ec5ae30107496d8116 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -21,6 +21,9 @@ namespace :app do } Communication::Website::Post.find_each { |post| post.update(text: post.old_text) + } + Communication::Website::Page.find_each { |page| + page.update(text: page.old_text) } Communication::Website::Medium.find_each { |medium| medium.send(:set_featured_images)