Release 1.5.13
This commit is contained in:
@@ -15,10 +15,39 @@ module.exports = function registerScreensRoutes(app, deps) {
|
||||
};
|
||||
}
|
||||
|
||||
function applyConnectionCounts(screens, dashboardScreens) {
|
||||
const countsById = new Map();
|
||||
const countsBySlug = new Map();
|
||||
|
||||
(dashboardScreens || []).forEach(function (screen) {
|
||||
const count = Number(screen && screen.player_connection_count || 0);
|
||||
const id = screen && screen.id !== undefined && screen.id !== null ? String(screen.id) : '';
|
||||
const slug = String(screen && screen.slug || '').trim();
|
||||
|
||||
if (id) {
|
||||
countsById.set(id, count);
|
||||
}
|
||||
if (slug) {
|
||||
countsBySlug.set(slug, count);
|
||||
}
|
||||
});
|
||||
|
||||
return (screens || []).map(function (screen) {
|
||||
const slug = String(screen && screen.slug || '').trim();
|
||||
const id = screen && screen.id !== undefined && screen.id !== null ? String(screen.id) : '';
|
||||
const playerConnectionCount = countsBySlug.has(slug)
|
||||
? countsBySlug.get(slug)
|
||||
: countsById.get(id) || 0;
|
||||
|
||||
return Object.assign({}, screen, {
|
||||
player_connection_count: playerConnectionCount
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
app.get('/screens', requireQueryPermission('screens.read', 'screens.update'), async function (req, res, next) {
|
||||
try {
|
||||
if (req.query.edit) {
|
||||
const data = await buildDashboardState(pool);
|
||||
const screen = await common.fetchScreenById(pool, Number(req.query.edit));
|
||||
if (!screen) {
|
||||
return res.status(404).send('Screen not found');
|
||||
@@ -27,10 +56,14 @@ module.exports = function registerScreensRoutes(app, deps) {
|
||||
return res.send(pages.renderScreenEditPage(screen, editData, req.query.message ? String(req.query.message) : '', req.currentUser));
|
||||
}
|
||||
const page = Math.max(1, Math.floor(Number(req.query.page) || 1));
|
||||
const data = await common.fetchScreensPage(pool, page, LIST_PAGE_SIZE);
|
||||
const search = common.getSearchQuery(req);
|
||||
const sort = common.getSortQuery(req);
|
||||
const direction = common.getSortDirectionQuery(req);
|
||||
const dashboardState = await buildDashboardState(pool);
|
||||
const data = await common.fetchScreensPage(pool, page, LIST_PAGE_SIZE, search, sort, direction);
|
||||
res.send(pages.renderScreensPage({
|
||||
screens: data.screens || [],
|
||||
pagination: buildPagination(data.totalItems, data.currentPage, 'page', {}, LIST_PAGE_SIZE, 'screens', 'Screen pages')
|
||||
screens: applyConnectionCounts(data.screens || [], dashboardState.screens || []),
|
||||
pagination: buildPagination(data.totalItems, data.currentPage, 'page', { search: search, sort: sort, direction: direction }, LIST_PAGE_SIZE, 'screens', 'Screen pages')
|
||||
}, req.query.message ? String(req.query.message) : '', req.currentUser));
|
||||
} catch (error) {
|
||||
next(error);
|
||||
|
||||
Reference in New Issue
Block a user