UNPKG

devexpress-reporting

Version:

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

104 lines (103 loc) 4.83 kB
/** * DevExpress HTML/JS Reporting (designer\wizard\pages\fullscreen\ai\aiEnterReportPromptPage.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 { $dx, createDeferred } from '@devexpress/analytics-core/analytics-internal-native'; import { getLocalization, PathRequest } from '@devexpress/analytics-core/analytics-utils'; import { FullscreenWizardPage } from '@devexpress/analytics-core/analytics-wizard'; import * as ko from 'knockout'; import { FullscreenReportWizardPageId } from '../../../pageId'; import { ReportType } from '../../../reportWizardState'; import { FieldListProvider } from '@devexpress/analytics-core/analytics-internal'; import { _restoreDataSourceFromState } from '../../chooseAvailableDataSourcePage'; import { FieldListController } from '../../../../internal/fieldlist/_fieldListController'; class AIFieldListController extends FieldListController { canSelect(item) { return false; } } export class AIEnterReportPromptPage extends FullscreenWizardPage { constructor(options) { super(); this.options = options; this._rootItems = ko.observableArray([]); this._reportPromptPlaceholder = getLocalization('Type in a detailed report description', 'ASPxReportsStringId.ReportDesigner_Wizard_AI_EnterReportDescription_PromptPlaceholder'); this._dataStructureSectionTitle = getLocalization('Data source structure', 'ASPxReportsStringId.ReportDesigner_Wizard_AI_EnterReportDescription_DataSourceStructure'); this._promptSectionTitle = getLocalization('Enter your prompt', 'ASPxReportsStringId.ReportDesigner_Wizard_AI_EnterReportDescription_PromptTitle'); this._suggestionsSectionTitle = getLocalization('Predefined prompts', 'ASPxReportsStringId.ReportDesigner_Wizard_AI_EnterReportDescription_PredefinedPrompts'); this._showDataStructure = false; this._reportPrompt = ko.observable(''); const fieldListProvider = new FieldListProvider((pathRequest) => { return options.fieldListCallBack(new PathRequest(pathRequest.fullPath), this._dataSource, false); }, this._rootItems); this._fieldListModel = { itemsProvider: fieldListProvider, treeListController: new AIFieldListController(), selectedPath: ko.observable(null), expandRootItems: true }; } initialize(state) { this._reportPrompt(state.reportPrompt ? state.reportPrompt : ''); this._showDataStructure = state.reportType === ReportType.Standard; if (this._showDataStructure) { this._dataSource = _restoreDataSourceFromState(state.newDataSource || state.dataSource); this._rootItems([this._dataSource]); } return createDeferred().resolve().promise(); } canNext() { return false; } canFinish() { return !!this._reportPrompt(); } commit() { return createDeferred().resolve({ reportPrompt: this._reportPrompt() }).promise(); } _getSuggentionListOptions() { return { items: this.options.predefinedReportPrompts, displayExpr: 'title', onItemClick: (event) => { this._reportPrompt(event.itemData.text); } }; } _customLoadPanelViewModel(element, isLoading) { const position = $dx(element).closest('.dxrd-wizard-content').find('.dxrd-wizard-work-content')[0]; return { visible: isLoading, shading: true, position: { of: position }, message: '', container: position, shadingColor: 'rgba(0,0,0,0.4)', }; } _getPromptTextAreaOptions() { return { value: this._reportPrompt, placeholder: this._reportPromptPlaceholder, valueChangeEvent: 'keyup' }; } } export function _registerAIEnterReportPromptPage(factory, options) { factory.registerMetadata(FullscreenReportWizardPageId.AIEnterReportPromptPage, { create: () => new AIEnterReportPromptPage({ fieldListCallBack: options.callbacks.fieldListsCallback, predefinedReportPrompts: options.aiReportGenerationSettings.predefinedReportPrompts || [] }), getState: (state) => state, setState: (data, state) => state.reportPrompt = data.reportPrompt, resetState: (state, defaultState) => state.reportPrompt = defaultState.reportPrompt, template: 'dxrd-page-ai-report-layout', navigationPanelText: getLocalization('Enter Report Description', 'ASPxReportsStringId.ReportDesigner_Wizard_AI_EntrerReportDescription') }); }