c16d633d4b
refs https://github.com/TryGhost/Ghost/issues/7860 - remove preview pane from content screen - add basic post status filters - replace custom infinite scroll with ember-infinity and increase trigger threshold for improved scroll behaviour Commits: * basic content list + filter using existing infinite scroll and pagination * swap our custom pagination + infinite loader for `ember-infinity` * minor cleanups * reset scroll position when changing filter * fix tests * remove client-side sorting step as we no longer have a live collection * remove unused `mobile-index-route` * add acceptance tests for content screen filters
67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
/* eslint-disable max-statements-per-line */
|
|
import {Response} from 'ember-cli-mirage';
|
|
|
|
export function paginatedResponse(modelName) {
|
|
return function (schema, request) {
|
|
let page = +request.queryParams.page || 1;
|
|
let limit = +request.queryParams.limit || 15;
|
|
let allModels = this.serialize(schema[modelName].all())[modelName];
|
|
|
|
return paginateModelArray(modelName, allModels, page, limit);
|
|
};
|
|
}
|
|
|
|
export function paginateModelArray(modelName, allModels, page, limit) {
|
|
let pages, next, prev, models;
|
|
|
|
if (limit === 'all') {
|
|
pages = 1;
|
|
} else {
|
|
limit = +limit;
|
|
|
|
let start = (page - 1) * limit;
|
|
let end = start + limit;
|
|
|
|
pages = Math.ceil(allModels.length / limit);
|
|
models = allModels.slice(start, end);
|
|
|
|
if (start > 0) {
|
|
prev = page - 1;
|
|
}
|
|
|
|
if (end < allModels.length) {
|
|
next = page + 1;
|
|
}
|
|
}
|
|
|
|
return {
|
|
meta: {
|
|
pagination: {
|
|
page,
|
|
limit,
|
|
pages,
|
|
total: allModels.length,
|
|
next: next || null,
|
|
prev: prev || null
|
|
}
|
|
},
|
|
[modelName]: models || allModels
|
|
};
|
|
}
|
|
|
|
export function maintenanceResponse() {
|
|
return new Response(503, {}, {
|
|
errors: [{
|
|
errorType: 'Maintenance'
|
|
}]
|
|
});
|
|
}
|
|
|
|
export function versionMismatchResponse() {
|
|
return new Response(400, {}, {
|
|
errors: [{
|
|
errorType: 'VersionMismatchError'
|
|
}]
|
|
});
|
|
}
|