1
0
mirror of https://gitlab.com/bramw/baserow.git synced 2024-11-22 07:42:36 +00:00
bramw_baserow/web-frontend/modules/database/services/view/bufferedRows.js

130 lines
2.8 KiB
JavaScript

import addPublicAuthTokenHeader from '@baserow/modules/database/utils/publicView'
export default (client, storePrefix) => {
return {
fetchRows({
viewId,
limit = 100,
offset = null,
includeFieldOptions = false,
includeRowMetadata = true,
search = '',
searchMode = '',
signal = null,
publicUrl = false,
publicAuthToken = null,
orderBy = null,
filters = {},
includeFields = [],
excludeFields = [],
}) {
const params = new URLSearchParams()
params.append('limit', limit)
const include = []
if (offset !== null) {
params.append('offset', offset)
}
if (includeFieldOptions) {
include.push('field_options')
}
if (includeRowMetadata) {
include.push('row_metadata')
}
if (include.length > 0) {
params.append('include', include.join(','))
}
if (search) {
params.append('search', search)
if (searchMode) {
params.append('search_mode', searchMode)
}
}
if (orderBy || orderBy === '') {
params.append('order_by', orderBy)
}
if (includeFields.length > 0) {
params.append('include_fields', includeFields.join(','))
}
if (excludeFields.length > 0) {
params.append('exclude_fields', excludeFields.join(','))
}
Object.keys(filters).forEach((key) => {
filters[key].forEach((value) => {
params.append(key, value)
})
})
const config = { params }
if (publicAuthToken) {
addPublicAuthTokenHeader(config, publicAuthToken)
}
if (signal !== null) {
config.signal = signal
}
const url = publicUrl ? 'public/rows/' : ''
return client.get(
`/database/views/${storePrefix}/${viewId}/${url}`,
config
)
},
fetchCount({
viewId,
search = '',
searchMode = '',
signal = null,
publicUrl = false,
publicAuthToken = null,
filters = {},
}) {
const params = new URLSearchParams()
params.append('count', true)
if (search) {
params.append('search', search)
if (searchMode) {
params.append('search_mode', searchMode)
}
}
Object.keys(filters).forEach((key) => {
filters[key].forEach((value) => {
params.append(key, value)
})
})
const config = { params }
if (signal !== null) {
config.signal = signal
}
if (publicAuthToken) {
addPublicAuthTokenHeader(config, publicAuthToken)
}
const url = publicUrl ? 'public/rows/' : ''
return client.get(
`/database/views/${storePrefix}/${viewId}/${url}`,
config
)
},
}
}