32 lines
1.0 KiB
JavaScript
32 lines
1.0 KiB
JavaScript
// Timetable group list page renderer.
|
|
|
|
const { renderView } = require('../../../view');
|
|
|
|
function formatNextStartLabel(value, formatDashboardDate) {
|
|
if (!value) {
|
|
return 'No entries';
|
|
}
|
|
|
|
const label = typeof formatDashboardDate === 'function'
|
|
? formatDashboardDate(value)
|
|
: String(value);
|
|
return label || 'No entries';
|
|
}
|
|
|
|
module.exports = function renderTimetableGroupsPage(data, message, currentUser, formatDashboardDate) {
|
|
const timetableGroups = (data.timetableGroups || []).map(function (timetableGroup) {
|
|
return Object.assign({}, timetableGroup, {
|
|
nextStartLabel: formatNextStartLabel(timetableGroup.next_start_datetime, formatDashboardDate),
|
|
nextStartValue: timetableGroup.next_start_datetime ? new Date(timetableGroup.next_start_datetime).toISOString() : ''
|
|
});
|
|
});
|
|
|
|
return renderView('data-sources/timetables/list', {
|
|
title: 'Timetables',
|
|
active: 'timetables',
|
|
message: message,
|
|
currentUser: currentUser || null,
|
|
timetableGroups: timetableGroups,
|
|
pagination: data.pagination || null
|
|
});
|
|
}; |