added default base page
This commit is contained in:
@@ -17,6 +17,8 @@ use Drupal\search_api\Entity\Index;
|
||||
*/
|
||||
class Base extends ControllerBase {
|
||||
|
||||
|
||||
|
||||
private $limit = 15;
|
||||
private $offset = 0;
|
||||
|
||||
@@ -56,6 +58,24 @@ class Base extends ControllerBase {
|
||||
|
||||
}
|
||||
|
||||
private function defaultQuery(){
|
||||
$entity_storage = \Drupal::entityTypeManager()->getStorage('node');
|
||||
$this->query = $entity_storage->getQuery()
|
||||
->condition('type', 'materiau')
|
||||
// ->condition('status', '1')
|
||||
->range($this->offset, $this->limit)
|
||||
->accessCheck(TRUE)
|
||||
->sort('changed', 'DESC');
|
||||
// ->condition('field_example', 'test_value')
|
||||
$this->results = $this->query->execute();
|
||||
|
||||
$this->count_query = $entity_storage->getQuery()
|
||||
->condition('type', 'materiau')
|
||||
->accessCheck(TRUE)
|
||||
// ->condition('status', '1')
|
||||
->count();
|
||||
$this->count = $this->count_query->execute();
|
||||
}
|
||||
/**
|
||||
* get params from request
|
||||
*/
|
||||
@@ -79,8 +99,6 @@ class Base extends ControllerBase {
|
||||
$this->parseRequest($request);
|
||||
|
||||
$resp = [
|
||||
'keys' => $this->keys,
|
||||
'term' => $this->term,
|
||||
'range' => array(
|
||||
'offset' => $this->offset,
|
||||
'limit' => $this->limit
|
||||
@@ -90,6 +108,8 @@ class Base extends ControllerBase {
|
||||
if ($this->keys) {
|
||||
$this->sapiQuery();
|
||||
|
||||
$resp['keys'] = $this->keys;
|
||||
$resp['term'] = $this->term;
|
||||
$resp['count'] = $this->results->getResultCount();
|
||||
$resp['infos'] = t('The search found @count result(s) with keywords @keys.', array(
|
||||
"@count" => $resp['count'],
|
||||
@@ -117,6 +137,22 @@ class Base extends ControllerBase {
|
||||
// $resp['items'] = $items;
|
||||
$resp['uuids'] = $uuids;
|
||||
$resp['nids'] = $nids;
|
||||
} else {
|
||||
// no keys or terms to search for
|
||||
// display the default base page
|
||||
$this->defaultQuery();
|
||||
// $uuids = [];
|
||||
$nids = [];
|
||||
foreach ($this->results as $result) {
|
||||
// $uuids[] = $result->getField('uuid')->getValues()[0];
|
||||
$nids[] = $result;
|
||||
}
|
||||
// $resp['uuids'] = $uuids;
|
||||
$resp['nids'] = $nids;
|
||||
$resp['count'] = $this->count;
|
||||
$resp['infos'] = t('Please use the search form to search from our @count materials.', array(
|
||||
"@count" => $resp['count']
|
||||
));
|
||||
}
|
||||
|
||||
return new JsonResponse($resp);
|
||||
@@ -163,7 +199,7 @@ class Base extends ControllerBase {
|
||||
|
||||
$resp['items'] = $this->items;
|
||||
}else{
|
||||
$resp['#markup'] = "no keys to search for";
|
||||
$resp['#markup'] = t("no keys to search for");
|
||||
}
|
||||
|
||||
return $resp;
|
||||
|
File diff suppressed because one or more lines are too long
@@ -140,8 +140,11 @@ import 'theme/assets/styles/main.scss'
|
||||
if (to.path == '/') {
|
||||
classes.push('path-home')
|
||||
} else {
|
||||
const path_parts = to.path.replace(/^\//, '').split('/')
|
||||
// TODO: remove language relative prefix from path classes (fr, en, etc)
|
||||
const path_parts = to.path
|
||||
.replace(/^\//, '')
|
||||
// remove language relative prefix from path classes (fr, en, etc)
|
||||
.replace(/^\D{2,3}\//, '')
|
||||
.split('/')
|
||||
for (var i = 0; i < path_parts.length; i++) {
|
||||
if (i == 0) {
|
||||
var c = 'path-' + path_parts[i]
|
||||
|
@@ -70,6 +70,12 @@ export default {
|
||||
this.$store.commit('Search/setTerm', params.get('term'))
|
||||
this.pagetitle = params.get('keys')
|
||||
this.newSearch()
|
||||
}else{
|
||||
// load default base page
|
||||
this.$store.commit('Search/setKeys', '')
|
||||
this.$store.commit('Search/setTerm', '')
|
||||
this.pagetitle = 'Base'
|
||||
this.newSearch()
|
||||
}
|
||||
},
|
||||
beforeRouteUpdate (to, from, next) {
|
||||
|
@@ -86,7 +86,11 @@ export default {
|
||||
commit('resetCount')
|
||||
commit('resetNoresults')
|
||||
commit('resetOffset')
|
||||
this.commit('Common/setPagetitle', state.keys)
|
||||
if(state.keys || state.term){
|
||||
this.commit('Common/setPagetitle', state.keys)
|
||||
}else{
|
||||
this.commit('Common/setPagetitle', 'Base')
|
||||
}
|
||||
dispatch('getResults')
|
||||
},
|
||||
nextPage ({ dispatch, commit, state }, $infiniteLoadingstate) {
|
||||
|
Reference in New Issue
Block a user