Adds userPrefs settings for items per page in all listing. Items list has per colection settings.

This commit is contained in:
Mateus Machado Luna 2018-06-12 16:12:55 -03:00
parent 8c49777539
commit 70fc9779b8
6 changed files with 108 additions and 60 deletions

View File

@ -75,7 +75,6 @@ export default {
let prevValue = this.itemsPerPage;
this.$eventBusSearch.setItemsPerPage(value);
this.$userPrefs.set('items_per_page', value, prevValue);
},
onPageChange(page) {
if(page == 0)
@ -90,10 +89,9 @@ export default {
getFirstItem(){
if( this.totalItems == 0 )
return 0;
return ( this.itemsPerPage * ( this.page - 1 ) + 1)
},
},
}
}
</script>

View File

@ -103,29 +103,36 @@ UserPrefsPlugin.install = function (Vue, options = {}) {
tainacanPrefs: {
'items_per_page': 12,
'collections_per_page': 12
'collections_per_page': 12,
'taxonomies_per_page': 12,
'events_per_page': 12
},
init() {
let data = {'meta': {'tainacan_prefs': this.tainacanPrefs} };
wpApi.get('/users/me/')
.then( res => {
if (res.data.meta['tainacan_prefs'] == undefined) {
wpApi.post('/users/me/', qs.stringify(data))
if (res.data.meta['tainacan_prefs'] == undefined || res.data.meta['tainacan_prefs'] == '') {
let data = {'meta': {'tainacan_prefs': JSON.stringify(this.tainacanPrefs)} };
wpApi.post('/users/me/', qs.stringify(data))
.then( updatedRes => {
let prefs = JSON.parse(updatedRes.data.meta['tainacan_prefs']);
this.tainacanPrefs = prefs;
});
} else {
let prefs = JSON.parse(res.data.meta['tainacan_prefs']);
this.tainacanPrefs = prefs;
}
})
.catch(error => {
});
},
get() {
fetch(key) {
return new Promise(( resolve, reject ) => {
wpApi.get('/users/me/')
.then( res => {
if (res.data.meta['tainacan_prefs']['items_per_page']) {
resolve( res.data.meta['tainacan_prefs']['items_per_page'] );
let prefs = JSON.parse(res.data.meta['tainacan_prefs']);
this.tainacanPrefs[key] = prefs[key];
if (prefs[key]) {
resolve( prefs[key] );
} else {
reject( { message: 'Key does not exists in user preference.', value: false } );
reject('Key ' + key + 'does not exists in user preference.');
}
})
.catch(error => {
@ -133,18 +140,31 @@ UserPrefsPlugin.install = function (Vue, options = {}) {
});
});
},
get(key) {
return this.tainacanPrefs[key];
},
set(key, value) {
this.tainacanPrefs[key] = value;
let data = {'meta': {'tainacan_prefs': this.tainacanPrefs} };
let data = {'meta': {'tainacan_prefs': JSON.stringify(this.tainacanPrefs)} };
return new Promise(( resolve, reject ) => {
wpApi.post('/users/me/', qs.stringify(data))
.then( res => {
resolve( res.data );
let prefs = JSON.parse(res.data.meta['tainacan_prefs']);
this.tainacanPrefs[key] = prefs[key];
if (prefs[key]) {
resolve( prefs[key] );
} else {
reject('Key ' + key + 'does not exists in user preference.');
}
})
.catch(error => {
reject( error );
});
});
},
clear() {
let data = {'meta': {'tainacan_prefs': ''} };
wpApi.post('/users/me/', qs.stringify(data))
}
}

View File

@ -35,7 +35,7 @@
:is-loading="isLoading"
:total-categories="totalCategories"
:page="page"
:categories-per-page="categoriesPerPage"
:categories-per-page="taxonomiesPerPage"
:categories="categories"/>
<!-- Empty state image -->
@ -68,7 +68,7 @@
<div class="shown-items">
{{
$i18n.get('info_showing_categories') +
(categoriesPerPage * (page - 1) + 1) +
(taxonomiesPerPage * (page - 1) + 1) +
$i18n.get('info_to') +
getLastCategoryNumber() +
$i18n.get('info_of') + totalCategories + '.'
@ -79,7 +79,7 @@
horizontal
:label="$i18n.get('label_categories_per_page')">
<b-select
:value="categoriesPerPage"
:value="taxonomiesPerPage"
@input="onChangeCategoriesPerPage"
:disabled="categories.length <= 0">
<option value="12">12</option>
@ -96,7 +96,7 @@
:current.sync="page"
order="is-centered"
size="is-small"
:per-page="categoriesPerPage"/>
:per-page="taxonomiesPerPage"/>
</div>
</div>
</div>
@ -117,7 +117,7 @@
isLoading: false,
totalCategories: 0,
page: 1,
categoriesPerPage: 12,
taxonomiesPerPage: 12,
status: ''
}
},
@ -136,9 +136,14 @@
this.loadCategories();
},
onChangeCategoriesPerPage(value) {
let prevValue = this.categoriesPerPage;
this.categoriesPerPage = value;
this.$userPrefs.set('categories_per_page', value, prevValue);
this.taxonomiesPerPage = value;
this.$userPrefs.set('taxonomies_per_page', value)
.then((newValue) => {
this.taxonomiesPerPage = newValue;
})
.catch(() => {
this.$console.log("Error settings user prefs for taxonomies per page")
});
this.loadCategories();
},
onPageChange(page) {
@ -148,7 +153,7 @@
loadCategories() {
this.isLoading = true;
this.fetchCategories({ 'page': this.page, 'categoriesPerPage': this.categoriesPerPage, 'status': this.status })
this.fetchCategories({ 'page': this.page, 'taxonomiesPerPage': this.taxonomiesPerPage, 'status': this.status })
.then((res) => {
this.isLoading = false;
this.totalCategories = res.total;
@ -158,29 +163,29 @@
});
},
getLastCategoryNumber() {
let last = (Number(this.categoriesPerPage * (this.page - 1)) + Number(this.categoriesPerPage));
let last = (Number(this.taxonomiesPerPage * (this.page - 1)) + Number(this.taxonomiesPerPage));
return last > this.totalCategories ? this.totalCategories : last;
}
},
computed: {
categories(){
return this.getCategories();
// for (let category of categories)
// category['creation'] = this.$i18n.get('info_created_by') +
// category['author_name'] + '<br>' + this.$i18n.get('info_date') +
// moment(category['creation_date'], 'YYYY-MM-DD').format('DD/MM/YYYY');
}
},
created() {
this.$userPrefs.get('categories_per_page')
.then((value) => {
this.categoriesPerPage = value;
})
.catch(() => {
this.$userPrefs.set('categories_per_page', 12, null);
});
this.taxonomiesPerPage = this.$userPrefs.get('taxonomies_per_page');
},
mounted(){
this.$userPrefs.fetch('taxonomies_per_page')
.then((value) => {
if (this.taxonomiesPerPage != value) {
this.taxonomiesPerPage = value;
this.loadCategories;
}
})
.catch(() => {
this.$userPrefs.set('taxonomies_per_page', 12);
});
this.loadCategories();
}
}

View File

@ -165,9 +165,14 @@ export default {
this.loadCollections();
},
onChangeCollectionsPerPage(value) {
let prevValue = this.collectionsPerPage;
this.collectionsPerPage = value;
this.$userPrefs.set('collections_per_page', value, prevValue);
this.$userPrefs.set('collections_per_page', value)
.then((newValue) => {
this.collectionsPerPage = newValue;
})
.catch(() => {
this.$console.log("Error settings user prefs for collection per page")
});
this.loadCollections();
},
onPageChange(page) {
@ -202,14 +207,8 @@ export default {
}
},
created() {
this.collectionsPerPage = this.$userPrefs.get('collections_per_page');
this.isLoadingMetadatumTypes = true;
this.$userPrefs.get('collections_per_page')
.then((value) => {
this.collectionsPerPage = value;
})
.catch(() => {
this.$userPrefs.set('collections_per_page', 12, null);
});
this.fetchMetadatumMappers()
.then(() => {
this.isLoadingMetadatumMappers = false;
@ -219,6 +218,16 @@ export default {
});
},
mounted(){
this.$userPrefs.fetch('collections_per_page')
.then((value) => {
if (this.collectionsPerPage != value) {
this.collectionsPerPage = value;
this.loadCollections;
}
})
.catch(() => {
this.$userPrefs.set('collections_per_page', 12);
});
this.loadCollections();
}
}

View File

@ -84,9 +84,14 @@
'getEvents'
]),
onChangeEventsPerPage(value) {
let prevValue = this.eventsPerPage;
this.eventsPerPage = value;
this.$userPrefs.set('events_per_page', value, prevValue);
this.$userPrefs.set('events_per_page', value)
.then((newValue) => {
this.eventsPerPage = newValue;
})
.catch(() => {
this.$console.log("Error settings user prefs for events per page")
});
this.loadEvents();
},
onPageChange(page) {
@ -134,16 +139,20 @@
}
},
created() {
this.eventsPerPage = this.$userPrefs.get('events_per_page');
this.isRepositoryLevel = (this.$route.params.collectionId === undefined);
this.$userPrefs.get('events_per_page')
.then((value) => {
this.eventsPerPage = value;
})
.catch(() => {
this.$userPrefs.set('events_per_page', 12, null);
});
},
mounted(){
this.$userPrefs.fetch('events_per_page')
.then((value) => {
if (this.eventsPerPage != value) {
this.eventsPerPage = value;
this.loadEvents;
}
})
.catch(() => {
this.$userPrefs.set('events_per_page', 12);
});
this.loadEvents();
if (!this.isRepositoryLevel) {

View File

@ -39,8 +39,10 @@ export default {
this.collectionId = parseInt(this.$route.params.collectionId);
if (this.$route.name == null || this.$route.name == undefined || this.$route.name == 'CollectionItemsPage' || this.$route.name == 'ItemsPage') {
if (this.$route.query.perpage == undefined)
this.$route.query.perpage = 12;
if (this.$route.query.perpage == undefined) {
let perPage = (this.collectionId != undefined ? this.$userPrefs.get('items_per_page_' + this.collectionId) : this.$userPrefs.get('items_per_page'));
this.$route.query.perpage = perPage ? perPage : 12;
}
if (this.$route.query.paged == undefined)
this.$route.query.paged = 1;
if (this.$route.query.order == undefined)
@ -55,8 +57,7 @@ export default {
}
this.loadItems(to);
}
}
}
},
methods: {
@ -105,6 +106,12 @@ export default {
this.updateURLQueries();
},
setItemsPerPage(itemsPerPage) {
let prefsPerPage = this.collectionId != undefined ? 'items_per_page_' + this.collectionId : 'items_per_page';
this.$userPrefs.set(prefsPerPage, itemsPerPage)
.catch(() => {
this.$console.log("Error settings user prefs for items per page")
});
this.$store.dispatch('search/setItemsPerPage', itemsPerPage);
this.updateURLQueries();
},