UNPKG

@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.

90 lines (89 loc) 2.89 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { groupBy, orderBy } from '@progress/kendo-data-query'; import { iterator } from '../../common/util'; const flip = fn => a => b => fn(b, a); const sort = flip(orderBy); const group = flip(groupBy); /** * @hidden */ export const compose = (...args) => (data) => args.reduceRight((acc, curr) => curr(acc), data); /** * @hidden */ export const processEvents = (_start, _end) => compose(group([{ field: "startDate" }]), sort([{ field: "start", dir: "asc" }, { field: "end", dir: "asc" }])); function flattenGroupsAndAddIds(scope) { return function* flattenGroups(groups) { for (let index = 0; index < groups.length; index++) { const groupItem = groups[index]; yield { type: "group", dataItem: groupItem, rowSpan: groupItem.items.length, elementId: `k-scheduler-${scope.counter}-${index}` }; for (let itemIndex = 1; itemIndex < groupItem.items.length; itemIndex++) { const item = groupItem.items[itemIndex]; yield { type: "event", dataItem: item, elementId: `k-scheduler-${scope.counter}-${index}-item-${itemIndex}` }; } } }; } /** @hidden */ export class EmptyIterator { [iterator]() { return { next: () => ({ done: true, value: null }) }; } toString() { return "Empty Iterator"; } } let seed = 0; /** * @hidden */ export class TaskCollection { start; end; events; counter; // used to give unique ids to event elements static empty() { return (new EmptyIterator()); } constructor(start, end, events) { this.start = start; this.end = end; this.events = events; this.counter = seed; seed++; } createIterator = compose(flattenGroupsAndAddIds(this), processEvents(this.start, this.end)); [iterator]() { return this.createIterator(this.events); } itemAt(index) { const taskIterator = this.createIterator(this.events); let idx = 0; let item; do { item = taskIterator.next(); if (item && idx === index) { const value = item.value; return value.type === 'group' ? value.dataItem.items[0] : value.dataItem; } idx++; } while (item); } toString() { return this.events.toString(); } }