diff --git a/app/controllers/admin/communication/unsplash_controller.rb b/app/controllers/admin/communication/unsplash_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..e21b2007ba96963ae3342520496f54700437b6ac --- /dev/null +++ b/app/controllers/admin/communication/unsplash_controller.rb @@ -0,0 +1,9 @@ +class Admin::Communication::UnsplashController < Admin::Communication::ApplicationController + layout false + + def index + @search = params[:search] + @photos = @search ? Unsplash::Photo.search(@search, 1, 18, :squarish) + : [] + end +end diff --git a/app/views/admin/application/unsplash/_photo.html.erb b/app/views/admin/communication/unsplash/_photo.html.erb similarity index 100% rename from app/views/admin/application/unsplash/_photo.html.erb rename to app/views/admin/communication/unsplash/_photo.html.erb diff --git a/app/views/admin/application/unsplash/_selector.html.erb b/app/views/admin/communication/unsplash/_selector.html.erb similarity index 78% rename from app/views/admin/application/unsplash/_selector.html.erb rename to app/views/admin/communication/unsplash/_selector.html.erb index 4d37385ad7bd4e416082e6c4ddd729159f03bd0a..3c8b114cd7f9ffd17ffefa2b2c5d6851760d17ec 100644 --- a/app/views/admin/application/unsplash/_selector.html.erb +++ b/app/views/admin/communication/unsplash/_selector.html.erb @@ -1,9 +1,9 @@ -<% unless image.attached? %> +<% if !image.attached? && text.present? %> <p>Voulez-vous utiliser une de ces images Unsplash ?</p> <div class="row"> <% Unsplash::Photo.search(text, 1, 4, :squarish).each do |photo| %> <div class="col-6"> - <%= render 'admin/application/unsplash/photo', photo: photo %> + <%= render 'admin/communication/unsplash/photo', photo: photo %> </div> <% end %> </div> @@ -31,7 +31,7 @@ <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> - <form class="row"> + <div class="row"> <div class="col-lg-9"> <input type="text" name="search" @@ -45,12 +45,14 @@ Chercher </button> </div> - </form> + </div> <div class="row"> - <% Unsplash::Photo.search(text, 1, 18, :squarish).each do |photo| %> - <div class="col-6 col-lg-2"> - <%= render 'admin/application/unsplash/photo', photo: photo %> - </div> + <% if text %> + <% Unsplash::Photo.search(text, 1, 18, :squarish).each do |photo| %> + <div class="col-6 col-lg-2"> + <%= render 'admin/communication/unsplash/photo', photo: photo %> + </div> + <% end %> <% end %> </div> </div> diff --git a/app/views/admin/communication/unsplash/index.html.erb b/app/views/admin/communication/unsplash/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..1adb90b3cb3d20d8291defa3fb4fec7bcfc9851a --- /dev/null +++ b/app/views/admin/communication/unsplash/index.html.erb @@ -0,0 +1,5 @@ +<% @photos.each do |photo| %> + <div class="col-6 col-lg-2"> + <%= render 'admin/communication/unsplash/photo', photo: photo %> + </div> +<% end %> diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb index 882ed8be446900a3f34882a768e5d0c186d804dd..37226745ef636158988a8d945363911d4d49579c 100644 --- a/app/views/admin/communication/website/posts/_form.html.erb +++ b/app/views/admin/communication/website/posts/_form.html.erb @@ -52,11 +52,9 @@ label: false, input_html: { accept: '.jpg,.jpeg,.png,.svg' }, preview: true - %> - <%= f.input :featured_image_alt %> - </div> - <div class="card-body"> - <%= render 'admin/application/unsplash/selector', + %> + <%= f.input :featured_image_alt %> + <%= render 'admin/communication/unsplash/selector', image: post.featured_image, text: post.image_keywords %> </div> diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 8e3cfeb11a6f02f1bd38a25c432cc4585f7f19e5..10d17934837fb273e56942d8035770a3fa98d49f 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -1,4 +1,5 @@ namespace :communication do + get 'unsplash' => 'unsplash#index' resources :websites do get 'home' => 'website/home#edit' patch 'home' => 'website/home#update'