Skip to content

Commit 4da4561

Browse files
authored
Scheduler: add options class (DevExpress#30231)
Co-authored-by: Vladimir Bushmanov <[email protected]>
1 parent 5671fc7 commit 4da4561

File tree

68 files changed

+1495
-1078
lines changed

Some content is hidden

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

68 files changed

+1495
-1078
lines changed

packages/devextreme/js/__internal/core/m_errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default errorUtils({
8080

8181
W0007: '\'{0}\' Globalize culture is not defined',
8282

83-
W0008: 'Invalid view name: \'{0}\'',
83+
W0008: 'Invalid view type: {0}',
8484

8585
W0009: 'Invalid time zone name: \'{0}\'',
8686

packages/devextreme/js/__internal/scheduler/__tests__/performance.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('scheduler', () => {
3030
startDayHour: 8,
3131
firstDayOfWeek: 1,
3232
height: 600,
33-
});
33+
} as any);
3434
await timezoneUtils.cacheTimeZones();
3535

3636
expect(container.classList).toContain('dx-scheduler');

packages/devextreme/js/__internal/scheduler/a11y_status/a11y_status_text.test.ts

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ describe('getA11yStatusText', () => {
99
name: 'Two Weeks',
1010
type: 'week',
1111
intervalCount: 2,
12+
groupOrientation: 'horizontal',
13+
maxAppointmentsPerCell: 'auto',
14+
allDayPanelMode: 'all',
1215
},
1316
new Date(2021, 10, 17, 1),
1417
new Date(2021, 10, 27, 12),
@@ -18,7 +21,14 @@ describe('getA11yStatusText', () => {
1821

1922
it('should return text month view', () => {
2023
expect(getA11yStatusText(
21-
'month',
24+
{
25+
name: 'Month',
26+
type: 'month',
27+
intervalCount: 1,
28+
groupOrientation: 'horizontal',
29+
maxAppointmentsPerCell: 'auto',
30+
allDayPanelMode: 'all',
31+
},
2232
new Date(2021, 9, 27, 1),
2333
new Date(2021, 11, 3, 12),
2434
20,
@@ -27,7 +37,14 @@ describe('getA11yStatusText', () => {
2737

2838
it('should return text week view', () => {
2939
expect(getA11yStatusText(
30-
'week',
40+
{
41+
name: 'Week',
42+
type: 'week',
43+
intervalCount: 1,
44+
groupOrientation: 'horizontal',
45+
maxAppointmentsPerCell: 'auto',
46+
allDayPanelMode: 'all',
47+
},
3148
new Date(2021, 10, 21, 1),
3249
new Date(2021, 10, 27, 12),
3350
20,
@@ -36,7 +53,14 @@ describe('getA11yStatusText', () => {
3653

3754
it('should return text day view', () => {
3855
expect(getA11yStatusText(
39-
'day',
56+
{
57+
name: 'Day',
58+
type: 'day',
59+
intervalCount: 1,
60+
groupOrientation: 'horizontal',
61+
maxAppointmentsPerCell: 'auto',
62+
allDayPanelMode: 'all',
63+
},
4064
new Date(2021, 10, 24, 1),
4165
new Date(2021, 10, 24, 12),
4266
20,
@@ -45,7 +69,14 @@ describe('getA11yStatusText', () => {
4569

4670
it('should return text with indicator on the view', () => {
4771
expect(getA11yStatusText(
48-
'day',
72+
{
73+
name: 'Day',
74+
type: 'day',
75+
intervalCount: 1,
76+
groupOrientation: 'horizontal',
77+
maxAppointmentsPerCell: 'auto',
78+
allDayPanelMode: 'all',
79+
},
4980
new Date(2021, 10, 24, 1),
5081
new Date(2021, 10, 24, 12),
5182
20,
@@ -55,7 +86,14 @@ describe('getA11yStatusText', () => {
5586

5687
it('should return text with indicator out of the view', () => {
5788
expect(getA11yStatusText(
58-
'day',
89+
{
90+
name: 'Day',
91+
type: 'day',
92+
intervalCount: 1,
93+
groupOrientation: 'horizontal',
94+
maxAppointmentsPerCell: 'auto',
95+
allDayPanelMode: 'all',
96+
},
5997
new Date(2021, 10, 24, 1),
6098
new Date(2021, 10, 24, 12),
6199
20,

packages/devextreme/js/__internal/scheduler/a11y_status/a11y_status_text.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import dateLocalization from '@js/common/core/localization/date';
22
import messageLocalization from '@js/common/core/localization/message';
3-
import { isObject } from '@js/core/utils/type';
43
import type { ViewType } from '@js/ui/scheduler';
54

6-
import type { RawViewType } from '../types';
5+
import type { NormalizedView } from '../utils/options/types';
76

87
const KEYS = {
98
dateRange: 'dxScheduler-dateRange',
@@ -46,16 +45,15 @@ const localizeName = (viewName?: string, viewType?: string): string => {
4645
};
4746

4847
export const getA11yStatusText = (
49-
view: RawViewType,
48+
view: NormalizedView | undefined,
5049
startDate: Date,
5150
endDate: Date,
5251
appointmentCount: number,
5352
indicatorTime?: Date,
5453
): string => {
55-
const viewType = isObject(view) ? view.type : view;
56-
const viewName = isObject(view) ? view.name : undefined;
54+
const viewType = view?.type;
55+
const viewName = view?.name;
5756
const viewTypeLabel = localizeName(viewName, viewType);
58-
5957
const isMonth = viewType === 'month' || viewType === 'timelineMonth';
6058
const startDateText = isMonth ? localizeMonth(startDate) : localizeDate(startDate);
6159
const endDateText = isMonth ? localizeMonth(endDate) : localizeDate(endDate);

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,3 @@ export const APPOINTMENT_SETTINGS_KEY = 'dxAppointmentSettings';
44

55
export const VERTICAL_GROUP_ORIENTATION = 'vertical';
66
export const HORIZONTAL_GROUP_ORIENTATION = 'horizontal';
7-
8-
export const VIEWS = {
9-
DAY: 'day',
10-
WEEK: 'week',
11-
WORK_WEEK: 'workWeek',
12-
MONTH: 'month',
13-
TIMELINE_DAY: 'timelineDay',
14-
TIMELINE_WEEK: 'timelineWeek',
15-
TIMELINE_WORK_WEEK: 'timelineWorkWeek',
16-
TIMELINE_MONTH: 'timelineMonth',
17-
AGENDA: 'agenda',
18-
};
19-
export const VIEW_TYPES = Object.values(VIEWS);
20-
export const TIMELINE_VIEWS = [
21-
VIEWS.TIMELINE_DAY,
22-
VIEWS.TIMELINE_WEEK,
23-
VIEWS.TIMELINE_WORK_WEEK,
24-
VIEWS.TIMELINE_MONTH,
25-
];

packages/devextreme/js/__internal/scheduler/header/m_header.ts

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import $ from '@js/core/renderer';
88
import { getPathParts } from '@js/core/utils/data';
99
import dateUtils from '@js/core/utils/date';
1010
import { extend } from '@js/core/utils/extend';
11-
import type { dxSchedulerOptions, ViewType } from '@js/ui/scheduler';
1211
import Toolbar from '@js/ui/toolbar';
1312
import Widget from '@js/ui/widget/ui.widget';
14-
import { viewsUtils } from '@ts/scheduler/r1/utils/index';
1513

1614
import type { Direction } from './constants';
1715
import SchedulerCalendar from './m_calendar';
@@ -22,16 +20,14 @@ import {
2220
getCaption,
2321
getNextIntervalDate,
2422
getStep,
25-
getViewName,
26-
getViewType,
2723
nextWeek,
28-
validateViews,
2924
} from './m_utils';
3025
import {
3126
getDropDownViewSwitcher,
3227
getTabViewSwitcher,
3328
} from './m_view_switcher';
3429
import { getTodayButtonOptions } from './today';
30+
import type { HeaderOptions, IntervalOptions } from './types';
3531

3632
const CLASSES = {
3733
component: 'dx-scheduler-header',
@@ -43,31 +39,28 @@ const ITEM_NAMES = {
4339
viewSwitcher: 'viewSwitcher',
4440
};
4541

46-
export class SchedulerHeader extends Widget<dxSchedulerOptions> {
47-
currentView: any;
48-
42+
export class SchedulerHeader extends Widget<HeaderOptions> {
4943
eventMap: any;
5044

5145
_toolbar!: Toolbar;
5246

5347
_calendar: any;
5448

55-
get views() {
56-
return this.option('views');
57-
}
58-
5949
get captionText() {
6050
return this._getCaption().text;
6151
}
6252

63-
get intervalOptions() {
64-
const step = getStep(this.currentView);
65-
const intervalCount = this.option('intervalCount');
53+
getIntervalOptions(date: Date): IntervalOptions {
54+
const currentView = this.option('currentView');
55+
const step = getStep(currentView.type);
6656
const firstDayOfWeek = this.option('firstDayOfWeek');
67-
const agendaDuration = this.option('agendaDuration');
6857

6958
return {
70-
step, intervalCount, firstDayOfWeek, agendaDuration,
59+
date,
60+
step,
61+
firstDayOfWeek,
62+
intervalCount: currentView.intervalCount,
63+
agendaDuration: currentView.agendaDuration,
7164
};
7265
}
7366

@@ -81,13 +74,8 @@ export class SchedulerHeader extends Widget<dxSchedulerOptions> {
8174
_createEventMap() {
8275
this.eventMap = new Map(
8376
[
84-
['currentView', [(view) => {
85-
this.currentView = viewsUtils.getCurrentView(
86-
getViewName(view) as string,
87-
this.option('views') as ViewType[],
88-
);
89-
}]],
90-
['views', [validateViews]],
77+
['currentView', []],
78+
['views', []],
9179
['currentDate', [this._getCalendarOptionUpdater('value')]],
9280
['min', [this._getCalendarOptionUpdater('min')]],
9381
['max', [this._getCalendarOptionUpdater('max')]],
@@ -152,11 +140,6 @@ export class SchedulerHeader extends Widget<dxSchedulerOptions> {
152140
this._createEventMap();
153141

154142
this.$element().addClass(CLASSES.component);
155-
156-
this.currentView = viewsUtils.getCurrentView(
157-
getViewName(this.option('currentView') as ViewType) as string,
158-
this.option('views') as ViewType[],
159-
);
160143
}
161144

162145
_render() {
@@ -191,7 +174,7 @@ export class SchedulerHeader extends Widget<dxSchedulerOptions> {
191174
}
192175

193176
_createToolbarConfig() {
194-
const options = this.option('toolbar') as any;
177+
const options = this.option('toolbar');
195178
const parsedItems = options.items.map((element) => this._parseItem(element));
196179

197180
return {
@@ -232,10 +215,7 @@ export class SchedulerHeader extends Widget<dxSchedulerOptions> {
232215
}
233216

234217
_updateCurrentView(view) {
235-
const onCurrentViewChange = this.option('onCurrentViewChange') as any;
236-
onCurrentViewChange(view.name);
237-
238-
this._callEvent('currentView', view);
218+
this.option('onCurrentViewChange')(view.name);
239219
}
240220

241221
_updateCalendarValueAndCurrentDate(date) {
@@ -244,9 +224,7 @@ export class SchedulerHeader extends Widget<dxSchedulerOptions> {
244224
}
245225

246226
_updateCurrentDate(date) {
247-
const onCurrentDateChange = this.option('onCurrentDateChange') as any;
248-
onCurrentDateChange(date);
249-
227+
this.option('onCurrentDateChange')(date);
250228
this._callEvent('currentDate', date);
251229
}
252230

@@ -278,19 +256,16 @@ export class SchedulerHeader extends Widget<dxSchedulerOptions> {
278256

279257
_getNextDate(direction: Direction, initialDate?: Date) {
280258
const date = initialDate ?? this.option('currentDate');
281-
const options = { ...this.intervalOptions, date };
259+
const options = this.getIntervalOptions(date);
282260

283261
return getNextIntervalDate(options, direction);
284262
}
285263

286-
_isMonth() {
287-
return getViewType(this.currentView) === 'month';
288-
}
289-
290264
_getDisplayedDate() {
291-
const startViewDate = new Date(this.option('startViewDate') as any);
265+
const startViewDate = new Date(this.option('startViewDate'));
266+
const isMonth = this.option('currentView')?.type === 'month';
292267

293-
return this._isMonth() ? nextWeek(startViewDate) : startViewDate;
268+
return isMonth ? nextWeek(startViewDate) : startViewDate;
294269
}
295270

296271
_getCaptionOptions() {
@@ -302,7 +277,7 @@ export class SchedulerHeader extends Widget<dxSchedulerOptions> {
302277

303278
date = dateUtils.trimTime(date);
304279

305-
return { ...this.intervalOptions, date };
280+
return this.getIntervalOptions(date);
306281
}
307282

308283
_getCaption() {

0 commit comments

Comments
 (0)