Removes most of unecessary requests for metadata endpoint on filters creation hook.

This commit is contained in:
Mateus Machado Luna 2019-10-08 16:47:05 -03:00
parent 45a09358ce
commit 1782f3b0ed
8 changed files with 17 additions and 110 deletions

View File

@ -301,7 +301,7 @@
default: false,
},
metadatum_type: String,
metadatum_object: Object,
query: Object,
isRepositoryLevel: Boolean,
isCheckbox: {
type: Boolean,

View File

@ -51,7 +51,6 @@
results:'',
selected:'',
options: [],
metadatum_object: {},
label: ''
}
},

View File

@ -39,46 +39,27 @@
</template>
<script>
import { tainacan as axios, isCancel } from '../../../js/axios/axios';
import { isCancel } from '../../../js/axios/axios';
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue';
export default {
created(){
let endpoint = '/collection/' + this.collectionId + '/metadata/' + this.metadatumId +'?nopaging=1';
if (this.isRepositoryLevel || this.collectionId == 'default')
endpoint = '/metadata?nopaging=1';
axios.get(endpoint)
.then( res => {
let result = res.data;
if ( result && result.metadata_type ){
this.metadatum_object = result;
if (!this.isUsingElasticSearch)
this.loadOptions();
}
})
.catch(error => {
this.$console.log(error);
});
},
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
data(){
return {
options: [],
selected: [],
metadatum_object: {}
selected: []
}
},
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
watch: {
selected: function(){
//this.selected = val;
this.onSelect();
}
},
mounted() {
if (!this.isUsingElasticSearch)
this.loadOptions();
},
methods: {
loadOptions(skipSelected) {
let promise = null;
@ -164,7 +145,6 @@
//taxonomy: this.taxonomy,
collectionId: this.collectionId,
metadatum_type: this.metadatumType,
metadatum_object: this.metadatum_object,
isRepositoryLevel: this.isRepositoryLevel,
query: this.query
},

View File

@ -77,23 +77,8 @@
dateInter,
filterTypeMixin
],
created() {
let endpoint = '/collection/' + this.collectionId + '/metadata/' + this.metadatumId;
if (this.isRepositoryLevel || this.collectionId == 'default')
endpoint = '/metadata/'+ this.metadatumId;
axios.get(endpoint)
.then( res => {
let result = res.data;
if( result && result.metadata_type ){
this.metadatum_object = result;
this.selectedValues();
}
})
.catch(error => {
this.$console.log(error);
});
mounted() {
this.selectedValues();
},
data(){
return {
@ -104,8 +89,7 @@
isTouched: false,
isValid: false,
clear: false,
type: 'numeric',
metadatum_object: {}
type: 'numeric'
}
},
watch: {

View File

@ -121,31 +121,12 @@
dateInter,
filterTypeMixin
],
created() {
let endpoint = '/collection/' + this.collectionId + '/metadata/' + this.metadatumId;
if (this.isRepositoryLevel || this.collectionId == 'default')
endpoint = '/metadata/'+ this.metadatumId;
axios.get(endpoint)
.then( res => {
let result = res.data;
if ( result && result.metadata_type ){
this.metadatum_object = result;
this.selectedValues();
}
})
.catch(error => {
this.$console.log(error);
});
},
mounted() {
this.selectedValues();
},
data(){
return {
value: null,
metadatum_object: {},
comparator: '=', // =, !=, >, >=, <, <=
}
},

View File

@ -75,7 +75,7 @@ export const dynamicFilterTypeMixin = {
if (isInCheckboxModal || search || !this.isUsingElasticSearch) {
const source = axios.CancelToken.source();
let currentQuery = JSON.parse(JSON.stringify(this.query));
if (currentQuery.fetch_only != undefined) {
delete currentQuery.fetch_only;

View File

@ -79,26 +79,6 @@
wpAjax,
filterTypeMixin
],
created() {
this.filterTypeOptions = this.filter.filter_type_options;
let endpoint = '/collection/' + this.collectionId + '/metadata/' + this.metadatumId;
if (this.isRepositoryLevel || this.collectionId == 'default')
endpoint = '/metadata/'+ this.metadatumId;
axios.get(endpoint)
.then( res => {
let result = res.data;
if ( result && result.metadata_type ){
this.metadatum_object = result;
this.selectedValues();
}
})
.catch(error => {
this.$console.log(error);
});
},
mounted() {
this.selectedValues();
},
@ -106,7 +86,6 @@
return {
value: null,
filterTypeOptions: [],
metadatum_object: {},
comparator: '=' // =, !=, >, >=, <, <=
}
},

View File

@ -29,32 +29,12 @@
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
export default {
created(){
let endpoint = '/collection/' + this.collectionId + '/metadata/' + this.metadatumId;
if (this.isRepositoryLevel || this.collectionId == 'default')
endpoint = '/metadata/'+ this.metadatumId;
axios.get(endpoint)
.then( res => {
let result = res.data;
if( result && result.metadata_type ){
this.metadatum_object = result;
if (!this.isUsingElasticSearch)
this.loadOptions();
}
})
.catch(error => {
this.$console.error(error);
});
},
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
data(){
return {
options: []
}
},
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
watch: {
selected(value) {
if (value)
@ -74,6 +54,10 @@
return undefined;
}
},
mounted(){
if (!this.isUsingElasticSearch)
this.loadOptions();
},
methods: {
loadOptions(){
// Cancels previous Request