diff --git a/app/controllers/admin/research/journals/volumes_controller.rb b/app/controllers/admin/research/journals/volumes_controller.rb index 5d693ca975adc44de6a0424e4f8ac50cd4c48aa4..f8395fa9e4b26030e03aada3affe0c50cb8f0b69 100644 --- a/app/controllers/admin/research/journals/volumes_controller.rb +++ b/app/controllers/admin/research/journals/volumes_controller.rb @@ -58,7 +58,7 @@ class Admin::Research::Journals::VolumesController < Admin::Research::Journals:: def volume_params params.require(:research_journal_volume) .permit( - :title, :slug, :number, :keywords, :published, :published_at, :meta_description, :text, + :title, :slug, :number, :keywords, :published, :published_at, :meta_description, :summary, :text, :featured_image, :featured_image_infos, :featured_image_delete, :featured_image_alt, :featured_image_credit ) .merge(university_id: current_university.id) diff --git a/app/controllers/admin/research/journals_controller.rb b/app/controllers/admin/research/journals_controller.rb index b05662b967515c579312fd9cc08e11d8c7d9d98f..6ccc4ead71e421ea263a734aa51386caeadff3fd 100644 --- a/app/controllers/admin/research/journals_controller.rb +++ b/app/controllers/admin/research/journals_controller.rb @@ -53,7 +53,7 @@ class Admin::Research::JournalsController < Admin::Research::ApplicationControll def journal_params params.require(:research_journal) - .permit(:title, :meta_description, :issn, :access_token, :repository) + .permit(:title, :meta_description, :summary, :issn) .merge(university_id: current_university.id) end end diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index a22fb6efc8c72290b35d095a6b430e1d67659e21..ba31fe5647d9d23b7538539e105754248c51f586 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -111,6 +111,13 @@ class Communication::Website::Category < ApplicationRecord (ancestors.map(&:slug) << slug).join('-') end + def best_featured_image_source(fallback: true) + return self if featured_image.attached? + best_source = parent&.best_featured_image_source(fallback: false) + best_source ||= self if fallback + best_source + end + protected def last_ordered_element diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index d16d0e281d30a9e811a9909aef06c389bdabc82f..01499c8da5d93e38fb7fd87600ed886ba953d0e4 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -116,10 +116,10 @@ class Communication::Website::Page < ApplicationRecord "#{title}" end - def best_featured_image + def best_featured_image_source(fallback: true) # we don't want to fallback on homepage featured_image - return featured_image if featured_image.attached? || is_home? || parent&.is_home? - parent&.best_featured_image + return self if featured_image.attached? || is_home? || parent&.is_home? + parent&.best_featured_image_source end def best_bodyclass diff --git a/app/models/concerns/with_featured_image.rb b/app/models/concerns/with_featured_image.rb index 5def3f002ddd93a2f638bb0ea74aa7c79e16cbf6..4543ce6fc1c2b948ba663ed3168e9a9551508f9b 100644 --- a/app/models/concerns/with_featured_image.rb +++ b/app/models/concerns/with_featured_image.rb @@ -8,8 +8,20 @@ module WithFeaturedImage end # Can be overwrite to get featured_image from associated objects (ex: parents) - def best_featured_image(fallback: true) - featured_image + def best_featured_image_source(fallback: true) + self + end + + def best_featured_image + best_featured_image_source.featured_image + end + + def best_featured_image_alt + best_featured_image_source.featured_image_alt + end + + def best_featured_image_credit + best_featured_image_source.featured_image_credit end def add_unsplash_image(id) diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 99dcc822cce1aaf6d2638917dfb1057ae3b3b4fa..9eec8676b0ec5d81319b22b27f3d8ec226a917fa 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -126,11 +126,11 @@ class Education::Program < ApplicationRecord "#{name}" end - def best_featured_image(fallback: true) - return featured_image if featured_image.attached? - best_image = parent&.best_featured_image(fallback: false) - best_image ||= featured_image if fallback - best_image + def best_featured_image_source(fallback: true) + return self if featured_image.attached? + best_source = parent&.best_featured_image_source(fallback: false) + best_source ||= self if fallback + best_source end def git_path(website) diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb index f88661be1c7b3d92ea9d218d5c0bb19fb5522ec0..2cf68b7922040236d1c417deb01a3ed36976d67d 100644 --- a/app/models/research/journal.rb +++ b/app/models/research/journal.rb @@ -3,10 +3,9 @@ # Table name: research_journals # # id :uuid not null, primary key -# access_token :string # issn :string # meta_description :text -# repository :string +# summary :text # title :string # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 858aad6addbdfb9439075d0f8cb7ebbb66302006..7954879f64c50607d1a5c0b6ccf18ae3eb2599e0 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -11,6 +11,7 @@ # published :boolean default(FALSE) # published_at :datetime # slug :string +# summary :text # text :text # title :string # created_at :datetime not null diff --git a/app/views/admin/application/featured_image/_show.html.erb b/app/views/admin/application/featured_image/_show.html.erb index 31ded1fa4c23cf7b987ce7b664d5f702e0b7f656..6e3c9ee6b76ad475e4090a4a14a7ac172f65e88b 100644 --- a/app/views/admin/application/featured_image/_show.html.erb +++ b/app/views/admin/application/featured_image/_show.html.erb @@ -1,23 +1,26 @@ -<% if about.featured_image.attached? %> +<% if about.best_featured_image.attached? %> <div class="card flex-fill w-100"> <div class="card-header"> <h2 class="card-title mb-0 h5"> <%= about.class.human_attribute_name :featured_image %> + <% unless about.featured_image.attached? %> + (<%= t('admin.inheritance.sentence_without_link').downcase %>) + <% end %> </h2> </div> <div class="card-body"> - <% image = about.featured_image.variable? ? about.featured_image.variant(resize: '600') - : about.featured_image %> + <% image = about.best_featured_image.variable? ? about.best_featured_image.variant(resize: '600') + : about.best_featured_image %> <%= image_tag image, class: 'img-fluid mb-2' %> - <% if about.featured_image_credit %> + <% if about.best_featured_image_alt %> <p class="mb-0"> - <%= about.featured_image_alt %> + <%= about.best_featured_image_alt %> </p> <% end %> - <% if about.featured_image_credit %> - <p class="small mb-0"> - <%= about.featured_image_credit.html_safe %> - </p> + <% if about.best_featured_image_credit %> + <div class="small mb-0"> + <%= sanitize about.best_featured_image_credit %> + </div> <% end %> </div> </div> diff --git a/app/views/admin/application/featured_image/_static.html.erb b/app/views/admin/application/featured_image/_static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..12e6953f1f610be00416291540fadb544e4c6872 --- /dev/null +++ b/app/views/admin/application/featured_image/_static.html.erb @@ -0,0 +1,10 @@ +<% +best_featured_image = @about.best_featured_image +if best_featured_image&.attached? +%> +image: + id: "<%= best_featured_image.blob.id %>" + alt: "<%= @about.best_featured_image_alt %>" + credit: > + <%= prepare_html_for_static @about.best_featured_image_credit, @about.university %> +<% end %> diff --git a/app/views/admin/communication/unsplash/_static.html.erb b/app/views/admin/communication/unsplash/_static.html.erb deleted file mode 100644 index 2264bbf50564bb181d33d5edd4bfc9244073e96c..0000000000000000000000000000000000000000 --- a/app/views/admin/communication/unsplash/_static.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<% -featured_image = @about&.best_featured_image || @about.featured_image -if featured_image.attached? -%> -image: - id: "<%= featured_image.blob.id %>" - alt: "<%= @about.featured_image_alt %>" - credit: > - <%= prepare_html_for_static @about.featured_image_credit, @about.university %> -<% end %> diff --git a/app/views/admin/communication/websites/categories/static.html.erb b/app/views/admin/communication/websites/categories/static.html.erb index 015ae14d9c4ec618638cbc5d99dd237a9c6fd2c6..01c2e54a0f63171fba4f35c1020590bbcd2fb866 100644 --- a/app/views/admin/communication/websites/categories/static.html.erb +++ b/app/views/admin/communication/websites/categories/static.html.erb @@ -12,7 +12,7 @@ children: <% end %> <% end %> position: <%= @about.position %> -<%= render 'admin/communication/unsplash/static' %> +<%= render 'admin/application/featured_image/static' %> <%= render 'admin/application/meta_description/static' %> <%= render 'admin/application/summary/static' %> <%= render 'admin/communication/blocks/static', about: @about %> diff --git a/app/views/admin/communication/websites/pages/static.html.erb b/app/views/admin/communication/websites/pages/static.html.erb index 1c31214a481bb0fee8f49068cf1cb8ce3776591e..211f38113bb59e5e27121d35142f36e45a727893 100644 --- a/app/views/admin/communication/websites/pages/static.html.erb +++ b/app/views/admin/communication/websites/pages/static.html.erb @@ -13,7 +13,7 @@ has: <% end %> position: <%= @about.position %> bodyclass: <%= @about.best_bodyclass %> -<%= render 'admin/communication/unsplash/static' %> +<%= render 'admin/application/featured_image/static' %> <% if @about.children.published.any? %> children: <% @about.children.published.ordered.each do |child| %> diff --git a/app/views/admin/communication/websites/posts/static.html.erb b/app/views/admin/communication/websites/posts/static.html.erb index 3da24344ae40e7bf3c3b0ef8a75b7bd0508e1f93..e89b9fd4cac31e15f5478a9a45f9680a84c91c29 100644 --- a/app/views/admin/communication/websites/posts/static.html.erb +++ b/app/views/admin/communication/websites/posts/static.html.erb @@ -16,7 +16,7 @@ categories: - "<%= category.slug_with_ancestors_slugs %>" <% end %> <% end %> -<%= render 'admin/communication/unsplash/static' %> +<%= render 'admin/application/featured_image/static' %> <%= render 'admin/application/meta_description/static' %> <%= render 'admin/application/summary/static' %> <%= render 'admin/communication/blocks/static', about: @about %> diff --git a/app/views/admin/education/programs/static.html.erb b/app/views/admin/education/programs/static.html.erb index 85007b6ca513c033c55998fd372813d2501f3e62..fc78a8f231898e3c70e1cd104a8a5d0a8b877882 100644 --- a/app/views/admin/education/programs/static.html.erb +++ b/app/views/admin/education/programs/static.html.erb @@ -27,7 +27,7 @@ parent: <%= @about.parent.name %> url: <%= @about.parent.current_permalink_in_website(@website)&.path %> <% end %> -<%= render 'admin/communication/unsplash/static' %> +<%= render 'admin/application/featured_image/static' %> related_category: "<%= @website.categories.find_by(program_id: @about.id)&.slug_with_ancestors_slugs %>" diplomas: "<%= @about.diploma&.slug %>" teachers: diff --git a/app/views/admin/research/journals/_form.html.erb b/app/views/admin/research/journals/_form.html.erb index 3573f57b2c8a2b305f81d3eded484ac0e16f8508..1d9fbaa4ad4500cc869a78755a9fc6cc350d7b1d 100644 --- a/app/views/admin/research/journals/_form.html.erb +++ b/app/views/admin/research/journals/_form.html.erb @@ -7,6 +7,7 @@ <div class="card flex-fill w-100"> <div class="card-body"> <%= f.input :title %> + <%= render 'admin/application/summary/form', f: f, about: journal %> <%= f.input :issn %> </div> </div> diff --git a/app/views/admin/research/journals/show.html.erb b/app/views/admin/research/journals/show.html.erb index be32a34b38d55e410e7cc1b3bc59db929bdb7024..4cf2893c0aabc906c5052480805a21efce60aa54 100644 --- a/app/views/admin/research/journals/show.html.erb +++ b/app/views/admin/research/journals/show.html.erb @@ -11,6 +11,7 @@ <% if @journal.issn %><%= Research::Journal.human_attribute_name('issn') %> <%= @journal.issn %><% end %> <% end %> +<%= render 'admin/application/summary/show', about: @journal %> <div class="card mt-5"> <div class="card-header"> <div class="float-end"> diff --git a/app/views/admin/research/journals/static.html.erb b/app/views/admin/research/journals/static.html.erb index 278021cc4d71c3261f878527995c083d3f06fd59..51381c1943e09469651d7946b8adc2bc363481df 100644 --- a/app/views/admin/research/journals/static.html.erb +++ b/app/views/admin/research/journals/static.html.erb @@ -4,4 +4,5 @@ title: > issn: > <%= @about.issn %> <%= render 'admin/application/meta_description/static' %> +<%= render 'admin/application/summary/static' %> --- diff --git a/app/views/admin/research/journals/volumes/_form.html.erb b/app/views/admin/research/journals/volumes/_form.html.erb index 3bcfdafabf5fbee101692ea5532772df5e732d13..7d39bfe89911ab1eda2c2dd64151cc649f4afc48 100644 --- a/app/views/admin/research/journals/volumes/_form.html.erb +++ b/app/views/admin/research/journals/volumes/_form.html.erb @@ -10,6 +10,7 @@ </div> <div class="card-body"> <%= f.input :title %> + <%= render 'admin/application/summary/form', f: f, about: volume %> <%= f.input :text, as: :summernote %> </div> </div> diff --git a/app/views/admin/research/journals/volumes/show.html.erb b/app/views/admin/research/journals/volumes/show.html.erb index 9d58f2d987330b67ef766cb39c56dab37d46d7a4..3294c87dc9f948c429d38adb63cf23e119dff031 100644 --- a/app/views/admin/research/journals/volumes/show.html.erb +++ b/app/views/admin/research/journals/volumes/show.html.erb @@ -2,6 +2,7 @@ <div class="row"> <div class="col-md-9"> + <%= render 'admin/application/summary/show', about: @volume %> <div class="card flex-fill w-100"> <div class="card-header"> <h2 class="card-title mb-0 h5"><%= t('content') %></h2> diff --git a/app/views/admin/research/journals/volumes/static.html.erb b/app/views/admin/research/journals/volumes/static.html.erb index bd0d0a26b7b6cc0766697c261044303cfa11a4ec..284cefba7cc7a2268aa2ad1271fa97c9d65798f9 100644 --- a/app/views/admin/research/journals/volumes/static.html.erb +++ b/app/views/admin/research/journals/volumes/static.html.erb @@ -6,7 +6,8 @@ issn: "<%= @about.journal.issn %>" keywords: > <%= @about.keywords %> date: "<%= @about.published_at.iso8601 %>" -<%= render 'admin/communication/unsplash/static' %> +<%= render 'admin/application/featured_image/static' %> <%= render 'admin/application/meta_description/static' %> +<%= render 'admin/application/summary/static' %> --- <%= prepare_html_for_static @about.text, @about.university %> diff --git a/db/migrate/20230112131744_remove_website_attributes_from_research_journals.rb b/db/migrate/20230112131744_remove_website_attributes_from_research_journals.rb new file mode 100644 index 0000000000000000000000000000000000000000..0f1e9050997a06b4e432b88654341d1b78a85673 --- /dev/null +++ b/db/migrate/20230112131744_remove_website_attributes_from_research_journals.rb @@ -0,0 +1,6 @@ +class RemoveWebsiteAttributesFromResearchJournals < ActiveRecord::Migration[7.0] + def change + remove_column :research_journals, :access_token, :string + remove_column :research_journals, :repository, :string + end +end diff --git a/db/migrate/20230112145505_add_summary_to_research_models.rb b/db/migrate/20230112145505_add_summary_to_research_models.rb new file mode 100644 index 0000000000000000000000000000000000000000..6d46d872c00438ad4cca352153a8733b8d72b810 --- /dev/null +++ b/db/migrate/20230112145505_add_summary_to_research_models.rb @@ -0,0 +1,6 @@ +class AddSummaryToResearchModels < ActiveRecord::Migration[7.0] + def change + add_column :research_journals, :summary, :text + add_column :research_journal_volumes, :summary, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index 40bb669c26123d6f3aeb573a47ea10460556949b..042e3b820bbf50485f0917f9fb22c68a9f5e1463 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -611,6 +611,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_12_151136) do t.boolean "published", default: false t.text "text" t.text "featured_image_credit" + t.text "summary" t.index ["research_journal_id"], name: "index_research_journal_volumes_on_research_journal_id" t.index ["university_id"], name: "index_research_journal_volumes_on_university_id" end @@ -621,9 +622,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_12_151136) do t.text "meta_description" t.datetime "created_at", null: false t.datetime "updated_at", null: false - t.string "access_token" - t.string "repository" t.string "issn" + t.text "summary" t.index ["university_id"], name: "index_research_journals_on_university_id" end