diff --git a/app/controllers/admin/communication/unsplash_controller.rb b/app/controllers/admin/communication/unsplash_controller.rb index 9455efd575acbf1afdbe8c77b55bb141a71ff4b9..b48411c31c323dc49df08905139553c061e64869 100644 --- a/app/controllers/admin/communication/unsplash_controller.rb +++ b/app/controllers/admin/communication/unsplash_controller.rb @@ -4,16 +4,19 @@ class Admin::Communication::UnsplashController < Admin::Communication::Applicati def index if params[:query].blank? @search = [] + @total = 0 + @total_pages = 0 else - @search = Unsplash::Search.search "/search/photos", - Unsplash::Photo, - { - query: params[:query], - page: (params[:page] || 1), - per_page: (params[:per_page] || 10), - orientation: (params[:orientation] || 'squarish'), - lang: (params[:lang] || 'en') - } + p = { + query: params[:query], + page: (params[:page] || 1), + per_page: (params[:per_page] || 10), + orientation: (params[:orientation] || 'squarish'), + lang: (params[:lang] || 'en') + } + @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/communication/unsplash/_selector.html.erb b/app/views/admin/communication/unsplash/_selector.html.erb index f2a61486056d3d4f2c39fdd130faae465013ed78..73c95967cd317f4ca648477778c4868a0451f7b2 100644 --- a/app/views/admin/communication/unsplash/_selector.html.erb +++ b/app/views/admin/communication/unsplash/_selector.html.erb @@ -11,6 +11,8 @@ 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) %> <div id="unsplash-app" v-cloak> @@ -91,7 +93,7 @@ lang = about&.language&.iso_code if about.respond_to? :language return { selected: {}, parameters: { - url: '<%= admin_communication_unsplash_path(format: :json) %>', + url: '<%= path %>', per_page: 12, lang: '<%= lang %>', query: '<%= search || "" %>' @@ -132,7 +134,7 @@ lang = about&.language&.iso_code if about.respond_to? :language } }.bind(this); - xmlHttp.open( "GET", this.parameters.url + '&query=' + this.parameters.query + '&per_page=' + this.parameters.per_page + '&page=' + this.page + '&lang=' + this.parameters.lang, false ); + xmlHttp.open( "GET", this.parameters.url + '?query=' + this.parameters.query + '&per_page=' + this.parameters.per_page + '&page=' + this.page + '&lang=' + this.parameters.lang, false ); xmlHttp.send( null ); }, select(image) { diff --git a/app/views/admin/communication/unsplash/index.json.jbuilder b/app/views/admin/communication/unsplash/index.json.jbuilder index 92b97a30660a76adbe570b063e11e851cc19d189..b086b20e32d7618a7812cbc37f9fcd5bd0a3f010 100644 --- a/app/views/admin/communication/unsplash/index.json.jbuilder +++ b/app/views/admin/communication/unsplash/index.json.jbuilder @@ -1,5 +1,5 @@ -json.total @search.total -json.total_pages @search.total_pages +json.total @total +json.total_pages @total_pages json.results @search do |photo| json.partial! 'admin/communication/unsplash/photo', photo: photo end