/** sap.m */ import Button from 'sap/m/Button'; import type ComboBox from 'sap/m/ComboBox'; import type Dialog from 'sap/m/Dialog'; /** sap.ui.core */ import type UI5Element from 'sap/ui/core/Element'; /** sap.ui.base */ import type Event from 'sap/ui/base/Event'; /** sap.ui.model */ import JSONModel from 'sap/ui/model/json/JSONModel'; /** sap.ui.rta */ import type RuntimeAuthoring from 'sap/ui/rta/RuntimeAuthoring'; /** sap.ui.dt */ import OverlayRegistry from 'sap/ui/dt/OverlayRegistry'; /** sap.ui.fl */ import { type AddFragmentChangeContentType } from 'sap/ui/fl/Change'; import type Selector from 'sap/ui/fl/Selector'; import { getResourceModel } from '../../i18n.js'; import { MessageBarType, setApplicationRequiresReload } from '@sap-ux-private/control-property-editor-common'; import { getFragmentTemplateName } from '../../cpe/additional-change-info/add-xml-additional-info.js'; import { CommunicationService } from '../../cpe/communication-service.js'; import { QuickActionTelemetryData } from '../../cpe/quick-actions/quick-action-definition.js'; import { getError } from '../../utils/error.js'; import { sendInfoCenterMessage } from '../../utils/info-center-message.js'; import type { AddFragmentData, DeferredXmlFragmentData } from '../add-fragment.js'; import { getFragments } from '../api-handler.js'; import CommandExecutor from '../command-executor.js'; import ControlUtils from '../control-utils.js'; import BaseDialog from './BaseDialog.controller.js'; const radix = 10; export type AddFragmentModel = JSONModel & { getProperty(sPath: '/title'): string; getProperty(sPath: '/completeView'): boolean; getProperty(sPath: '/newFragmentName'): string; getProperty(sPath: '/selectedIndex'): number; getProperty(sPath: '/selectedAggregation/value'): string; }; export interface AddFragmentOptions { title: string; aggregation?: string; defaultAggregationArrayIndex?: number; } /** * @namespace open.ux.preview.client.adp.controllers */ export default class AddFragment extends BaseDialog { private readonly data?: AddFragmentData; constructor( name: string, overlays: UI5Element, rta: RuntimeAuthoring, readonly options: AddFragmentOptions, data?: AddFragmentData, telemetryData?: QuickActionTelemetryData ) { super(name, telemetryData); this.rta = rta; this.overlays = overlays; this.model = new JSONModel({ title: options.title, completeView: options.aggregation === undefined }); this.commandExecutor = new CommandExecutor(this.rta); this.data = data; } /** * Setups the Dialog and the JSON Model * * @param {Dialog} dialog - Dialog instance */ async setup(dialog: Dialog): Promise { this.dialog = dialog; this.setEscapeHandler(); await this.buildDialogData(); const resourceModel = await getResourceModel('open.ux.preview.client'); this.dialog.setModel(resourceModel, 'i18n'); this.dialog.setModel(this.model); this.dialog.open(); } /** * Handles the change in aggregations * * @param event Event */ onAggregationChanged(event: Event) { const source = event.getSource(); const selectedKey = source.getSelectedKey(); const selectedItem = source.getSelectedItem(); let selectedItemText = ''; if (selectedItem) { selectedItemText = selectedItem.getText(); } this.model.setProperty('/selectedAggregation/key', selectedKey); this.model.setProperty('/selectedAggregation/value', selectedItemText); let newSelectedControlChildren: string[] | number[] = Object.keys( ControlUtils.getControlAggregationByName(this.getRuntimeControl(), selectedItemText) ); newSelectedControlChildren = newSelectedControlChildren.map((key) => { return Number.parseInt(key, radix); }); this.specialIndexHandling(selectedItemText); const updatedIndexArray: { key: number; value: number }[] = this.fillIndexArray(newSelectedControlChildren); this.model.setProperty('/index', updatedIndexArray); this.model.setProperty('/selectedIndex', updatedIndexArray.length - 1); } /** * Handles create button press * * @param event Event */ async onCreateBtnPress(event: Event) { const source = event.getSource