fixed cards display order
This commit is contained in:
parent
01cee3ba8a
commit
5da3b3c90a
|
@ -99,18 +99,21 @@ class Base extends ControllerBase {
|
||||||
|
|
||||||
$resp['options'] = $this->query->getOptions();
|
$resp['options'] = $this->query->getOptions();
|
||||||
|
|
||||||
$items = [];
|
// $items = [];
|
||||||
|
$uuids = [];
|
||||||
foreach ($this->results as $result) {
|
foreach ($this->results as $result) {
|
||||||
$nid = $result->getField('nid')->getValues()[0];
|
// $nid = $result->getField('nid')->getValues()[0];
|
||||||
$uuid = $result->getField('uuid')->getValues()[0];
|
// $uuid = $result->getField('uuid')->getValues()[0];
|
||||||
$title = $result->getField('title')->getValues()[0]->getText();
|
// $title = $result->getField('title')->getValues()[0]->getText();
|
||||||
$items[] = [
|
// $items[] = [
|
||||||
'nid' => $nid,
|
// 'nid' => $nid,
|
||||||
'uuid' => $uuid,
|
// 'uuid' => $uuid,
|
||||||
'title' => $title,
|
// 'title' => $title,
|
||||||
];
|
// ];
|
||||||
|
$uuids[] = $result->getField('uuid')->getValues()[0];
|
||||||
}
|
}
|
||||||
$resp['items'] = $items;
|
// $resp['items'] = $items;
|
||||||
|
$resp['uuids'] = $uuids;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new JsonResponse($resp);
|
return new JsonResponse($resp);
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -231,7 +231,7 @@ article.node--type-frontpage{
|
||||||
|
|
||||||
.card{
|
.card{
|
||||||
position: relative;
|
position: relative;
|
||||||
width:200px; height:295px;
|
width:210px; height:295px;
|
||||||
header{
|
header{
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom:0;
|
bottom:0;
|
||||||
|
@ -257,6 +257,7 @@ article.node--type-frontpage{
|
||||||
img:not(:first-of-type){
|
img:not(:first-of-type){
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top:0; left:0;
|
top:0; left:0;
|
||||||
|
z-index:1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ export default {
|
||||||
state : {
|
state : {
|
||||||
keys: "",
|
keys: "",
|
||||||
term: "",
|
term: "",
|
||||||
|
uuids: [],
|
||||||
items: [],
|
items: [],
|
||||||
offset: 0,
|
offset: 0,
|
||||||
limit: 15,
|
limit: 15,
|
||||||
|
@ -21,6 +22,12 @@ export default {
|
||||||
|
|
||||||
// mutations
|
// mutations
|
||||||
mutations : {
|
mutations : {
|
||||||
|
setUuids (state, uuids) {
|
||||||
|
state.uuids = uuids
|
||||||
|
},
|
||||||
|
resetUuids (state) {
|
||||||
|
state.uuids = []
|
||||||
|
},
|
||||||
setItems (state, items) {
|
setItems (state, items) {
|
||||||
state.items = items
|
state.items = items
|
||||||
},
|
},
|
||||||
|
@ -51,6 +58,7 @@ export default {
|
||||||
actions : {
|
actions : {
|
||||||
newSearch({ dispatch, commit, state }) {
|
newSearch({ dispatch, commit, state }) {
|
||||||
console.log('Search newSearch');
|
console.log('Search newSearch');
|
||||||
|
commit('resetUuids')
|
||||||
commit('resetItems')
|
commit('resetItems')
|
||||||
commit('resetOffset')
|
commit('resetOffset')
|
||||||
dispatch('getResults')
|
dispatch('getResults')
|
||||||
|
@ -70,20 +78,21 @@ export default {
|
||||||
// commit('setItems', data.items)
|
// commit('setItems', data.items)
|
||||||
commit('setInfos', data.infos)
|
commit('setInfos', data.infos)
|
||||||
commit('setCount', data.count)
|
commit('setCount', data.count)
|
||||||
dispatch('getItems', data.items)
|
commit('setUuids', data.uuids)
|
||||||
|
dispatch('getItems', data.uuids)
|
||||||
})
|
})
|
||||||
.catch(( error ) => {
|
.catch(( error ) => {
|
||||||
console.warn('Issue with getResults', error)
|
console.warn('Issue with getResults', error)
|
||||||
Promise.reject(error)
|
Promise.reject(error)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
getItems({ dispatch, commit, state}, itemslist) {
|
getItems({ dispatch, commit, state }, uuids) {
|
||||||
let params = {
|
let params = {
|
||||||
// include: 'images', // no needs to include thanks to consumers_image_styles module
|
// include: 'images', // no needs to include thanks to consumers_image_styles module
|
||||||
'filter[uuids-groupe][group][conjunction]': 'OR'
|
'filter[uuids-groupe][group][conjunction]': 'OR'
|
||||||
};
|
};
|
||||||
for (var i = 0; i < itemslist.length; i++) {
|
for (var i = 0; i < uuids.length; i++) {
|
||||||
let uuid = itemslist[i].uuid
|
let uuid = uuids[i]
|
||||||
params[`filter[${uuid}][condition][path]`] = 'id'
|
params[`filter[${uuid}][condition][path]`] = 'id'
|
||||||
params[`filter[${uuid}][condition][value]`] = uuid
|
params[`filter[${uuid}][condition][value]`] = uuid
|
||||||
params[`filter[${uuid}][condition][operator]`] = '='
|
params[`filter[${uuid}][condition][operator]`] = '='
|
||||||
|
@ -94,7 +103,7 @@ export default {
|
||||||
return JSONAPI.get('node/materiau?'+q)
|
return JSONAPI.get('node/materiau?'+q)
|
||||||
.then(({ data }) => {
|
.then(({ data }) => {
|
||||||
console.log('search getItems data', data)
|
console.log('search getItems data', data)
|
||||||
dispatch('parseItems', data)
|
dispatch('parseItems', {data:data.data, uuids:uuids})
|
||||||
// commit('setItems', data.items)
|
// commit('setItems', data.items)
|
||||||
})
|
})
|
||||||
.catch(( error ) => {
|
.catch(( error ) => {
|
||||||
|
@ -102,13 +111,18 @@ export default {
|
||||||
Promise.reject(error)
|
Promise.reject(error)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
parseItems({ dispatch, commit, state }, { data }) {
|
parseItems({ dispatch, commit, state }, { data, uuids }) {
|
||||||
console.log('search parseItems data', data)
|
// data comes from jsonapi query
|
||||||
|
// uuids comes from solr search query (we loop from uuids to conserve the search results order)
|
||||||
|
console.log('search parseItems data, uuids', data, uuids)
|
||||||
let items = []
|
let items = []
|
||||||
for (var i = 0; i < data.length; i++) {
|
// for (var i = 0; i < data.length; i++) {
|
||||||
let itemsrc = data[i]
|
for (var i = 0; i < uuids.length; i++) {
|
||||||
let attrs = itemsrc.attributes
|
let uuid = uuids[i]
|
||||||
let relations = itemsrc.relationships
|
let item_index = data.findIndex(p => p.id == uuid)
|
||||||
|
let item_src = data[item_index]
|
||||||
|
let attrs = item_src.attributes
|
||||||
|
let relations = item_src.relationships
|
||||||
|
|
||||||
// get field values
|
// get field values
|
||||||
let item = {
|
let item = {
|
||||||
|
@ -119,15 +133,15 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get images included values
|
// get images included values
|
||||||
let imgsrc = relations.images.data
|
let img_src = relations.images.data
|
||||||
item.images = []
|
item.images = []
|
||||||
for (var j = 0; j < imgsrc.length; j++) {
|
for (var j = 0; j < img_src.length; j++) {
|
||||||
// // https://stackoverflow.com/questions/11258077/how-to-find-index-of-an-object-by-key-and-value-in-an-javascript-array
|
// // https://stackoverflow.com/questions/11258077/how-to-find-index-of-an-object-by-key-and-value-in-an-javascript-array
|
||||||
// let index = included.findIndex(p => p.id == imgsrc[j].id)
|
// let index = included.findIndex(p => p.id == img_src[j].id)
|
||||||
// let img = included[index]
|
// let img = included[index]
|
||||||
item.images.push({
|
item.images.push({
|
||||||
title: imgsrc[j].meta.title,
|
title: img_src[j].meta.title,
|
||||||
url: imgsrc[j].meta.imageDerivatives.links.card_medium.href
|
url: img_src[j].meta.imageDerivatives.links.card_medium.href
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue