Skip to content

Commit 9ba8b5e

Browse files
committed
Scheduler: move view model files to one folder
1 parent f42adde commit 9ba8b5e

57 files changed

Lines changed: 288 additions & 93 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/devextreme/js/__internal/scheduler/appointments/m_appointment_collection.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ import { getAppointmentGroupValues } from '../utils/resource_manager/appointment
3535
import { getGroupTexts } from '../utils/resource_manager/group_utils';
3636
import { AgendaAppointment } from './appointment/agenda_appointment';
3737
import { Appointment } from './appointment/m_appointment';
38-
import { getAppointmentTakesSeveralDays, sortAppointmentsByStartDate } from './data_provider/m_utils';
3938
import { createAgendaAppointmentLayout, createAppointmentLayout } from './m_appointment_layout';
4039
import { getAppointmentDateRange } from './resizing/m_core';
4140
import { countVisibleAppointments } from './utils/countVisibleAppointments';
41+
import { getAppointmentTakesSeveralDays, sortAppointmentsByStartDate } from './utils/m_utils';
4242

4343
const COMPONENT_CLASS = 'dx-scheduler-scrollable-appointments';
4444

@@ -577,9 +577,6 @@ class SchedulerAppointments extends CollectionWidget {
577577
this._applyResourceDataAttr(element);
578578
const rawAppointment = (this as any)._getItemData(element);
579579
const geometry = this.invoke('getAppointmentGeometry', settings);
580-
const allowResize = this.option('allowResize') && (!isDefined(settings.skipResizing) || isString(settings.skipResizing));
581-
const allowDrag = this.option('allowDrag');
582-
const { allDay } = settings;
583580

584581
if (settings.virtual) {
585582
const appointmentConfig = {
@@ -592,6 +589,9 @@ class SchedulerAppointments extends CollectionWidget {
592589

593590
this._processVirtualAppointment(settings, element, rawAppointment, deferredColor);
594591
} else {
592+
const allowResize = this.option('allowResize') && (!isDefined(settings.skipResizing) || isString(settings.skipResizing));
593+
const allowDrag = this.option('allowDrag');
594+
const { allDay } = settings;
595595
const { groups, groupsLeafs, resourceById } = this.option('getResourceManager')();
596596
const config: any = {
597597
data: rawAppointment,

packages/devextreme/js/__internal/scheduler/appointments/data_provider/m_utils.ts renamed to packages/devextreme/js/__internal/scheduler/appointments/utils/m_utils.ts

File renamed without changes.

packages/devextreme/js/__internal/scheduler/m_scheduler.ts

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@ import { custom as customDialog } from '@js/ui/dialog';
3131
import type { Appointment, AppointmentTooltipShowingEvent } from '@js/ui/scheduler';
3232
import errors from '@js/ui/widget/ui.errors';
3333
import { dateUtilsTs } from '@ts/core/utils/date';
34+
import { AppointmentDataProvider } from '@ts/scheduler/view_model/generate_view_model/data_provider/m_appointment_data_provider';
3435

3536
import { createA11yStatusContainer } from './a11y_status/a11y_status_render';
3637
import { getA11yStatusText } from './a11y_status/a11y_status_text';
3738
import { AppointmentForm } from './appointment_popup/m_form';
3839
import { ACTION_TO_APPOINTMENT, AppointmentPopup } from './appointment_popup/m_popup';
39-
import { AppointmentDataProvider } from './appointments/data_provider/m_appointment_data_provider';
4040
import AppointmentCollection from './appointments/m_appointment_collection';
4141
import { SchedulerHeader } from './header/m_header';
4242
import type { HeaderOptions } from './header/types';
43-
import AppointmentLayoutManager from './m_appointments_layout_manager';
4443
import { CompactAppointmentsHelper } from './m_compact_appointments_helper';
4544
import { AppointmentTooltipInfo } from './m_data_structures';
4645
import { hide as hideLoading, show as showLoading } from './m_loading';
@@ -51,7 +50,6 @@ import timeZoneUtils, { type TimezoneLabel } from './m_utils_time_zone';
5150
import { createTimeZoneCalculator } from './r1/timezone_calculator/index';
5251
import {
5352
excludeFromRecurrence,
54-
getAppointmentDataItems,
5553
getToday,
5654
isAppointmentTakesAllDay,
5755
isDateAndTimeView,
@@ -60,11 +58,7 @@ import {
6058
import { SchedulerOptionsBaseWidget } from './scheduler_options_base_widget';
6159
import { DesktopTooltipStrategy } from './tooltip_strategies/m_desktop_tooltip_strategy';
6260
import { MobileTooltipStrategy } from './tooltip_strategies/m_mobile_tooltip_strategy';
63-
import type {
64-
AppointmentDataItem,
65-
AppointmentViewModel,
66-
SafeAppointment,
67-
} from './types';
61+
import type { AppointmentViewModel } from './types';
6862
import { AppointmentAdapter } from './utils/appointment_adapter/appointment_adapter';
6963
import { AppointmentDataAccessor } from './utils/data_accessor/appointment_data_accessor';
7064
import type { IFieldExpr } from './utils/index';
@@ -76,6 +70,7 @@ import { setAppointmentGroupValues } from './utils/resource_manager/appointment_
7670
import { getLeafGroupValues } from './utils/resource_manager/group_utils';
7771
import { createResourceEditorModel } from './utils/resource_manager/popup_utils';
7872
import { ResourceManager } from './utils/resource_manager/resource_manager';
73+
import AppointmentLayoutManager from './view_model/m_appointments_layout_manager';
7974
import SchedulerAgenda from './workspaces/m_agenda';
8075
import SchedulerTimelineDay from './workspaces/m_timeline_day';
8176
import SchedulerTimelineMonth from './workspaces/m_timeline_month';
@@ -156,10 +151,6 @@ const RECURRENCE_EDITING_MODE = {
156151
class Scheduler extends SchedulerOptionsBaseWidget {
157152
// NOTE: Do not initialize variables here, because `_initMarkup` function runs before constructor,
158153
// and initialization in constructor will erase the data
159-
filteredItems!: SafeAppointment[];
160-
161-
preparedItems!: AppointmentDataItem[];
162-
163154
_timeZoneCalculator!: any;
164155

165156
postponedOperations: any;
@@ -204,7 +195,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
204195

205196
_recurrenceDialog: any;
206197

207-
_layoutManager: any;
198+
_layoutManager!: AppointmentLayoutManager;
208199

209200
_appointmentForm: any;
210201

@@ -558,7 +549,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
558549
}
559550

560551
_isAgenda() {
561-
return this.getLayoutManager().appointmentRenderingStrategyName === 'agenda';
552+
return this._layoutManager.appointmentRenderingStrategyName === 'agenda';
562553
}
563554

564555
_allowDragging() {
@@ -578,10 +569,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
578569
}
579570

580571
_isAllDayExpanded() {
581-
return this.option('showAllDayPanel') && this.appointmentDataProvider.hasAllDayAppointments(
582-
this.filteredItems,
583-
this.preparedItems,
584-
);
572+
return this.option('showAllDayPanel') && this._layoutManager.hasAllDayAppointments();
585573
}
586574

587575
_filterAppointmentsByDate() {
@@ -661,14 +649,14 @@ class Scheduler extends SchedulerOptionsBaseWidget {
661649

662650
if (
663651
!this._isAgenda()
664-
&& this.filteredItems
652+
&& this._layoutManager
665653
&& workspace
666654
&& !isAgendaWorkspaceComponent(workspace)
667655
) {
668656
if (isForce || (!isFixedHeight || !isFixedWidth)) {
669657
workspace.option('allDayExpanded', this._isAllDayExpanded());
670658
workspace._dimensionChanged();
671-
const appointments = this.getLayoutManager().createAppointmentsMap(this.filteredItems);
659+
const appointments = this._layoutManager.createAppointmentsMap();
672660

673661
this._appointments.option('items', appointments);
674662
}
@@ -849,22 +837,13 @@ class Scheduler extends SchedulerOptionsBaseWidget {
849837
this._renderContentImpl();
850838
}
851839

852-
_updatePreparedItems(items?: Appointment[]): void {
853-
this.preparedItems = getAppointmentDataItems(
854-
items,
855-
this._dataAccessors,
856-
this.getViewOption('cellDuration'),
857-
this.timeZoneCalculator,
858-
);
859-
}
860-
861840
_dataSourceChangedHandler(result?: Appointment[]) {
862841
if (this._readyToRenderAppointments) {
863842
this._workSpaceRecalculation.done(() => {
864-
this._updatePreparedItems(result);
843+
this._layoutManager.prepareItems(result);
865844
this._renderAppointments();
866845
this._updateA11yStatus();
867-
this.getWorkSpace().onDataSourceChanged(this.filteredItems);
846+
this.getWorkSpace().onDataSourceChanged(this._layoutManager.filteredItems);
868847
});
869848
}
870849
}
@@ -881,13 +860,9 @@ class Scheduler extends SchedulerOptionsBaseWidget {
881860
return scrolling?.mode === 'virtual';
882861
}
883862

884-
_filterAppointments() {
885-
this.filteredItems = this.appointmentDataProvider.filter(this.preparedItems);
886-
}
887-
888863
_renderAppointments() {
889864
const workspace = this.getWorkSpace();
890-
this._filterAppointments();
865+
this._layoutManager.filterAppointments();
891866

892867
workspace.option('allDayExpanded', this._isAllDayExpanded());
893868

@@ -901,11 +876,9 @@ class Scheduler extends SchedulerOptionsBaseWidget {
901876
}
902877

903878
_getAppointmentsToRepaint(): AppointmentViewModel[] {
904-
const layoutManager = this.getLayoutManager();
905-
906-
const appointmentsMap = layoutManager.createAppointmentsMap(this.filteredItems);
879+
const appointmentsMap = this._layoutManager.createAppointmentsMap();
907880

908-
return layoutManager.getRepaintedAppointments(
881+
return this._layoutManager.getRepaintedAppointments(
909882
appointmentsMap,
910883
this.getAppointmentsInstance().option('items'),
911884
);
@@ -1183,8 +1156,6 @@ class Scheduler extends SchedulerOptionsBaseWidget {
11831156
}
11841157

11851158
_initMarkupCore() {
1186-
this.filteredItems = [];
1187-
this.preparedItems = [];
11881159
this._readyToRenderAppointments = hasWindow();
11891160

11901161
this._workSpace && this._cleanWorkspace();
@@ -1357,7 +1328,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
13571328
const result = extend({
13581329
resources: this.option('resources'),
13591330
getResourceManager: () => this.resourceManager,
1360-
getFilteredItems: () => this.filteredItems,
1331+
getFilteredItems: () => this._layoutManager.filteredItems,
13611332

13621333
noDataText: this.option('noDataText'),
13631334
firstDayOfWeek: this.option('firstDayOfWeek'),
@@ -1868,7 +1839,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
18681839
}
18691840

18701841
getRenderingStrategyInstance() {
1871-
return this.getLayoutManager().getRenderingStrategyInstance();
1842+
return this._layoutManager.getRenderingStrategyInstance();
18721843
}
18731844

18741845
getActions() {
@@ -1924,7 +1895,7 @@ class Scheduler extends SchedulerOptionsBaseWidget {
19241895
if (groups?.length) {
19251896
const { resourceById, groupsLeafs } = this.resourceManager;
19261897
const appointmentSettings = this._isAgenda()
1927-
? this.getLayoutManager()._positionMap[appointmentIndex][0]
1898+
? this._layoutManager._positionMap[appointmentIndex][0]
19281899
: utils.dataAccessors.getAppointmentSettings(element) || {};
19291900
const cellGroups = getLeafGroupValues(groupsLeafs, appointmentSettings.groupIndex);
19301901

packages/devextreme/js/__internal/scheduler/r1/utils/__tests__/base.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '../index';
1818

1919
jest.mock(
20-
'../../../appointments/data_provider/m_appointment_filter',
20+
'@ts/scheduler/view_model/filtering/m_appointment_filter',
2121
() => ({
2222
AppointmentFilterBaseStrategy: jest.fn(() => ({ strategy: 'base' })),
2323
AppointmentFilterVirtualStrategy: jest.fn(() => ({ strategy: 'virtual' })),

packages/devextreme/js/__internal/scheduler/r1/utils/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ export {
8484
formatWeekday,
8585
formatWeekdayAndDay,
8686
} from './format_weekday';
87-
export {
88-
getAppointmentDataItems,
89-
} from './get_appointment_data_items';
9087

9188
export const agendaUtils = {
9289
calculateStartViewDate,

packages/devextreme/js/__internal/scheduler/types.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,50 @@ export interface AppointmentDataItem {
2828
rawAppointment: SafeAppointment;
2929
}
3030

31-
// TODO: add correct types here. Agenda and other views have different types
32-
export interface BaseAppointmentViewModelSettings extends Record<string, unknown> {
31+
export interface BaseAppointmentViewModelSettings {
3332
allDay?: boolean;
3433
direction: string;
35-
height: number | string;
36-
width: number | string;
3734
groupIndex: number;
3835
sortedIndex: number;
3936
}
4037

38+
export interface AppointmentViewModelSettings extends BaseAppointmentViewModelSettings {
39+
index: number; // current level in stack
40+
count: number; // max level including appointments not in stack
41+
info: {
42+
sourceAppointment: {
43+
startDate: Date;
44+
endDate: Date;
45+
};
46+
appointment: {
47+
startDate: Date;
48+
endDate: Date;
49+
};
50+
};
51+
left: number;
52+
top: number;
53+
height: number;
54+
width: number;
55+
isCompact: boolean;
56+
appointmentReduced: 'head' | 'body' | 'tail' | undefined;
57+
partIndex: number;
58+
partTotalCount: number;
59+
}
60+
61+
export interface AgendaViewModelSettings extends BaseAppointmentViewModelSettings {
62+
agendaSettings: {
63+
startDate: Date;
64+
endDate: Date;
65+
};
66+
height: number;
67+
width: string;
68+
}
69+
4170
export interface AppointmentViewModel {
4271
itemData: SafeAppointment;
4372
needRepaint: boolean;
4473
needRemove: boolean;
45-
settings: BaseAppointmentViewModelSettings[];
74+
settings: (AppointmentViewModelSettings & AgendaViewModelSettings)[];
4675
}
4776

4877
export interface AppointmentGeometry {

packages/devextreme/testing/tests/DevExpress.ui.widgets.scheduler/appointment.dataProcessor.tests.js renamed to packages/devextreme/js/__internal/scheduler/view_model/appointment.dataProcessor.tests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getEmptyResourceManager,
99
getLoadedResources,
1010
getWorkspaceResourceConfig
11-
} from '../../helpers/scheduler/mockResourceManager.js';
11+
} from '../../../../testing/helpers/scheduler/mockResourceManager.js';
1212

1313
const {
1414
module,

0 commit comments

Comments
 (0)