From 54485b6aa14829001cc6251cd511bdb4d77f6d66 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Wed, 1 Feb 2023 17:30:41 +0100 Subject: [PATCH] wip --- .../communication/photo_import/unsplash.svg | 32 ++++++++ .../communication/photo_import_controller.rb | 41 ++++++++++ .../communication/unsplash_controller.rb | 22 ------ .../application/featured_image/_edit.html.erb | 2 +- .../_selector.html.erb | 75 ++++++++++--------- .../pexels.json.jbuilder} | 2 +- .../pexels}/_photo.json.jbuilder | 0 .../photo_import/unsplash.json.jbuilder | 5 ++ .../unsplash/_photo.json.jbuilder | 6 ++ config/locales/en.yml | 4 +- config/locales/fr.yml | 4 +- config/routes/admin/communication.rb | 5 +- 12 files changed, 135 insertions(+), 63 deletions(-) create mode 100644 app/assets/images/communication/photo_import/unsplash.svg create mode 100644 app/controllers/admin/communication/photo_import_controller.rb delete mode 100644 app/controllers/admin/communication/unsplash_controller.rb rename app/views/admin/communication/{unsplash => photo_import}/_selector.html.erb (70%) rename app/views/admin/communication/{unsplash/index.json.jbuilder => photo_import/pexels.json.jbuilder} (51%) rename app/views/admin/communication/{unsplash => photo_import/pexels}/_photo.json.jbuilder (100%) create mode 100644 app/views/admin/communication/photo_import/unsplash.json.jbuilder create mode 100644 app/views/admin/communication/photo_import/unsplash/_photo.json.jbuilder diff --git a/app/assets/images/communication/photo_import/unsplash.svg b/app/assets/images/communication/photo_import/unsplash.svg new file mode 100644 index 000000000..adde50407 --- /dev/null +++ b/app/assets/images/communication/photo_import/unsplash.svg @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generator: Adobe Illustrator 21.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> +<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" + viewBox="0 0 457.2 104.2" style="enable-background:new 0 0 457.2 104.2;" xml:space="preserve"> +<style type="text/css"> + .st0{clip-path:url(#SVGID_2_);} +</style> +<g> + <defs> + <rect id="SVGID_1_" width="457.2" height="104.2"/> + </defs> + <clipPath id="SVGID_2_"> + <use xlink:href="#SVGID_1_" style="overflow:visible;"/> + </clipPath> + <path class="st0" d="M59.9,38.7h27.5v48.7H0V38.7h27.5V63h32.3V38.7z M152.9,63.6c0,8.3-5.4,13.1-12.9,13.1 + c-7.3,0-12.8-4.9-12.8-13.1V24.4H115v39.1c0,15.4,11,25.2,25.1,25.2c14.2,0,25.1-9.8,25.1-25.2V24.4h-12.2V63.6z M196.6,42.5 + c-4.7,0-9.9,2-12.6,6.6v-5.4h-11.4v43.7h11.8V62.2c0-5.1,3-9.1,8.2-9.1c5.7,0,8.1,3.8,8.1,8.7v25.5h11.8V59.8 + C212.4,50.2,207.4,42.5,196.6,42.5 M239.9,60.9c0,0-4-0.8-6.5-1.3c-2.5-0.5-4-1.8-4-3.9c0-2.5,2.2-4.3,5.3-4.3 + c4.4,0,6.1,2.2,6.5,4.9h10.2c-0.1-6-4.8-13.8-16.5-13.8c-9.4,0-16.3,6.5-16.3,14.3c0,6.1,3.8,11.2,12.2,13l6,1.3 + c3.4,0.7,4.7,2.3,4.7,4.3c0,2.3-2.1,4.3-6,4.3c-4.7,0-7.3-2.7-7.9-5.8l-10.5,0c0.6,6.5,5.3,14.8,18.5,14.8 + c11.4,0,17.2-7.3,17.2-14.4C252.9,67.9,248.5,62.7,239.9,60.9 M303.1,65.4c0,13.2-8.3,23-20.6,23c-6,0-10.5-2.4-12.6-5.3v21.1 + h-11.8V43.7h11.4v5.4c2-3.4,6.8-6.4,13.4-6.4C295.7,42.7,303.1,52.5,303.1,65.4 M291.5,65.5c0-7.7-4.8-12.2-10.8-12.2 + s-10.9,4.5-10.9,12.2c0,7.7,4.9,12.3,10.9,12.3S291.5,73.3,291.5,65.5 M359.5,43.7h11.4v43.7h-11.8V82c-2,3.5-6.6,6.4-12.6,6.4 + c-12.3,0-20.6-9.8-20.6-23c0-13,7.4-22.7,20.1-22.7c6.6,0,11.3,3,13.4,6.4V43.7z M359.3,65.5c0-7.7-4.9-12.2-10.9-12.2 + s-10.8,4.5-10.8,12.2c0,7.8,4.8,12.3,10.8,12.3S359.3,73.2,359.3,65.5 M308.6,87.3h11.8V24.4h-11.8V87.3z M441,42.5 + c-4.2,0-9,1.4-11.8,4.8l0-22.9h-11.8l0,62.9l11.8,0l0-25.6c0.3-4.8,3.2-8.5,8.2-8.5c5.7,0,8.1,3.8,8.1,8.7l0,25.5l11.8,0l0-27.5 + C457.2,50.2,452.1,42.5,441,42.5 M399,60.9c0,0-4-0.8-6.5-1.3c-2.5-0.5-4-1.8-4-3.9c0-2.5,2.2-4.3,5.3-4.3c4.4,0,6.1,2.2,6.5,4.9 + h10.2c-0.1-6-4.8-13.8-16.5-13.8c-9.4,0-16.3,6.5-16.3,14.3c0,6.1,3.8,11.2,12.2,13l6,1.3c3.4,0.7,4.7,2.3,4.7,4.3 + c0,2.3-2.1,4.3-6,4.3c-4.7,0-7.3-2.7-7.9-5.8l-10.5,0c0.6,6.5,5.3,14.8,18.5,14.8c11.4,0,17.2-7.3,17.2-14.4 + C412,67.9,407.6,62.7,399,60.9 M59.9,0H27.5v24.4h32.3V0z"/> +</g> +</svg> diff --git a/app/controllers/admin/communication/photo_import_controller.rb b/app/controllers/admin/communication/photo_import_controller.rb new file mode 100644 index 000000000..34b301e9b --- /dev/null +++ b/app/controllers/admin/communication/photo_import_controller.rb @@ -0,0 +1,41 @@ +class Admin::Communication::PhotoImportController < Admin::Communication::ApplicationController + layout false + + def unsplash + @query = params[:query] + @search = [] + @total = 0 + @total_pages = 0 + if @query.present? + p = { + query: @query, + page: (params[:page].presence || 1), + per_page: (params[:per_page].presence || 10), + lang: (params[:lang].presence || 'en') + } + p[:orientation] = params[:orientation] if params.has_key? :orientation + @search = Unsplash::Search.search "/search/photos", Unsplash::Photo, p + @total = @search.total + @total_pages = @search.total_pages + end + end + + def pexels + @query = params[:query] + @search = [] + @total = 0 + @total_pages = 0 + if @query.present? + p = { + query: @query, + page: (params[:page].presence || 1), + per_page: (params[:per_page].presence || 10), + lang: (params[:lang].presence || 'en') + } + p[:orientation] = params[:orientation] if params.has_key? :orientation + @search = Unsplash::Search.search "/search/photos", Unsplash::Photo, p + @total = @search.total + @total_pages = @search.total_pages + end + end +end diff --git a/app/controllers/admin/communication/unsplash_controller.rb b/app/controllers/admin/communication/unsplash_controller.rb deleted file mode 100644 index 964023c35..000000000 --- a/app/controllers/admin/communication/unsplash_controller.rb +++ /dev/null @@ -1,22 +0,0 @@ -class Admin::Communication::UnsplashController < Admin::Communication::ApplicationController - layout false - - def index - if params[:query].blank? - @search = [] - @total = 0 - @total_pages = 0 - else - p = { - query: params[:query], - page: (params[:page].presence || 1), - per_page: (params[:per_page].presence || 10), - lang: (params[:lang].presence || 'en') - } - p[:orientation] = params[:orientation] if params.has_key? :orientation - @search = Unsplash::Search.search "/search/photos", Unsplash::Photo, p - @total = @search.total - @total_pages = @search.total_pages - end - end -end diff --git a/app/views/admin/application/featured_image/_edit.html.erb b/app/views/admin/application/featured_image/_edit.html.erb index 9fec944db..7e5d81300 100644 --- a/app/views/admin/application/featured_image/_edit.html.erb +++ b/app/views/admin/application/featured_image/_edit.html.erb @@ -16,5 +16,5 @@ input_html: { data: { 'summernote-config' => 'link' } } %> - <%= render 'admin/communication/unsplash/selector', about: about, f:f %> + <%= render 'admin/communication/photo_import/selector', about: about, f:f %> <% end %> diff --git a/app/views/admin/communication/unsplash/_selector.html.erb b/app/views/admin/communication/photo_import/_selector.html.erb similarity index 70% rename from app/views/admin/communication/unsplash/_selector.html.erb rename to app/views/admin/communication/photo_import/_selector.html.erb index 93de143ee..2421a212a 100644 --- a/app/views/admin/communication/unsplash/_selector.html.erb +++ b/app/views/admin/communication/photo_import/_selector.html.erb @@ -11,8 +11,9 @@ about_featured_image_alt = "##{about_identifier}_featured_image_alt" about_featured_image_credit = "##{about_identifier}_featured_image_credit" # fr, en... lang = about&.language&.iso_code if about.respond_to? :language -# /admin/communication/unsplash.json?query=Page%20de%20test&per_page=12&page=1&lang=fr -path = admin_communication_unsplash_path(website_id: nil, format: :json) +# /admin/communication/photo_import.json?query=Page%20de%20test&per_page=12&page=1&lang=fr +unsplash_path = admin_communication_unsplash_path(website_id: nil, format: :json) +pexels_path = admin_communication_pexels_path(website_id: nil, format: :json) %> <div id="unsplash-app" v-cloak> @@ -25,7 +26,7 @@ path = admin_communication_unsplash_path(website_id: nil, format: :json) data-bs-toggle="modal" data-bs-target="#unsplashModal" > - <%= t 'unsplash.open' %> + <%= t 'photo_import.open' %> </button> <input class="form-control string optional" type="hidden" @@ -36,20 +37,18 @@ path = admin_communication_unsplash_path(website_id: nil, format: :json) tabindex="-1" aria-labelledby="Unsplash" aria-hidden="true"> - <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable"> + <div class="modal-dialog modal-fullscreen modal-dialog-scrollable"> <div class="modal-content"> <div class="modal-header"> - <h5 class="modal-title" id="exampleModalLabel"> - <%= t 'unsplash.title' %> - </h5> + <h5 class="modal-title"> <%= t 'photo_import.title' %></h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> - <div class="row mb-3"> + <div class="row pure__row--small mb-3"> <div class="col-lg-9"> <input type="text" name="search" - placeholder="<%= t 'unsplash.placeholder' %>" + placeholder="<%= t 'photo_import.placeholder' %>" v-model="query" class="form-control"> </div> @@ -57,35 +56,43 @@ path = admin_communication_unsplash_path(website_id: nil, format: :json) <button type="button" class="btn btn-primary" v-on:click="research" - aria-label="<%= t 'unsplash.search' %>"> - <%= t 'unsplash.search' %> + aria-label="<%= t 'photo_import.search' %>"> + <%= t 'photo_import.search' %> </button> </div> </div> - <div class="row" ref="results"> - <p v-if="data.results.length === 0 || !data" > - <%= t 'unsplash.nothing' %> - </p> - <div v-for="image in data.results" class="col-6 col-lg-2"> - <img - :src="image.thumb" - :alt="image.alt" - v-on:click="select(image)" - class="img-fluid img-thumbnail mb-3" - :class="image === selected ? 'bg-secondary' : ''"> + <div class="row"> + <div class="col-md-6"> + <div class="row pure__row--small" ref="results"> + <p v-if="data.results.length === 0 || !data" > + <%= t 'photo_import.nothing' %> + </p> + <div v-for="image in data.results" class="col-6 col-lg-4"> + <img + :src="image.thumb" + :alt="image.alt" + v-on:click="select(image)" + class="img-fluid img-thumbnail mb-3" + :class="image === selected ? 'bg-secondary' : ''"> + </div> + </div> + <div class="row"> + <div class="col-lg-5"> + <a href="#" v-if="page > 1" v-on:click="page = page - 1" class="btn btn-light btn-sm"> + <%= t 'photo_import.previous' %> + </a> + </div> + <div class="col-lg-2 text-center"> + <%= image_tag 'communication/photo_import/unsplash.svg', width: 100, alt: 'Unsplash' %> + </div> + <div class="col-lg-5 text-end"> + <a href="#" v-if="page < data.total_pages" v-on:click="page = page + 1" class="btn btn-light btn-sm"> + <%= t 'photo_import.next' %> + </a> + </div> + </div> </div> </div> - <div class="d-flex" - :class="page === 1 ? 'justify-content-end' : 'justify-content-between'"> - <div href="#" - v-if="page > 1" - v-on:click="page = page - 1" - class="btn btn-light btn-sm"><%= t 'unsplash.previous' %></div> - <div href="#" - v-if="page < data.total_pages" - v-on:click="page = page + 1" - class="btn btn-light bt-sm"><%= t 'unsplash.next' %></div> - </div> </div> </div> </div> @@ -102,7 +109,7 @@ path = admin_communication_unsplash_path(website_id: nil, format: :json) return { selected: {}, parameters: { - url: '<%= path %>', + url: '<%= unsplash_path %>', per_page: 12, lang: '<%= lang %>', }, diff --git a/app/views/admin/communication/unsplash/index.json.jbuilder b/app/views/admin/communication/photo_import/pexels.json.jbuilder similarity index 51% rename from app/views/admin/communication/unsplash/index.json.jbuilder rename to app/views/admin/communication/photo_import/pexels.json.jbuilder index b086b20e3..5491f6229 100644 --- a/app/views/admin/communication/unsplash/index.json.jbuilder +++ b/app/views/admin/communication/photo_import/pexels.json.jbuilder @@ -1,5 +1,5 @@ json.total @total json.total_pages @total_pages json.results @search do |photo| - json.partial! 'admin/communication/unsplash/photo', photo: photo + json.partial! 'admin/communication/photo_import/unsplash/photo', photo: photo end diff --git a/app/views/admin/communication/unsplash/_photo.json.jbuilder b/app/views/admin/communication/photo_import/pexels/_photo.json.jbuilder similarity index 100% rename from app/views/admin/communication/unsplash/_photo.json.jbuilder rename to app/views/admin/communication/photo_import/pexels/_photo.json.jbuilder diff --git a/app/views/admin/communication/photo_import/unsplash.json.jbuilder b/app/views/admin/communication/photo_import/unsplash.json.jbuilder new file mode 100644 index 000000000..5491f6229 --- /dev/null +++ b/app/views/admin/communication/photo_import/unsplash.json.jbuilder @@ -0,0 +1,5 @@ +json.total @total +json.total_pages @total_pages +json.results @search do |photo| + json.partial! 'admin/communication/photo_import/unsplash/photo', photo: photo +end diff --git a/app/views/admin/communication/photo_import/unsplash/_photo.json.jbuilder b/app/views/admin/communication/photo_import/unsplash/_photo.json.jbuilder new file mode 100644 index 000000000..1dc8aac83 --- /dev/null +++ b/app/views/admin/communication/photo_import/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']['small'] +json.preview photo['urls']['regular'] diff --git a/config/locales/en.yml b/config/locales/en.yml index dba8c22cd..318ac19cf 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -292,14 +292,14 @@ en: date_with_hour: "%B %d, %Y %H:%M" today: Today true: Yes - unsplash: + photo_import: next: Next image nothing: No results for this search open: Search an image placeholder: Type your search here previous: Previous images search: Search - title: Images on Unsplash + title: Photo search validate: Validate views: pagination: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index b4db6f3ee..28b2136d7 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -292,14 +292,14 @@ fr: date_with_hour: "%d %B %Y %H:%M" today: Aujourd'hui true: Oui - unsplash: + photo_import: next: Images suivantes nothing: Aucun résultat pour cette recherche open: Chercher une image placeholder: Tapez votre recherche previous: Images précédentes search: Chercher - title: Recherche d'image sur Unsplash + title: Recherche d'image validate: Valider views: pagination: diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index c8f3af92d..eb13c2897 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -1,5 +1,8 @@ namespace :communication do - get 'unsplash' => 'unsplash#index' + scope 'photo-import' do + get 'unsplash' => 'photo_import#unsplash' + get 'pexels' => 'photo_import#pexels' + end resources :websites do member do get :import -- GitLab