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

New search query

parent 0161f240
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,7 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit" ...@@ -39,7 +39,7 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
<input type="text" <input type="text"
name="search" name="search"
placeholder="Recherche en anglais..." placeholder="Recherche en anglais..."
v-model="searchValue" v-model="params.query"
class="form-control"> class="form-control">
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
...@@ -52,8 +52,9 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit" ...@@ -52,8 +52,9 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
</div> </div>
</div> </div>
<div class="row" ref="results"> <div class="row" ref="results">
<p v-if="data.length === 0 || !data" >Aucun résultat</p> <p v-if="data.results.length === 0 || !data" >Aucun résultat</p>
<div v-for="image in data" class="col-6 col-lg-2">
<div v-for="image in data.results" class="col-6 col-lg-2">
<img <img
:src="image.thumb" :src="image.thumb"
:alt="image.alt" :alt="image.alt"
...@@ -61,12 +62,15 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit" ...@@ -61,12 +62,15 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
class="img-fluid img-thumbnail mb-3" class="img-fluid img-thumbnail mb-3"
:class="image === selected ? 'bg-secondary' : ''"> :class="image === selected ? 'bg-secondary' : ''">
</div> </div>
<%# <button v-if="data.results.length > 0 && data.total_pages > params.page">Plus de résultats</button> %>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<%# Include vue.js before call Vue.createApp %> <%# Include vue.js before call Vue.createApp %>
<%= javascript_include_tag 'vue' %> <%= javascript_include_tag 'vue' %>
...@@ -74,16 +78,23 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit" ...@@ -74,16 +78,23 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
var app = Vue.createApp({ var app = Vue.createApp({
data() { data() {
return { return {
quantity: 12,
searchValue: '<%= search %>',
unsplashUrl: '<%= admin_communication_unsplash_path(format: :json) %>',
selected: {}, selected: {},
params: {
url: '<%= admin_communication_unsplash_path(format: :json) %>',
per_page: 12,
page: 1,
lang: '<%= about&.language&.iso_code %>',
query: '<%= search || "" %>'
},
targets: { targets: {
image: '<%= about_featured_image_image %>', image: '<%= about_featured_image_image %>',
alt: '<%= about_featured_image_alt %>', alt: '<%= about_featured_image_alt %>',
credit: '<%= about_featured_image_credit %>' credit: '<%= about_featured_image_credit %>'
}, },
data: [] data: {
results: [],
total: 0
}
} }
}, },
mounted() { mounted() {
...@@ -93,7 +104,7 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit" ...@@ -93,7 +104,7 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
}, },
methods: { methods: {
search() { search() {
if (!this.searchValue) { if (!this.params.query) {
return null; return null;
} }
...@@ -101,9 +112,11 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit" ...@@ -101,9 +112,11 @@ about_featured_image_credit = "##{about_identifier}_featured_image_credit"
xmlHttp.onreadystatechange = function() { xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
this.data = JSON.parse(xmlHttp.responseText); this.data = JSON.parse(xmlHttp.responseText);
console.log(this.data)
} }
}.bind(this); }.bind(this);
xmlHttp.open( "GET", this.unsplashUrl + '&search=' + this.searchValue + '&quantity=' + this.quantity, false );
xmlHttp.open( "GET", this.params.url + '&query=' + this.params.query + '&per_page=' + this.params.per_page + '&page=' + this.params.page + '&lang=' + this.params.lang, false );
xmlHttp.send( null ); xmlHttp.send( null );
}, },
select(image) { select(image) {
......
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