Implement schedule WYSIWYG and UTC dates
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
// Schedule group add/edit renderer and defaults.
|
||||
|
||||
const { renderView } = require('../../../view');
|
||||
|
||||
function buildDefaultScheduleGroup() {
|
||||
return {
|
||||
id: null,
|
||||
name: '',
|
||||
shortDescription: ''
|
||||
};
|
||||
}
|
||||
|
||||
function formatDateTimeLocalValue(value) {
|
||||
if (!value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const year = String(date.getFullYear()).padStart(4, '0');
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}T${hours}:${minutes}`;
|
||||
}
|
||||
|
||||
module.exports = function renderScheduleGroupFormPage(scheduleGroup, scheduleEntries, mode, message, currentUser) {
|
||||
const isEdit = mode === 'edit';
|
||||
const viewScheduleGroup = Object.assign(buildDefaultScheduleGroup(), scheduleGroup || {});
|
||||
const viewScheduleEntries = Array.isArray(scheduleEntries) && scheduleEntries.length
|
||||
? scheduleEntries.map(function (entry) {
|
||||
return Object.assign({}, entry, {
|
||||
startValue: formatDateTimeLocalValue(entry.start_datetime),
|
||||
endValue: formatDateTimeLocalValue(entry.end_datetime)
|
||||
});
|
||||
})
|
||||
: [{ id: null, title: '', short_description: '', startValue: '', endValue: '', sort_order: 0 }];
|
||||
|
||||
return renderView('data-sources/schedules/form', {
|
||||
title: isEdit ? 'Edit schedule group' : 'Add schedule group',
|
||||
active: 'schedules',
|
||||
message: message,
|
||||
currentUser: currentUser || null,
|
||||
isEdit: isEdit,
|
||||
scheduleGroup: viewScheduleGroup,
|
||||
scheduleEntries: viewScheduleEntries,
|
||||
inUse: Boolean(viewScheduleGroup.inUse),
|
||||
assetVersion: Date.now().toString(36)
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
// Schedule 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 renderScheduleGroupsPage(data, message, currentUser, formatDashboardDate) {
|
||||
const scheduleGroups = (data.scheduleGroups || []).map(function (scheduleGroup) {
|
||||
return Object.assign({}, scheduleGroup, {
|
||||
nextStartLabel: formatNextStartLabel(scheduleGroup.next_start_datetime, formatDashboardDate),
|
||||
nextStartValue: scheduleGroup.next_start_datetime ? new Date(scheduleGroup.next_start_datetime).toISOString() : ''
|
||||
});
|
||||
});
|
||||
|
||||
return renderView('data-sources/schedules/list', {
|
||||
title: 'Schedules',
|
||||
active: 'schedules',
|
||||
message: message,
|
||||
currentUser: currentUser || null,
|
||||
scheduleGroups: scheduleGroups,
|
||||
pagination: data.pagination || null
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user