Adapt taxonomies filters for facets endpoints (ref. #94)

This commit is contained in:
eduardohumberto 2018-08-21 21:04:36 -03:00 committed by Mateus Machado Luna
parent 92a1b401d6
commit a798caca91
4 changed files with 61 additions and 90 deletions

View File

@ -120,11 +120,27 @@ class REST_Facets_Controller extends REST_Controller {
}
} else {
$metadatum_id = $metadatum->get_id();
$offset = '';
$number = '';
if($request['offset'] >= 0 && $request['number'] >= 1){
$offset = $request['offset'];
$number = $request['number'];
}
if($request['collection_id']) {
$response = $this->metadatum_repository->fetch_all_metadatum_values( $request['collection_id'], $metadatum->get_id() );
if($request['search']){
if($collection_id) {
$response = $this->metadatum_repository->fetch_all_metadatum_values( $collection_id, $metadatum_id, $request['search'], $offset, $number );
} else {
$response = $this->metadatum_repository->fetch_all_metadatum_values( null, $metadatum_id, $request['search'], $offset, $number);
}
} else {
$response = $this->metadatum_repository->fetch_all_metadatum_values( null, $metadatum->get_id() );
if($collection_id) {
$response = $this->metadatum_repository->fetch_all_metadatum_values( $collection_id, $metadatum_id, '', $offset, $number);
} else {
$response = $this->metadatum_repository->fetch_all_metadatum_values( null, $metadatum_id, '', $offset, $number);
}
}
}

View File

@ -98,18 +98,6 @@
}
},
methods: {
getValuesTaxonomy( taxonomy ){
return axios.get(`/taxonomy/${taxonomy}/terms?hideempty=0&order=asc&parent=0&number=${this.filter.max_options}`)
.then( res => {
for (let item of res.data) {
this.taxonomy = item.taxonomy;
this.options.push(item);
}
})
.catch(error => {
this.$console.log(error);
});
},
loadOptions(){
this.isLoading = true;

View File

@ -12,8 +12,8 @@
<option
v-for=" (option, index) in options"
:key="index"
:label="option.name"
:value="option.id">{{ option.name }}</option>
:label="option.label"
:value="option.value">{{ option.label }}</option>
</b-select>
</div>
</template>
@ -63,44 +63,25 @@ export default {
}
},
methods: {
getValuesTaxonomy(taxonomy) {
return axios
.get("/taxonomy/" + taxonomy + "/terms?hideempty=0&order=asc")
.then(res => {
for (let item of res.data) {
this.taxonomy = item.taxonomy;
this.options.push(item);
}
})
.catch(error => {
this.$console.log(error);
});
},
loadOptions() {
let promise = null;
this.isLoading = true;
axios
.get("/collection/" + this.collection + "/metadata/" + this.metadatum)
.then(res => {
let metadatum = res.data;
promise = this.getValuesTaxonomy(
metadatum.metadata_type_options.taxonomy_id
);
axios.get('/collection/'+ this.collection +'/facets/' + this.metadatum + `?hideempty=0&order=asc`)
.then( res => {
promise
.then(() => {
this.isLoading = false;
this.selectedValues();
})
.catch(error => {
this.$console.log("error select", error);
this.isLoading = false;
});
})
.catch(error => {
this.$console.log(error);
});
for (let item of res.data) {
this.taxonomy = item.taxonomy;
this.taxonomy_id = item.taxonomy_id;
this.options.push(item);
}
this.isLoading = false;
this.selectedValues();
})
.catch(error => {
this.$console.log(error);
this.isLoading = false;
});
},
getOptions(parent, level = 0) {
// retrieve only ids
@ -111,7 +92,7 @@ export default {
term["level"] = level;
result.push(term);
const levelTerm = level + 1;
const children = this.getOptions(term.id, levelTerm);
const children = this.getOptions(term.value, levelTerm);
result = result.concat(children);
}
}
@ -148,12 +129,12 @@ export default {
});
let valueIndex = this.options.findIndex(
option => option.id == this.selected
option => option.value == this.selected
);
if (valueIndex >= 0) {
this.$eventBusSearch.$emit("sendValuesToTags", {
filterId: this.filter.id,
value: this.options[valueIndex].name
value: this.options[valueIndex].label
});
}
}

View File

@ -124,53 +124,38 @@
},
methods: {
search( query ){
let promise = null;
this.isLoading = true;
this.options = [];
const q = query;
const endpoint = this.isRepositoryLevel ? '/metadata/' + this.metadatum : '/collection/'+ this.collection +'/metadata/' + this.metadatum;
let endpoint = this.isRepositoryLevel ? '/facets/' + this.metadatum : '/collection/'+ this.collection +'/facets/' + this.metadatum;
axios.get(endpoint)
.then( res => {
let metadatum = res.data;
promise = this.getValuesTaxonomy( metadatum.metadata_type_options.taxonomy_id, q );
this.isLoading = true;
promise.then( () => {
this.isLoading = false;
})
.catch( error => {
this.$console.log('error select', error );
this.isLoading = false;
});
})
.catch(error => {
this.$console.log(error);
});
},
getValuesTaxonomy( taxonomy, query ){
endpoint += '?hideempty=0&order=asc';
let valuesToIgnore = [];
for(let val of this.selected)
for(let val of this.selected){
valuesToIgnore.push( val.value );
return axios.get('/taxonomy/' + taxonomy + '/terms?hideempty=0&order=asc' ).then( res => {
}
return axios.get(endpoint).then( res => {
for (let term of res.data) {
if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
let indexToIgnore = valuesToIgnore.findIndex(value => value == term.id);
let indexToIgnore = valuesToIgnore.findIndex(value => value == term.value);
if (indexToIgnore < 0) {
if( term.name.toLowerCase().indexOf( query.toLowerCase() ) >= 0 ){
if( term.label.toLowerCase().indexOf( query.toLowerCase() ) >= 0 ){
this.taxonomy = term.taxonomy;
this.options.push({label: term.name, value: term.id});
this.options.push({label: term.label, value: term.value});
}
}
} else {
if( term.name.toLowerCase().indexOf( query.toLowerCase() ) >= 0 ){
if( term.label.toLowerCase().indexOf( query.toLowerCase() ) >= 0 ){
this.taxonomy = term.taxonomy;
this.options.push({label: term.name, value: term.id});
this.options.push({label: term.label, value: term.value});
}
}
}
this.isLoading = false;
})
.catch(error => {
this.isLoading = false;
this.$console.log(error);
});
},
@ -189,13 +174,14 @@
}
},
getTerm( taxonomy, id ){
return axios.get('/taxonomy/' + taxonomy + '/terms/' + id + '?order=asc&hideempty=0' )
.then( res => {
this.selected.push({ label: res.data.name, value: res.data.id })
})
.catch(error => {
this.$console.log(error);
});
//getting a specific value from api, does not need be in fecat api
return axios.get('/taxonomy/' + taxonomy + '/terms/' + id + '?order=asc&hideempty=0' )
.then( res => {
this.selected.push({ label: res.data.name, value: res.data.id })
})
.catch(error => {
this.$console.log(error);
});
}
}
}