add dragging to catalog contents
This commit is contained in:
45
cateditor/src/pagination.js
Normal file
45
cateditor/src/pagination.js
Normal file
@ -0,0 +1,45 @@
|
||||
|
||||
export function paginateModels(models) {
|
||||
for (let model of models) {
|
||||
// ensure sizes
|
||||
model.size = modelSize(model)
|
||||
}
|
||||
|
||||
let pages = []
|
||||
let currentSize = 0
|
||||
let currentPage = []
|
||||
for (let model of models) {
|
||||
currentSize += model.size
|
||||
if (currentSize > 3) {
|
||||
pages.push(currentPage)
|
||||
currentPage = [model]
|
||||
currentSize = model.size
|
||||
} else {
|
||||
currentPage.push(model)
|
||||
}
|
||||
}
|
||||
if (currentPage.length > 0) {
|
||||
pages.push(currentPage)
|
||||
}
|
||||
|
||||
return pages
|
||||
}
|
||||
|
||||
export function modelSize(model) {
|
||||
if (!model || !model.ids) return 0
|
||||
if (model.ids.length <= 4) return 1
|
||||
if (model.ids.length <= 8) return 2
|
||||
return 3
|
||||
}
|
||||
|
||||
export function sectionModels(section) {
|
||||
// remove pages, return models (blocks) in order
|
||||
let models = []
|
||||
if (section && section.pages) {
|
||||
for (let page of section.pages) {
|
||||
models.push(...page)
|
||||
}
|
||||
}
|
||||
|
||||
return models
|
||||
}
|
||||
Reference in New Issue
Block a user