Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination #126

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Modal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div role="dialog" :class="['modal',effect]" @click="backdrop&&action(false,1)" @transitionend="transition = false">
<div role="dialog" :class="['modal',effect,type]" @click="backdrop&&action(false,1)" @transitionend="transition = false" style="display:none;">
<div :class="['modal-dialog',{'modal-lg':large,'modal-sm':small}]" role="document" :style="{width: optionalWidth}" @click.stop="action(null)">
<div class="modal-content">
<slot name="modal-header">
Expand Down Expand Up @@ -27,8 +27,9 @@ export default {
props: {
backdrop: {type: Boolean, default: true},
callback: {type: Function, default: null},
cancelText: {type: String, default: 'Close'},
effect: {type: String, default: null},
cancelText: { type: String, default: 'Close' },
effect: { type: String, default: null },
type: { type: String, default: null },
large: {type: Boolean, default: false},
okText: {type: String, default: 'Save changes'},
small: {type: Boolean, default: false},
Expand Down
99 changes: 99 additions & 0 deletions src/Pagination.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<template>
<nav>
<ul class="pagination justify-content-center">
<li v-if="showPrevious()" :class="{ 'disabled' : currentPage <= 1, 'page-item' : true }">
<a class="page-link" href="#" v-if="currentPage <= 1">
<span aria-hidden="true">{{ config.previousText }}</span>
</a>
<a class="page-link" href="#" v-if="currentPage > 1 " :aria-label="config.ariaPrevious" @click.prevent="changePage(currentPage - 1)">
<span aria-hidden="true">{{ config.previousText }}</span>
</a>
</li>
<li v-for="num in array" :class="{ 'active': num === currentPage, 'page-item' : true }">
<a class="page-link" href="#" @click.prevent="changePage(num)">{{ num }}</a>
</li>
<li v-if="showNext()" :class="{ 'disabled' : currentPage === lastPage || lastPage === 0, 'page-item' : true }">
<a class="page-link" href="#" v-if="currentPage === lastPage || lastPage === 0">
<span aria-hidden="true">{{ config.nextText }}</span>
</a>
<a class="page-link" href="#" v-if="currentPage < lastPage" :aria-label="config.ariaNext" @click.prevent="changePage(currentPage + 1)">
<span aria-hidden="true">{{ config.nextText }}</span>
</a>
</li>
</ul>
</nav>
</template>
<script>

export default {
props: {
total: {
type: Number,
required: true
},
pageSize: {
type: Number,
required: true
},
callback: {
type: Function,
required: true
},
options: {
type: Object
},
},
data() {
return { currentPage: 1 }
},
computed: {
_total() { return this.total },
_pageSize() { return this.pageSize },
lastPage() {
let _total = this._total / this._pageSize;
return _total >= 1 ? _total : 1;
},
array() {

let _from = this.currentPage - this.config.offset;
if (_from < 1)
_from = 1;

let _to = _from + (this.config.offset * 2);
if (_to >= this.lastPage)
_to = this.lastPage;

let _arr = [];
while (_from <= _to) {
_arr.push(_from);
_from++;
}

return _arr;
},
config() {
return Object.assign({
offset: 2,
ariaNext: 'Próximo',
ariaPrevious: 'Anterior',
previousText: '«',
nextText: '»',
alwaysShowPrevNext: true
}, this.options);
}
},
methods: {
showPrevious() {
return this.config.alwaysShowPrevNext || this.currentPage > 1;
},
showNext() {
return this.config.alwaysShowPrevNext || this.currentPage < this.lastPage;
},
changePage(page) {
if (this.currentPage === page) return;
this.currentPage = page;
this.callback(page);
}
}
};
</script>
123 changes: 62 additions & 61 deletions src/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
</select>
<ul class="dropdown-menu">
<template v-if="list.length">
<li v-if="canSearch" class="bs-searchbox">
<li v-if="canSearch" class="input-group padding-5 dropdown-item">
<input type="text" :placeholder="searchText||text.search" class="form-control" autocomplete="off" ref="search"
v-model="searchValue"
@keyup.esc="close"
/>
<span v-show="searchValue" class="close" @click="clearSearch">&times;</span>
</li>
<li v-if="required&&!clearButton"><a @mousedown.prevent="clear() && close()">{{ placeholder || text.notSelected }}</a></li>
<li v-for="option in filteredOptions" :id="option[optionsValue]">
<a @mousedown.prevent="select(option[optionsValue])">
<li class="dropdown-item" v-if="required&&!clearButton"><a @mousedown.prevent="clear() && close()">{{ placeholder || text.notSelected }}</a></li>
<li class="dropdown-item" v-for="option in filteredOptions" :id="option[optionsValue]" @mousedown.prevent="select(option[optionsValue])">
<a @mousedown.prevent="">
<span v-html="option[optionsLabel]"></span>
<span class="glyphicon glyphicon-ok check-mark" v-show="isSelected(option[optionsValue])"></span>
</a>
Expand Down Expand Up @@ -84,7 +83,7 @@ export default {
},
computed: {
canSearch () { return this.minSearch ? this.list.length >= this.minSearch : this.search },
classes () { return [{open: this.show, disabled: this.disabled}, this.class, this.isLi ? 'dropdown' : this.inInput ? 'input-group-btn' : 'btn-group'] },
classes() { return [{ open: this.show, disabled: this.disabled }, this.class, this.isLi ? 'dropdown' : this.inInput ? 'input-group-btn' : 'input-group'] },
filteredOptions () {
var search = (this.searchValue || '').toLowerCase()
return !search ? this.list : this.list.filter(el => {
Expand Down Expand Up @@ -261,82 +260,84 @@ export default {
</script>

<style scoped>
.padding-5 {
padding: 5px;
}
.form-control.dropdown-toggle{
height: auto;
padding-right: 24px;
height: auto !important;
padding-right: 24px !important;
}
.form-control.dropdown-toggle:after{
content: ' ';
position: absolute;
right: 13px;
top: 50%;
margin: -1px 0 0;
border-top: 4px dashed;
border-top: 4px solid \9;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
content: ' ' !important;
position: absolute !important;
right: 13px !important;
top: 50% !important;
margin: -1px 0 0 !important;
border-top: 4px dashed !important;
border-top: 4px solid \9 !important;
border-right: 4px solid transparent !important;
border-left: 4px solid transparent !important;
}
.bs-searchbox {
position: relative;
margin: 4px 8px;
position: relative !important;
margin: 4px 8px !important;
}
.bs-searchbox .close {
position: absolute;
top: 0;
right: 0;
z-index: 2;
display: block;
width: 34px;
height: 34px;
line-height: 34px;
text-align: center;
position: absolute !important;
top: 0 !important;
right: 0 !important;
z-index: 2 !important;
display: block !important;
width: 34px !important;
height: 34px !important;
line-height: 34px !important;
text-align: center !important;
}
.bs-searchbox input:focus,
.form-control.dropdown-toggle:focus {
outline: 0;
outline: 0 !important;
border-color: #66afe9 !important;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6);
box-shadow: inset 0 1px 1px rgba(0,0,0,.075),0 0 8px rgba(102,175,233,.6) !important;
}
.secret {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
border: 0 !important;
clip: rect(0 0 0 0) !important;
height: 1px !important;
margin: -1px !important;
overflow: hidden !important;
padding: 0 !important;
position: absolute !important;
width: 1px !important;
}
.form-control.dropdown-toggle>.close { margin-left: 5px;}
.notify.out { position: relative; }
.form-control.dropdown-toggle>.close { margin-left: 5px !important;}
.notify.out { position: relative !important; }
.notify.in,
.notify>div {
position: absolute;
width: 96%;
margin: 0 2%;
min-height: 26px;
padding: 3px 5px;
background: #f5f5f5;
border: 1px solid #e3e3e3;
box-shadow: inset 0 1px 1px rgba(0,0,0,.05);
pointer-events: none;
position: absolute !important;
width: 96% !important;
margin: 0 2% !important;
min-height: 26px !important;
padding: 3px 5px !important;
background: #f5f5f5 !important;
border: 1px solid #e3e3e3 !important;
box-shadow: inset 0 1px 1px rgba(0,0,0,.05) !important;
pointer-events: none !important;
}
.notify>div {
top: 5px;
z-index: 1;
top: 5px !important;
z-index: 1 !important;
}
.notify.in {
opacity: .9;
bottom: 5px;
opacity: .9 !important;
bottom: 5px !important;
}
.btn-group-justified .dropdown-toggle>span:not(.close) {
width: calc(100% - 18px);
display: inline-block;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
margin-bottom: -4px;
width: calc(100% - 18px) !important;
display: inline-block !important;
overflow: hidden !important;
white-space: nowrap !important;
text-overflow: ellipsis !important;
margin-bottom: -4px !important;
}
.btn-group-justified .dropdown-menu { width: 100%; }
.dropdown-menu { width: 100% !important; }
</style>