@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) • 3.75 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 { Injectable, EventEmitter, NgZone } from '@angular/core';
import { Subject } from 'rxjs';
import { debounceTime } from 'rxjs/operators';
import { EditMode } from '../types';
import { isPresent } from '../common/util';
import * as i0 from "@angular/core";
// const toSimilarDate = (date: ZonedDate): Date => new Date(
// date.getFullYear(), date.getMonth(), date.getDay(),
// date.getHours(), date.getMinutes(), date.getSeconds(),
// date.getMilliseconds()
// );
// const toUTCDateTime = (localDate: Date): Date => new Date(Date.UTC(
// localDate.getFullYear(),
// localDate.getMonth(),
// localDate.getDate(),
// localDate.getHours(),
// localDate.getMinutes(),
// localDate.getSeconds(),
// localDate.getMilliseconds()
// ));
/**
* @hidden
*/
export class EditService {
ngZone;
changes = new EventEmitter();
changed;
editedEvent;
newEventGroup;
changedSource = new Subject();
constructor(ngZone) {
this.ngZone = ngZone;
this.changed = this.changedSource.asObservable().pipe(debounceTime(0));
}
endEdit() {
const formGroup = this.hasNewEvent ? this.newEventGroup.group : this.editedEvent.formGroup;
this.changes.emit({ action: 'cancel', formGroup });
}
removeEvent(dataItem) {
this.changes.emit({ action: 'remove', dataItem });
}
addEvent(formGroup) {
this.newEventGroup = { formGroup };
this.onChanged();
}
editEvent(dataItem, formGroup = undefined, mode) {
this.editedEvent = { dataItem, formGroup, mode };
this.onChanged();
}
close() {
this.newEventGroup = this.editedEvent = null;
this.onChanged();
}
save() {
const { dataItem, formGroup } = this.context;
this.changes.emit({
action: 'save',
dataItem,
formGroup,
isNew: this.hasNewEvent,
mode: this.occurrenceEditMode
});
}
isEditing() {
return isPresent(this.context);
}
get occurrenceEditMode() {
if (this.hasNewEvent) {
return EditMode.Series;
}
else {
return this.editedEvent.mode || EditMode.Event;
}
}
get hasNewEvent() {
return isPresent(this.newEventGroup);
}
get newEvent() {
if (this.hasNewEvent) {
return this.newEventGroup.group.value;
}
return {};
}
get context() {
if (this.hasNewEvent) {
return this.newEventGroup;
}
return this.editedEvent;
}
onChanged() {
this.ngZone.runOutsideAngular(() => {
this.changedSource.next();
});
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: EditService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: EditService, providedIn: 'root' });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: EditService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root'
}]
}], ctorParameters: function () { return [{ type: i0.NgZone }]; } });