Skip to content

Commit c16077c

Browse files
authored
refactor resource processor with promises (DevExpress#29632)
Co-authored-by: Vladimir Bushmanov <[email protected]>
1 parent 8ddc31f commit c16077c

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
import { countVisibleAppointments } from './utils/countVisibleAppointments';
@@ -621,13 +622,10 @@ class SchedulerAppointments extends CollectionWidget {
621622

622623
getAppointmentColor: this.option('getAppointmentColor'),
623624
getResourceDataAccessors: this.option('getResourceDataAccessors'),
625+
getResourceProcessor: this.option('getResourceProcessor'),
624626
timeZoneCalculator: this.option('timeZoneCalculator'),
625627
};
626628

627-
if (this.isAgendaView) {
628-
const agendaResourceProcessor = this.option('getAgendaResourceProcessor')();
629-
config.createPlainResourceListAsync = (rawAppointment) => agendaResourceProcessor.createListAsync(rawAppointment);
630-
}
631629
(this as any)._createComponent(
632630
element,
633631
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
@@ -68,7 +68,6 @@ import subscribes from './m_subscribes';
6868
import { utils } from './m_utils';
6969
import timeZoneUtils from './m_utils_time_zone';
7070
import { SchedulerOptionsValidator, SchedulerOptionsValidatorErrorsHandler } from './options_validator/index';
71-
import { AgendaResourceProcessor } from './resources/m_agenda_resource_processor';
7271
import {
7372
createExpressions,
7473
createResourceEditorModel,
@@ -77,6 +76,7 @@ import {
7776
loadResources,
7877
setResourceToAppointment,
7978
} from './resources/m_utils';
79+
import { ResourceProcessor } from './resources/resource_processor';
8080
import { DesktopTooltipStrategy } from './tooltip_strategies/m_desktop_tooltip_strategy';
8181
import { MobileTooltipStrategy } from './tooltip_strategies/m_mobile_tooltip_strategy';
8282
import type {
@@ -191,7 +191,7 @@ class Scheduler extends Widget<any> {
191191

192192
_dataAccessors!: AppointmentDataAccessor;
193193

194-
agendaResourceProcessor: any;
194+
agendaResourceProcessor!: ResourceProcessor;
195195

196196
_actions: any;
197197

@@ -609,7 +609,7 @@ class Scheduler extends Widget<any> {
609609
break;
610610
case 'resources':
611611
this._dataAccessors.resources = createExpressions(this.option('resources'));
612-
this.agendaResourceProcessor.initializeState(this.option('resources'));
612+
this.agendaResourceProcessor = new ResourceProcessor(this.option('resources'));
613613
this.updateInstances();
614614
this.option('resourceLoaderMap').clear();
615615

@@ -1041,7 +1041,7 @@ class Scheduler extends Widget<any> {
10411041

10421042
this._subscribes = subscribes;
10431043

1044-
this.agendaResourceProcessor = new AgendaResourceProcessor(this.option('resources'));
1044+
this.agendaResourceProcessor = new ResourceProcessor(this.option('resources'));
10451045

10461046
this._optionsValidator = new SchedulerOptionsValidator();
10471047

@@ -1586,7 +1586,7 @@ class Scheduler extends Widget<any> {
15861586
getResources: () => this.option('resources'),
15871587
getLoadedResources: () => this.option('loadedResources'),
15881588
getResourceDataAccessors: this.getResourceDataAccessors.bind(this),
1589-
getAgendaResourceProcessor: () => this.agendaResourceProcessor,
1589+
getResourceProcessor: () => this.agendaResourceProcessor,
15901590
getAppointmentColor: this.createGetAppointmentColor(),
15911591

15921592
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)