Moves URL update responsability from pagination compoment to eventBus
This commit is contained in:
parent
359cdc7e3a
commit
fb046a998f
|
@ -136,6 +136,7 @@
|
|||
:disabled="formHasErrors">{{ $i18n.get('save') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help is-danger">{{ formErrorMessage }}</p>
|
||||
</form>
|
||||
|
||||
<b-loading
|
||||
|
@ -175,7 +176,8 @@ export default {
|
|||
}, {
|
||||
value: 'trash',
|
||||
label: this.$i18n.get('trash')
|
||||
}]
|
||||
}],
|
||||
formErrorMessage: '',
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -209,8 +211,19 @@ export default {
|
|||
this.isLoading = false;
|
||||
|
||||
this.$router.push(this.$routerHelper.getItemPath(this.form.collectionId, this.itemId));
|
||||
}).catch(error => {
|
||||
this.$console.error(error);
|
||||
})
|
||||
.catch((errors) => {
|
||||
for (let error of errors.errors) {
|
||||
for (let attribute of Object.keys(error)){
|
||||
//this.editFormErrors[attribute] = error[attribute];
|
||||
this.$console.log(error);
|
||||
|
||||
eventBus.errors.push({ field_id: 7031, errors: error[attribute]});
|
||||
}
|
||||
}
|
||||
this.$console.log(eventBus.errors);
|
||||
this.formErrorMessage = errors.error_message;
|
||||
|
||||
this.isLoading = false;
|
||||
});
|
||||
},
|
||||
|
@ -306,7 +319,6 @@ export default {
|
|||
formHasErrors(){
|
||||
return eventBus.errors.length > 0;
|
||||
}
|
||||
|
||||
},
|
||||
created(){
|
||||
// Obtains collection ID
|
||||
|
|
|
@ -302,7 +302,7 @@ export default {
|
|||
this.collectionId = this.$route.params.collectionId;
|
||||
|
||||
|
||||
this.fetchFields({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel})
|
||||
this.fetchFields({collectionId: this.collectionId, isRepositoryLevel: this.isRepositoryLevel, isContextEdit: true})
|
||||
.then(() => {
|
||||
this.isLoadingFields = false;
|
||||
})
|
||||
|
|
|
@ -68,27 +68,20 @@ export default {
|
|||
'getItemsPerPage',
|
||||
'getPostQuery'
|
||||
]),
|
||||
...mapActions('search', [
|
||||
'setPage',
|
||||
'setItemsPerPage'
|
||||
]),
|
||||
onChangeItemsPerPage(value) {
|
||||
if( this.itemsPerPage == value){
|
||||
return false;
|
||||
}
|
||||
|
||||
let prevValue = this.itemsPerPage;
|
||||
this.setItemsPerPage( value );
|
||||
this.$userPrefs.set('items_per_page', value, prevValue);
|
||||
|
||||
this.updateURLQueries();
|
||||
let prevValue = this.itemsPerPage;
|
||||
this.itemsPerPage = value;
|
||||
eventFilterBus.setItemsPerPage(value);
|
||||
this.$userPrefs.set('items_per_page', value, prevValue);
|
||||
},
|
||||
onPageChange(page) {
|
||||
if(page == 0)
|
||||
return;
|
||||
|
||||
this.setPage( page );
|
||||
this.updateURLQueries();
|
||||
eventFilterBus.setPage(this.page);
|
||||
},
|
||||
getLastItemNumber() {
|
||||
let last = (Number(this.itemsPerPage*(this.page - 1)) + Number(this.itemsPerPage));
|
||||
|
@ -101,25 +94,19 @@ export default {
|
|||
|
||||
return ( this.itemsPerPage * ( this.page - 1 ) + 1)
|
||||
},
|
||||
updateURLQueries(){
|
||||
this.$router.push({ query: {} });
|
||||
this.$router.push({ query: this.getPostQuery() });
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.$userPrefs.get('items_per_page')
|
||||
.then((value) => {
|
||||
this.itemsPerPage = value;
|
||||
this.setPage(this.page);
|
||||
this.setItemsPerPage(this.itemsPerPage);
|
||||
this.updateURLQueries();
|
||||
eventFilterBus.setPage(this.page);
|
||||
eventFilterBus.setItemsPerPage(this.itemsPerPage);
|
||||
})
|
||||
.catch(() => {
|
||||
this.$userPrefs.set('items_per_page', 12, null);
|
||||
this.itemsPerPage = 12;
|
||||
this.setPage(this.page);
|
||||
this.setItemsPerPage(this.itemsPerPage);
|
||||
this.updateURLQueries();
|
||||
eventFilterBus.setPage(this.page);
|
||||
eventFilterBus.setItemsPerPage(this.itemsPerPage);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ export default {
|
|||
|
||||
this.loadItems();
|
||||
|
||||
this.fetchFields({ collectionId: this.collectionId, isRepositoryLevel: false }).then((res) => {
|
||||
this.fetchFields({ collectionId: this.collectionId, isRepositoryLevel: false, isContextEdit: false }).then((res) => {
|
||||
let rawFields = res;
|
||||
this.tableFields.push({ label: this.$i18n.get('label_thumbnail'), field: 'featured_image', slug: 'featured_image', visible: true });
|
||||
for (let field of rawFields) {
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
:label="field.field.name"
|
||||
:message="getErrorMessage"
|
||||
:type="fieldTypeMessage">
|
||||
<span
|
||||
v-if="field.field.required == 'yes'"
|
||||
class="required-field-asterisk"
|
||||
:class="fieldTypeMessage">*</span>
|
||||
<help-button
|
||||
:title="field.field.name"
|
||||
:message="field.field.description"/>
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import Vue from 'vue';
|
||||
import store from './store/store'
|
||||
import router from './../admin/js/router.js';
|
||||
|
||||
export const eventFilterBus = new Vue({
|
||||
router,
|
||||
store,
|
||||
data: {
|
||||
componentsTag: [],
|
||||
|
@ -11,6 +13,11 @@ export const eventFilterBus = new Vue({
|
|||
created(){
|
||||
this.$on('input', data => this.add_metaquery(data) );
|
||||
},
|
||||
watch: {
|
||||
'$route.query' () {
|
||||
console.log(this.$route.query);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add_metaquery( data ){
|
||||
if ( data && data.collection_id ){
|
||||
|
@ -57,5 +64,15 @@ export const eventFilterBus = new Vue({
|
|||
});
|
||||
}
|
||||
},
|
||||
setPage(page) {
|
||||
store.dispatch('search/setPage', page);
|
||||
router.push({ query: {} });
|
||||
router.push({ query: store.getters['search/getPostQuery'] });
|
||||
},
|
||||
setItemsPerPage(itemsPerPage) {
|
||||
store.dispatch('search/setItemsPerPage', itemsPerPage);
|
||||
router.push({ query: {} });
|
||||
router.push({ query: store.getters['search/getPostQuery'] });
|
||||
}
|
||||
}
|
||||
});
|
|
@ -11,7 +11,6 @@ export const eventBus = new Vue({
|
|||
if( tainacan_plugin.components ){
|
||||
this.componentsTag = tainacan_plugin.components;
|
||||
}
|
||||
this.$on('input', data => this.updateValue(data) );
|
||||
},
|
||||
methods : {
|
||||
registerComponent( name ){
|
||||
|
@ -61,6 +60,7 @@ export const eventBus = new Vue({
|
|||
},
|
||||
getErrors(field_id){
|
||||
let error = this.errors.find( errorItem => errorItem.field_id === field_id );
|
||||
console.log(this.errors);
|
||||
return ( error ) ? error.errors : false
|
||||
},
|
||||
setValues(){
|
||||
|
@ -101,7 +101,7 @@ export const eventBus = new Vue({
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
import axios from '../../../axios/axios';
|
||||
import qs from 'qs';
|
||||
|
||||
export const fetchFields = ({ commit }, {collectionId, isRepositoryLevel}) => {
|
||||
export const fetchFields = ({ commit }, {collectionId, isRepositoryLevel, isContextEdit }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let endpoint = '';
|
||||
if (!isRepositoryLevel)
|
||||
|
@ -9,7 +9,10 @@ export const fetchFields = ({ commit }, {collectionId, isRepositoryLevel}) => {
|
|||
else
|
||||
endpoint = '/fields/';
|
||||
|
||||
axios.tainacan.get(endpoint + '?context=edit')
|
||||
if (isContextEdit)
|
||||
endpoint += '?context=edit';
|
||||
|
||||
axios.tainacan.get(endpoint)
|
||||
.then((res) => {
|
||||
let fields= res.data;
|
||||
commit('setFields', fields);
|
||||
|
|
Loading…
Reference in New Issue