@progress/kendo-angular-scheduler
Version:
Kendo UI Scheduler Angular - Outlook or Google-style angular scheduler calendar. Full-featured and customizable embedded scheduling from the creator developers trust for professional UI components.
108 lines (107 loc) • 4.21 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { getField } from '../common/util';
import { parseRule, serializeRule } from '@progress/kendo-recurrence';
/**
* @hidden
*/
export const markAllAsTouched = (control) => {
control.markAsTouched();
if (control.hasOwnProperty('controls')) {
const controls = control.controls;
for (const inner in controls) {
if (controls.hasOwnProperty(inner)) {
markAllAsTouched(controls[inner]);
}
}
}
};
/**
* @hidden
*/
export function diff(obj1, obj2, fields) {
for (let idx = 0; idx < fields.length; idx++) {
const field = fields[idx];
if (!areEqual(getField(obj1, field), getField(obj2, field))) {
return true;
}
}
return false;
}
/**
* @hidden
*/
export function areEqual(value1, value2) {
if (value1 && value1.getTime && value2 && value2.getTime) {
return value1.getTime() === value2.getTime();
}
else if (Array.isArray(value1)) {
if (!Array.isArray(value2) || value1.length !== value2.length) {
return false;
}
for (let idx = 0; idx < value1.length; idx++) {
if (value1[idx] !== value2[idx]) {
return false;
}
}
return true;
}
return value1 == value2;
}
const DATE_ACCESSORS = ['getFullYear', 'getMonth', 'getDate', 'getHours', 'getMinutes', 'getSeconds', 'getMilliseconds'];
/**
* @hidden
*/
export function seriesDate(head, occurrence, current, field) {
const values = [];
const headDate = getField(head, field);
const occurrenceDate = getField(occurrence, field);
const currentDate = getField(current, field);
DATE_ACCESSORS.forEach(accessor => {
values.push(occurrenceDate[accessor]() === currentDate[accessor]() ? headDate[accessor]() : currentDate[accessor]());
});
return new Date(...values);
}
/**
* @hidden
*/
export function updateRecurrenceRule(valueSrc, valueGoal) {
const rrule = parseRule({ recurrenceRule: valueSrc.recurrenceRule });
// parseRule sets weekStart to 0 if not present which then adds it to the serialized rule
if (!valueSrc.recurrenceRule.includes("WKST")) {
rrule.weekStart = undefined;
}
if (valueSrc.start?.getDate() !== valueGoal.start?.getDate()) {
if (rrule.byYearDay?.length > 0) {
// when the event is recurring on more than one day of the year
const itemIndex = rrule.byYearDay.findIndex(yearDay => yearDay === valueSrc.start?.getDate());
if (itemIndex !== -1) {
rrule.byYearDay[itemIndex] = valueGoal.start?.getDate();
}
}
if (rrule.byMonthDay?.length > 0) {
// when the event is recurring on more than one day of the month
const itemIndex = rrule.byMonthDay.findIndex(monthDay => monthDay === valueSrc.start?.getDate());
if (itemIndex !== -1) {
rrule.byMonthDay[itemIndex] = valueGoal.start?.getDate();
}
}
}
if (valueSrc.start?.getDay() !== valueGoal.start?.getDay() && rrule.byWeekDay?.length > 0) {
// when the event is recurring on more than one day of the week
const itemIndex = rrule.byWeekDay.findIndex(weekDayRule => weekDayRule.day === valueSrc.start?.getDay());
if (itemIndex !== -1) {
rrule.byWeekDay[itemIndex].day = valueGoal.start?.getDay();
}
}
if (valueSrc.start?.getMonth() !== valueGoal.start?.getMonth() && rrule.byMonth?.length > 0) {
// when the event is recurring on more than one month of the year
const itemIndex = rrule.byMonth.findIndex(month => month === valueSrc.start?.getMonth());
if (itemIndex !== -1) {
rrule.byMonth[itemIndex] = valueGoal.start?.getMonth();
}
}
return serializeRule(rrule);
}