devexpress-reporting
Version:
DevExpress Reporting provides the capability to develop a reporting application to create and customize reports.
716 lines (715 loc) • 36.5 kB
JavaScript
/**
* DevExpress HTML/JS Reporting (viewer\ai\_aiPanelModel.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
*/
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import themes from 'devextreme/ui/themes';
import { BaseRenderingModel, mutable } from '@devexpress/analytics-core/analytics-serializer-native';
import { $dx, DxDeferred, formatUnicorn } from '@devexpress/analytics-core/analytics-internal-native';
import { getLocalization, TabInfo } from '@devexpress/analytics-core/analytics-utils-native';
import { getParentContainer } from '@devexpress/analytics-core/analytics-internal-native';
import { AIServicesEnabled, MessageHandler } from '../settings';
import { createViewModel, TextSourceTarget } from './_aiPanel.viewmodel';
import { getCurrentResolution } from '../internal/_utils';
export class AITabInfo extends TabInfo {
constructor(model, template, visible) {
super({
text: getLocalization('AI Operations', 'ASPxReportsStringId.AIPanel_PanelHeaderLabel'),
template,
model,
localizationId: 'ASPxReportsStringId.AIPanel_PanelHeaderLabel',
imageClassName: 'aitab',
imageTemplateName: 'dxrd-svg-tabs-aitab',
visible
});
}
}
export class AIPanelViewModel extends BaseRenderingModel {
get _currentPage() {
return this.reportPreview?.currentPage;
}
constructor(reportPreview, settings) {
super();
this.reportPreview = reportPreview;
this.settings = settings;
this.aiProcessingRequestDeferred = new DxDeferred();
this.tranlsatePagesDeferred = [];
this.ignore = true;
this.languages = [];
this.TextSourceTargetText = {
Document: getLocalization('Entire Document', 'ASPxReportsStringId.AIPanel_TargetTypeDocument'),
Page: getLocalization('Page', 'ASPxReportsStringId.AIPanel_TargetType_Page'),
Selection: getLocalization('Selection', 'ASPxReportsStringId.AIPanel_TargetTypeSelection')
};
this.InvalidLanguageErrorMsg = getLocalization('Select a language', 'ASPxReportsStringId.AIPanel_InvalidLanguageValueErrorMsg');
this.SummarizeActionText = getLocalization('Summarize', 'ASPxReportsStringId.AIPanel_SummarizeAction');
this.TranslateActionText = getLocalization('Translate', 'ASPxReportsStringId.AIPanel_TranslateAction');
this.TranslateDocumentInPlaceText = getLocalization('Translate Inline', 'ASPxReportsStringId.WebDocumentViewer_AI_TranslateInline_MenuAction');
this.warningMsg = 'Text is too long to process within a single request. Text will be split into sections and processed in {0} steps. Proceed?';
this.targets = [
{ key: TextSourceTarget.Document, text: this.TextSourceTargetText.Document },
{ key: TextSourceTarget.Page, text: this.TextSourceTargetText.Page },
{ key: TextSourceTarget.Selection, text: this.TextSourceTargetText.Selection }
];
const translationSettings = settings?.translationSettings;
this.languages = translationSettings?.languages ?? [];
this.inlineTranslationEnabled = !!(translationSettings?.inlineTranslationEnabled && this.languages?.length > 0);
this.translationEnabled = !!(translationSettings?.translationEnabled && this.languages?.length > 0);
this.summarizationEnabled = settings?.summarizationSettings?.summarizationEnabled ?? false;
const aiEnabled = this.inlineTranslationEnabled || this.translationEnabled || this.summarizationEnabled || AIServicesEnabled();
AIServicesEnabled(aiEnabled);
const getDisabled = () => reportPreview.documentBuilding || !reportPreview.documentId || reportPreview.pageIndex === -1;
const tabInfoVisible = () => !getDisabled() && AIServicesEnabled() && (this.translationEnabled || this.summarizationEnabled);
this.tabInfo = new AITabInfo(this, 'dxrd-preview-ai-panel', tabInfoVisible());
const menuItemId = {
MenuRoot: 'dx_ai_menu_root_item',
Summarize: 'dx_summarize_text',
Translate: 'dx_translate',
TranslateInPlaceRoot: 'dx_translate_in_place_root',
TranslatePageInPlace: 'dx_translate_page_in_place',
TranslateSelectionInPlace: 'dx_translate_selection_in_place',
TranslateDocumentInPlace: 'dx_translate_document_in_place',
RevertToOriginalRoot: 'dx_revert_to_original_root',
RevertPageToOriginal: 'dx_revert_page_to_original_root',
RevertAllDocumentToOriginal: 'dx_revert_all_document_to_original_root',
};
const aiMenuItems = [{
text: this.SummarizeActionText,
key: menuItemId.Summarize,
visible: this.summarizationEnabled
},
{
text: this.TranslateActionText,
visible: this.translationEnabled,
items: this.languages.map(language => {
return { ...language, key: menuItemId.Translate };
}),
},
{
text: this.TranslateDocumentInPlaceText,
visible: this.inlineTranslationEnabled,
id: menuItemId.TranslateInPlaceRoot,
items: [{
text: getLocalization('Current Page', 'ASPxReportsStringId.WebDocumentViewer_AI_CurrentPage_MenuActions'),
id: menuItemId.TranslatePageInPlace,
items: this.languages.map(language => {
return { ...language, key: menuItemId.TranslatePageInPlace };
}),
}, {
text: getLocalization('Entire Document', 'ASPxReportsStringId.WebDocumentViewer_AI_EntireDocument_MenuAction'),
id: menuItemId.TranslateDocumentInPlace,
items: this.languages.map(language => {
return { ...language, key: menuItemId.TranslateDocumentInPlace };
}),
},
...this.languages.map(language => { return { ...language, key: menuItemId.TranslateSelectionInPlace }; }),
{
text: getLocalization('Revert to Original', 'ASPxReportsStringId.WebDocumentViewer_AI_RevertToOriginal'),
id: menuItemId.RevertAllDocumentToOriginal,
key: menuItemId.RevertAllDocumentToOriginal
}]
}];
const that = this;
this.smartTagAIMenu = {
dataSource: [{
text: '',
icon: 'dxrd-svg-menu-aimenu',
items: aiMenuItems,
id: menuItemId.MenuRoot
}],
hideSubmenuOnMouseLeave: false,
onItemClick(e) {
e.event?.stopPropagation();
if (!e.itemData || !e.itemData['key'] || that.loading)
return;
const itemKey = e.itemData['key'];
that.selectedTarget = TextSourceTarget.Selection;
if (itemKey === menuItemId.Summarize) {
that.selectedPage = that._currentPage?.pageIndex;
that.IsBrickSelected ? that.selectedTarget = TextSourceTarget.Selection : that.selectedTarget = TextSourceTarget.Page;
that.expandAITabPanel();
that.onSummarizeClick();
}
else if (itemKey === menuItemId.TranslatePageInPlace || itemKey === menuItemId.TranslateSelectionInPlace) {
that.onTranslateClick(e.itemData['id'], true);
}
else if (itemKey === menuItemId.TranslateDocumentInPlace) {
that.onTranslateClick(e.itemData['id'], true, true);
}
else if (itemKey === menuItemId.Translate) {
that.expandAITabPanel();
that.selectedLanguage = e.itemData['id'];
that.selectedPage = that._currentPage?.pageIndex;
if (!that.selectedLanguage) {
that.languageSelectBoxComponent?.option({
validationStatus: 'invalid',
validationErrors: [{ message: this.InvalidLanguageErrorMsg }]
});
return;
}
that.IsBrickSelected ? that.selectedTarget = TextSourceTarget.Selection : that.selectedTarget = TextSourceTarget.Page;
that.onTranslateClick(that.selectedLanguage);
}
else if (itemKey === menuItemId.RevertPageToOriginal) {
that.revertToOriginal(false);
}
else if (itemKey === menuItemId.RevertAllDocumentToOriginal) {
that.revertToOriginal(true);
}
},
onSubmenuShowing: (e) => {
const that = this;
const popupContainer = getParentContainer(e['element']);
e['submenu']._overlay.option('container', popupContainer);
e['submenu']._overlay.option('focusStateEnabled', false);
e['submenu']._overlay.option('position', { collision: 'none', boundary: popupContainer });
e['submenu']._attachHoverEvents();
const submenuItems = e['submenu'].option('items');
let repaint = false;
submenuItems.forEach(function (item) {
let innerItemsUpdates = false;
let visible = item.visible;
switch (item.id) {
case menuItemId.RevertToOriginalRoot:
visible = !!that._currentPage.aiCustomDocumentStorageId || that.documentHasTranslation;
item.internalFields?.item?.items?.forEach(innterItem => {
const pageHasTranslation = !!that._currentPage?.aiCustomDocumentStorageId;
if (innterItem.id === menuItemId.RevertPageToOriginal && innterItem.visible !== pageHasTranslation) {
innterItem.visible = pageHasTranslation;
innerItemsUpdates = true;
}
});
break;
case menuItemId.RevertPageToOriginal:
visible = !!that._currentPage.aiCustomDocumentStorageId;
break;
case menuItemId.RevertAllDocumentToOriginal:
visible = that.documentHasTranslation;
break;
case menuItemId.TranslateInPlaceRoot:
item.internalFields?.item?.items?.forEach(innterItem => {
const shouldChange = innterItem.visible !== !that.IsBrickSelected;
if (innterItem.id === menuItemId.TranslateDocumentInPlace && shouldChange) {
innterItem.visible = !that.IsBrickSelected;
innerItemsUpdates = true;
}
if (innterItem.id === menuItemId.TranslatePageInPlace && shouldChange) {
innterItem.visible = !that.IsBrickSelected;
innerItemsUpdates = true;
}
if (innterItem.key === menuItemId.TranslateSelectionInPlace && innterItem.visible !== that.IsBrickSelected) {
innterItem.visible = that.IsBrickSelected;
innerItemsUpdates = true;
}
if (innterItem.id === menuItemId.RevertAllDocumentToOriginal && innterItem.visible != that.documentHasTranslation) {
innterItem.visible = that.documentHasTranslation;
innerItemsUpdates = true;
}
});
break;
}
if (item.visible !== visible) {
item.visible = visible;
repaint = true;
}
if (innerItemsUpdates && item.internalFields?.item) {
item.internalFields.item.visible = visible;
item.items = item.internalFields.item.items;
repaint = true;
}
});
if (repaint) {
e['submenu'].option('visible', true);
e['submenu'].repaint();
}
},
onItemRendered(e) {
if (e?.itemData?.id === menuItemId.MenuRoot) {
e.itemElement?.setAttribute?.('aria-label', 'AI Menu');
}
},
visible: AIServicesEnabled()
};
window.addEventListener('resize', that.resizeResultArea);
this.addDisposable(() => window.removeEventListener('resize', that.resizeResultArea), reportPreview.events.on('documentIdChanged', (args) => {
this.tabInfo.visible = tabInfoVisible();
this.dispose();
}), reportPreview.events.on('documentBuildingChanged', (args) => {
this.tabInfo.visible = tabInfoVisible();
this.pagesListDataSource = [];
if (!args.newValue && args.oldValue && this.reportPreview.pageIndex !== -1) {
this.reportPreview.pages.forEach(page => {
this.pagesListDataSource.push({ key: page.pageIndex, text: (page.pageIndex + 1).toString() });
});
}
this.dispose();
}), reportPreview.events.on('reportIdChanged', (args) => {
this.dispose();
}), reportPreview.events.on('currentPageChanged', (args) => {
if (args.newValue) {
const currentPage = args.newValue;
this.selectedPage = currentPage.pageIndex;
currentPage.smartTagAIMenu = this.smartTagAIMenu;
this.currentPageSelectionSubcriber && this.currentPageSelectionSubcriber();
this.updateAIMenuToPage();
this.currentPageSelectionSubcriber = currentPage.events.on('activeBricksChanged', (args) => {
this.handleSelectedBrickChangedEvent(args.newValue);
});
}
}), reportPreview.events.on('showMultipagePreviewChanged', (args) => {
this.updateAIMenuToPage();
}));
this.addDisposable(AIServicesEnabled.subscribe(() => {
this.tabInfo.visible = tabInfoVisible();
}));
}
expandAITabPanel() {
this.reportPreview.tabPanel?.toggleTabVisibility({ model: this.tabInfo }, true);
}
get progressBar() {
return this.reportPreview?.progressBar;
}
get documentHasTranslation() {
return this.reportPreview?.pages.some(page => !!page.aiCustomDocumentStorageId) ?? false;
}
get IsBrickSelected() {
return this._currentPage?.getActiveBrick()?.length > 0;
}
handleSelectedBrickChangedEvent(selectedBricks) {
if (selectedBricks.length === 0) {
this.updateAIMenuToPage();
return;
}
let topBrick = selectedBricks[0];
selectedBricks.forEach(brick => {
if (brick.top < topBrick.top)
topBrick = brick;
else if (brick.top == topBrick.top && brick.left < topBrick.left)
topBrick = brick;
});
const topP = topBrick.topP;
this._currentPage.smartTagAIMenuPosition = {
heightP: topBrick.heightP,
topP: topBrick.top >= 0 ? topP : '0%',
widthP: topBrick.widthP,
leftP: this.reportPreview.rtlViewer ? '0%' : 'calc(100% - 40px)',
rightP: this.reportPreview.rtlViewer ? 'calc(100% + 40px)' : '0%'
};
}
updateAIMenuToPage() {
if (!this._currentPage)
return;
this.selectedTarget = TextSourceTarget.Page;
this._currentPage.smartTagAIMenuPosition = {
heightP: '3%',
topP: this.reportPreview?.showMultipagePreview ? '2px' : '0%',
widthP: '11%',
leftP: this.reportPreview?.showMultipagePreview ? 'calc(100% - 40px)' : '100%',
rightP: '0%'
};
}
updateViewModel(args) {
const viewModel = this.getViewModel();
if (args.propertyName === 'aiProcessingResultText') {
viewModel.aiProcessingResultText = this.aiProcessingResultText;
if (this.aiProcessingResultText && this.aiProcessingResultText.length > 0)
viewModel.resultVisible = true;
else
viewModel.resultVisible = false;
this.resizeResultArea();
}
else if (args.propertyName === 'warningTextLimitPopupVisible') {
viewModel.warningTextLimitPopupVisible = this.warningTextLimitPopupVisible;
}
else if (args.propertyName === 'pageSelectBoxVisible' || args.propertyName === 'pagesListDataSource') {
viewModel.pageSelectBoxOptions.dataSource = this.pagesListDataSource;
viewModel.pageSelectBoxOptions.visible = this.pageSelectBoxVisible;
viewModel.pageSelectBoxVisible = this.pageSelectBoxVisible;
}
else if (args.propertyName === 'proceedForAllChunks') {
viewModel.proceedForAllCheckBoxOptions.value = this.proceedForAllChunks;
}
else if (args.propertyName === 'proceedNextButtonClick') {
viewModel.proceedNextButtonClick = this.proceedNextButtonClick;
}
else if (args.propertyName === 'loading') {
if (!this.loading) {
viewModel.buttons.summarizeTextButton.text = this.SummarizeActionText;
viewModel.buttons.translateTextButton.text = this.TranslateActionText;
viewModel.buttons.translateTextButton.disabled = false;
viewModel.buttons.summarizeTextButton.disabled = false;
}
else {
viewModel.buttons.translateTextButton.disabled = true;
viewModel.buttons.summarizeTextButton.disabled = true;
}
}
else if (args.propertyName === 'selectedPage') {
viewModel.pageSelectBoxOptions.value = this.selectedPage;
}
else if (args.propertyName === 'selectedTarget') {
viewModel.targetSelectBoxOptions.value = this.selectedTarget;
this.pageSelectBoxVisible = (this.selectedTarget === TextSourceTarget.Page);
viewModel.pageSelectBoxVisible = this.pageSelectBoxVisible;
viewModel.pageSelectBoxOptions.visible = this.pageSelectBoxVisible;
}
else if (args.propertyName === 'selectedLanguage') {
viewModel.languageSelectBoxOptions.value = this.selectedLanguage;
}
else if (args.propertyName === 'copyButtonTemplate') {
viewModel.buttons.copyResultButton.template = this.copyButtonTemplate;
}
else if (args.propertyName === 'limitExceededWarningMsg') {
viewModel.limitExceededWarningMsg = this.limitExceededWarningMsg;
}
}
createViewModel() {
return createViewModel.call(this, super.createViewModel());
}
onPropertyChanged(args) {
if (args.propertyName === 'aiProcessingResultText') {
this.resizeResultArea();
}
else if (args.propertyName === 'loading') {
if (!this.loading) {
this.summarizeButtonLoader?.option('visible', false);
this.translateButtonLoader?.option('visible', false);
}
}
}
get translateWholeDocument() {
return this.selectedTarget === TextSourceTarget.Document;
}
_preparetextProcessingButtonTemplate(data, container) {
const buttonIndicatorElement = document.createElement('div');
const buttonContainer = document.createElement('div');
const buttonTextElement = document.createElement('span');
buttonIndicatorElement.style.height = '20px';
buttonIndicatorElement.style.width = '20px';
buttonContainer.className = 'dxrd-ai-button-container';
buttonTextElement.className = 'dxrd-ai-button-text';
buttonTextElement.textContent = data.text;
buttonContainer.appendChild(buttonTextElement);
$dx(container).append(buttonIndicatorElement);
$dx(container).append(buttonContainer);
return buttonIndicatorElement;
}
_getTextContentToProcess() {
let page;
const useSelectedContent = this.selectedTarget === TextSourceTarget.Selection;
if (useSelectedContent)
page = this._currentPage;
else if (!this.translateWholeDocument)
page = this.reportPreview.pages[this.selectedPage];
if (page)
page.shouldSendRequest = false;
return this.translateWholeDocument ? '' : (page?.getBricksTextContent(useSelectedContent) ?? '');
}
copyResultClick(e) {
const animateCopy = () => {
this.copyButtonTemplate = 'dxrd-svg-toolbox-checkbox';
setTimeout(() => {
this.copyButtonTemplate = 'dxrd-svg-toolbar-copy';
}, 3000);
};
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(this.aiProcessingResultText).then(() => {
animateCopy();
});
}
else {
const tempTextArea = document.createElement('textarea');
tempTextArea.value = this.aiProcessingResultText;
tempTextArea.style.position = 'absolute';
tempTextArea.style.left = '-9999px';
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand('copy');
document.body.removeChild(tempTextArea);
animateCopy();
}
}
onSummarizeClick() {
if (this.loading)
return;
this.clearProcessing();
this.loading = true;
const viewModel = this.getViewModel();
if (this.summarizeButtonLoader) {
viewModel.buttons.summarizeTextButton.text = '';
this.summarizeButtonLoader.option('visible', true);
}
const text = this._getTextContentToProcess();
this.summarizeText(text, this.selectedLanguage);
}
onTranslateClick(language, translateInPlace = false, allDocument = false) {
if (this.loading && !translateInPlace)
return;
if (!translateInPlace) {
this.clearProcessing();
this.loading = true;
const viewModel = this.getViewModel();
if (this.translateButtonLoader) {
viewModel.buttons.translateTextButton.text = '';
this.translateButtonLoader.option('visible', true);
}
const text = this._getTextContentToProcess();
this.translateText(text);
}
else {
if (allDocument)
this.translateDocument(language);
else {
const brickIndexes = this._currentPage?.getActiveBrick()?.map(brick => brick.indexes) ?? [];
this.translateDocumentPage(brickIndexes, this._currentPage.pageIndex, language, this._currentPage.aiCustomDocumentStorageId);
}
}
}
revertPageToOriginal(page) {
if (!!page.aiCustomDocumentStorageId) {
page._useOriginal = true;
this._updatePageImage(page);
}
}
revertToOriginal(allPages = false) {
if (allPages) {
this.reportPreview.pages.forEach(page => this.revertPageToOriginal(page));
}
else {
this.revertPageToOriginal(this._currentPage);
}
}
clearTranslatePagesDeffereds() {
this.tranlsatePagesDeferred.length && this.tranlsatePagesDeferred.forEach(deferred => deferred.reject());
this.tranlsatePagesDeferred = [];
}
cancelDocumentTranslation() {
this.clearTranslatePagesDeffereds();
this.progressBar.complete(this.reportPreview.documentId);
this.reportPreview?.pages.forEach(page => page.aiOperationInProgress = false);
}
startProgressBar() {
this.progressBar.text = getLocalization('Translating the document...', 'ASPxReportsStringId.WebDocumentViewer_AI_TranslatingDocument');
this.progressBar.cancelText = getLocalization('Cancel', 'AnalyticsCoreStringId.SearchDialog_Cancel');
this.progressBar.startProgress(this.reportPreview.documentId, (documentId) => this.cancelDocumentTranslation());
}
translateDocument(language) {
this.clearTranslatePagesDeffereds();
this.startProgressBar();
let totalPagesProcessed = 0;
const totalPages = this.reportPreview.pages.length;
const step = 100 / totalPages;
this.reportPreview.pages.forEach(page => {
const translatePageDeffered = new DxDeferred();
this.tranlsatePagesDeferred.push(translatePageDeffered);
page.aiOperationInProgress = true;
this.reportPreview.requestWrapper.translateDocumentInPlaseRequest([], language ?? 'en', false, '', 0, page.pageIndex, page.aiCustomDocumentStorageId, this.ignore)
.then(result => translatePageDeffered.resolve(result), fail => translatePageDeffered.reject())
.always(() => {
page.aiOperationInProgress = false;
this.progressBar.progress += step;
totalPagesProcessed += 1;
if (totalPagesProcessed == totalPages) {
this.loading = false;
this.progressBar.complete(this.reportPreview.documentId);
}
});
translatePageDeffered.done(result => this._handeTranslateInPlaseResult(result, page, (prevResultText, nextChunkPosition, aiCustomDocumentStorageId) => this.translateDocumentPage([], page.pageIndex, language, aiCustomDocumentStorageId, prevResultText, nextChunkPosition)));
translatePageDeffered.fail(() => page.loading = false);
});
}
translateDocumentPage(brickIndexes, pageIndex, language, aiCustomDocumentStorageId, prevResponse, currentChunkPosition) {
const page = this.reportPreview.pages[pageIndex];
if (!page)
return;
page.aiOperationInProgress = true;
const ignore = true;
this.aiProcessingRequestDeferred = new DxDeferred();
this.reportPreview.requestWrapper.translateDocumentInPlaseRequest(brickIndexes, language, false, prevResponse, currentChunkPosition, pageIndex, aiCustomDocumentStorageId, ignore)
.then(result => this.aiProcessingRequestDeferred.resolve(result), fail => this.aiProcessingRequestDeferred.reject())
.always(() => page && (page.aiOperationInProgress = false));
this.aiProcessingRequestDeferred.done((result) => {
this._handeTranslateInPlaseResult(result, page, (prevResultText, nextChunkPosition, aiCustomDocumentStorageId) => this.translateDocumentPage(brickIndexes, pageIndex, language, aiCustomDocumentStorageId, prevResultText, nextChunkPosition));
}).always(() => page && (page.aiOperationInProgress = false));
}
translateText(text, prevResponse, currentChunkPosition) {
const ignore = true;
this.aiProcessingRequestDeferred = new DxDeferred();
this.reportPreview.requestWrapper.translateTextRequest(text, this.selectedLanguage ?? 'en', this.translateWholeDocument, prevResponse, currentChunkPosition, false, ignore)
.then(result => this.aiProcessingRequestDeferred.resolve(result), fail => this.failRequestHandler(fail, ignore));
this.aiProcessingRequestDeferred.done((result) => {
this._handleTextProcessingResult(result, (prevResultText, nextChunkPosition) => this.translateText(text, prevResultText, nextChunkPosition));
});
}
summarizeText(text, language, prevResponse, currentChunkPosition) {
this.aiProcessingRequestDeferred = new DxDeferred();
this.reportPreview.requestWrapper.summarizeTextRequest(text, this.translateWholeDocument, prevResponse, currentChunkPosition, language, this.ignore)
.then(result => this.aiProcessingRequestDeferred.resolve(result), fail => this.failRequestHandler(fail, this.ignore));
this.aiProcessingRequestDeferred.done((result) => {
result.language = language;
this._handleTextProcessingResult(result, (prevResultText, nextChunkPosition) => this.summarizeText(text, language, prevResultText, nextChunkPosition), true);
});
}
_handeTranslateInPlaseResult(result, page, nextChunkRequestFunc) {
if (result.success) {
if (result.requestAgain) {
let nextChunkPosition = result.chunkIndex;
if (nextChunkPosition === -1 || (result.text && result.text.length))
nextChunkPosition += 1;
if (this.proceedForAllChunks) {
nextChunkRequestFunc(result.text, nextChunkPosition, result.aiCustomDocumentStorageId);
}
else {
const remainingChunkRequests = parseInt(result.totalChunks) - nextChunkPosition;
this.limitExceededWarningMsg = formatUnicorn(getLocalization(this.warningMsg, 'ASPxReportsStringId.AIPanel_LimitExceededWarning'), remainingChunkRequests);
this.warningTextLimitPopupVisible = true;
this.proceedNextButtonClick = (e) => {
this.warningTextLimitPopupVisible = false;
nextChunkRequestFunc(result.text, nextChunkPosition);
};
}
}
else {
page.aiCustomDocumentStorageId = result.aiCustomDocumentStorageId;
this._updatePageImage(page);
}
}
else {
this.failRequestHandler(result.errorMessage, false);
}
}
_handleTextProcessingResult(result, nextChunkRequestFunc, isSummary = false) {
if (result.success) {
if (!isSummary)
this.aiProcessingResultText += result.text;
if (result.requestAgain) {
let nextChunkPosition = result.chunkIndex;
if (nextChunkPosition === -1 || (result.text && result.text.length))
nextChunkPosition += 1;
if (this.proceedForAllChunks) {
nextChunkRequestFunc(result.text, nextChunkPosition);
}
else {
const remainingChunkRequests = parseInt(result.totalChunks) - nextChunkPosition;
this.limitExceededWarningMsg = formatUnicorn(getLocalization(this.warningMsg, 'ASPxReportsStringId.AIPanel_LimitExceededWarning'), remainingChunkRequests);
this.warningTextLimitPopupVisible = true;
this.proceedNextButtonClick = (e) => {
this.warningTextLimitPopupVisible = false;
nextChunkRequestFunc(result.text, nextChunkPosition);
};
}
}
else {
if (isSummary) {
if (result.language) {
this.reportPreview.requestWrapper.translateTextRequest(result.text, result.language, false, '', 0, true, this.ignore)
.then(translateResult => {
if (translateResult.success) {
this.aiProcessingResultText = translateResult.text;
this.clearProcessing(false);
}
else
this.failRequestHandler(result.errorMessage, this.ignore);
}, fail => {
this.aiProcessingResultText = result.text;
this.failRequestHandler(fail, this.ignore);
});
}
else {
this.aiProcessingResultText = result.text;
this.clearProcessing(false);
}
}
else {
this.clearProcessing(false);
}
}
}
else {
this.failRequestHandler(result.errorMessage, this.ignore);
}
}
_updatePageImage(page) {
const currentPage = page ?? this._currentPage;
currentPage.shouldSendRequest = true;
if (currentPage.actualResolution === 0)
currentPage.actualResolution = getCurrentResolution(this.reportPreview.zoom);
currentPage._updateImageSrc(true);
setTimeout(() => { currentPage._onImageSrcChanged(); }, 10);
}
resizeResultArea() {
const aiPanelElement = document.getElementById('dxrd-preview-ai-panel-id');
const resultTextElement = document.getElementById('dxrd-ai-panel-text-area-id');
if (aiPanelElement && resultTextElement) {
const offset = (themes.current()?.startsWith('material') ?? false) ? 245 : 225;
resultTextElement.style.height = (aiPanelElement.clientHeight - offset) + 'px';
}
else {
resultTextElement && (resultTextElement.style.height = '100%');
}
}
failRequestHandler(errorMessage, clear) {
errorMessage && MessageHandler().processError(errorMessage, true);
clear && this.clearProcessing(false);
}
clearProcessing(clearContent = true) {
this.loading = false;
this.prevRespose = '';
if (clearContent)
this.aiProcessingResultText = '';
this.aiProcessingRequestDeferred?.reject();
this.warningTextLimitPopupVisible = false;
this.proceedForAllChunks = false;
this.warningTextLimitPopupVisible = false;
}
disabled() {
return false;
}
dispose() {
this.clearProcessing();
}
}
__decorate([
mutable('')
], AIPanelViewModel.prototype, "aiProcessingResultText", void 0);
__decorate([
mutable('en')
], AIPanelViewModel.prototype, "selectedLanguage", void 0);
__decorate([
mutable('document')
], AIPanelViewModel.prototype, "selectedTarget", void 0);
__decorate([
mutable(0)
], AIPanelViewModel.prototype, "selectedPage", void 0);
__decorate([
mutable(false)
], AIPanelViewModel.prototype, "proceedForAllChunks", void 0);
__decorate([
mutable(false)
], AIPanelViewModel.prototype, "warningTextLimitPopupVisible", void 0);
__decorate([
mutable(false)
], AIPanelViewModel.prototype, "pageSelectBoxVisible", void 0);
__decorate([
mutable()
], AIPanelViewModel.prototype, "proceedNextButtonClick", void 0);
__decorate([
mutable('dxrd-svg-toolbar-copy')
], AIPanelViewModel.prototype, "copyButtonTemplate", void 0);
__decorate([
mutable('')
], AIPanelViewModel.prototype, "limitExceededWarningMsg", void 0);
__decorate([
mutable(false)
], AIPanelViewModel.prototype, "loading", void 0);
__decorate([
mutable([])
], AIPanelViewModel.prototype, "pagesListDataSource", void 0);