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 { } 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']) { if($request['search']){
$response = $this->metadatum_repository->fetch_all_metadatum_values( $request['collection_id'], $metadatum->get_id() ); if($collection_id) {
$response = $this->metadatum_repository->fetch_all_metadatum_values( $collection_id, $metadatum_id, $request['search'], $offset, $number );
} else { } else {
$response = $this->metadatum_repository->fetch_all_metadatum_values( null, $metadatum->get_id() ); $response = $this->metadatum_repository->fetch_all_metadatum_values( null, $metadatum_id, $request['search'], $offset, $number);
}
} else {
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: { 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(){ loadOptions(){
this.isLoading = true; this.isLoading = true;

View File

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

View File

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