UNPKG

devexpress-reporting

Version:

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

128 lines (127 loc) 5.74 kB
/** * DevExpress HTML/JS Reporting (designer\wizard\pages\fullscreen\ai\aiEnterReportPromptPage.js) * Version: 26.1.3 * Build date: Jun 16, 2026 * Copyright (c) 2012 - 2026 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'; import { ReportAIService } from '../../../../services/_aiService'; import { ReportWizardService } from '../../../../services/_reportWizardService'; import { MasterDetailRequestModel } from '../../../internal/_masterDetailRequestModel'; 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; this._state = state; if (this._showDataStructure) { this._dataSource = _restoreDataSourceFromState(state.newDataSource || state.dataSource); this._rootItems([this._dataSource]); } return createDeferred().resolve().promise(); } canNext() { return !!this._reportPrompt(); } canFinish() { return false; } commit() { const reportPrompt = this._reportPrompt(); const deferred = createDeferred(); const state = { ...this._state, reportPrompt }; const wizardReportModelJson = ReportWizardService.createNewWizardRequest(state, MasterDetailRequestModel, null, null); ReportAIService.startReportGeneration(wizardReportModelJson) .done((id) => { deferred.resolve({ id: id, reportPrompt: reportPrompt }); }).fail((error) => { deferred.reject(error); }); return deferred.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; state.id = data.id; }, resetState: (state, defaultState) => { state.reportPrompt = defaultState.reportPrompt; state.id = defaultState.id; }, template: 'dxrd-page-ai-report-layout', navigationPanelText: getLocalization('Enter Report Description', 'ASPxReportsStringId.ReportDesigner_Wizard_AI_EntrerReportDescription') }); }