Added support for negative page num

e.g. -1 means last page, -2 means the 2nd from last, and so on
will only accept up to -N where N is the amount of pages
anything lower will alwasy return the first page
this works for both list uploads and list users APIs

fixed some Object.assign in dashboard.js

added bottom control buttons in manage users
This commit is contained in:
Bobby Wibowo 2020-05-02 22:42:23 +07:00
parent 89e5f775ec
commit 41d52d947b
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
6 changed files with 35 additions and 15 deletions

View File

@ -370,8 +370,9 @@ self.listUsers = async (req, res, next) => {
if (!count)
return res.json({ success: true, users: [], count })
let offset = req.params.page
if (offset === undefined) offset = 0
let offset = Number(req.params.page)
if (isNaN(offset)) offset = 0
else if (offset < 0) offset = Math.max(0, Math.ceil(count / 25) + offset)
const users = await db.table('users')
.limit(25)

View File

@ -1021,8 +1021,9 @@ self.list = async (req, res) => {
if (!count)
return res.json({ success: true, files: [], count })
let offset = req.params.page
if (offset === undefined) offset = 0
let offset = Number(req.params.page)
if (isNaN(offset)) offset = 0
else if (offset < 0) offset = Math.max(0, Math.ceil(count / 25) + offset)
const columns = ['id', 'name', 'userid', 'size', 'timestamp']
if (temporaryUploads)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1119,9 +1119,9 @@ page.deleteUpload = id => {
// Reload upload list
// eslint-disable-next-line compat/compat
page.getUploads(Object.assign({
page.getUploads(Object.assign(page.views[page.currentView], {
autoPage: true
}, page.views[page.currentView]))
}))
}
})
}
@ -1153,9 +1153,9 @@ page.bulkDeleteUploads = () => {
// Reload uploads list
// eslint-disable-next-line compat/compat
page.getUploads(Object.assign({
page.getUploads(Object.assign(page.views[page.currentView], {
autoPage: true
}, page.views[page.currentView]))
}))
}
})
}
@ -1904,6 +1904,7 @@ page.getUsers = (params = {}) => {
page.currentView = 'users'
page.cache.users = {}
if (params.pageNum < 0) params.pageNum = Math.max(0, pages + params.pageNum)
const pagination = page.paginate(response.data.count, 25, params.pageNum)
const filter = `
@ -1984,6 +1985,17 @@ page.getUsers = (params = {}) => {
</div>
`
// Do some string replacements for bottom controls
const bottomFiltersId = 'bFilters'
const bottomJumpId = 'bJumpToPage'
const bottomExtraControls = extraControls
.replace(/id="filters"/, `id="${bottomFiltersId}"`)
.replace(/(data-action="filter-uploads")/, `$1 data-filtersid="${bottomFiltersId}"`)
.replace(/id="jumpToPage"/, `id="${bottomJumpId}"`)
.replace(/(data-action="jump-to-page")/g, `$1 data-jumpid="${bottomJumpId}"`)
const bottomPagination = pagination
.replace(/(data-action="page-ellipsis")/g, `$1 data-jumpid="${bottomJumpId}"`)
// Whether there are any unselected items
let unselected = false
@ -2007,7 +2019,9 @@ page.getUsers = (params = {}) => {
</tbody>
</table>
</div>
${pagination}
${controls}
${bottomExtraControls}
${bottomPagination}
`
const table = document.querySelector('#table')
@ -2156,7 +2170,11 @@ page.createUser = () => {
content: div
})
page.getUsers(page.views.users)
// Reload users list
// eslint-disable-next-line compat/compat
page.getUsers(Object.assign(page.views.users, {
pageNum: -1
}))
}).catch(page.onAxiosError)
})
}
@ -2372,9 +2390,9 @@ page.deleteUser = id => {
// Reload users list
// eslint-disable-next-line compat/compat
page.getUsers(Object.assign({
page.getUsers(Object.assign(page.views.users, {
autoPage: true
}, page.views.users))
}))
}).catch(page.onAxiosError)
})
}

View File

@ -1,5 +1,5 @@
{
"1": "1588432149",
"1": "1588434130",
"2": "1581416390",
"3": "1581416390",
"4": "1581416390",