Skip to content

Commit 5af607a

Browse files
authored
refactor resource processor with promises (DevExpress#29650)
Co-authored-by: Vladimir Bushmanov <[email protected]>
1 parent 10ed2ff commit 5af607a

File tree

12 files changed

+451
-524
lines changed

12 files changed

+451
-524
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import type { dxElementWrapper } from '@js/core/renderer';
2+
import $ from '@js/core/renderer';
3+
import type { ResourceProcessor } from '@ts/scheduler/resources/resource_processor';
4+
5+
import {
6+
APPOINTMENT_CONTENT_CLASSES,
7+
} from '../../m_classes';
8+
import { Appointment } from './m_appointment';
9+
10+
export class AgendaAppointment extends Appointment {
11+
get coloredElement(): dxElementWrapper {
12+
return this.$element().find(`.${APPOINTMENT_CONTENT_CLASSES.AGENDA_MARKER}`);
13+
}
14+
15+
get resourceProcessor(): ResourceProcessor {
16+
const getResourceProcessor = this.option('getResourceProcessor') as () => ResourceProcessor;
17+
return getResourceProcessor();
18+
}
19+
20+
_renderResourceList(): void {
21+
// eslint-disable-next-line no-void
22+
void this.resourceProcessor
23+
.getAppointmentResourcesValues(this.rawAppointment)
24+
.then((list) => {
25+
const parent = this.$element().find(`.${APPOINTMENT_CONTENT_CLASSES.APPOINTMENT_CONTENT_DETAILS}`);
26+
const container = $('<div>')
27+
.addClass(APPOINTMENT_CONTENT_CLASSES.AGENDA_RESOURCE_LIST)
28+
.appendTo(parent);
29+
30+
list.forEach((item) => {
31+
const itemContainer = $('<div>')
32+
.addClass(APPOINTMENT_CONTENT_CLASSES.AGENDA_RESOURCE_LIST_ITEM)
33+
.appendTo(container);
34+
35+
$('<div>')
36+
.text(`${item.label}:`)
37+
.appendTo(itemContainer);
38+
39+
$('<div>')
40+
.addClass(APPOINTMENT_CONTENT_CLASSES.AGENDA_RESOURCE_LIST_ITEM_VALUE)
41+
.text(item.values.join(', '))
42+
.appendTo(itemContainer);
43+
});
44+
});
45+
}
46+
47+
_render(): void {
48+
super._render();
49+
this._renderResourceList();
50+
}
51+
}

packages/devextreme/js/__internal/scheduler/appointments/m_appointment.ts renamed to packages/devextreme/js/__internal/scheduler/appointments/appointment/m_appointment.ts

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable max-classes-per-file */
21
import { move } from '@js/common/core/animation/translator';
32
import eventsEngine from '@js/common/core/events/core/events_engine';
43
import pointerEvents from '@js/common/core/events/pointer';
@@ -10,15 +9,13 @@ import DOMComponent from '@js/core/dom_component';
109
import Guid from '@js/core/guid';
1110
import type { dxElementWrapper } from '@js/core/renderer';
1211
import $ from '@js/core/renderer';
13-
import { Deferred } from '@js/core/utils/deferred';
1412
import { extend } from '@js/core/utils/extend';
1513
import { isDefined } from '@js/core/utils/type';
1614
import Resizable from '@js/ui/resizable';
1715
import { hide, show } from '@ts/ui/tooltip/m_tooltip';
1816

1917
import {
2018
ALL_DAY_APPOINTMENT_CLASS,
21-
APPOINTMENT_CONTENT_CLASSES,
2219
APPOINTMENT_DRAG_SOURCE_CLASS,
2320
APPOINTMENT_HAS_RESOURCE_COLOR_CLASS,
2421
DIRECTION_APPOINTMENT_CLASSES,
@@ -27,9 +24,9 @@ import {
2724
REDUCED_APPOINTMENT_CLASS,
2825
REDUCED_APPOINTMENT_ICON,
2926
REDUCED_APPOINTMENT_PARTS_CLASSES,
30-
} from '../m_classes';
31-
import { getRecurrenceProcessor } from '../m_recurrence';
32-
import type { AppointmentDataAccessor } from '../utils';
27+
} from '../../m_classes';
28+
import { getRecurrenceProcessor } from '../../m_recurrence';
29+
import type { AppointmentDataAccessor } from '../../utils';
3330

3431
const DEFAULT_HORIZONTAL_HANDLES = 'left right';
3532
const DEFAULT_VERTICAL_HANDLES = 'top bottom';
@@ -359,47 +356,3 @@ export class Appointment extends DOMComponent {
359356
}
360357

361358
registerComponent('dxSchedulerAppointment', Appointment);
362-
363-
export class AgendaAppointment extends Appointment {
364-
get coloredElement() {
365-
return (this.$element() as any).find(`.${APPOINTMENT_CONTENT_CLASSES.AGENDA_MARKER}`);
366-
}
367-
368-
_getDefaultOptions() {
369-
return extend(super._getDefaultOptions(), {
370-
// @ts-expect-error
371-
createPlainResourceListAsync: new Deferred(),
372-
});
373-
}
374-
375-
_renderResourceList(container, list) {
376-
list.forEach((item) => {
377-
const itemContainer = $('<div>')
378-
.addClass(APPOINTMENT_CONTENT_CLASSES.AGENDA_RESOURCE_LIST_ITEM)
379-
.appendTo(container);
380-
381-
$('<div>')
382-
.text(`${item.label}:`)
383-
.appendTo(itemContainer);
384-
385-
$('<div>')
386-
.addClass(APPOINTMENT_CONTENT_CLASSES.AGENDA_RESOURCE_LIST_ITEM_VALUE)
387-
.text(item.values.join(', '))
388-
.appendTo(itemContainer);
389-
});
390-
}
391-
392-
_render() {
393-
super._render();
394-
395-
const createPlainResourceListAsync: any = this.option('createPlainResourceListAsync');
396-
createPlainResourceListAsync(this.rawAppointment).done((list) => {
397-
const parent = (this.$element() as any).find(`.${APPOINTMENT_CONTENT_CLASSES.APPOINTMENT_CONTENT_DETAILS}`);
398-
const container = $('<div>')
399-
.addClass(APPOINTMENT_CONTENT_CLASSES.AGENDA_RESOURCE_LIST)
400-
.appendTo(parent);
401-
402-
this._renderResourceList(container, list);
403-
});
404-
}
405-
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ import timeZoneUtils from '../m_utils_time_zone';
3333
import { getPathToLeaf } from '../resources/m_utils';
3434
import type { AppointmentViewModel } from '../types';
3535
import type { AppointmentDataAccessor } from '../utils';
36+
import { AgendaAppointment } from './appointment/agenda_appointment';
37+
import { Appointment } from './appointment/m_appointment';
3638
import { getAppointmentTakesSeveralDays, sortAppointmentsByStartDate } from './data_provider/m_utils';
37-
import { AgendaAppointment, Appointment } from './m_appointment';
3839
import { createAgendaAppointmentLayout, createAppointmentLayout } from './m_appointment_layout';
3940
import { getAppointmentDateRange } from './resizing/m_core';
4041

@@ -616,13 +617,10 @@ class SchedulerAppointments extends CollectionWidget {
616617

617618
getAppointmentColor: this.option('getAppointmentColor'),
618619
getResourceDataAccessors: this.option('getResourceDataAccessors'),
620+
getResourceProcessor: this.option('getResourceProcessor'),
619621
timeZoneCalculator: this.option('timeZoneCalculator'),
620622
};
621623

622-
if (this.isAgendaView) {
623-
const agendaResourceProcessor = this.option('getAgendaResourceProcessor')();
624-
config.createPlainResourceListAsync = (rawAppointment) => agendaResourceProcessor.createListAsync(rawAppointment);
625-
}
626624
(this as any)._createComponent(
627625
element,
628626
this.isAgendaView ? AgendaAppointment : Appointment,

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import subscribes from './m_subscribes';
6464
import { utils } from './m_utils';
6565
import timeZoneUtils from './m_utils_time_zone';
6666
import { SchedulerOptionsValidator, SchedulerOptionsValidatorErrorsHandler } from './options_validator/index';
67-
import { AgendaResourceProcessor } from './resources/m_agenda_resource_processor';
6867
import {
6968
createExpressions,
7069
createResourceEditorModel,
@@ -73,6 +72,7 @@ import {
7372
loadResources,
7473
setResourceToAppointment,
7574
} from './resources/m_utils';
75+
import { ResourceProcessor } from './resources/resource_processor';
7676
import { DesktopTooltipStrategy } from './tooltip_strategies/m_desktop_tooltip_strategy';
7777
import { MobileTooltipStrategy } from './tooltip_strategies/m_mobile_tooltip_strategy';
7878
import type {
@@ -185,7 +185,7 @@ class Scheduler extends Widget<any> {
185185

186186
_dataAccessors!: AppointmentDataAccessor;
187187

188-
agendaResourceProcessor: any;
188+
agendaResourceProcessor!: ResourceProcessor;
189189

190190
_actions: any;
191191

@@ -606,7 +606,7 @@ class Scheduler extends Widget<any> {
606606
break;
607607
case 'resources':
608608
this._dataAccessors.resources = createExpressions(this.option('resources'));
609-
this.agendaResourceProcessor.initializeState(this.option('resources'));
609+
this.agendaResourceProcessor = new ResourceProcessor(this.option('resources'));
610610
this.updateInstances();
611611
this.option('resourceLoaderMap').clear();
612612

@@ -1034,7 +1034,7 @@ class Scheduler extends Widget<any> {
10341034

10351035
this._subscribes = subscribes;
10361036

1037-
this.agendaResourceProcessor = new AgendaResourceProcessor(this.option('resources'));
1037+
this.agendaResourceProcessor = new ResourceProcessor(this.option('resources'));
10381038

10391039
this._optionsValidator = new SchedulerOptionsValidator();
10401040

@@ -1580,7 +1580,7 @@ class Scheduler extends Widget<any> {
15801580
getResources: () => this.option('resources'),
15811581
getLoadedResources: () => this.option('loadedResources'),
15821582
getResourceDataAccessors: this.getResourceDataAccessors.bind(this),
1583-
getAgendaResourceProcessor: () => this.agendaResourceProcessor,
1583+
getResourceProcessor: () => this.agendaResourceProcessor,
15841584
getAppointmentColor: this.createGetAppointmentColor(),
15851585

15861586
getAppointmentDataProvider: () => this.appointmentDataProvider,

packages/devextreme/js/__internal/scheduler/resources/m_agenda_resource_processor.ts

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)