UNPKG

react-application-core

Version:

A react-based application core for the business applications.

231 lines 8.63 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var _a; Object.defineProperty(exports, "__esModule", { value: true }); exports.CronField = void 0; var React = require("react"); var R = require("ramda"); var util_1 = require("../../../util"); var field_component_1 = require("../field/field.component"); var definition_1 = require("../../../definition"); var calendar_1 = require("../../calendar"); /** * @component-impl * @stable [28.12.2020] */ var CronField = /** @class */ (function (_super) { __extends(CronField, _super); /** * @stable [28.12.2020] * @param originalProps */ function CronField(originalProps) { var _this = _super.call(this, originalProps) || this; _this.getCalendarCellElement = _this.getCalendarCellElement.bind(_this); _this.onDaySelect = _this.onDaySelect.bind(_this); return _this; } /** * @stable [28.12.2020] * @param value * @protected */ CronField.prototype.isValueDefined = function (value) { return !R.isNil(value); }; Object.defineProperty(CronField.prototype, "defaultValue", { /** * @stable [15.12.2019] * @returns {string} */ get: function () { var _this = this; var _a = this.originalProps, defaultValue = _a.defaultValue, period = _a.period; return util_1.TypeUtils.isDef(defaultValue) ? defaultValue : (util_1.ConditionUtils.ifNotNilThanValue(CronField.DEFAULT_VALUES_FACTORIES[period], function (factory) { return factory(_this.returnNeverExecutablePeriodAsEmptyValue); }, defaultValue)); }, enumerable: false, configurable: true }); Object.defineProperty(CronField.prototype, "inputAttachmentElement", { /** * @stable [28.12.2020] * @protected */ get: function () { var _this = this; var cronEntity = this.newCronEntity; return (React.createElement(calendar_1.Calendar, { showOnlyCurrentDays: true, selectedDays: this.days.filter(function (day) { return _this.isDaySelected(cronEntity, day); }), className: definition_1.CronFieldClassesEnum.CALENDAR, gridConfiguration: { wrapperClassName: definition_1.CronFieldClassesEnum.CALENDAR_WRAPPER, }, calendarEntity: this.calendarEntity, renderer: this.getCalendarCellElement, onSelect: this.onDaySelect })); }, enumerable: false, configurable: true }); /** * @stable [28.12.2020] * @protected */ CronField.prototype.getFieldClassName = function () { return util_1.ClsUtils.joinClassName(_super.prototype.getFieldClassName.call(this), definition_1.CronFieldClassesEnum.CRON_FIELD); }; /** * @stable [28.12.2020] * @param calendarDayEntity * @private */ CronField.prototype.onDaySelect = function (calendarDayEntity) { var cronDay = calendarDayEntity.cronDay, day = calendarDayEntity.day; var period = this.originalProps.period; var cronEntity = this.newCronEntity; switch (period) { case definition_1.CronPeriodsEnum.WEEKLY: if (cronEntity.hasDayOfWeek(cronDay)) { cronEntity.excludeDaysOfWeeks(cronDay); } else { cronEntity.addDaysOfWeeks(cronDay); } break; case definition_1.CronPeriodsEnum.MONTHLY: if (cronEntity.hasDayOfMonth(day)) { cronEntity.excludeDaysOfMonths(day); } else { cronEntity.addDaysOfMonths(day); } break; } this.onChangeManually(cronEntity.toExpression(this.returnNeverExecutablePeriodAsEmptyValue)); }; Object.defineProperty(CronField.prototype, "returnNeverExecutablePeriodAsEmptyValue", { /** * @stable [28.12.2020] * @private */ get: function () { return this.originalProps.returnNeverExecutablePeriodAsEmptyValue; }, enumerable: false, configurable: true }); /** * @stable [28.12.2020] * @param entity * @param day * @private */ CronField.prototype.isDaySelected = function (entity, day) { switch (this.originalProps.period) { case definition_1.CronPeriodsEnum.WEEKLY: return entity.hasDayOfWeek(this.dc.asCronDay({ index: day, isoWeek: this.isoWeek })); } return entity.hasDayOfMonth(day); }; /** * @stable [28.12.2020] * @param weekDayEntity * @private */ CronField.prototype.getCalendarCellElement = function (weekDayEntity) { var date = weekDayEntity.date, day = weekDayEntity.day; return (React.createElement(React.Fragment, null, date ? date.getDate() : this.dc.getWeekdayShortest({ index: day, isoWeek: this.isoWeek }))); }; Object.defineProperty(CronField.prototype, "calendarEntity", { /** * @stable [28.12.2020] * @private */ get: function () { switch (this.originalProps.period) { case definition_1.CronPeriodsEnum.WEEKLY: return this.dc.asCalendarWeekEntity({ isoWeek: this.isoWeek }); } return null; }, enumerable: false, configurable: true }); Object.defineProperty(CronField.prototype, "days", { /** * @stable [28.12.2020] * @private */ get: function () { switch (this.originalProps.period) { case definition_1.CronPeriodsEnum.WEEKLY: return definition_1.CRON_ALL_DAYS_OF_WEEK_VALUES; } return definition_1.CRON_ALL_DAYS_OF_MONTH_VALUES; }, enumerable: false, configurable: true }); Object.defineProperty(CronField.prototype, "newCronEntity", { /** * @stable [28.12.2020] * @private */ get: function () { return util_1.CronEntity.newInstance().fromExpression(this.value); }, enumerable: false, configurable: true }); Object.defineProperty(CronField.prototype, "isoWeek", { /** * @stable [28.12.2020] * @private */ get: function () { return this.originalProps.isoWeek; }, enumerable: false, configurable: true }); /** * @stable [28.12.2020] */ CronField.defaultProps = util_1.PropsUtils.mergeWithParentDefaultProps({ period: definition_1.CronPeriodsEnum.MONTHLY, returnNeverExecutablePeriodAsEmptyValue: true, type: 'hidden', }, field_component_1.Field); /** * @stable [28.12.2020] */ CronField.DEFAULT_VALUES_FACTORIES = (_a = {}, _a[definition_1.CronPeriodsEnum.MONTHLY] = function (returnNeverExecutablePeriodAsEmptyValue) { return util_1.CronEntity.newInstance() .withMinutes(0) .withHours(0) .withDaysOfMonths() .toExpression(returnNeverExecutablePeriodAsEmptyValue); }, _a[definition_1.CronPeriodsEnum.WEEKLY] = function (returnNeverExecutablePeriodAsEmptyValue) { return util_1.CronEntity.newInstance() .withMinutes(0) .withHours(0) .withDaysOfWeeks() .toExpression(returnNeverExecutablePeriodAsEmptyValue); }, _a); return CronField; }(field_component_1.Field)); exports.CronField = CronField; //# sourceMappingURL=cron-field.component.js.map