UNPKG

@cute-dw/core

Version:

This TypeScript library is the main part of a more powerfull package designed for the fast WEB software development. The cornerstone of the library is the **DataStore** class, which might be useful when you need a full control of the data, but do not need

1,061 lines (1,059 loc) 186 kB
var _a; import { Component, EventEmitter, Input, Output } from '@angular/core'; import { BehaviorSubject, Subscription } from 'rxjs'; import { ResultCode } from '../util/enum/ResultCode'; import { DataStore, ROW_ID_KEY } from '../datastore/DataStore'; import { EventProducer } from '../util/rxjs/EventProducer'; import { Objects } from '../util/Objects'; import { DwColumnsChangeEvent, DwDoubleClickedEvent, DwItemFocusChangedEvent, DwProcessEnterEvent, DwRowFocusChangedEvent, DwRowFocusChangingEvent } from '../datastore/events'; import { Arrays } from '../util/Arrays'; import * as i0 from "@angular/core"; const SELECTION_COLNAME = "select"; /** * A DataWindow object allows users to display, manipulate, and update database or other information. * @version 1.0.0 * @author Alexander V. Strelkov <alv.strelkov@gmail.com> * @copyright © ALEXANDER STRELKOV 2022 * @license MIT * @see {@link DataStore} */ export class DataWindow { get controller() { return this._controller; } set controller(co) { if (co) { this._controller = co; this._controller.setDataWindow(this); } } get ds() { return this._dataStore; } ; set ds(mainDS) { let rc; //if (!mainDS || this._primaryDS === mainDS) return; if (!mainDS || this._primaryDSCreationStamp === mainDS.creationStamp) return; this._primaryDS = mainDS; this._primaryDSCreationStamp = mainDS.creationStamp; /* if (this._primaryCreateSubscription) { this._rootSubscription.remove(this._primaryCreateSubscription); } this._primaryCreateSubscription = mainDS.onCreate.subscribe(() => { rc = this._dataStore.create(mainDS.getOptions()); rc = mainDS.shareData(this._dataStore); this._currentCell = -1; let names: string[] = []; this.controls = this._dataStore.getControls("detail", true) as DwObject[]; this.controls.forEach((c) => { if (c.visible ?? true) { names.push(c.name); } }); this.columnNames = [...names]; }) this._rootSubscription.add(this._primaryCreateSubscription); */ const opts = mainDS.getOptions(); if (opts) { clearInterval(this._intervalId); this._intervalId = undefined; rc = this._dataStore.setHttpService(mainDS.httpService); rc = this._dataStore.create(opts); rc = mainDS.shareData(this._dataStore); this._currentCell = -1; let names = []; this.controls = this._dataStore.getControls("detail", true); this.controls.forEach((c) => { if (c.visible ?? true) { names.push(c.name); } }); if (this._dataStore.getOptions().datawindow?.grid?.selection ?? false) { this.columnNames = [SELECTION_COLNAME, ...names]; } else { this.columnNames = [...names]; } if (this._dataStore.timerInterval) { this._intervalId = window.setInterval(() => this.cuteOnTimer.emit(), this._dataStore.timerInterval); } } } /** Control names in the detail band */ get columnNames() { return this._columnNames; } ; set columnNames(value) { if (!Arrays.equals(this._columnNames, value ?? [])) { this._columnNames = [...value]; this.onColumnsChange$.next(new DwColumnsChangeEvent(this._columnNames)); } } ; constructor() { this._dataStore = new DataStore(); this._canRedraw = true; this._currentCell = -1; this._columnNames = []; // Visible columns this._rootSubscription = new Subscription(); /** Auto run setRow() method on data changed */ this.autoSetRow = true; /** Actual data in the Primary! buffer */ this.dwData = []; /** Controls array in the detail band */ this.controls = []; // PUBLIC EVENTS this.cuteOnClick = new EventEmitter(); this.cuteOnDoubleClick = new EventEmitter(); //@Output() cuteOnProcessEnter = new EventEmitter<DwProcessEnterEvent>(); this.cuteOnGetFocus = new EventEmitter(); this.cuteOnLoseFocus = new EventEmitter(); this.cuteOnTimer = new EventEmitter(); // MAIN DW EVENTS this.onColumnsChange$ = new BehaviorSubject(new DwColumnsChangeEvent([])); this.onDeleteRow$ = new EventProducer(); this.onEditChanged$ = new EventProducer(); this.onInsertRow$ = new EventProducer(); this.onItemChanged$ = new EventProducer(); this.onItemError$ = new EventProducer(); this.onItemFocusChanged$ = new EventProducer(); this.onProcessEnter$ = new EventProducer(); this.onRowFocusChanged$ = new EventProducer(); this.onRowFocusChanging$ = new EventProducer(); // SECONDARY DW EVENTS this.dweRedraw$ = new EventProducer(); this.dweRowDeleted$ = new EventProducer(); /** * JavaScript's `typeof` operator returns `[object DataWindow]` */ this[_a] = "DataWindow"; //super(); } /** * Collect all subscriptions into the one place */ subscribeOnEvents() { const subscriptions = []; subscriptions.push( // onDeleteRow this.onDeleteRow$.subscribe((event) => { this._controller?.onBeforeDeleteRow(event); if (!event.defaultPrevented) { let result = true; let row = -1; const selected = this.getSelectedRows(); if (selected.length > 0) { const oldRow = this.getRow(); this.setRedraw(false); for (let i = selected.length - 1; i >= 0; i--) { row = this.indexOf(selected[i]); if (event.dropOnly) { result = (this.rowsDiscard(row, row) == ResultCode.SUCCESS); } else { result = (this.deleteRow(row) == ResultCode.SUCCESS); } if (!result) { break; } } this.setRedraw(true); this.setRow(Math.min(oldRow, this.rowCount() - 1)); this.dweRowDeleted$.trigger(event); } else { row = event.row || -1; if (event.dropOnly) { result = (this.rowsDiscard(row, row) == ResultCode.SUCCESS); } else { // TODO // Send Delete row to source object result = (this.deleteRow(row) == ResultCode.SUCCESS); } if (result) { this.dweRowDeleted$.trigger(event); } } /* if (result) { this.cuteOnRowDeleted.emit(data.row); if (this.groupCount() > 0) { this.groupCalc(); } } */ } // !Prevented }), // onEditChanged this.onEditChanged$.subscribe(event => this._controller?.onEditChanged(event)), // onInsertRow this.onInsertRow$.subscribe(event => { this._controller?.onBeforeInsertRow(event); if (!event.defaultPrevented) { this.insertRowHandler(event); } }), // onItemFocusChanged this.onItemFocusChanged$.subscribe(event => { this._controller?.onItemFocusChanged(event); }), // onItemChanged this.onItemChanged$.subscribe(event => { this._controller?.onItemChanged(event); }), // onItemError this.onItemError$.subscribe(event => { this._controller?.onItemError(event); }), // onDoubleClicked this.cuteOnDoubleClick.subscribe((event) => { this._controller?.onDoubleClicked(event); if (!event.defaultPrevented) { const peEvent = new DwProcessEnterEvent(event.row, event.dwo); this.processEnterHandler(peEvent); } }), // onGetFocus this.cuteOnGetFocus.subscribe(event => { this._controller?.onGetFocus(); }), // onLoseFocus this.cuteOnLoseFocus.subscribe(event => { this._controller?.onLoseFocus(); }), // onTimer this.cuteOnTimer.subscribe(() => this._controller?.onTimer()), // onProcessEnter this.onProcessEnter$.subscribe(event => { this.processEnterHandler(event); }), // dataStream this.ds.dataStream.subscribe(data => { this.dataStreamHandler(data); }), // onItemChanged (push event) this.ds.onItemChanged.subscribe(event => { this.onItemChanged$.trigger(event); }), // onItemError (push event) this.ds.onItemError.subscribe(event => { this.onItemError$.trigger(event); }), // onHttpError this.ds.onHttpError.subscribe(event => console.log(event)), // onDbError this.ds.onDbError.subscribe(event => console.log(event)), // onRetrieveStart this.ds.onRetrieveStart.subscribe(event => { this._controller?.onRetrieveStart(event); }), // onRetrieveEnd this.ds.onRetrieveEnd.subscribe(event => { this._controller?.onRetrieveEnd(event); }), // onRowChanged this.ds.onRowChanged.subscribe(event => { this._controller?.onRowChanged(event); }), // onRowFocusChanged this.onRowFocusChanged$.subscribe(event => { this._controller?.onRowFocusChanged(event); }), // onRowFocusChanging this.onRowFocusChanging$.subscribe(event => { this._controller?.onRowFocusChanging(event); }), // onUpdateStart this.ds.onUpdateStart.subscribe(event => { this._controller?.onUpdateStart(event); }), // onUpdateEnd this.ds.onUpdateEnd.subscribe(event => { this._controller?.onUpdateEnd(event); })); subscriptions.forEach(s => this._rootSubscription.add(s)); } /** * Unsubscribe all subscriptions that was set before */ unsubscribeFromEvents() { this._rootSubscription.unsubscribe(); } /* Internal event handlers */ dataStreamHandler(data) { this.dwData = data; if (this.autoSetRow && data.length > 0) { this.setRow(0); } } insertRowHandler(event) { return ResultCode.SUCCESS; } processEnterHandler(event) { this._controller?.onShowProperties(event); if (!event.defaultPrevented) { return ResultCode.SUCCESS; } return ResultCode.FAILURE; } /** * Occurs when the user clicks a button inside a DataWindow object * @param col * @param row * @param event */ buttonClicked(col, row, event) { console.log(event); //alert(`${col.name} / ${row}`); //if (this.ds) { let v = this.getItem(row, "notactive"); //if (event.target) // (event.target as any).loading = true; this.setItem(row, "notactive", !v); this.setRow(row); //} } doubleClicked(row, dwo, event) { this.cuteOnDoubleClick.emit(new DwDoubleClickedEvent(row, dwo, event)); } /** * Occurs when the context menu item clicked * @param mi {@link MenuItem} object * * @abstract * @since 0.0.0 */ menuItemClicked(mi) { } /* Properties */ /** * Current cell in the `Grid` style */ get currentCell() { return this._currentCell; } set currentCell(index) { if (index >= 0 && index < this.getControlCount()) { this._currentCell = index; } else { throw new Error(`Invalid cell number: ${index}`); } } /** * Returns redraw flag that was set by setRedraw method * @see {@link setRedraw} * @since 0.0.0 */ get canRedraw() { return this._canRedraw; } /** * @since 0.0.0 */ get httpService() { return this.ds.httpService; } /** * Loading status * @readonly * @since 0.0.0 */ get loading() { return this.ds.loading; } /** * Updating status * @readonly * @since 0.0.0 */ get updating() { return this.ds.updating; } /** * Primary buffer data * @since 0.0.0 */ get data() { return this.ds.data; } /** * Gets data stream as Observable object * @readonly * @since 0.0.0 */ get dataStream() { return this.ds.dataStream; } /** * Checks for any updates that may be pending * @readonly * @since 0.0.0 */ get updatesPending() { return this.ds.updatesPending; } /** * Current filter value * @since 0.0.0 */ get filterValue() { return this.ds.filterValue; } set filterValue(value) { this.ds.filterValue = value; } /** * Current sort value * @since 0.0.0 */ get sortValue() { return this.ds.sortValue; } set sortValue(value) { this.ds.sortValue = value; } /* Methods */ /** * Displays rows in a DataWindow that pass the current filter criteria. Rows that do not meet the filter criteria are moved to the filter buffer. * When the {@link retrieve} method retrieves data for the DataWindow, it applies the filter that was defined * for the DataWindow object, if any. * * @returns Returns `Promise` of 1 if it succeeds and -1 if an error occurs. * @async * @see {@link filterValue} * @since 0.0.0 */ async applyFilter() { return await this.ds.applyFilter(); } /** * Sorts the rows in a DataWindow control or DataStore using the DataWindow's current sort criteria. * When the {@link retrieve} method retrieves data for the DataStore, it applies the sort criteria that were defined for * the DataStore object, if any. * @returns Returns a `Promise` of 1 if it succeeds and -1 if an error occurs. * @async * @see {@link sortValue} * @since 0.0.0 */ async applySort() { return await this.ds.applySort(); } /** * For compatibility only * @see {@link setFocus} * @since 0.0.0 */ focus() { this.setFocus(); } /** * Applies the contents of the DataWindow's edit control to the current item in the buffer of a DataWindow control or DataStore. * The data in the edit control must pass the validation rule for the column before it can be stored in the item. * @returns Returns 1 if it succeeds and -1 if it fails (for example, the data did not pass validation). * @since 0.0.0 */ acceptText() { return this.ds.acceptText(); } /** * Creates a DataWindow object using {@link DataStoreOptions} object. It fully substitutes the current internal structure of a DataStore object. * * @param options An object of `DataStoreOptions` class * @returns 1 if it succeeds and -1 if an error occurs. * @since 0.5.0 */ create(options) { return this.ds.create(options); } /** * Cancels the retrieval process in a DataWindow/DataStore object * @see {@link retrieve} * @since 0.0.0 */ dbCancel() { return this.ds.dbCancel(); } /** * Gets array of DataWindow controls * @param band Target band to which controls must belong. Default is `all`. * @returns Array of `DwObject` objects */ getControlsArray(band = "all") { return this.ds.getControls(band, true); } /** * Gets cloned value of the current config options * @returns DataStoreOptions * @since 0.0.0 */ getOptions() { return this.ds.getOptions(); } /** * Reports the modification status of a row or a column within a row. The modification status determines the type of * SQL statement the Update method will generate for the row or column. * @param row A value identifying the row for which you want the status * @param column The column for which you want the status. Column can be a column number or a column name. * The column number is the number of the column as it is listed in the Column Specification. * @param bufferType A value identifying the DataWindow buffer containing the row for which you want status * @returns * A value of the `ItemStatus` enumerated datatype. If column is null, getItemStatus returns the status of row. * If there is no DataWindow object assigned to the DataWindow control or DataStore, getItemStatus returns undefined. * @since 0.0.0 */ getItemStatus(row, column = null, bufferType = "Primary!") { return this.ds.getItemStatus(row, column, bufferType); } /** * Changes the modification status of a row or a column within a row. The modification status determines the type of * SQL statement the Update method will generate for the row. * @param row The row location in which you want to set the status. * @param column The column location in which you want to set the status. Column can be a column number or a column name. * To set the status for the row, enter null for column. * @param bufferType A value identifying the DataWindow buffer that contains the row. * @param status A value of the ItemStatus enumerated datatype * @returns 1 if it succeeds and -1 if an error occurs. * @since 0.0.0 */ setItemStatus(row, column, bufferType, status) { return this.ds.setItemStatus(row, column, bufferType, status); } /** * Sets the value of a row and column in a DataWindow control or DataStore to the specified value. * * @param row The row location of the data. * @param column The column location of the data. Column can be a column number or a column name. The column number is the number of the column as it is listed in the Column Specification * @param value The value to which you want to set the data at the row and column location. The datatype of the value must be the same datatype as the column * @returns Returns 1 if it succeeds and -1 if an error occurs. * @see {@link getItem} * @since 0.0.0 */ setItem(row, column, value) { return this.ds.setItem(row, column, value); } /** * Reports whether the row has been modified. * * @param row Row number or object to check * @param dwbuffer Internal DataStore buffer type * @returns {boolean} _true_ if the row has been modified and _false_ if it has not. * @see {@link isRowNew} * @see {@link getNextModified} * @since 0.0.0 */ isRowModified(row, dwbuffer = "Primary!") { return this.ds.isRowModified(row, dwbuffer); } /** * Reports whether the row has been newly inserted. * * @param row Row number or object to check * @param dwbuffer Internal DataStore buffer type * @returns {boolean} _true_ if the row is new and _false_ if it was retrieved from the database. * @see {@link isRowModified} * @since 0.0.0 */ isRowNew(row, dwbuffer = "Primary!") { return this.ds.isRowNew(row, dwbuffer); } /** * Returns the number of rows currently available in the DataWindow (all the rows retrieved minus any deleted rows * plus any inserted rows minus any rows that have been filtered out). * @returns Number of rows * @since 0.0.0 */ rowCount() { return this.ds.rowCount(); } /** * Gets row count in the filtered rows buffer * @returns Row count * @see {@link deletedCount} * @see {@link rowCount} * @since 0.0.0 */ filteredCount() { return this.ds.filteredCount(); } /** * Gets row count in the deleted rows buffer * @returns Row count * @see {@link rowCount} * @see {@link filteredCount} * @see {@link modifiedCount} * @since 0.0.0 */ deletedCount() { return this.ds.deletedCount(); } /** * Reports the number of rows that have been modified but not updated in a DataWindow or DataStore. * @returns {number} The number of rows that have been modified in the primary and filter buffer. * Returns 0 if no rows have been modified or if all modified rows have been updated in the database table. * @see {@link rowCount} * @see {@link deletedCount} * @since 0.0.0 */ modifiedCount() { return this.ds.modifiedCount(); } /** * Deletes a row from the primary buffer of a DataWindow control, DataStore object. * If the DataWindow is not updatable, all storage associated with the row is cleared. * If the DataWindow is updatable, DeleteRow moves the row to the DataWindow's delete buffer * The row is not deleted from the database table until the application calls the Update method. * * @param row A value identifying the row you want to delete. To delete the current row, specify `NaN` for row. * @returns 1 if the row is successfully deleted and -1 if an error occurs. * @since 0.0.0 */ deleteRow(row = NaN) { return this.ds.deleteRow(row); } /** * Reports the values of properties of a DataWindow object and controls within the DataWindow object. * Each column and graphic control in the DataWindow has a set of properties. You specify one or more * properties as a string, and Describe returns the values of the properties. * @param propertyList A string list (array) of properties or Evaluate functions * @returns * Returns array of values that includes a primitive value for each property or Evaluate function. * If the property list contains only one item, Describe returns single value. * Describe returns an undefined value if there is no value for a property. * Describe returns null for property if its value is not a primitive. * @example * let arr = dw.describe("datawindow.paginator.pageSize", "datawindow.paginator.showFirstLastPage"); * console.log(arr); // 20, true * let dh = dw.describe("datawindow.header.height"); * console.log(dh); // 48 * let foo = dw.describe("datawindow.bla-bla.bla"); * console.log(foo); // undefined * * @since 0.0.0 */ describe(...propertyList) { return this.ds.describe(...propertyList); } /** * Evaluates CuteScript expression on DataWindow's row * * @param expr Expression on `CuteScript` * @param row Row index in the DataStore * @param options Additional parameters that change the meaning of the result * @returns Result of script evaluation * @since 0.0.0 */ eval(expr, row, options) { let val = undefined; if (this.ds && expr) { val = this.ds.evalExpr(expr, row); } if (val == undefined) { val = options?.defValue; } if (val && (options?.prefix || options?.suffix)) { val = options.prefix || '' + val + options.suffix || ''; } return val; } /** * Allows you to evaluate DataWindow expressions within a javascript code using data in the DataWindow. * * @param expr Expression you want to evaluate directly * @param row The number of the row for which you want to evaluate the expression. * @returns Result of evaluation * @see {@link evalExpr} * @since 0.0.0 */ evaluate(expr, row) { return this.ds.evaluate(expr, row); } /** * Finds the next row in a DataWindow or DataStore in which data meets a specified condition. * * @param expr A string whose value is a boolean expression that you want to use as the search criterion. The expression includes column names. * @param startRow A value identifying the row location at which to begin the search. * Start can be greater than the number of last row in DataStore for searching in backward direction. * @param endRow A value identifying the row location at which to end the search. End can be greater than the number of the last row. * To search backward, make end row less than start. * @returns {number} Returns the number of the first row that meets the search criteria within the search range. Returns -1 if no rows are found and one of these negative numbers if an error occurs: * -2 General error, * -3 Bad argument * @since 0.0.0 */ find(expr, startRow, endRow) { return this.ds.find(expr, startRow, endRow); } /** * Returns a sorted set of unique values calculated by the specified expression over each row of the DataStore * @param expr Expression to evaluate over each row * @returns Sorted set of the distinct values */ distinctValues(expr) { return this.ds.distinctValues(expr); } /** * Gets index of the row object in the Primary! buffer * * @param oRow Object * @returns Object's index value if found, -1 if object was not found in the buffer * @since 0.0.0 */ indexOf(oRow) { return this.ds.indexOf(oRow); } /** * Inserts a row in a DataWindow or DataStore. If any columns have default values, the row is initialized with * these values before it is displayed. InsertRow simply inserts the row without changing the display or the current row. * To scroll to the row and make it the current row, call ScrollToRow. To simply make it the current row, call SetRow. * A newly inserted row (with a status flag of New!) is not included in the modified count until data is entered in the row * (its status flag becomes NewModified!). * * @param row {number} A value identifying the row before which you want to insert a row. To insert a row at the end, specify Infinity. * @returns The number of the row that was added if it succeeds and -1 if an error occurs. * @since 0.0.0 */ insertRow(row = Infinity) { return this.ds.insertRow(row); } /** * Saves the contents of a DataWindow or DataStore in the format you specify * @param exportType An enumerated value of the `SaveAsType` * @param headings Optional. Add headers string for CSV and TXT formats. Default value is _true_. * @returns A `Promise` that resolves to string in the specified format */ async exportString(exportType, headings = true) { return await this.ds.exportString(exportType, headings); } /** * Inserts data into a DataWindow control or DataStore from tab-separated, comma-separated, or XML/JSON data in a string. * * @param importType An enumerated value of the `SaveAsType` * @param source A string from which you want to copy the data. The string should contain tab-separated or comma-separated columns or XML/JSON with one row per line * @param options Optional object with the following optional properties: ** _startRow_ The number of the first detail row in the string that you want to copy. The default is 0. ** _endRow_ The number of the last detail row in the string that you want to copy. The default is the rest of the rows. ** _startCol_ The number of the first column in the string that you want to copy. The default is 0. ** _endCol_ The number of the last column in the string that you want to copy. The default is the rest of the columns. ** _dwStartCol_ The number of the first column in the DataWindow control or DataStore that should receive data. The default is 0. * @returns {Promise} A `Promise` that resolves to the number of rows that were imported if it succeeds or one of the following negative integers if an error occurs: ** -1 No rows or startrow value supplied is greater than the number of rows in the string, ** -3 Invalid argument, ** -4 Invalid input, ** -11 XML Parsing Error; XML parser libraries not found or XML not well-formed, ** -12 XML Template does not exist or does not match the DataWindow, ** -13 Unsupported DataWindow style for import, ** -14 Error resolving DataWindow nesting ** -15 JSON Parsing Error * @since 0.0.0 * @async */ async importString(importType, source, options) { return await this.ds.importString(importType, source, options); } /** * Accesses the database to retrieve values for all columns that can be updated and refreshes all timestamp columns in a row in a DataWindow control or DataStore. The values from the database are redisplayed in the row. * @param row A value identifying the row to reselect * @returns `Promise` object that returns 1 if it is successful and -1 if the row cannot be reselected (for example, the DataWindow object cannot be updated or the row was deleted by another user) * @since 0.0.0 * @see {@link reselectRows} */ reselectRow(row) { return this.ds.reselectRow(row); } /** * Gets data from the specified row and column values in the specified Buffer. You can obtain the * data that was originally retrieved and stored in the database from the original buffer, * as well as the current value in the primary, delete, or filter buffers. * * @param row A value identifying the row location of the data. * @param column The column location of the data. Column can be a column number or a column name. * @param bufferType A value identifying the DataWindow buffer from which you want to get the data. * @param original A boolean indicating whether you want to return the original or current values for row and column: * _true_ - returns the original values (the values initially retrieved from the database). * _false_ - (Default) returns the current values. * @returns Returns the value in the specified row and column. Returns _null_ if the column value is null or * if there is no DataWindow object assigned to the DataWindow control or DataStore. * @since 0.0.0 */ getItem(row, column, bufferType = "Primary!", original = false) { return this.ds.getItem(row, column, bufferType, original); } /** * Reports the number of the current row in a DataWindow control or DataStore object. * @returns The number of the current row in dwcontrol. Returns -1 if no row is current * @since 0.0.0 */ getRow() { return this.ds.getRow(); } /** * Sets the current row in a DataWindow control or DataStore. * @param newRow The row you want to make current * @returns Returns 1 if it succeeds, 0 if the row is the current row indeed, and -1 if an error occurs. * @since 0.0.0 * @description * This method emits the following events: * * {@link DwRowFocusChangingEvent} * * {@link DwRowFocusChangedEvent} */ setRow(newRow) { let rc = ResultCode.FAILURE; const currentRow = this.getRow(); if (newRow == currentRow) { rc = ResultCode.NOTHING; } else if (newRow >= 0 && newRow < this.rowCount()) { const event = new DwRowFocusChangingEvent(currentRow, newRow); this.onRowFocusChanging$.trigger(event); if (!event.defaultPrevented) { rc = this.ds.setRow(newRow); if (rc == ResultCode.SUCCESS) { this.onRowFocusChanged$.trigger(new DwRowFocusChangedEvent(newRow)); } } } return rc; } /** * Gets the unique row identifier of a row in a DataWindow control or DataStore object from the row number associated with that row. * The row identifier value is not the same as the row number value used in many DataWindow and DataStore function calls and * should not be used for the row number value. Instead, you should first convert the unique row identifier into a row number by calling * GetRowFromRowId. * * @param row A number specifying the row number for which you want the associated row identifier. * @param bufferType A value of the dwBuffer enumerated datatype. Default is Primary! * @returns Returns the row identifier in buffer. Returns -1 if the row identifier is not in the current buffer and -1 if an error occurs. * @see {@link getRowFromRowId} * @since 0.0.0 */ getRowIdFromRow(row, bufferType = "Primary!") { return this.ds.getRowIdFromRow(row, bufferType); } /** * Gets the row number of a row in a DataWindow control or DataStore object from the unique row identifier associated with that row. * * @param rowID A number specifying the row identifier for which you want the associated row number. * @param bufferType A value of the dwBuffer enumerated datatype. Default is Primary! * @returns Returns the row number in buffer. Returns -1 if the row number is not in the current buffer * @see {@link getRowIdFromRow} * @since 0.0.0 */ getRowFromRowId(rowID, bufferType = "Primary!") { return this.ds.getRowFromRowId(rowID, bufferType); } /** * Gets current row's data object * * @param {number} row Optional row number. Default is current row in the DataWindow/DataStore * @returns Row object or null if row number is invalid * @since 0.0.0 */ getRowObject(row) { return this.ds.getRowObject(row || this.getRow()); } /** * Obtains the first visible row in the DataWindow control * @returns {number} Row number or -1 if error occurs * @since 0.0.0 */ getFirstVisibleRow() { return -1; } /** * Obtains the last visible row in the DataWindow control * @returns {number} Row number or -1 if error occurs * @since 0.0.0 */ getLastVisibleRow() { return -1; } /** * Obtains the number of the column the user clicked or double-clicked in a DataWindow control or DataStore object. * @returns Returns the number of the column that the user clicked or double-clicked in dwcontrol. * Returns -1 if the user did not click or double-click a column (for example, the user double-clicked outside the data area, * in text or spaces between columns, or in the header, summary, or footer area). * @abstract * @since 0.0.0 */ getClickedColumn() { return -1; } /** * Gets visible columns count in the DataWindow * @since 0.0.0 */ getControlCount() { return this.controls.length; } /** * Gets count of table columns * @returns Number of columns * @since 0.0.0 */ columnCount() { return this.ds.columnCount(); } /** * Obtains the number of the current column. The current column is the column that has focus. * @returns The number of the current column in dwcontrol. Returns -1 if no column is current. * @since 0.0.0 */ getColumn() { return this.ds.getColumn(); } /** * Obtains the name of the current column. The current column is the column that has the focus. * @returns Returns the name of the current column in dwcontrol. * Returns the empty string ("") if no column is current or if an error occurs. * @since 0.0.0 */ getColumnName() { return this.ds.getColumnName(); } /** * Obtains the column's data type by its index or name * @param col {number|string} Column identifier * @returns {string} Column's data type or "!" if column with specified name/index is not found * @since 0.0.0 */ getColumnType(col) { return this.ds.getColumnType(col); } /** * Obtains DataWindow control as a DwObject object by its index or name. * * @param indexOrName Optional. DataWindow control's ordered number or string name. If this parameter is null function applies a current cell * number. Default value is null * @returns {DwObject|null} DataWindow's control object * * @example * const dw = (dwEmpList) as DwBaseComponent; * let dwo = dw.getDwObject(0); * let cName = dwo.name; // ID * dwo = dw.getDwObject("emp_name"); * let cType = dwo.colType; * * @see {@link currentCell} * @since 0.0.0 */ getDwObject(indexOrName = null) { let vc = null; let index = -1; if (indexOrName == null) { indexOrName = this.currentCell; } if (typeof (indexOrName) === "string") { indexOrName = indexOrName.trim(); index = this.controls.findIndex(c => c.name == indexOrName); // Case sensitive !!! } else index = indexOrName; if (index >= 0 && index < this.controls.length) { vc = this.controls[index]; } return vc; } /** * Obtains the values in the code table for the column * * @param column The column for which you want to get CodeTable items. Column can be a column number (integer) or a column name (string). * @returns CodeTable items array * @since 0.0.0 */ getValues(column) { return this.ds.getValues(column); } /** * Obtains the value of an item in a value list or code table associated with a column in a DataWindow * * @param column The column for which you want the item. Column can be a column number (integer) or a column name (string). * @param index The number of the item in the value list or the code table for the edit style. * @returns Returns the item identified by index in the value list. Returns null if the index is not valid or the column does not have a value list or code table. * @since 0.0.0 */ getValue(column, index) { return this.ds.getValue(column, index); } getValueByCode(column, value) { return this.ds.getValueByCode(column, value); } /** * Determines if the specified `column` has a table of display values and corresponding data values * @param column Column's name or number * @returns _True_ if the column definition contains a code table structure, else returns _false_ */ hasCodeTable(column) { return this.ds.hasCodeTable(column); } /** * Obtains the display value in the code table associated with the data value in the specified column. * @param column The column for which you want the code table display value. Column's value can be a text or column's definition number * @param value Key value to search the display value in the code table * @returns {string} Display text for the column's value or value itself if it was not found in the column's value list or code table * @see {@link getValue} * @see {@link getValueByCode} * @since 0.0.0 */ getDisplayValue(column, value) { return this.ds.getDisplayValue(column, value); } /** * * @param nCol * @returns */ getControlCssWidth(nCol) { const dwo = this.getDwObject(nCol); let res = "auto"; if (dwo) { if (Objects.isNumber(dwo.width)) { res = dwo.width + "px"; } } return res; } /** * Accesses the database to retrieve rows with values of parameters, filter and sort conditions that is * currently used in the DataWindow/DataStore. * @returns {Promise} Promise object * @since 0.0.0 */ reselectRows() { return this.ds.reselectRows(); } /** * Clears all the data from a DataWindow control or DataStore object. * Reset is not the same as deleting rows from the DataWindow object or * child DataWindow. Reset affects the application only, not the database. * If you delete rows and then call the Update method, the rows are deleted from * the database table associated with the DataWindow object. If you call Reset and * then call Update, no changes are made to the table. * * @returns 1 if it succeeds and -1 if an error occurs. The return value is usually not used. * @since 0.0.0 */ reset() { return this.ds.reset(); } /** * When a row is changed, inserted, or deleted, its update flag is set, making it marked for update. * By default, the Update method turns these flags off. If you want to coordinate updates of more than * one DataWindow or DataStore, however, you can prevent Update from clearing the flags. Then, after you verify * that all the updates succeeded, you can call ResetUpdate for each DataWindow to clear the flags. * If one of the updates failed, you can keep the update flags, prompt the user to fix the problem, and * try the updates again. * You can find out which rows are marked for update with the GetItemStatus method. If a row is in the * delete buffer or if it is in the primary or filter buffer and has NewModified! or DataModified! status, * its update flag is set. After update flags are cleared, all rows have the status NotModified! or New! and * the delete buffer is empty * @returns Completion code * @see {@link update} * @since 0.0.0 */ resetUpdate() { return this.ds.resetUpdate(); } /** * Retrieves rows from the database for a DataWindow control or DataStore. If arguments are included, * the argument values are used for the retrieval arguments in the SQL SELECT statement for the DataWindow * object or child DataWindow. * * @method retrieve * @param {...any} args One or more values that you want to use as retrieval arguments * @returns {Promise} Promise object * @since 0.0.0 */ retrieve(...args) { return this.ds.retrieve(...args); } /** * Updates the DataWindow with the changes made in a DataWindow control or DataStore. * Method {@link update} can also call {@link acceptText} for the current row and column before it updates the database. * @param accept (optional) A `boolean` value specifying whether the DataWindow control or DataStore should automatically perform an AcceptText prior to performing the update. Default is _true_. * @param resetflag (optional) A `boolean` value specifying whether the DataWindow control or DataStore should automatically reset the update flags. Default is _true_. * @returns {Promise<ResultCode>} `Promise` of update result code: Success(1), Failure(-1) or Nothing(0) happenings * @see {@link acceptText} * @see {@link resetUpdate} * @see {@link updatesPending} * @see {@link updating} * @since 0.0.0 */ update(accept = true, resetflag = true) { return this.ds.update(accept, resetflag); } /** * Copies a range of rows from one DataWindow control (or DataStore object) to another, or from one buffer to another within a single DataWindow control (or DataStore). * * @param startrow The number of the first row you want to copy. * @param endrow The number of the last row you want to copy. * @param srcbuffer A value of the BufferType identifying the DataWindow buffer from which you want to copy rows. * @param target A reference to the DataWindow control or DataStore object to which you want to copy the rows. Target can be the same DataWindow (or DataStore) or another DataWindow (or DataStore) * @param beforerow The number of the row before which you want to insert the copied rows. To insert after the last row, use any value that is greater than the number of existing rows. * @param destbuffer A value of the BufferType enumerated datatype identifying the target DataWindow buffer for the copied rows. * @returns Returns 1 if it succeeds, 0 if nothing happens and -1 if an error occurs. * @since 0.0.0 */ rowsCopy(startrow, endrow, srcbuffer, target, beforerow, destbuffer) { return this.ds.rowsCopy(startrow, endrow, srcbuffer, target, beforerow, destbuffer); } /** * Clears a range of rows from one DataWindow control (or DataStore) and inserts them in another. * Alternatively, RowsMove moves rows from one buffer to another within a single DataWindow control * (or DataStore). * * @param startrow The number of the first row you want to move. * @param endrow The number of the last row you want to move. * @param srcbuffer A value of the BufferType identifying the DataWindow buffer from which you want to move rows. * @param target A reference to the DataWindow control or DataStore object to which you want to move the rows. Target can be the same DataWindow (or DataStore) or another DataWindow (or DataStore) * @param beforerow The number of the row before which you want to insert the moved rows. To insert after the last row, use any value that is greater than the number of existing rows. * @param destbuffer A value of the BufferType enumerated datatype identifying the target DataWindow buffer for the moving rows. * @returns Returns 1 if it succeeds, 0 if nothing happens and -1 if an error occurs. * @since 0.0.0 */ rowsMove(startrow, endrow, srcbuffer, target, beforerow, destbuffer) { return this.ds.rowsMove(startrow, endrow, srcbuffer, target, beforerow, destbuffer); } /** * Discards a range of rows in a DataWindow control. Once a row has been discarded using RowsDiscard, you cannot restore the row. * You have to retrieve it again from the database. * * @param startrow The number of the first row you want to discard. * @param endrow The number of the last row you want to discard. * @param dwbuffer A value of the BufferType enumerated datatype * @returns Returns 1 if it succeeds, 0 if nothing was deleted and -1 if an error occurs. * @since 0.0.0 */ rowsDiscard(startrow, endrow, dwbuffer = "Primary!") { return this.ds.rowsDiscard(startrow, endrow, dwbuffer); } /** * Sets the current column in a DataWindow control or DataStore. * * @param col The column you want to make current. Column can be a column number or a column name. * @returns Returns 1 if it succeeds and -1 if an error occurs. * If column is less than 0 or greater than the number of columns - 1, SetColumn fails. * @since 0.0.0 * @event DwItemFocusChangedEvent */ setColumn(col) { const rc = this.ds.setColumn(col); if (rc == ResultCode.SUCCESS) { this.onItemFocusChanged$.trigger(new DwItemFocusChangedEvent(this.getRow(), this.ds.getColumnName())); } return rc; } /** * Controls the automatic redrawing of an object or control after each change to its properties. * By default, CuteDW redraws a control after each change to properties that affect appearance. * Use SetRedraw to turn off redrawing temporarily in order to avoid flicker and reduce redrawing time * when you are making several changes to the properties of an object or control. * If the window is not visible, SetRedraw fails. * * @param redraw A boolean value that controls whether DataWindow redraws an object automatically after a change. Values are: * _true_ - Automatically redraw the object or control after each change to its properties, * _false_ - Do not redraw after each change. * @returns Returns 1 if it succeeds and -1 if an error occurs. * @since 0.0.0 */ setRedraw(redraw) { if (redraw) { this._canRedraw = true; this.dweRedraw$.trigger(); } else this._canRedraw = false; return ResultCode.SUCCESS; } /** * Gets the total number of pages when a DataWindow object is being viewed * @returns The total number of pages */ pageCount() { return -1; } /** * Gets the number of the current page * @returns The number of the current page */ pageIndex() { return -1; } /** * Gets the maximum number of rows per page * @returns The current page size */ pageSize() { return -1; } /** * Scrolls the DataWindow a specified number of lines up or down. * * @param lines A value specifying the direction and number of lines you want to scroll. To scroll down, use a positive value. To scroll up, use a negative value. * @returns The `Promise` to return the line number of the first visible line in dwcontrol if it succeeds, or -1 if an error occurs. * * @abstract * @asyn