Skip to content
This repository has been archived by the owner on May 31, 2019. It is now read-only.

Commit

Permalink
User paging.
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Feb 4, 2016
1 parent a9edc09 commit fcfbc90
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 15 additions & 1 deletion client/views/admin/users/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'
import moment from 'moment'
import {withParams} from '../../../url'

export default ({search, users}) => {
export default ({more, page, search, url, users}) => {
return <div>
<a href='/admin/users/new' className='btn btn-sm btn-default pull-right'>
New User
Expand Down Expand Up @@ -50,5 +51,18 @@ export default ({search, users}) => {
})}
</tbody>
</table>
<hr/>
{more
? <a href={withParams(url, {page: page + 1})} className='pull-right'>
Next Page →
</a>
: ''
}
{page > 1
? <a href={withParams(url, {page: page - 1})}>
← Previous Page
</a>
: ''
}
</div>
}
12 changes: 10 additions & 2 deletions routes/admin/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ router.find('user_id', '_user', () => db.User.select(`exists(
router.get('/', (req, res) => {
let users = db.User

// Search
if (req.query.search) {
users = users.where(
"search @@ to_tsquery('simple', ?)", `${req.query.search}:*`
)
}

users.order('email').all().then((users) => {
res.react({users: users})
// Pagination
const page = res.locals.page = +(req.query.page || 1)

users.order('email').paginate(page, 100).then((users) => {
res.react({
more: users.more,
page: page,
users: users
})
}).catch(res.error)
})

Expand Down

0 comments on commit fcfbc90

Please sign in to comment.