Skip to content
Snippets Groups Projects
Commit fdfd04e5 authored by alexisben's avatar alexisben
Browse files

Merge branch 'feature/unsplash' of https://github.com/noesya/osuny into feature/unsplash

parents b35acd37 3e01b1ef
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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 || "" %>'
......@@ -145,11 +147,10 @@ lang = about&.language&.iso_code if about.respond_to? :language
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
this.data = JSON.parse(xmlHttp.responseText);
console.log(this.data)
}
}.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) {
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment