Adds default value for max_options, Fixes Pagination (issue #83)

This commit is contained in:
weryques 2018-08-02 16:42:15 -03:00
parent cd70c24527
commit 181151e444
5 changed files with 37 additions and 7 deletions

View File

@ -24,13 +24,19 @@
v-if="!isSearching && !isTaxonomy" v-if="!isSearching && !isTaxonomy"
class="modal-card-body tainacan-checkbox-list-container"> class="modal-card-body tainacan-checkbox-list-container">
<a <a
v-if="checkboxListOffset"
role="button" role="button"
class="tainacan-checkbox-list-page-changer" class="tainacan-checkbox-list-page-changer"
@click="beforePage"> @click="beforePage">
<b-icon <b-icon
icon="chevron-left"/> icon="chevron-left"/>
</a> </a>
<ul class="tainacan-modal-checkbox-list-body"> <ul
:class="{
'tainacan-modal-checkbox-list-body-dynamic-m-l': !checkboxListOffset,
'tainacan-modal-checkbox-list-body-dynamic-m-r': noMorePage,
}"
class="tainacan-modal-checkbox-list-body">
<li <li
class="tainacan-li-checkbox-list" class="tainacan-li-checkbox-list"
v-for="(option, key) in options" v-for="(option, key) in options"
@ -46,6 +52,7 @@
:active.sync="isCheckboxListLoading"/> :active.sync="isCheckboxListLoading"/>
</ul> </ul>
<a <a
v-if="!noMorePage"
role="button" role="button"
class="tainacan-checkbox-list-page-changer" class="tainacan-checkbox-list-page-changer"
@click="nextPage"> @click="nextPage">
@ -196,6 +203,7 @@
collection: this.collection_id, collection: this.collection_id,
isCheckboxListLoading: false, isCheckboxListLoading: false,
isSearchingLoading: false, isSearchingLoading: false,
noMorePage: 0,
} }
}, },
created() { created() {
@ -208,10 +216,12 @@
methods: { methods: {
beforePage(){ beforePage(){
this.checkboxListOffset -= this.maxNumOptionsCheckboxList; this.checkboxListOffset -= this.maxNumOptionsCheckboxList;
this.noMorePage = 0;
//console.log(this.checkboxListOffset, this.maxNumOptionsCheckboxList);
if(this.checkboxListOffset < 0){ if(this.checkboxListOffset < 0){
this.checkboxListOffset = 0; this.checkboxListOffset = 0;
return;
} }
this.isCheckboxListLoading = true; this.isCheckboxListLoading = true;
@ -219,7 +229,12 @@
this.getOptions(this.checkboxListOffset); this.getOptions(this.checkboxListOffset);
}, },
nextPage(){ nextPage(){
this.checkboxListOffset = this.options.length; if(!this.noMorePage) {
this.checkboxListOffset += this.maxNumOptionsCheckboxList - 1;
}
// 0 20 / 19 20 / 39 20 / 59 20
//console.log(this.checkboxListOffset, this.maxNumOptionsCheckboxList);
this.isCheckboxListLoading = true; this.isCheckboxListLoading = true;
@ -611,6 +626,15 @@
flex-direction: column; flex-direction: column;
flex-wrap: wrap; flex-wrap: wrap;
padding: 0 !important; padding: 0 !important;
max-height: 253px;
}
.tainacan-modal-checkbox-list-body-dynamic-m-l {
margin-left: 34px !important;
}
.tainacan-modal-checkbox-list-body-dynamic-m-r {
margin-right: 34px !important;
} }
.tainacan-search-results-container { .tainacan-search-results-container {
@ -623,6 +647,7 @@
display: flex; display: flex;
flex-direction: column; flex-direction: column;
flex-wrap: wrap; flex-wrap: wrap;
max-height: 253px;
} }
.tainacan-li-no-children { .tainacan-li-no-children {

View File

@ -112,9 +112,9 @@
let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ? let collectionTarget = ( this.metadatum_object && this.metadatum_object.metadata_type_options.collection_id ) ?
this.metadatum_object.metadata_type_options.collection_id : this.collection_id; this.metadatum_object.metadata_type_options.collection_id : this.collection_id;
promise = this.getValuesRelationship( collectionTarget, null, null, 0, this.filter.max_options); promise = this.getValuesRelationship( collectionTarget, null, [], 0, this.filter.max_options);
} else { } else {
promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel, 0, this.filter.max_options ); promise = this.getValuesPlainText( this.metadatum, null, this.isRepositoryLevel, [], 0, this.filter.max_options );
} }
promise.then(() => { promise.then(() => {

View File

@ -76,6 +76,8 @@ export const filter_type_mixin = {
if (opts.length) { if (opts.length) {
this.options = opts; this.options = opts;
} else {
this.noMorePage = 1;
} }
if (this.filter.max_options && this.options.length >= this.filter.max_options) { if (this.filter.max_options && this.options.length >= this.filter.max_options) {
@ -145,6 +147,8 @@ export const filter_type_mixin = {
if (opts.length) { if (opts.length) {
this.options = opts; this.options = opts;
} else {
this.noMorePage = 1;
} }
if (this.filter.max_options && this.options.length >= this.filter.max_options) { if (this.filter.max_options && this.options.length >= this.filter.max_options) {

View File

@ -90,7 +90,8 @@ class Filters extends Repository {
'title' => __( 'Max of options', 'tainacan' ), 'title' => __( 'Max of options', 'tainacan' ),
'type' => 'integer/string', 'type' => 'integer/string',
'description' => __( 'The max number of options to be showed in filter sidebar.', 'tainacan' ), 'description' => __( 'The max number of options to be showed in filter sidebar.', 'tainacan' ),
'validation' => '' 'validation' => '',
'default' => 4
] ]
]); ]);
} }

View File

@ -860,7 +860,7 @@ class Metadata extends Repository {
$pagination = ''; $pagination = '';
if($offset >= 0 && $number >= 1){ if($offset >= 0 && $number >= 1){
$pagination = $wpdb->prepare("LIMIT %d, %d", (int) $offset, (int) $number); $pagination = $wpdb->prepare("LIMIT %d,%d", (int) $offset, (int) $number);
} }
// If no has logged user or actual user can not read private posts // If no has logged user or actual user can not read private posts