UNPKG

devexpress-reporting

Version:

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

56 lines (55 loc) 2.46 kB
/** * DevExpress HTML/JS Reporting (chart\widgets\_chartDataSourceEditor.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 { localizeNoneString } from '@devexpress/analytics-core/analytics-internal'; import { createViewModelGenerator } from '@devexpress/analytics-core/analytics-serializer-native'; import { Editor } from '@devexpress/analytics-core/analytics-widgets'; import * as ko from 'knockout'; export class ChartDataSourceEditor extends Editor { constructor() { super(...arguments); this.options = null; } createViewModel() { return createViewModelGenerator(super.createViewModel()) .generateProperty('generateOptions', (dataSources, popupContainer) => this.generateOptions(dataSources, popupContainer)) .getViewModel(); } generateOptions(dataSources, popupContainer) { if (!this.options) { const disabled = ko.computed(() => { return this._get('disabled') || !dataSources() || dataSources().length === 0; }); const value = ko.computed({ read: () => { const unwrappedDataSources = dataSources(); const dataSource = unwrappedDataSources.filter(x => !!x && (x.value === this.value()))[0]; return ko.unwrap(dataSource && dataSource.displayName); }, write: (newVal) => { const unwrappedDataSources = dataSources(); const dataSource = unwrappedDataSources.filter(x => !!x && (ko.unwrap(x.displayName) === newVal))[0]; this.value(dataSource && dataSource.value); } }); this._disposables.push(value); this._disposables.push(disabled); this.options = { displayExpr: (dataSource) => { return dataSource?.value ? ko.unwrap(dataSource.displayName) : localizeNoneString('none'); }, dataSource: dataSources, disabled: disabled, value: value, valueExpr: 'displayName', displayCustomValue: true, dropDownOptions: { container: popupContainer } }; } return this.options; } }