UNPKG

devexpress-reporting

Version:

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

181 lines (180 loc) 7.81 kB
/** * DevExpress HTML/JS Reporting (designer\bands\xrDetailReportBand.js) * Version: 25.1.3 * Build date: Jun 26, 2025 * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * License: https://www.devexpress.com/Support/EULAs/universal.xml */ import { checkModelReady, deserializeChildArray, getFullPath, HoverInfo } from '@devexpress/analytics-core/analytics-internal'; import { FilterStringOptions } from '@devexpress/analytics-core/analytics-widgets'; import * as ko from 'knockout'; import { collectAvailableParameters } from '../dataObjects/metadata/_parameterUtils'; import { bandSurfaceCollapsedHeight } from './bandSurfaceCollapsedHeight'; import { BandSurface, BandViewModel } from './xrBand'; import { SubBandViewModel } from './xrSubband'; import { VerticalBandViewModel } from './xrVerticalBand'; import { addBandToContainer } from './_bandContainerUtils'; import { changeLevels, coerceNewLevelValueOnReordering, getExistedSameLevelBand, getMaxLevel, levelSetup, NEW_DETAILBAND_DEFAULT_LEVEL, REMOVED_DETAILBAND_LEVEL, sortBands } from './_bandUtils'; export class DetailReportBand extends BandViewModel { constructor(band, parent, serializer) { super(band, parent, serializer); this._disposables.push(this.dataSource.subscribe((newVal) => { if (!newVal) { this.dataMember(null); } })); const dataMember = ko.pureComputed(() => { return getFullPath(this.getPath('dataMember'), this.dataMember()); }); const disabled = ko.pureComputed(() => !this.dataSource()); this.filterString = new FilterStringOptions(this._filterString, dataMember, disabled); this._disposables.push(dataMember); this._disposables.push(disabled); this.filterString.helper.parameters = ko.computed(() => { return collectAvailableParameters(this.root['parameters']()); }); this._disposables.push(this.filterString.helper.parameters); this._disposables.push(this.maxLevel = ko.pureComputed(() => getMaxLevel(this.parentModel().bands().filter(b => b instanceof DetailReportBand)))); this._disposables.push(this.level = ko.pureComputed({ read: () => this._level(), write: (newValue) => levelSetup(this, newValue) })); levelSetup(this, this.level()); } initHeight() { let oldHeight = 0; this._disposables.push(this.height = ko.pureComputed({ read: () => { if (checkModelReady(this.root)) { const verticalBand = this.bands().filter(x => x instanceof VerticalBandViewModel)[0]; let height = 0; if (verticalBand) height = verticalBand.height(); oldHeight = this.bands().filter(x => !(x instanceof VerticalBandViewModel)).reduce((sum, b) => { return sum + b.height(); }, height); } return oldHeight; }, write: (newHeight) => { if (checkModelReady(this.root)) { const deltaHeight = newHeight - this.height.peek(), oldHeight = this.bands()[this.bands().length - 1].height.peek(); this.bands()[this.bands().length - 1].height(oldHeight + deltaHeight); } } })); } createChildsArray(band, serializer) { const factory = this.getControlFactory(); this.bands = deserializeChildArray(band.Bands, this, (item) => { return new (factory.controlsMap[item['@ControlType']].type || BandViewModel)(item, this, serializer); }); const bands = this.bands.peek(); if (bands) { bands.sort(sortBands); } if (this.bands().length === 0) this.createChild({ '@ControlType': 'DetailBand', '@HeightF': this.height(), '@Dpi': this.dpi() }); } addChild(control) { if (control instanceof BandViewModel && !(control instanceof SubBandViewModel)) { addBandToContainer(this, control); } } coerceDefaultLevelValue(newValue) { return newValue === NEW_DETAILBAND_DEFAULT_LEVEL ? 0 : newValue; } _updateLevelsOnInsertWithDefaultLevel(maxLevel) { this._level(maxLevel + 1); } _updateLevelsOnInsert(maxLevel, newLevelValue) { const parentBands = this.parentModel().bands; if (!parentBands) return null; const parentDetailBands = this.getFilteredParentBands(); const existedSameLevelBand = getExistedSameLevelBand(parentDetailBands, newLevelValue); if (!existedSameLevelBand) { this._level(maxLevel + 1); return; } const existedSameLevelBandIndex = parentDetailBands.indexOf(existedSameLevelBand); changeLevels(parentDetailBands, existedSameLevelBandIndex, parentDetailBands.length); this._level(newLevelValue); } updateLevelsOnInsert(maxLevel, newValue) { if (newValue === NEW_DETAILBAND_DEFAULT_LEVEL) this._updateLevelsOnInsertWithDefaultLevel(maxLevel); else this._updateLevelsOnInsert(maxLevel, newValue); } _reorderLevelsCore(newLevelValue) { const parentDetailBands = this.getFilteredParentBands(); const existedSameLevelBand = getExistedSameLevelBand(parentDetailBands, newLevelValue); const startIndex = parentDetailBands.indexOf(existedSameLevelBand); const endIndex = parentDetailBands.indexOf(this); changeLevels(parentDetailBands, startIndex, endIndex); this._level(newLevelValue); } reorderLevels(maxLevel, newValue) { newValue = coerceNewLevelValueOnReordering(newValue, 0, maxLevel); this._reorderLevelsCore(newValue); } getFilteredParentBands() { return this.parentModel().bands().filter(b => b instanceof DetailReportBand); } removeChild(control) { control?.level(REMOVED_DETAILBAND_LEVEL); super.removeChild(control); control?._level(REMOVED_DETAILBAND_LEVEL); this.bands.sort(sortBands); } dispose() { super.dispose(); this.disposeObservableArray(this.bands); this.resetObservableArray(this.bands); } } export class DetailReportBandSurface extends BandSurface { dispose() { super.dispose(); } getChildrenCollection() { return this.bandsHolder.bands; } createUnderCursor() { const _underCursor = ko.observable(new HoverInfo()); this._disposables.push(this.underCursor = ko.pureComputed({ read: () => { _underCursor().isOver = this.bandsHolder.checkUnderCursor(); return _underCursor(); }, write: (val) => { _underCursor(val); } })); } getTotalHeight() { return this.bandsHolder.getTotalHeight(); } getHeight() { if (this.collapsed()) { return bandSurfaceCollapsedHeight; } else { return this.bandsHolder.getHeight(); } } getHasOwnRuler() { return this.collapsed(); } constructor(band, context) { super(band, context, { _height: (o) => o.height }); this.templateName = 'dxrd-detailreportband'; this.selectionTemplate = 'dxrd-detailreportband-selection'; this.leftMarginTemplate = 'dxrd-detail-report-band-coordinate-grid'; this._disposables.push(ko.computed(() => { const isSomeParentCollapsed = this.collapsed() || this.isSomeParentCollapsed(); this.bandsHolder.bands().forEach((band) => { band.isSomeParentCollapsed(isSomeParentCollapsed); }); })); } }