From 53a669bbeee8de8bbec5b245cd056446ebb3b9ec Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Thu, 5 May 2022 11:03:34 +0200 Subject: [PATCH] credit --- .../javascripts/admin/commons/unsplash.js | 2 + .../communication/unsplash_controller.rb | 3 +- .../communication/website/posts_controller.rb | 7 +- app/models/communication/website/post.rb | 1 + .../communication/unsplash/_photo.html.erb | 4 +- .../unsplash/_photo.json.jbuilder | 6 ++ .../communication/unsplash/_selector.html.erb | 6 +- .../unsplash/index.json.jbuilder | 3 + .../website/posts/_form.html.erb | 89 ++++++++++++------- .../communication/website/posts/show.html.erb | 16 +++- .../website/posts/static.html.erb | 7 +- config/locales/communication/en.yml | 1 + config/locales/communication/fr.yml | 1 + config/routes/admin/communication.rb | 3 + ...d_credit_to_communication_website_posts.rb | 5 ++ db/schema.rb | 22 ++++- test/fixtures/communication/website/posts.yml | 1 + 17 files changed, 130 insertions(+), 47 deletions(-) create mode 100644 app/views/admin/communication/unsplash/_photo.json.jbuilder create mode 100644 app/views/admin/communication/unsplash/index.json.jbuilder create mode 100644 db/migrate/20220505083115_add_credit_to_communication_website_posts.rb diff --git a/app/assets/javascripts/admin/commons/unsplash.js b/app/assets/javascripts/admin/commons/unsplash.js index 5cedab936..bb6201e2e 100644 --- a/app/assets/javascripts/admin/commons/unsplash.js +++ b/app/assets/javascripts/admin/commons/unsplash.js @@ -5,10 +5,12 @@ $('[data-unsplash]').click(function (e) { id = $image.data('unsplash'), preview = $image.data('preview'), alt = $image.data('alt'), + credit = $image.data('credit'), $input = $('#unsplashInput'); e.stopPropagation(); $('[data-unsplash]').removeClass('bg-secondary'); $('#communication_website_post_featured_image_alt').val(alt); + $('#communication_website_post_featured_image_credit').summernote('code', credit); $('.communication_website_post_featured_image img').attr('src', preview); $image.addClass('bg-secondary'); $input.val(id); diff --git a/app/controllers/admin/communication/unsplash_controller.rb b/app/controllers/admin/communication/unsplash_controller.rb index e21b2007b..3d7554dd9 100644 --- a/app/controllers/admin/communication/unsplash_controller.rb +++ b/app/controllers/admin/communication/unsplash_controller.rb @@ -3,7 +3,8 @@ class Admin::Communication::UnsplashController < Admin::Communication::Applicati def index @search = params[:search] - @photos = @search ? Unsplash::Photo.search(@search, 1, 18, :squarish) + @quantity = params[:quantity] || 18 + @photos = @search ? Unsplash::Photo.search(@search, 1, @quantity, :squarish) : [] end end diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb index c27475b6f..da9017274 100644 --- a/app/controllers/admin/communication/website/posts_controller.rb +++ b/app/controllers/admin/communication/website/posts_controller.rb @@ -36,6 +36,11 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web breadcrumb end + def static + @about = @post + render layout: false + end + def new @post.website = @website @post.author_id = current_user.person&.id @@ -88,7 +93,7 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web .permit( :university_id, :website_id, :title, :description, :description_short, :text, :published, :published_at, :featured_image, :featured_image_delete, - :featured_image_infos, :featured_image_alt, :slug, :pinned, + :featured_image_infos, :featured_image_alt, :featured_image_credit, :slug, :pinned, :author_id, :language_id, category_ids: [] ) .merge(university_id: current_university.id) diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 534f0d369..7e952010e 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -6,6 +6,7 @@ # description :text # description_short :text # featured_image_alt :string +# featured_image_credit :text # github_path :text # pinned :boolean default(FALSE) # published :boolean default(FALSE) diff --git a/app/views/admin/communication/unsplash/_photo.html.erb b/app/views/admin/communication/unsplash/_photo.html.erb index f7c30fc80..454d292b9 100644 --- a/app/views/admin/communication/unsplash/_photo.html.erb +++ b/app/views/admin/communication/unsplash/_photo.html.erb @@ -2,6 +2,8 @@ class: 'img-fluid img-thumbnail mb-3', data: { unsplash: photo['id'], + filename: "#{photo['id']}.jpg", preview: photo['urls']['regular'], - alt: "Photo by <a href=\"https://unsplash.com/@#{ photo['user']['username'] }?utm_source=#{ Unsplash.configuration.utm_source }&utm_medium=referral\"> #{ photo['user']['name'] }</a> on <a href=\"https://unsplash.com/?utm_source=#{ Unsplash.configuration.utm_source }&utm_medium=referral\">Unsplash</a>" + alt: photo['alt_description'], + credit: "Photo by <a href=\"https://unsplash.com/@#{ photo['user']['username'] }?utm_source=#{ Unsplash.configuration.utm_source }&utm_medium=referral\"> #{ photo['user']['name'] }</a> on <a href=\"https://unsplash.com/?utm_source=#{ Unsplash.configuration.utm_source }&utm_medium=referral\">Unsplash</a>" } %> diff --git a/app/views/admin/communication/unsplash/_photo.json.jbuilder b/app/views/admin/communication/unsplash/_photo.json.jbuilder new file mode 100644 index 000000000..34175cfbd --- /dev/null +++ b/app/views/admin/communication/unsplash/_photo.json.jbuilder @@ -0,0 +1,6 @@ +json.id photo['id'] +json.filename "#{photo['id']}.jpg" +json.alt photo['alt_description'] +json.credit "Photo by <a href=\"https://unsplash.com/@#{ photo['user']['username'] }?utm_source=#{ Unsplash.configuration.utm_source }&utm_medium=referral\"> #{ photo['user']['name'] }</a> on <a href=\"https://unsplash.com/?utm_source=#{ Unsplash.configuration.utm_source }&utm_medium=referral\">Unsplash</a>" +json.thumb photo['urls']['thumb'] +json.preview photo['urls']['regular'] diff --git a/app/views/admin/communication/unsplash/_selector.html.erb b/app/views/admin/communication/unsplash/_selector.html.erb index 3c8b114cd..8736d6d59 100644 --- a/app/views/admin/communication/unsplash/_selector.html.erb +++ b/app/views/admin/communication/unsplash/_selector.html.erb @@ -12,7 +12,7 @@ class="btn btn-secondary btn-sm" data-bs-toggle="modal" data-bs-target="#unsplashModal"> - Chercher une autre image sur Unsplash + Chercher une image </button> <input class="form-control string optional" type="hidden" @@ -31,7 +31,7 @@ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> - <div class="row"> + <div class="row mb-3"> <div class="col-lg-9"> <input type="text" name="search" @@ -40,7 +40,7 @@ </div> <div class="col-lg-3"> <button type="button" - class="btn btn-primary btn-sm" + class="btn btn-primary" aria-label="Chercher"> Chercher </button> diff --git a/app/views/admin/communication/unsplash/index.json.jbuilder b/app/views/admin/communication/unsplash/index.json.jbuilder new file mode 100644 index 000000000..c22e78b8f --- /dev/null +++ b/app/views/admin/communication/unsplash/index.json.jbuilder @@ -0,0 +1,3 @@ +json.array! @photos do |photo| + json.partial! 'admin/communication/unsplash/photo', photo: photo +end diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb index 37226745e..6709add4f 100644 --- a/app/views/admin/communication/website/posts/_form.html.erb +++ b/app/views/admin/communication/website/posts/_form.html.erb @@ -11,6 +11,33 @@ <%= f.input :text, as: :summernote %> </div> </div> + <div class="row"> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"> + <%= t('activerecord.attributes.communication/website/post.categories') %> + </h5> + </div> + <div class="card-body"> + <%= f.association :categories, + label_text: false, + as: :check_boxes, + collection: collection_tree_for_checkboxes(@website.categories) if @website.categories.any? %> + </div> + </div> + </div> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('seo') %></h5> + </div> + <div class="card-body"> + <%= f.input :description %> + </div> + </div> + </div> + </div> </div> <div class="col-md-4"> <div class="card flex-fill w-100"> @@ -18,27 +45,37 @@ <h5 class="card-title mb-0"><%= t('metadata') %></h5> </div> <div class="card-body"> - <%= f.input :slug, - as: :string, - input_html: post.persisted? ? {} : { - class: 'js-slug-input', - data: { source: '#communication_website_post_title' } - } %> + <% if can? :publish, post %> + <div class="row"> + <div class="col-6"> + <%= f.input :published %> + </div> + <div class="col-6"> + <%= f.input :pinned %> + </div> + </div> + <%= f.input :published_at, html5: true %> + <% end %> <% if @website.languages.many? %> <%= f.input :language_id, collection: @website.languages, include_blank: false %> <% elsif @website.languages.any? %> <%= f.input :language_id, as: :hidden, input_html: { value: @website.languages.first.id }, wrapper: false %> <% end %> - <% if can? :publish, post %> - <%= f.input :published %> - <%= f.input :published_at, html5: true %> - <% end %> - <%= f.input :pinned %> <% if current_user.author? || current_user.contributor? %> - <%= f.input :author_id, as: :hidden, input_html: { value: current_user.person&.id }, wrapper: false %> + <%= f.input :author_id, + as: :hidden, + input_html: { value: current_user.person&.id }, wrapper: false %> <% else %> - <%= f.association :author, collection: current_university.people.ordered, label_method: :to_s_alphabetical %> + <%= f.association :author, + collection: current_university.people.ordered, + label_method: :to_s_alphabetical %> <% end %> + <%= f.input :slug, + as: :string, + input_html: post.persisted? ? {} : { + class: 'js-slug-input', + data: { source: '#communication_website_post_title' } + } %> </div> </div> <div class="card flex-fill w-100"> @@ -54,32 +91,16 @@ preview: true %> <%= f.input :featured_image_alt %> + <%= f.input :featured_image_credit, + as: :summernote, + input_html: { + data: { 'summernote-config' => 'mini' } + } %> <%= render 'admin/communication/unsplash/selector', image: post.featured_image, text: post.image_keywords %> </div> </div> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"> - <%= t('activerecord.attributes.communication/website/post.categories') %> - </h5> - </div> - <div class="card-body"> - <%= f.association :categories, - label_text: false, - as: :check_boxes, - collection: collection_tree_for_checkboxes(@website.categories) if @website.categories.any? %> - </div> - </div> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('seo') %></h5> - </div> - <div class="card-body"> - <%= f.input :description %> - </div> - </div> </div> </div> <% content_for :action_bar_right do %> diff --git a/app/views/admin/communication/website/posts/show.html.erb b/app/views/admin/communication/website/posts/show.html.erb index f7af5c34f..874feb401 100644 --- a/app/views/admin/communication/website/posts/show.html.erb +++ b/app/views/admin/communication/website/posts/show.html.erb @@ -59,9 +59,16 @@ </div> <div class="card-body"> <%= image_tag @post.featured_image.variant(resize: '600'), class: 'img-fluid mb-3' %> - <p class="small mb-0"> - <%= @post.featured_image_alt %> - </p> + <% if @post.featured_image_credit %> + <p class="mb-0"> + <%= @post.featured_image_alt %> + </p> + <% end %> + <% if @post.featured_image_credit %> + <p class="small mb-0"> + <%= @post.featured_image_credit.html_safe %> + </p> + <% end %> </div> </div> <% end %> @@ -86,6 +93,9 @@ <% content_for :action_bar_left do %> <%= destroy_link @post %> + <%= link_to t('static'), + static_admin_communication_website_post_path(@post), + class: button_classes('btn-light') if current_user.server_admin? %> <% end %> <% content_for :action_bar_right do %> diff --git a/app/views/admin/communication/website/posts/static.html.erb b/app/views/admin/communication/website/posts/static.html.erb index 277e081a6..b33785c98 100644 --- a/app/views/admin/communication/website/posts/static.html.erb +++ b/app/views/admin/communication/website/posts/static.html.erb @@ -16,8 +16,11 @@ categories: <% end %> <% end %> <% if @about.featured_image.attached? %> -image: "<%= @about.featured_image.blob.id %>" -image_alt: "<%= @about.featured_image_alt %>" +image: + id: "<%= @about.featured_image.blob.id %>" + alt: "<%= @about.featured_image_alt %>" + credit: > + <%= prepare_html_for_static @about.featured_image_credit, @about.university %> <% end %> description: > <%= prepare_text_for_static @about.description %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 22b74a1f1..b65e067d5 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -112,6 +112,7 @@ en: description_short: Lead text featured_image: Featured image featured_image_alt: Alt text + featured_image_credit: Credit pinned: Pinned published: Published? published_at: Publication date diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 0fce32c9e..f98b5ee64 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -112,6 +112,7 @@ fr: description_short: Chapô featured_image: Image à la une featured_image_alt: Texte alternatif + featured_image_credit: Crédit pinned: Mis en avant published: Publié ? published_at: Date de publication diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 10d179348..c6716a4fe 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -28,6 +28,9 @@ namespace :communication do resources :authors, controller: 'website/authors', only: [:index, :show] resources :posts, controller: 'website/posts' do post :publish, on: :collection + member do + get :static + end end resources :curations, path: 'posts/curations', diff --git a/db/migrate/20220505083115_add_credit_to_communication_website_posts.rb b/db/migrate/20220505083115_add_credit_to_communication_website_posts.rb new file mode 100644 index 000000000..a5ee1fa33 --- /dev/null +++ b/db/migrate/20220505083115_add_credit_to_communication_website_posts.rb @@ -0,0 +1,5 @@ +class AddCreditToCommunicationWebsitePosts < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_posts, :featured_image_credit, :text + end +end diff --git a/db/schema.rb b/db/schema.rb index f5a8ea0a6..650a96126 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: 2022_04_28_171541) do +ActiveRecord::Schema.define(version: 2022_05_05_083115) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -349,6 +349,7 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.text "text" t.text "description_short" t.uuid "language_id" + t.text "featured_image_credit" t.index ["author_id"], name: "index_communication_website_posts_on_author_id" t.index ["communication_website_id"], name: "index_communication_website_posts_on_communication_website_id" t.index ["language_id"], name: "index_communication_website_posts_on_language_id" @@ -503,6 +504,23 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.index ["university_id"], name: "index_education_schools_on_university_id" end + create_table "external_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "title" + t.text "description" + t.string "address" + t.string "zipcode" + t.string "city" + t.string "country" + t.string "website" + t.string "phone" + t.string "mail" + t.boolean "active" + t.string "sirene" + t.integer "kind" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "languages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "iso_code" @@ -692,8 +710,8 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.string "linkedin" t.boolean "is_alumnus", default: false t.text "description_short" - t.boolean "is_author" t.string "name" + t.boolean "is_author" t.index ["university_id"], name: "index_university_people_on_university_id" t.index ["user_id"], name: "index_university_people_on_user_id" end diff --git a/test/fixtures/communication/website/posts.yml b/test/fixtures/communication/website/posts.yml index a887bab47..6904e28b4 100644 --- a/test/fixtures/communication/website/posts.yml +++ b/test/fixtures/communication/website/posts.yml @@ -6,6 +6,7 @@ # description :text # description_short :text # featured_image_alt :string +# featured_image_credit :text # github_path :text # pinned :boolean default(FALSE) # published :boolean default(FALSE) -- GitLab