UNPKG

@hicoder/angular-cli

Version:

Angular UI componenets and service generator. It works with the mean-rest-express package to generate the end to end web application. The input to this generator is the Mongoose schema defined for the express application. mean-rest-express exposes the Res

96 lines (87 loc) 2.33 kB
const logger = require('./log'); const calendarOpts = [ 'calendarTitle', 'calendarGroup', 'calendarStartTime', 'calendarEndTime', 'calendarRepeat', 'calendarRepeatStart', 'calendarRepeatEnd', ]; function checkCalendarOpts(API, schemaName, view) { if (!['L', 'R', 'U', 'C'].includes(API)) { return false; } let optNums = {}; for (let opt of calendarOpts) { optNums[opt] = 0; } let hasCalendar = false; let calendarObj = {}; for (let opt of calendarOpts) { for (let f of view) { if (f[opt]) { hasCalendar = true; optNums[opt]++; calendarObj[opt] = f.fieldName; f.calendarObj = calendarObj; } } } if (!hasCalendar) { return false; } for (let opt of calendarOpts) { let optNum = optNums[opt]; if (optNum > 1) { logger.error( `${schemaName} ${API} - more than one field are defined for ${opt}` ); hasCalendar = false; } if (optNum == 0) { logger.error( `${schemaName} ${API} - to use calendar, a field needs to be defined for ${opt}` ); hasCalendar = false; } } if (!hasCalendar) { return false; } for (let f of view) { if ((f.calendarStartTime || f.calendarEndTime) && f.type !== 'SchemaDate') { logger.error( `${schemaName} ${API}:${f.fieldName} - calendarStartTime and calendarEndTime must be on a Date field.` ); hasCalendar = false; } if ((f.calendarRepeatStart || f.calendarRepeatEnd) && f.type !== 'SchemaDate') { logger.error( `${schemaName} ${API}:${f.fieldName} - calendarRepeatStart and calendarRepeatEnd must be on a Date field.` ); hasCalendar = false; } if ( (f.calendarTitle || f.calendarGroup || f.calendarRepeat) && f.type !== 'SchemaString' ) { logger.error( `${schemaName} ${API}:${f.fieldName} - calendarTitle, calendarGroup and calendarRepeat must be on a String field.` ); hasCalendar = false; } } return [hasCalendar, calendarObj]; } const defaultCalendarOptions = { listCalendarRoute: false, isReadOnly: false, defaultView: 'month', // 'month', 'week', 'day' weekHourRange: [0, 24], // [9, 21] }; module.exports = { calendarOpts, checkCalendarOpts, defaultCalendarOptions, };