devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
82 lines (81 loc) • 3.37 kB
JavaScript
/**
* DevExtreme (esm/__internal/scheduler/utils/resource_manager/resource_manager.js)
* Version: 25.1.3
* Build date: Wed Jun 25 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import {
getResourceIndex
} from "../data_accessor/appointment_resource_data_accessor";
import {
ResourceLoader
} from "../loader/resource_loader";
import {
getAppointmentColor
} from "./appointment_color_utils";
import {
getAppointmentGroupValues,
getAppointmentResources
} from "./appointment_groups_utils";
import {
groupResources
} from "./group_utils";
export class ResourceManager {
constructor(config) {
this.resources = [];
this.resourceById = {};
this.groups = [];
this.groupsLeafs = [];
this.groupsTree = [];
null === config || void 0 === config || config.filter(getResourceIndex).forEach((item => {
const loader = new ResourceLoader(item);
this.resourceById[loader.resourceIndex] = loader;
this.resources.push(loader)
}))
}
async load(groupsToLoad) {
let forceReload = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : false;
await Promise.all(groupsToLoad.map((group => {
var _this$resourceById$gr;
return null === (_this$resourceById$gr = this.resourceById[group]) || void 0 === _this$resourceById$gr ? void 0 : _this$resourceById$gr.load(forceReload)
})))
}
async loadGroupResources() {
let groups = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : [];
let forceReload = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : false;
await this.load(groups, forceReload);
const {
groupTree: groupTree,
groupLeafs: groupLeafs
} = groupResources(this.resourceById, groups);
this.groups = groups;
this.groupsLeafs = groupLeafs;
this.groupsTree = groupTree;
return this.groupResources()
}
groupCount() {
return this.groupsLeafs.length
}
groupResources() {
return this.groups.map((group => this.resourceById[group])).filter(Boolean)
}
async loadAppointmentsResources(items) {
let forceReload = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : false;
const groupsToLoad = Object.keys(this.resourceById).filter((resourceIndex => !this.resourceById[resourceIndex].isLoaded() && items.some((item => this.resourceById[resourceIndex].idsGetter(item).length > 0))));
await this.load(groupsToLoad, forceReload)
}
async getAppointmentColor(appointmentConfig) {
return getAppointmentColor(this.resources, this.groupsLeafs, this.groups, appointmentConfig)
}
async getAppointmentResourcesValues(appointment) {
const appointmentGroups = getAppointmentGroupValues(appointment, this.resources);
const groups = Object.keys(appointmentGroups);
await this.load(groups);
return getAppointmentResources(appointmentGroups, this.resourceById)
}
dispose() {
Object.values(this.resourceById).forEach((item => item.dispose()))
}
}