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, default: false,
}, },
metadatum_type: String, metadatum_type: String,
metadatum_object: Object, query: Object,
isRepositoryLevel: Boolean, isRepositoryLevel: Boolean,
isCheckbox: { isCheckbox: {
type: Boolean, type: Boolean,

View File

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

View File

@ -39,46 +39,27 @@
</template> </template>
<script> <script>
import { tainacan as axios, isCancel } from '../../../js/axios/axios'; import { isCancel } from '../../../js/axios/axios';
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin'; import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue'; import CheckboxRadioModal from '../../../admin/components/other/checkbox-radio-modal.vue';
export default { export default {
created(){ mixins: [filterTypeMixin, dynamicFilterTypeMixin],
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);
});
},
data(){ data(){
return { return {
options: [], options: [],
selected: [], selected: []
metadatum_object: {}
} }
}, },
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
watch: { watch: {
selected: function(){ selected: function(){
//this.selected = val;
this.onSelect(); this.onSelect();
} }
}, },
mounted() {
if (!this.isUsingElasticSearch)
this.loadOptions();
},
methods: { methods: {
loadOptions(skipSelected) { loadOptions(skipSelected) {
let promise = null; let promise = null;
@ -164,7 +145,6 @@
//taxonomy: this.taxonomy, //taxonomy: this.taxonomy,
collectionId: this.collectionId, collectionId: this.collectionId,
metadatum_type: this.metadatumType, metadatum_type: this.metadatumType,
metadatum_object: this.metadatum_object,
isRepositoryLevel: this.isRepositoryLevel, isRepositoryLevel: this.isRepositoryLevel,
query: this.query query: this.query
}, },

View File

@ -77,23 +77,8 @@
dateInter, dateInter,
filterTypeMixin filterTypeMixin
], ],
created() { mounted() {
let endpoint = '/collection/' + this.collectionId + '/metadata/' + this.metadatumId; this.selectedValues();
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);
});
}, },
data(){ data(){
return { return {
@ -104,8 +89,7 @@
isTouched: false, isTouched: false,
isValid: false, isValid: false,
clear: false, clear: false,
type: 'numeric', type: 'numeric'
metadatum_object: {}
} }
}, },
watch: { watch: {

View File

@ -121,31 +121,12 @@
dateInter, dateInter,
filterTypeMixin 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() { mounted() {
this.selectedValues(); this.selectedValues();
}, },
data(){ data(){
return { return {
value: null, value: null,
metadatum_object: {},
comparator: '=', // =, !=, >, >=, <, <= comparator: '=', // =, !=, >, >=, <, <=
} }
}, },

View File

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

View File

@ -79,26 +79,6 @@
wpAjax, wpAjax,
filterTypeMixin 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() { mounted() {
this.selectedValues(); this.selectedValues();
}, },
@ -106,7 +86,6 @@
return { return {
value: null, value: null,
filterTypeOptions: [], filterTypeOptions: [],
metadatum_object: {},
comparator: '=' // =, !=, >, >=, <, <= comparator: '=' // =, !=, >, >=, <, <=
} }
}, },

View File

@ -29,32 +29,12 @@
import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin'; import { filterTypeMixin, dynamicFilterTypeMixin } from '../filter-types-mixin';
export default { export default {
created(){ mixins: [filterTypeMixin, dynamicFilterTypeMixin],
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);
});
},
data(){ data(){
return { return {
options: [] options: []
} }
}, },
mixins: [filterTypeMixin, dynamicFilterTypeMixin],
watch: { watch: {
selected(value) { selected(value) {
if (value) if (value)
@ -74,6 +54,10 @@
return undefined; return undefined;
} }
}, },
mounted(){
if (!this.isUsingElasticSearch)
this.loadOptions();
},
methods: { methods: {
loadOptions(){ loadOptions(){
// Cancels previous Request // Cancels previous Request