mirror of
https://github.com/astaxie/beego.git
synced 2025-06-21 15:40:17 +00:00
remove pkg directory;
remove build directory; remove githook directory;
This commit is contained in:
.travis.ymldoc.go
adapter
admin.goapp.gobeego.gobuild_info.gopolicy.gorouter.go
cache
config.goconfig
context
controller.godoc.goerror.gofilter.goflash.gofs.gograce
httplib
log.gologs
metric
migration
namespace.goorm
cmd.godb.godb_alias.gomodels.gomodels_boot.gomodels_fields.goorm.goorm_conds.goorm_log.goorm_queryset.goqb.goqb_mysql.goqb_tidb.goquery_setter_adapter.gotypes.goutils.goutils_test.go
plugins
apiauth
auth
authz
cors
session
couchbase
ledis
memcache
mysql
postgres
provider_adapter.goredis
redis_cluster
redis_sentinel
sess_cookie.gosess_cookie_test.gosess_file.gosess_file_test.gosess_mem.gosess_mem_test.gosess_test.gosess_utils.gosession.gossdb
store_adapter.goswagger
template.gotemplatefunc.gotemplatefunc_test.gotesting
toolbox
tree.gotree_test.goutils
caller.gocaller_test.go
captcha
debug.godebug_test.gofile.gomail.gomail_test.gopagination
rand.gorand_test.gosafemap.gosafemap_test.goslice.goslice_test.goutils.govalidation
build
build_info.goclient
cache
httplib
orm
README.mdcmd.gocmd_utils.godb.godb_alias.godb_alias_test.godb_mysql.godb_oracle.godb_postgres.godb_sqlite.godb_tables.godb_tidb.godb_utils.godo_nothing_orm.godo_nothing_orm_test.gofilter.gofilter_orm_decorator.gofilter_orm_decorator_test.gofilter_test.go
filter
bean
opentracing
prometheus
hints
invocation.gomigration
model_utils_test.gomodels.gomodels_boot.gomodels_fields.gomodels_info_f.gomodels_info_m.gomodels_test.gomodels_utils.gomodels_utils_test.goorm.goorm_conds.goorm_log.goorm_object.goorm_querym2m.goorm_queryset.goorm_raw.goorm_test.goqb.goqb_mysql.goqb_postgres.goqb_tidb.gotypes.goutils.goutils_test.gocore
bean
context.godoc.gofactory.gometadata.gotag_auto_wire_bean_factory.gotag_auto_wire_bean_factory_test.gotime_type_adapter.gotime_type_adapter_test.gotype_adapter.go
config
governor
logs
README.mdaccess_log.goaccess_log_test.go
alils
alils.goconfig.golog.pb.golog_config.golog_project.golog_store.gomachine_group.gorequest.gosignature.go
conn.goconn_test.goconsole.goconsole_test.goes
file.gofile_test.goformatter.goformatter_test.gojianliao.gojianliao_test.golog.golog_msg.golog_msg_test.golog_test.gologger.gologger_test.gomultifile.gomultifile_test.goslack.gosmtp.gosmtp_test.goutils
caller.gocaller_test.godebug.godebug_test.gofile.gofile_test.gokv.gokv_test.gomail.gomail_test.go
pagination
rand.gorand_test.gosafemap.gosafemap_test.goslice.goslice_test.gotestdata
time.goutils.goutils_test.govalidation
githook
pkg/adapter/logs
server/web
LICENSEadmin.goadmin_controller.goadmin_test.goadminui.gobeego.gofilter_chain_test.gofilter_test.goflash.goflash_test.gofs.go
captcha
config.goconfig_test.gocontext
acceptencoder.goacceptencoder_test.gocontext.gocontext_test.goinput.goinput_test.gooutput.go
controller.gocontroller_test.godoc.goerror.goerror_test.gofilter.goparam
renderer.goresponse.gofilter
apiauth
auth
authz
cors
opentracing
prometheus
grace
hooks.gomime.gonamespace.gonamespace_test.gopagination
parser.gopolicy.gorouter.gorouter_test.goserver.goserver_test.gosession
README.md
staticfile.gostaticfile_test.gostatistics.gostatistics_test.gocouchbase
ledis
memcache
mysql
postgres
redis
redis_cluster
redis_sentinel
sess_cookie.gosess_cookie_test.gosess_file.gosess_file_test.gosess_mem.gosess_mem_test.gosess_test.gosess_utils.gosession.gossdb
swagger
template.gotemplate_test.gotemplatefunc.gotemplatefunc_test.gotree.gotree_test.gounregroute_test.gotask
26
adapter/utils/pagination/controller.go
Normal file
26
adapter/utils/pagination/controller.go
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2014 beego Author. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package pagination
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/adapter/context"
|
||||
beecontext "github.com/astaxie/beego/server/web/context"
|
||||
"github.com/astaxie/beego/server/web/pagination"
|
||||
)
|
||||
|
||||
// SetPaginator Instantiates a Paginator and assigns it to context.Input.Data("paginator").
|
||||
func SetPaginator(ctx *context.Context, per int, nums int64) (paginator *Paginator) {
|
||||
return (*Paginator)(pagination.SetPaginator((*beecontext.Context)(ctx), per, nums))
|
||||
}
|
58
adapter/utils/pagination/doc.go
Normal file
58
adapter/utils/pagination/doc.go
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
Package pagination provides utilities to setup a paginator within the
|
||||
context of a http request.
|
||||
|
||||
Usage
|
||||
|
||||
In your beego.Controller:
|
||||
|
||||
package controllers
|
||||
|
||||
import "github.com/astaxie/beego/utils/pagination"
|
||||
|
||||
type PostsController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (this *PostsController) ListAllPosts() {
|
||||
// sets this.Data["paginator"] with the current offset (from the url query param)
|
||||
postsPerPage := 20
|
||||
paginator := pagination.SetPaginator(this.Ctx, postsPerPage, CountPosts())
|
||||
|
||||
// fetch the next 20 posts
|
||||
this.Data["posts"] = ListPostsByOffsetAndLimit(paginator.Offset(), postsPerPage)
|
||||
}
|
||||
|
||||
|
||||
In your view templates:
|
||||
|
||||
{{if .paginator.HasPages}}
|
||||
<ul class="pagination pagination">
|
||||
{{if .paginator.HasPrev}}
|
||||
<li><a href="{{.paginator.PageLinkFirst}}">{{ i18n .Lang "paginator.first_page"}}</a></li>
|
||||
<li><a href="{{.paginator.PageLinkPrev}}">«</a></li>
|
||||
{{else}}
|
||||
<li class="disabled"><a>{{ i18n .Lang "paginator.first_page"}}</a></li>
|
||||
<li class="disabled"><a>«</a></li>
|
||||
{{end}}
|
||||
{{range $index, $page := .paginator.Pages}}
|
||||
<li{{if $.paginator.IsActive .}} class="active"{{end}}>
|
||||
<a href="{{$.paginator.PageLink $page}}">{{$page}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
{{if .paginator.HasNext}}
|
||||
<li><a href="{{.paginator.PageLinkNext}}">»</a></li>
|
||||
<li><a href="{{.paginator.PageLinkLast}}">{{ i18n .Lang "paginator.last_page"}}</a></li>
|
||||
{{else}}
|
||||
<li class="disabled"><a>»</a></li>
|
||||
<li class="disabled"><a>{{ i18n .Lang "paginator.last_page"}}</a></li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{end}}
|
||||
|
||||
See also
|
||||
|
||||
http://beego.me/docs/mvc/view/page.md
|
||||
|
||||
*/
|
||||
package pagination
|
112
adapter/utils/pagination/paginator.go
Normal file
112
adapter/utils/pagination/paginator.go
Normal file
@ -0,0 +1,112 @@
|
||||
// Copyright 2014 beego Author. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package pagination
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/astaxie/beego/core/utils/pagination"
|
||||
)
|
||||
|
||||
// Paginator within the state of a http request.
|
||||
type Paginator pagination.Paginator
|
||||
|
||||
// PageNums Returns the total number of pages.
|
||||
func (p *Paginator) PageNums() int {
|
||||
return (*pagination.Paginator)(p).PageNums()
|
||||
}
|
||||
|
||||
// Nums Returns the total number of items (e.g. from doing SQL count).
|
||||
func (p *Paginator) Nums() int64 {
|
||||
return (*pagination.Paginator)(p).Nums()
|
||||
}
|
||||
|
||||
// SetNums Sets the total number of items.
|
||||
func (p *Paginator) SetNums(nums interface{}) {
|
||||
(*pagination.Paginator)(p).SetNums(nums)
|
||||
}
|
||||
|
||||
// Page Returns the current page.
|
||||
func (p *Paginator) Page() int {
|
||||
return (*pagination.Paginator)(p).Page()
|
||||
}
|
||||
|
||||
// Pages Returns a list of all pages.
|
||||
//
|
||||
// Usage (in a view template):
|
||||
//
|
||||
// {{range $index, $page := .paginator.Pages}}
|
||||
// <li{{if $.paginator.IsActive .}} class="active"{{end}}>
|
||||
// <a href="{{$.paginator.PageLink $page}}">{{$page}}</a>
|
||||
// </li>
|
||||
// {{end}}
|
||||
func (p *Paginator) Pages() []int {
|
||||
return (*pagination.Paginator)(p).Pages()
|
||||
}
|
||||
|
||||
// PageLink Returns URL for a given page index.
|
||||
func (p *Paginator) PageLink(page int) string {
|
||||
return (*pagination.Paginator)(p).PageLink(page)
|
||||
}
|
||||
|
||||
// PageLinkPrev Returns URL to the previous page.
|
||||
func (p *Paginator) PageLinkPrev() (link string) {
|
||||
return (*pagination.Paginator)(p).PageLinkPrev()
|
||||
}
|
||||
|
||||
// PageLinkNext Returns URL to the next page.
|
||||
func (p *Paginator) PageLinkNext() (link string) {
|
||||
return (*pagination.Paginator)(p).PageLinkNext()
|
||||
}
|
||||
|
||||
// PageLinkFirst Returns URL to the first page.
|
||||
func (p *Paginator) PageLinkFirst() (link string) {
|
||||
return (*pagination.Paginator)(p).PageLinkFirst()
|
||||
}
|
||||
|
||||
// PageLinkLast Returns URL to the last page.
|
||||
func (p *Paginator) PageLinkLast() (link string) {
|
||||
return (*pagination.Paginator)(p).PageLinkLast()
|
||||
}
|
||||
|
||||
// HasPrev Returns true if the current page has a predecessor.
|
||||
func (p *Paginator) HasPrev() bool {
|
||||
return (*pagination.Paginator)(p).HasPrev()
|
||||
}
|
||||
|
||||
// HasNext Returns true if the current page has a successor.
|
||||
func (p *Paginator) HasNext() bool {
|
||||
return (*pagination.Paginator)(p).HasNext()
|
||||
}
|
||||
|
||||
// IsActive Returns true if the given page index points to the current page.
|
||||
func (p *Paginator) IsActive(page int) bool {
|
||||
return (*pagination.Paginator)(p).IsActive(page)
|
||||
}
|
||||
|
||||
// Offset Returns the current offset.
|
||||
func (p *Paginator) Offset() int {
|
||||
return (*pagination.Paginator)(p).Offset()
|
||||
}
|
||||
|
||||
// HasPages Returns true if there is more than one page.
|
||||
func (p *Paginator) HasPages() bool {
|
||||
return (*pagination.Paginator)(p).HasPages()
|
||||
}
|
||||
|
||||
// NewPaginator Instantiates a paginator struct for the current http request.
|
||||
func NewPaginator(req *http.Request, per int, nums interface{}) *Paginator {
|
||||
return (*Paginator)(pagination.NewPaginator(req, per, nums))
|
||||
}
|
Reference in New Issue
Block a user