UNPKG

devexpress-reporting

Version:

DevExpress Reporting provides the capability to develop a reporting application to create and customize reports.

92 lines (91 loc) 4.17 kB
/** * DevExpress HTML/JS Reporting (designer\localization\_localizationEngine.js) * Version: 24.2.6 * Build date: Mar 18, 2025 * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * License: https://www.devexpress.com/Support/EULAs/universal.xml */ import { koUtils, replaceInvalidSymbols } from '@devexpress/analytics-core/analytics-internal'; import { Disposable } from '@devexpress/analytics-core/analytics-utils'; import * as ko from 'knockout'; import { defaultCulture } from '../../common/defaultCulture'; import { LocalizationDictionary } from './_localization'; export class ReportLocalizationEngine extends Disposable { constructor(report) { super(); this.report = report; this.items = new LocalizationDictionary(); this.add = (cultureCode, component, propertyName, value, target) => { const node = this.items.get(cultureCode); if (!node) { this.items.add(cultureCode).setValue(component, propertyName, value, target); } else node.setValue(component, propertyName, value, target); }; this.save = (cultureCode = this.report.language()) => { this.report.enumerateComponents().forEach((control) => { if (control.getLocalizationProperties) { control.getLocalizationProperties().forEach(item => this.add(cultureCode, control, item.propertyName, item.value, item.target)); } }); }; this.apply = (cultureCode) => { const localizationItem = this.items.get(cultureCode); if (!localizationItem) { this.items.add(cultureCode); this.apply(cultureCode); } else { const needUpdate = !this.report['_update'](); needUpdate && this.report['_update'](true); localizationItem.getInheritedProperties().forEach(localizationPropertyInfo => { localizationPropertyInfo.component.applyLocalization(localizationPropertyInfo.propertyName, localizationPropertyInfo.value); }); needUpdate && this.report['_update'](false); } }; this.serialize = () => { const outArray = []; const _avalibleComponents = this.report.enumerateComponents(); const _avalibleComponentsDictionary = {}; const _getUniqueName = (component) => { return replaceInvalidSymbols(component.controlType + ko.unwrap(component.name)); }; _avalibleComponents.forEach(component => { _avalibleComponentsDictionary[_getUniqueName(component)] = component; }); const canSerialize = (component) => { const item = _avalibleComponentsDictionary[_getUniqueName(component)]; return item && component === item; }; const existingTargets = []; this.items.keys().forEach(key => { outArray.push(...this.items.get(key).serialize(canSerialize, existingTargets)); }); return outArray; }; report._localizationItems().forEach(item => { const component = koUtils.unwrap(item.component); if (component) { const propertyName = koUtils.unwrap(item.propertyName); const target = component.getLocalizationProperty(propertyName)?.target; this.add(item.culture(), component, propertyName, item.propertyValue, target); } }); } recalculateUnits(coef) { this.items.keys().forEach((key) => { key !== this.report.language() && this.items.get(key).properties.forEach(x => x.recalculate && x.recalculate(coef)); }); } hasCulture(cultureCode) { const item = this.items.get(cultureCode); return item && item.isLocalized(); } isLocalized() { return this.items.keys().some((key) => { return key !== defaultCulture && this.items.get(key).properties.length > 0; }); } }