Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AppointmentDataAccessor, type IFieldExpr } from '../utils';
import { AppointmentDataAccessor } from '../utils/data_accessor/appointment_data_accessor';
import type { IFieldExpr } from '../utils/data_accessor/types';

export const mockFieldExpressions: IFieldExpr = {
startDateExpr: 'startDate',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { extend } from '@js/core/utils/extend';
import Form from '@js/ui/form';
import { current, isFluent } from '@js/ui/themes';

import { createAppointmentAdapter } from '../m_appointment_adapter';
import timeZoneUtils from '../m_utils_time_zone';

const SCREEN_SIZE_OF_SINGLE_COLUMN = 600;
Expand Down Expand Up @@ -153,13 +152,6 @@ export class AppointmentForm {
});
}

_createAppointmentAdapter(rawAppointment) {
return createAppointmentAdapter(
rawAppointment,
this.scheduler.getDataAccessors(),
);
}

_dateBoxValueChanged(args, dateExpr, isNeedCorrect) {
validateAppointmentFormDate(args.component, args.value, args.previousValue);

Expand Down Expand Up @@ -386,7 +378,7 @@ export class AppointmentForm {
editorOptions: {
firstDayOfWeek: this.scheduler.getFirstDayOfWeek(),
timeZoneCalculator: this.scheduler.getTimeZoneCalculator(),
getStartDateTimeZone: () => this._createAppointmentAdapter(this.formData).startDateTimeZone,
getStartDateTimeZone: () => this.scheduler.getDataAccessors().get('startDateTimeZone', this.formData),
},
label: {
text: ' ',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
isPopupFullScreenNeeded,
} from '@ts/scheduler/r1/appointment_popup/index';

import { createAppointmentAdapter } from '../m_appointment_adapter';
import { hide as hideLoading, show as showLoading } from '../m_loading';
import { AppointmentAdapter } from '../utils/appointment_adapter/appointment_adapter';
import { getAppointmentGroupValues, getRawAppointmentGroupValues } from '../utils/resource_manager/appointment_groups_utils';

const toMs = dateUtils.dateToMilliseconds;
Expand Down Expand Up @@ -187,26 +187,19 @@ export class AppointmentPopup {
}

_createAppointmentAdapter(rawAppointment) {
return createAppointmentAdapter(
return new AppointmentAdapter(
rawAppointment,
this.scheduler.getDataAccessors(),
this.scheduler.getTimeZoneCalculator(),
);
}

_updateForm() {
const { data } = this.state.appointment;
const appointment = this._createAppointmentAdapter(this._createFormData(data));

if (appointment.startDate) {
appointment.startDate = appointment.calculateStartDate('toAppointment');
}

if (appointment.endDate) {
appointment.endDate = appointment.calculateEndDate('toAppointment');
}

const formData = appointment.clone().source();
const appointment = this._createFormData(data);
const formData = this._createAppointmentAdapter(appointment)
.clone()
.calculateDates(this.scheduler.getTimeZoneCalculator(), 'toAppointment')
.source;

this.form.readOnly = this._isReadOnly(formData);
this.form.updateFormData(formData);
Expand Down Expand Up @@ -255,7 +248,9 @@ export class AppointmentPopup {

const { repeat } = this.form.formData;
const adapter = this._createAppointmentAdapter(this.form.formData);
const clonedAdapter = adapter.clone({ pathTimeZone: 'fromAppointment' } as any); // TODO:
const clonedAdapter = adapter
.clone()
.calculateDates(this.scheduler.getTimeZoneCalculator(), 'fromAppointment');
const shouldClearRecurrenceRule = !repeat && !!clonedAdapter.recurrenceRule;

this._addMissingDSTTime(adapter, clonedAdapter);
Expand All @@ -264,7 +259,7 @@ export class AppointmentPopup {
clonedAdapter.recurrenceRule = '';
}

const appointment = clonedAdapter.source();
const appointment = clonedAdapter.source;
delete appointment.repeat; // TODO

switch (this.state.action) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
REDUCED_APPOINTMENT_PARTS_CLASSES,
} from '../../m_classes';
import { getRecurrenceProcessor } from '../../m_recurrence';
import type { AppointmentDataAccessor } from '../../utils';
import type { AppointmentDataAccessor } from '../../utils/data_accessor/appointment_data_accessor';
import type { AppointmentProperties } from './m_types';
import {
getAriaDescription,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import dateLocalization from '@js/common/core/localization/date';
import messageLocalization from '@js/common/core/localization/message';
import { isDefined } from '@js/core/utils/type';
import { PathTimeZoneConversion } from '@ts/scheduler/r1/timezone_calculator/const';

import type { AppointmentProperties } from './m_types';

Expand All @@ -17,10 +16,7 @@ const getDate = (options: AppointmentProperties, propName: 'endDate' | 'startDat
}

const date = new Date(result);
const gridDate = options.timeZoneCalculator?.createDate(
date,
{ path: PathTimeZoneConversion.fromSourceToGrid },
);
const gridDate = options.timeZoneCalculator?.createDate(date, 'toGrid');

return gridDate ?? date;
};
Expand All @@ -32,7 +28,7 @@ const getDateText = (options: AppointmentProperties): string => {
const endDateText = localizeDate(endDate);
const startTimeText = localizeTime(startDate);
const endTimeText = localizeTime(endDate);
const isAllDay = Boolean(options.dataAccessors.get('allDay', options.data));
const isAllDay = options.dataAccessors.get('allDay', options.data);
const allDayText = messageLocalization.format('dxScheduler-allDay');

if (startDateText === endDateText) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import config from '@js/core/config';
import { combineRemoteFilter } from '@ts/scheduler/r1/filterting/index';
import type { AppointmentDataItem, SafeAppointment } from '@ts/scheduler/types';
import type { AppointmentDataAccessor } from '@ts/scheduler/utils';

import { combineRemoteFilter } from '../../r1/filterting/index';
import type { AppointmentDataItem, SafeAppointment } from '../../types';
import type { AppointmentDataAccessor } from '../../utils/data_accessor/appointment_data_accessor';
import { AppointmentDataSource } from './m_appointment_data_source';
import { AppointmentFilterBaseStrategy } from './m_appointment_filter';
import { AppointmentFilterVirtualStrategy } from './m_appointment_filter_virtual';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { equalByValue } from '@js/core/utils/common';
import dateUtils from '@js/core/utils/date';
import { isDefined } from '@js/core/utils/type';
import { dateUtilsTs } from '@ts/core/utils/date';

import { getRecurrenceProcessor } from '../../m_recurrence';
import {
getDatesWithoutTime, isAppointmentTakesAllDay, isTimelineView,
} from '@ts/scheduler/r1/utils/index';
import type { AppointmentDataItem, SafeAppointment } from '@ts/scheduler/types';
import type { AppointmentDataAccessor } from '@ts/scheduler/utils';
import type { ResourceLoader } from '@ts/scheduler/utils/loader/resource_loader';
import { getAppointmentGroupValues } from '@ts/scheduler/utils/resource_manager/appointment_groups_utils';
import type ViewDataProvider from '@ts/scheduler/workspaces/view_model/m_view_data_provider';

import { createAppointmentAdapter } from '../../m_appointment_adapter';
import { getRecurrenceProcessor } from '../../m_recurrence';
} from '../../r1/utils/index';
import type { AppointmentDataItem, SafeAppointment } from '../../types';
import { AppointmentAdapter } from '../../utils/appointment_adapter/appointment_adapter';
import type { AppointmentDataAccessor } from '../../utils/data_accessor/appointment_data_accessor';
import type { ResourceLoader } from '../../utils/loader/resource_loader';
import { getAppointmentGroupValues } from '../../utils/resource_manager/appointment_groups_utils';
import type ViewDataProvider from '../../workspaces/view_model/m_view_data_provider';
import {
_appointmentPartInInterval,
compareDateWithEndDayHour,
Expand Down Expand Up @@ -98,10 +98,9 @@ export class AppointmentFilterBaseStrategy {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
hasAllDayAppointments(filteredItems, preparedItems: AppointmentDataItem[]): boolean {
return filteredItems
.map((item) => createAppointmentAdapter(
.map((item) => new AppointmentAdapter(
item,
this.dataAccessors,
this.timeZoneCalculator,
))
.some((item) => isAppointmentTakesAllDay(item, this.allDayPanelMode));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import dateUtils from '@js/core/utils/date';
import dateSerialization from '@js/core/utils/date_serialization';
import type { AppointmentDataAccessor } from '@ts/scheduler/utils';

import timeZoneUtils from '../../m_utils_time_zone';
import type { AppointmentDataAccessor } from '../../utils/data_accessor/appointment_data_accessor';

const toMs = dateUtils.dateToMilliseconds;

Expand Down Expand Up @@ -66,7 +66,10 @@ export const compareDateWithEndDayHour = (options) => {
return result;
};

export const getAppointmentTakesSeveralDays = (adapter) => !dateUtils.sameDate(adapter.startDate, adapter.endDate);
export const getAppointmentTakesSeveralDays = (dates: {
startDate: Date;
endDate: Date;
}) => !dateUtils.sameDate(dates.startDate, dates.endDate);

// eslint-disable-next-line @typescript-eslint/naming-convention
export const _appointmentPartInInterval = (startDate, endDate, startDayHour, endDayHour) => {
Expand Down Expand Up @@ -102,9 +105,7 @@ export const getRecurrenceException = (appointmentAdapter, timeZoneCalculator, t
export const _convertRecurrenceException = (exceptionString, startDate, timeZoneCalculator, timeZone) => {
exceptionString = exceptionString.replace(/\s/g, '');

const getConvertedToTimeZone = (date) => timeZoneCalculator.createDate(date, {
path: 'toGrid',
});
const getConvertedToTimeZone = (date) => timeZoneCalculator.createDate(date, 'toGrid');

const exceptionDate = dateSerialization.deserializeDate(exceptionString);
const convertedStartDate = getConvertedToTimeZone(startDate);
Expand All @@ -126,8 +127,8 @@ export const sortAppointmentsByStartDate = (
dataAccessors: AppointmentDataAccessor,
) => {
appointments.sort((a, b) => {
const firstDate = new Date(dataAccessors.get('startDate', a.settings || a));
const secondDate = new Date(dataAccessors.get('startDate', b.settings || b));
const firstDate = dataAccessors.get('startDate', a.settings || a);
const secondDate = dataAccessors.get('startDate', b.settings || b);

return Math.sign(firstDate.getTime() - secondDate.getTime());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import CollectionWidget from '@js/ui/collection/ui.collection_widget.edit';
import { dateUtilsTs } from '@ts/core/utils/date';

import { APPOINTMENT_SETTINGS_KEY } from '../constants';
import { createAppointmentAdapter } from '../m_appointment_adapter';
import { APPOINTMENT_CONTENT_CLASSES, APPOINTMENT_DRAG_SOURCE_CLASS, APPOINTMENT_ITEM_CLASS } from '../m_classes';
import { getRecurrenceProcessor } from '../m_recurrence';
import timeZoneUtils from '../m_utils_time_zone';
import type { AppointmentViewModel } from '../types';
import type { AppointmentDataAccessor } from '../utils';
import { AppointmentAdapter } from '../utils/appointment_adapter/appointment_adapter';
import type { AppointmentDataAccessor } from '../utils/data_accessor/appointment_data_accessor';
import { getAppointmentGroupValues } from '../utils/resource_manager/appointment_groups_utils';
import { getGroupTexts } from '../utils/resource_manager/group_utils';
import { AgendaAppointment } from './appointment/agenda_appointment';
Expand Down Expand Up @@ -739,12 +739,10 @@ class SchedulerAppointments extends CollectionWidget {
timeZoneCalculator,
) {
const sourceAppointment = (this as any)._getItemData($element);

const gridAdapter = createAppointmentAdapter(
const gridAdapter = new AppointmentAdapter(
sourceAppointment,
dataAccessors,
timeZoneCalculator,
);
).clone();

gridAdapter.startDate = new Date(dateRange.startDate);
gridAdapter.endDate = new Date(dateRange.endDate);
Expand All @@ -754,45 +752,44 @@ class SchedulerAppointments extends CollectionWidget {
* If we transform dates fromGrid and back through DST then we'll lose one hour.
* TODO(1): refactor computation around DST globally
*/
const convertedBackAdapter = gridAdapter.clone();
convertedBackAdapter
.calculateDates('fromGrid')
.calculateDates('toGrid');
const convertedBackAdapter = gridAdapter
.clone()
.calculateDates(timeZoneCalculator, 'fromGrid')
.calculateDates(timeZoneCalculator, 'toGrid');

const startDateDelta = gridAdapter.startDate.getTime() - convertedBackAdapter.startDate.getTime();
const endDateDelta = gridAdapter.endDate.getTime() - convertedBackAdapter.endDate.getTime();

gridAdapter.startDate = dateUtilsTs.addOffsets(gridAdapter.startDate, [startDateDelta]);
gridAdapter.endDate = dateUtilsTs.addOffsets(gridAdapter.endDate, [endDateDelta]);

const data = gridAdapter
.calculateDates(timeZoneCalculator, 'fromGrid')
.source;

this.notifyObserver('updateAppointmentAfterResize', {
target: sourceAppointment,
data: gridAdapter.calculateDates('fromGrid').source(),
data,
$appointment: $element,
});
}

_getEndResizeAppointmentStartDate(e, rawAppointment, appointmentInfo) {
const timeZoneCalculator = this.option('timeZoneCalculator');
const appointmentAdapter = createAppointmentAdapter(
const appointmentAdapter = new AppointmentAdapter(
rawAppointment,
this.dataAccessors,
timeZoneCalculator,
);

let { startDate } = appointmentInfo;
const recurrenceProcessor = getRecurrenceProcessor();
const { recurrenceRule, startDateTimeZone } = appointmentAdapter;
const { startDateTimeZone, isRecurrent } = appointmentAdapter;
const isAllDay = this.invoke('isAllDay', rawAppointment);
const isRecurrent = recurrenceProcessor.isValidRecurrenceRule(recurrenceRule);

if (!e.handles.top && !isRecurrent && !isAllDay) {
startDate = timeZoneCalculator.createDate(
appointmentAdapter.startDate,
{
appointmentTimeZone: startDateTimeZone,
path: 'toGrid',
},
'toGrid',
startDateTimeZone,
);
}

Expand Down Expand Up @@ -986,9 +983,9 @@ class SchedulerAppointments extends CollectionWidget {
if (recurrenceRule) {
const dates = appointment.settings || appointment;

const startDate = new Date(this.dataAccessors.get('startDate', dates));
const startDate = this.dataAccessors.get('startDate', dates);
const startDateTimeZone = this.dataAccessors.get('startDateTimeZone', appointment);
const endDate = new Date(this.dataAccessors.get('endDate', dates));
const endDate = this.dataAccessors.get('endDate', dates);
const appointmentDuration = endDate.getTime() - startDate.getTime();
const recurrenceException = this.dataAccessors.get('recurrenceException', appointment);
const startViewDate = this.invoke('getStartViewDate');
Expand Down Expand Up @@ -1052,7 +1049,7 @@ class SchedulerAppointments extends CollectionWidget {

for (let i = 1; i < partCount; i++) {
let startDate = this.dataAccessors.get('startDate', parts[i].settings);
startDate = timeZoneCalculator.createDate(startDate.getTime(), { path: 'toGrid' });
startDate = timeZoneCalculator.createDate(startDate.getTime(), 'toGrid');

if (startDate < endViewDate && startDate > startViewDate) {
result.parts.push(parts[i]);
Expand Down Expand Up @@ -1125,24 +1122,20 @@ class SchedulerAppointments extends CollectionWidget {

splitAppointmentByDay(appointment) {
const dates = appointment.settings || appointment;
const originalStartDate = new Date(this.dataAccessors.get('startDate', dates));
const originalStartDate = this.dataAccessors.get('startDate', dates);
let startDate = dateUtils.makeDate(originalStartDate);
let endDate = dateUtils.makeDate(this.dataAccessors.get('endDate', dates));
const maxAllowedDate = this.invoke('getEndViewDate');
const startDayHour = this.invoke('getStartDayHour');
const endDayHour = this.invoke('getEndDayHour');
const timeZoneCalculator = this.option('timeZoneCalculator');

const adapter = createAppointmentAdapter(
appointment,
this.dataAccessors,
timeZoneCalculator,
);
const adapter = new AppointmentAdapter(appointment, this.dataAccessors);
const appointmentIsLong = getAppointmentTakesSeveralDays(adapter);
const result: any = [];

startDate = timeZoneCalculator.createDate(startDate, { path: 'toGrid' });
endDate = timeZoneCalculator.createDate(endDate, { path: 'toGrid' });
startDate = timeZoneCalculator.createDate(startDate, 'toGrid');
endDate = timeZoneCalculator.createDate(endDate, 'toGrid');

if (startDate.getHours() <= endDayHour && startDate.getHours() >= startDayHour && !appointmentIsLong) {
result.push(this._applyStartDateToObj(new Date(startDate), {
Expand Down
Loading
Loading