diff --git a/code/src/GridAPI/ColumnManager.Events.ts b/code/src/GridAPI/ColumnManager.Events.ts deleted file mode 100644 index 67101413..00000000 --- a/code/src/GridAPI/ColumnManager.Events.ts +++ /dev/null @@ -1,21 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.ColumnManager.Events { - /** - * API method to subscribe to events of a specific column. - * - * @export - * @param {string} columnID column in which to attach to an event. - * @param {OSFramework.Event.Column.ColumnEventType} eventName event to which attach to. - * @param {OSFramework.Callbacks.OSColumn.ClickEvent} callback to be invoked qhen the event occurs. - */ - export function Subscribe( - columnID: string, - eventName: OSFramework.Event.Column.ColumnEventType, - // eslint-disable-next-line - callback: OSFramework.Callbacks.OSColumn.ClickEvent - ): void { - const column = GetColumnById(columnID); - column.columnEvents.addHandler(eventName, callback); - //TODO: [RGRIDT-636] in case the column is not found we should trigger an error. - } -} diff --git a/code/src/GridAPI/ColumnPicker.ts b/code/src/GridAPI/ColumnPicker.ts deleted file mode 100644 index 013d5498..00000000 --- a/code/src/GridAPI/ColumnPicker.ts +++ /dev/null @@ -1,55 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI { - /** - * API used defining column picker configs - */ - export namespace ColumnPicker { - /** - * Set the visibility of the hidden columns (Visible = False and CanBeHidden = True) on the grid Column Picker. - * By default, all columns are displayed in the Column Picker. - * @param gridID Grid ID - * @param showHiddenColumns Displays the name of the columns that are not visible and whose visibility cannot be changed. - */ - - export function SetColumnVisibility( - gridID: string, - showHiddenColumns: boolean - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any - ): any { - PerformanceAPI.SetMark('ColumnPicker.SetColumnVisibility'); - const responseObj = { - isSuccess: true, - message: OSFramework.Enum.ErrorMessages.SuccessMessage, - code: OSFramework.Enum.ErrorCodes.GRID_SUCCESS - }; - - if (!OSFramework.Helper.IsGridReady(gridID)) { - responseObj.isSuccess = false; - responseObj.message = - OSFramework.Enum.ErrorMessages.Grid_NotFound; - responseObj.code = OSFramework.Enum.ErrorCodes.CFG_GridNotFound; - return JSON.stringify(responseObj); - } - - try { - GridManager.GetGridById( - gridID - ).features.columnPicker.setShowHiddenColumns(showHiddenColumns); - } catch (error) { - responseObj.isSuccess = false; - responseObj.message = error.message; - responseObj.code = - OSFramework.Enum.ErrorCodes.API_FailedSetColumnVisibility; - } - - PerformanceAPI.SetMark('ColumnPicker.SetColumnVisibility-end'); - PerformanceAPI.GetMeasure( - '@datagrid-ColumnPicker.SetColumnVisibility', - 'ColumnPicker.SetColumnVisibility', - 'ColumnPicker.SetColumnVisibility-end' - ); - - return JSON.stringify(responseObj); - } - } -} diff --git a/code/src/GridAPI/Export.ts b/code/src/GridAPI/Export.ts deleted file mode 100644 index 40d59264..00000000 --- a/code/src/GridAPI/Export.ts +++ /dev/null @@ -1,59 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI { - /** - * API used to Configure exporting behavior - */ - export namespace Export { - /** - * Customize the exporting message of grid - * @param gridID Grid ID - * @param exportingMessage The message that will be shown in the grid when data is being exported. - * @param showMessage Set to True to show a custom message when data is being exported. By default, the message shown in “Your data is being exported.” - * @returns A JSON representing whether the operation was succesfull or not - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function CustomizeExportingMessage( - gridID: string, - exportingMessage: string, - showMessage: boolean - ): string { - PerformanceAPI.SetMark('Export.CustomizeExportingMessage'); - - const responseObj = { - isSuccess: true, - message: OSFramework.Enum.ErrorMessages.SuccessMessage, - code: OSFramework.Enum.ErrorCodes.GRID_SUCCESS - }; - - if (!OSFramework.Helper.IsGridReady(gridID)) { - responseObj.isSuccess = false; - responseObj.message = - OSFramework.Enum.ErrorMessages.Grid_NotFound; - responseObj.code = OSFramework.Enum.ErrorCodes.CFG_GridNotFound; - return JSON.stringify(responseObj); - } - try { - const grid = GridManager.GetGridById(gridID); - - grid.features.export.customizeExportingMessage( - exportingMessage, - showMessage - ); - } catch (error) { - responseObj.isSuccess = false; - responseObj.message = error.message; - responseObj.code = - OSFramework.Enum.ErrorCodes.API_FailedCustomizeExportingMessage; - } - - PerformanceAPI.SetMark('Export.CustomizeExportingMessage-end'); - PerformanceAPI.GetMeasure( - '@datagrid-Export.CustomizeExportingMessage', - 'Export.CustomizeExportingMessage', - 'Export.CustomizeExportingMessage-end' - ); - - return JSON.stringify(responseObj); - } - } -} diff --git a/code/src/GridAPI/Language.ts b/code/src/GridAPI/Language.ts deleted file mode 100644 index c0267afc..00000000 --- a/code/src/GridAPI/Language.ts +++ /dev/null @@ -1,26 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI { - export namespace Language { - /** - * - * - * @export - * @param {string} language - * @param {string} url - */ - export function SetLanguage(language: string, url: string): void { - PerformanceAPI.SetMark('Language.SetLanguage'); - - if (language !== '') { - WijmoProvider.Helper.Translation.SetLanguage(language, url); - } - - PerformanceAPI.SetMark('Language.SetLanguage-end'); - PerformanceAPI.GetMeasure( - '@datagrid-Language.SetLanguage', - 'Language.SetLanguage', - 'Language.SetLanguage-end' - ); - } - } -} diff --git a/code/src/GridAPI/View.ts b/code/src/GridAPI/View.ts deleted file mode 100644 index 3c49161e..00000000 --- a/code/src/GridAPI/View.ts +++ /dev/null @@ -1,59 +0,0 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI { - /** - * API used for saving and load View definitions - */ - export namespace View { - /** - * Get the current layout of a given grid - * @param gridID Grid ID - * @returns A JSON representing the current grid configuration - */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function GetViewLayout(gridID: string): string { - if (!OSFramework.Helper.IsGridReady(gridID)) return; - const grid = GridManager.GetGridById(gridID); - - PerformanceAPI.SetMark('View.GetViewLayout'); - - let output = ''; - - output = JSON.stringify(grid.getViewLayout()); - - PerformanceAPI.SetMark('View.GetViewLayout-end'); - PerformanceAPI.GetMeasure( - '@datagrid-View.GetViewLayout', - 'View.GetViewLayout', - 'View.GetViewLayout-end' - ); - - return output; - } - - /** - * Load a predefined layout on a given grid - * @param gridID Grid ID - * @param config A JSON representing a previous saved visualization - */ - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any - export function SetViewLayout(gridID: string, config: any): any { - if (!OSFramework.Helper.IsGridReady(gridID)) return; - const grid = GridManager.GetGridById(gridID); - - PerformanceAPI.SetMark('View.SetViewLayout'); - - let output = ''; - - output = JSON.stringify(grid.setViewLayout(config)); - - PerformanceAPI.SetMark('View.SetViewLayout-end'); - PerformanceAPI.GetMeasure( - '@datagrid-View.SetViewLayout', - 'View.SetViewLayout', - 'View.SetViewLayout-end' - ); - - return output; - } - } -} diff --git a/code/src/OSFramework/Configuration/Column/EditorConfigDate.ts b/code/src/OSFramework/Configuration/Column/EditorConfigDate.ts index 805b3bdb..73a9c816 100644 --- a/code/src/OSFramework/Configuration/Column/EditorConfigDate.ts +++ b/code/src/OSFramework/Configuration/Column/EditorConfigDate.ts @@ -12,7 +12,7 @@ namespace OSFramework.Configuration.Column { // eslint-disable-next-line constructor(config: any, isDateTime: boolean) { super(config); - this.defaultFormat = `${GridAPI.dateFormat}${ + this.defaultFormat = `${OutSystems.GridAPI.dateFormat}${ isDateTime ? ' HH:mm' : '' }`; diff --git a/code/src/OSFramework/Helper/GetClosestGrid.ts b/code/src/OSFramework/Helper/GetClosestGrid.ts index bc53dfa2..c7ad84ba 100644 --- a/code/src/OSFramework/Helper/GetClosestGrid.ts +++ b/code/src/OSFramework/Helper/GetClosestGrid.ts @@ -21,7 +21,7 @@ namespace OSFramework.Helper { // eslint-disable-next-line @typescript-eslint/no-unused-vars .getAttribute(OSFramework.Helper.Constants.uniqueIdAttribute); - return GridAPI.GridManager.GetGridById(uniqueId); + return OutSystems.GridAPI.GridManager.GetGridById(uniqueId); } return null; diff --git a/code/src/OSFramework/Helper/IsGridReady.ts b/code/src/OSFramework/Helper/IsGridReady.ts index ff183189..a3cf4af8 100644 --- a/code/src/OSFramework/Helper/IsGridReady.ts +++ b/code/src/OSFramework/Helper/IsGridReady.ts @@ -2,7 +2,7 @@ namespace OSFramework.Helper { export function IsGridReady(gridID: string): boolean { try { - const grid = GridAPI.GridManager.GetGridById(gridID); + const grid = OutSystems.GridAPI.GridManager.GetGridById(gridID); return grid.isReady; } catch (error) { return false; diff --git a/code/src/OSFramework/Helper/LogMessage.ts b/code/src/OSFramework/Helper/LogMessage.ts new file mode 100644 index 00000000..127fd34a --- /dev/null +++ b/code/src/OSFramework/Helper/LogMessage.ts @@ -0,0 +1,10 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +namespace OSFramework.Helper { + export const warningMessage = + 'This API is deprecated please use the new api'; + + export function LogWarningMessage(message: string): void { + // TODO mechanism to enable logging mesages (like in OS UI) + console.warn(message); + } +} diff --git a/code/src/GridAPI/Auxiliary.ts b/code/src/OutSystems/GridAPI/Auxiliary.ts similarity index 58% rename from code/src/GridAPI/Auxiliary.ts rename to code/src/OutSystems/GridAPI/Auxiliary.ts index 31165428..564ba982 100644 --- a/code/src/GridAPI/Auxiliary.ts +++ b/code/src/OutSystems/GridAPI/Auxiliary.ts @@ -2,7 +2,7 @@ * */ // eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.Auxiliary { +namespace OutSystems.GridAPI.Auxiliary { type APIHandler = { // eslint-disable-next-line callback: any; @@ -62,3 +62,45 @@ namespace GridAPI.Auxiliary { return OSFramework.Helper.GenerateHashCode(str); } } +/// Overrides for the old namespace - calls the new one, lets users know this is no longer in use + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.Auxiliary { + type APIHandler = { + // eslint-disable-next-line + callback: any; + errorCode: OSFramework.Enum.ErrorCodes; + gridID: string; + hasValue?: boolean; + }; + + export function CreateApiResponse({ + gridID, + callback, + errorCode, + hasValue = false + }: APIHandler): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Auxiliary.CreateApiResponse()'` + ); + + return OutSystems.GridAPI.Auxiliary.CreateApiResponse({ + gridID, + callback, + errorCode, + hasValue + }); + } + + /** + * Receives a string and generates the hashcode of it. + * @param str - string, typically the data to be showed in the grid. + * @returns hashcode to the str + */ + export function GetHashCode(str: string): number { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Auxiliary.GetHashCode()'` + ); + return OutSystems.GridAPI.Auxiliary.GetHashCode(str); + } +} diff --git a/code/src/GridAPI/Cells.ts b/code/src/OutSystems/GridAPI/Cell.ts similarity index 63% rename from code/src/GridAPI/Cells.ts rename to code/src/OutSystems/GridAPI/Cell.ts index c803327d..65e26fc3 100644 --- a/code/src/GridAPI/Cells.ts +++ b/code/src/OutSystems/GridAPI/Cell.ts @@ -1,8 +1,4 @@ -/** - * Namespace responsible for all API methods associated to the cells of the Data Grid. - */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.Cells { +namespace OutSystems.GridAPI.Cells { /** * Responsible for defining a specific cell as valid/invalid and showing an error message to the user when the content of that same cell is invalid. * @@ -194,3 +190,109 @@ namespace GridAPI.Cells { return JSON.stringify(responseObj); } } + +/** + * Namespace responsible for all API methods associated to the cells of the Data Grid. + */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.Cells { + /** + * Responsible for defining a specific cell as valid/invalid and showing an error message to the user when the content of that same cell is invalid. + * + * @export + * @param {string} gridID ID of the Grid. + * @param {number} rowIndex Index of the row that contains the cell to be validated. + * @param {string} columnID ID of the Column block in which the action of validation should be triggered. + * @param {boolean} isValid State to which the cell should get validated (valid/invalid). + * @param {string} errorMessage Message that the cell should show on a tooltip in case of an invalid state. + */ + export function SetValidationStatus( + gridID: string, + rowIndex: number, + columnID: string, + isValid: boolean, + errorMessage: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Cells.SetValidationStatus()'` + ); + return OutSystems.GridAPI.Cells.SetValidationStatus( + gridID, + rowIndex, + columnID, + isValid, + errorMessage + ); + } + + /** + * Responsible for running the actions that are in charge of the validation for a cell. + * + * @param {string} gridID ID of the Grid. + * @param {number} rowIndex Index of the row that contains the cells to be validated. + * @param {string} columnID ID of the Column block in which the action of validation should be triggered. + * @param {boolean} [triggerOnCellValueChange=true] Boolean that represents if we want to trigger the on value change event or not + */ + export function ValidateCell( + gridID: string, + rowIndex: number, + columnID: string, + triggerOnCellValueChange = true + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Cells.ValidateCell()'` + ); + return OutSystems.GridAPI.Cells.ValidateCell( + gridID, + rowIndex, + columnID, + triggerOnCellValueChange + ); + } + + /** + * Responsible for running the actions that are in charge of the validation per each column. + * Those actions might be included in the OnCellValueChange handler or in case the isMandatory column configuration is set. + * + * @param {string} gridID ID of the Grid. + * @param {number} rowIndex Index of the row that contains the cells to be validated. + */ + export function ValidateRow(gridID: string, rowIndex: number): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Cells.ValidateRow()'` + ); + return OutSystems.GridAPI.Cells.ValidateRow(gridID, rowIndex); + } + /** + * Responsible for updating a specific cell - + * This is needed in a case we wnat to update another column cell, for example when a cell content is denpendent on another. + * + * @param {string} gridID ID of the Grid. + * @param {number} rowIndex Index of the row that contains the cells to be validated. + * @param {string} columnID ID of the Column block in which the cell should be updated. + * @param {*} value New value to settled on the cell. + * @param {boolean} [showDirtyMark=true] Boolean that represents if the action should also show a dirty mark. + * @param {boolean} [triggerOnCellValueChange=true] Boolean that represents if we want to trigger the on value change event or not + */ + export function SetCellData( + gridID: string, + rowIndex: number, + columnID: string, + // eslint-disable-next-line + value: any, + showDirtyMark = true, + triggerOnCellValueChange = true + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Cells.SetCellData()'` + ); + return OutSystems.GridAPI.Cells.SetCellData( + gridID, + rowIndex, + columnID, + value, + showDirtyMark, + triggerOnCellValueChange + ); + } +} diff --git a/code/src/GridAPI/ColumnFreeze.ts b/code/src/OutSystems/GridAPI/ColumnFreeze.ts similarity index 75% rename from code/src/GridAPI/ColumnFreeze.ts rename to code/src/OutSystems/GridAPI/ColumnFreeze.ts index 99e13892..648563a6 100644 --- a/code/src/GridAPI/ColumnFreeze.ts +++ b/code/src/OutSystems/GridAPI/ColumnFreeze.ts @@ -1,5 +1,8 @@ +/** + * + */ // eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.ColumnFreeze { +namespace OutSystems.GridAPI.ColumnFreeze { /** * Responsable for freeze columns * @param gridID The grid where the action will be performed @@ -121,3 +124,40 @@ namespace GridAPI.ColumnFreeze { return JSON.stringify(responseObj); } } + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.ColumnFreeze { + /** + * Responsable for freeze columns + * @param gridID The grid where the action will be performed + * @param n Number of columns to freeze, when omitted the active cell will be used, and everything to its left will be freeze + */ + export function Freeze(gridID: string, n?: number): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnFreeze.Freeze()'` + ); + return OutSystems.GridAPI.ColumnFreeze.Freeze(gridID, n); + } + + /** + * Verifies if Grid has or not freezed columns + * @param gridID The grid where the action will be performed + */ + export function IsFrozen(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnFreeze.IsFrozen()'` + ); + return OutSystems.GridAPI.ColumnFreeze.IsFrozen(gridID); + } + + /** + * Responsable for free-up all columns freezed + * @param gridID The grid where the action will be performed + */ + export function Unfreeze(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnFreeze.Unfreeze()'` + ); + return OutSystems.GridAPI.ColumnFreeze.Unfreeze(gridID); + } +} diff --git a/code/src/OutSystems/GridAPI/ColumnManager.Events.ts b/code/src/OutSystems/GridAPI/ColumnManager.Events.ts new file mode 100644 index 00000000..46f8adf4 --- /dev/null +++ b/code/src/OutSystems/GridAPI/ColumnManager.Events.ts @@ -0,0 +1,47 @@ +namespace OutSystems.GridAPI.ColumnManager.Events { + /** + * API method to subscribe to events of a specific column. + * + * @export + * @param {string} columnID column in which to attach to an event. + * @param {OSFramework.Event.Column.ColumnEventType} eventName event to which attach to. + * @param {OSFramework.Callbacks.OSColumn.ClickEvent} callback to be invoked qhen the event occurs. + */ + export function Subscribe( + columnID: string, + eventName: OSFramework.Event.Column.ColumnEventType, + // eslint-disable-next-line + callback: OSFramework.Callbacks.OSColumn.ClickEvent + ): void { + const column = GetColumnById(columnID); + column.columnEvents.addHandler(eventName, callback); + //TODO: [RGRIDT-636] in case the column is not found we should trigger an error. + } +} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.ColumnManager.Events { + /** + * API method to subscribe to events of a specific column. + * + * @export + * @param {string} columnID column in which to attach to an event. + * @param {OSFramework.Event.Column.ColumnEventType} eventName event to which attach to. + * @param {OSFramework.Callbacks.OSColumn.ClickEvent} callback to be invoked qhen the event occurs. + */ + export function Subscribe( + columnID: string, + eventName: OSFramework.Event.Column.ColumnEventType, + // eslint-disable-next-line + callback: OSFramework.Callbacks.OSColumn.ClickEvent + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnManager.Events.Subscribe()'` + ); + return OutSystems.GridAPI.ColumnManager.Events.Subscribe( + columnID, + eventName, + callback + ); + } +} diff --git a/code/src/GridAPI/ColumnManager.ts b/code/src/OutSystems/GridAPI/ColumnManager.ts similarity index 69% rename from code/src/GridAPI/ColumnManager.ts rename to code/src/OutSystems/GridAPI/ColumnManager.ts index 2cc3d1d6..9357813d 100644 --- a/code/src/GridAPI/ColumnManager.ts +++ b/code/src/OutSystems/GridAPI/ColumnManager.ts @@ -1,8 +1,4 @@ -/** - * Namespace that contains functions responsible for interactions with columns. - */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.ColumnManager { +namespace OutSystems.GridAPI.ColumnManager { const columnMap = new Map(); //column.uniqueId -> grid.uniqueId const columnArr = new Array(); @@ -360,3 +356,176 @@ namespace GridAPI.ColumnManager { return JSON.stringify(responseObj); } } + +/** + * Namespace that contains functions responsible for interactions with columns. + */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.ColumnManager { + /** + * Add a given column to the grid group panel. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {string} columnID ID of the Column block that will be programmatically added to the grid group panel. + */ + export function AddColumnsToGroupPanel( + gridID: string, + ListOfColumnIDs: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnManager.AddColumnsToGroupPanel()'` + ); + return OutSystems.GridAPI.ColumnManager.AddColumnsToGroupPanel( + gridID, + ListOfColumnIDs + ); + } + + /** + * Creates the column for the provider with the given configurations. + * + * @param {string} columnID id of the column with which actions on the column can be performed. + * @param {OSFramework.Enum.ColumnType} type type of column to be created. + * @param {string} [configs='{}'] configurations in JSON format. + * @param {string} [editorConfig='{}'] configurations to be used when the column is in edit mode. + * @returns {*} {boolean} true if the column got created. + */ + export function CreateColumn( + columnID: string, + type: OSFramework.Enum.ColumnType, + configs = '{}', + editorConfig = '{}' + ): boolean { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnManager.CreateColumn()'` + ); + return OutSystems.GridAPI.ColumnManager.CreateColumn( + columnID, + type, + configs, + editorConfig + ); + } + + /** + * Returns a column based on ID + * @param columnID Column Id + */ + export function GetColumnById( + columnID: string + ): OSFramework.Column.IColumn { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnManager.GetColumnById()'` + ); + return OutSystems.GridAPI.ColumnManager.GetColumnById(columnID); + } + + /** + * Changes the property of a given column. + * + * @export + * @param {string} columnID id of the column with which actions on the column can be performed. + * @param {string} propertyName name of the property to be changed - some properties of the provider might not work out of be box. + * @param {*} propertyValue value to which the property should be changed to. + */ + export function ChangeProperty( + columnID: string, + propertyName: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types + propertyValue: any + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnManager.ChangeProperty()'` + ); + return OutSystems.GridAPI.ColumnManager.ChangeProperty( + columnID, + propertyName, + propertyValue + ); + } + + /** + * Destroys the column + * + * @export + * @param {string} columnID id of the column with which actions on the column can be performed. + */ + export function DestroyColumn(columnID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnManager.DestroyColumn()'` + ); + return OutSystems.GridAPI.ColumnManager.DestroyColumn(columnID); + } + + /** + * Set column aggregate in group panel + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {string} columnID id of the column with which actions on the column can be performed. + * @param {number} aggregate aggregate that will be applied on group panel. + */ + export function SetColumnAggregate( + gridID: string, + columnID: string, + aggregate: number + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnManager.SetColumnAggregate()'` + ); + return OutSystems.GridAPI.ColumnManager.SetColumnAggregate( + gridID, + columnID, + aggregate + ); + } + + /** + * Combines consecutive cells of a given grid column that have the same value into a single cell. + * + * @export + * @param {string} gridID + * @param {string} columnID + * @param {boolean} allowMerge + * @return {*} {string} + */ + export function MergeColumnCells( + gridID: string, + columnID: string, + allowMerge: boolean + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnManager.MergeColumnCells()'` + ); + return OutSystems.GridAPI.ColumnManager.MergeColumnCells( + gridID, + columnID, + allowMerge + ); + } + + /** + * Changes column header + * + * @export + * @param {string} gridID + * @param {string} columnID + * @param {string} header + * @return {*} {string} + */ + export function SetColumnHeader( + gridID: string, + columnID: string, + header: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnManager.SetColumnHeader()'` + ); + return OutSystems.GridAPI.ColumnManager.SetColumnHeader( + gridID, + columnID, + header + ); + } +} diff --git a/code/src/OutSystems/GridAPI/ColumnPicker.ts b/code/src/OutSystems/GridAPI/ColumnPicker.ts new file mode 100644 index 00000000..2c768840 --- /dev/null +++ b/code/src/OutSystems/GridAPI/ColumnPicker.ts @@ -0,0 +1,76 @@ +namespace OutSystems.GridAPI.ColumnPicker { + /** + * Set the visibility of the hidden columns (Visible = False and CanBeHidden = True) on the grid Column Picker. + * By default, all columns are displayed in the Column Picker. + * @param gridID Grid ID + * @param showHiddenColumns Displays the name of the columns that are not visible and whose visibility cannot be changed. + */ + export function SetColumnVisibility( + gridID: string, + showHiddenColumns: boolean + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any + ): any { + PerformanceAPI.SetMark('ColumnPicker.SetColumnVisibility'); + const responseObj = { + isSuccess: true, + message: OSFramework.Enum.ErrorMessages.SuccessMessage, + code: OSFramework.Enum.ErrorCodes.GRID_SUCCESS + }; + + if (!OSFramework.Helper.IsGridReady(gridID)) { + responseObj.isSuccess = false; + responseObj.message = OSFramework.Enum.ErrorMessages.Grid_NotFound; + responseObj.code = OSFramework.Enum.ErrorCodes.CFG_GridNotFound; + return JSON.stringify(responseObj); + } + + try { + GridManager.GetGridById( + gridID + ).features.columnPicker.setShowHiddenColumns(showHiddenColumns); + } catch (error) { + responseObj.isSuccess = false; + responseObj.message = error.message; + responseObj.code = + OSFramework.Enum.ErrorCodes.API_FailedSetColumnVisibility; + } + + PerformanceAPI.SetMark('ColumnPicker.SetColumnVisibility-end'); + PerformanceAPI.GetMeasure( + '@datagrid-ColumnPicker.SetColumnVisibility', + 'ColumnPicker.SetColumnVisibility', + 'ColumnPicker.SetColumnVisibility-end' + ); + + return JSON.stringify(responseObj); + } +} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI { + /** + * API used defining column picker configs + */ + export namespace ColumnPicker { + /** + * Set the visibility of the hidden columns (Visible = False and CanBeHidden = True) on the grid Column Picker. + * By default, all columns are displayed in the Column Picker. + * @param gridID Grid ID + * @param showHiddenColumns Displays the name of the columns that are not visible and whose visibility cannot be changed. + */ + + export function SetColumnVisibility( + gridID: string, + showHiddenColumns: boolean + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any + ): any { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ColumnPicker.SetColumnVisibility()'` + ); + return OutSystems.GridAPI.ColumnPicker.SetColumnVisibility( + gridID, + showHiddenColumns + ); + } + } +} diff --git a/code/src/GridAPI/ConditionalFormat.ts b/code/src/OutSystems/GridAPI/ConditionalFormat.ts similarity index 60% rename from code/src/GridAPI/ConditionalFormat.ts rename to code/src/OutSystems/GridAPI/ConditionalFormat.ts index 4ce9fcb1..e908ffea 100644 --- a/code/src/GridAPI/ConditionalFormat.ts +++ b/code/src/OutSystems/GridAPI/ConditionalFormat.ts @@ -1,5 +1,4 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.ConditionalFormat { +namespace OutSystems.GridAPI.ConditionalFormat { /** * Adds new conditional format rules to the desired binding. * @@ -16,7 +15,7 @@ namespace GridAPI.ConditionalFormat { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { PerformanceAPI.SetMark( 'ConditionalFormat.AddConditionalFormat' ); @@ -48,7 +47,7 @@ namespace GridAPI.ConditionalFormat { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { PerformanceAPI.SetMark( 'ConditionalFormat.RemoveConditionalFormat' ); @@ -66,3 +65,49 @@ namespace GridAPI.ConditionalFormat { ); } } + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.ConditionalFormat { + /** + * Adds new conditional format rules to the desired binding. + * + * @export + * @param {string} gridID + * @param {string} binding Column binding + * @param {Array} rules Rules for conditional formatting. + */ + export function AddConditionalFormat( + gridID: string, + binding: string, + rules: Array + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ConditionalFormat.AddConditionalFormat()'` + ); + return OutSystems.GridAPI.ConditionalFormat.AddConditionalFormat( + gridID, + binding, + rules + ); + } + + /** + * Removes rules of desired binding. + * + * @export + * @param {string} gridID + * @param {string} binding Column binding + */ + export function RemoveConditionalFormat( + gridID: string, + binding: string + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ConditionalFormat.RemoveConditionalFormat()'` + ); + return OutSystems.GridAPI.ConditionalFormat.RemoveConditionalFormat( + gridID, + binding + ); + } +} diff --git a/code/src/GridAPI/ContextMenu.Events.ts b/code/src/OutSystems/GridAPI/ContextMenu.Events.ts similarity index 53% rename from code/src/GridAPI/ContextMenu.Events.ts rename to code/src/OutSystems/GridAPI/ContextMenu.Events.ts index 5e9acc1f..fa7d6f48 100644 --- a/code/src/GridAPI/ContextMenu.Events.ts +++ b/code/src/OutSystems/GridAPI/ContextMenu.Events.ts @@ -1,5 +1,4 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.ContextMenu.Events { +namespace OutSystems.GridAPI.ContextMenu.Events { /** * API method to subscribe to events of the context menu, uses a menu item from the context menu to host the event. * @@ -19,7 +18,7 @@ namespace GridAPI.ContextMenu.Events { GridManager.Events.Subscribe( gridId, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { gridObj.features.contextMenu.contextMenuEvents.addHandler( eventName, callback @@ -28,3 +27,30 @@ namespace GridAPI.ContextMenu.Events { ); } } + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.ContextMenu.Events { + /** + * API method to subscribe to events of the context menu, uses a menu item from the context menu to host the event. + * + * @export + * @param menuItemID menu item in which to attach to an event. + * @param eventName event to which attach to. + * @param callback to be invoked qhen the event occurs. + */ + export function Subscribe( + menuItemID: string, + eventName: OSFramework.Event.Feature.ContextMenuEventType, + // eslint-disable-next-line + callback: OSFramework.Callbacks.ContextMenu.Toggle + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ContextMenu.Events.Subscribe()'` + ); + return OutSystems.GridAPI.ContextMenu.Events.Subscribe( + menuItemID, + eventName, + callback + ); + } +} diff --git a/code/src/GridAPI/ContextMenu.ts b/code/src/OutSystems/GridAPI/ContextMenu.ts similarity index 65% rename from code/src/GridAPI/ContextMenu.ts rename to code/src/OutSystems/GridAPI/ContextMenu.ts index b0632cd3..f153be36 100644 --- a/code/src/GridAPI/ContextMenu.ts +++ b/code/src/OutSystems/GridAPI/ContextMenu.ts @@ -1,5 +1,4 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.ContextMenu { +namespace OutSystems.GridAPI.ContextMenu { /** * Map a MenuItem.UniqueId to its Grid.UniqueId * Help us to know where to add/remove items @@ -62,7 +61,7 @@ namespace GridAPI.ContextMenu { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { gridObj.features.contextMenu.addMenuItem( menuItemId, label, @@ -100,7 +99,7 @@ namespace GridAPI.ContextMenu { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { gridObj.features.contextMenu.addMenuItemSeparator( menuItemId ); @@ -115,10 +114,14 @@ namespace GridAPI.ContextMenu { ); } else { //the grid was not found - throw "The context menu separator is being placed in a grid that doesn't exist"; + throw new Error( + "The context menu separator is being placed in a grid that doesn't exist" + ); } } else { - throw 'The context menu separator is not placed correctly in the grid'; + throw new Error( + 'The context menu separator is not placed correctly in the grid' + ); } } @@ -171,3 +174,79 @@ namespace GridAPI.ContextMenu { ); } } + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.ContextMenu { + /** + * Returns the GridId based on the menuItemId + * @param menuItemId UniqueId of our MenuItem + * @param lookUpDOM Search in DOM by the parent Grid + */ + export function GetGridByMenuId( + menuItemId: string, + lookUpDOM = true + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ContextMenu.GetGridByMenuId()'` + ); + return OutSystems.GridAPI.ContextMenu.GetGridByMenuId( + menuItemId, + lookUpDOM + ); + } + + /** + * Responsible for adding menu items + * @param menuItemId UniqueId defined on OS side + * @param label Label presented on menu + * @param enabled Flag used to enable the menu item + * @param clickEvent Function executed by the menu item + */ + export function AddItem( + menuItemId: string, + label: string, + enabled: boolean, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + clickEvent: OSFramework.Callbacks.ContextMenu.OSClickEvent + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ContextMenu.AddItem()'` + ); + return OutSystems.GridAPI.ContextMenu.AddItem( + menuItemId, + label, + enabled, + clickEvent + ); + } + + export function AddSeparator(menuItemId: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ContextMenu.AddSeparator()'` + ); + return OutSystems.GridAPI.ContextMenu.AddSeparator(menuItemId); + } + + export function ChangeProperty( + menuItemId: string, + propertyName: string, + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any + propertyValue: any + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ContextMenu.ChangeProperty()'` + ); + return OutSystems.GridAPI.ContextMenu.ChangeProperty( + menuItemId, + propertyName, + propertyValue + ); + } + + export function RemoveItem(menuItemId: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.ContextMenu.RemoveItem()'` + ); + return OutSystems.GridAPI.ContextMenu.RemoveItem(menuItemId); + } +} diff --git a/code/src/OutSystems/GridAPI/Export.ts b/code/src/OutSystems/GridAPI/Export.ts new file mode 100644 index 00000000..00717964 --- /dev/null +++ b/code/src/OutSystems/GridAPI/Export.ts @@ -0,0 +1,83 @@ +namespace OutSystems.GridAPI.Export { + /** + * Customize the exporting message of grid + * @param gridID Grid ID + * @param exportingMessage The message that will be shown in the grid when data is being exported. + * @param showMessage Set to True to show a custom message when data is being exported. By default, the message shown in “Your data is being exported.” + * @returns A JSON representing whether the operation was succesfull or not + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + export function CustomizeExportingMessage( + gridID: string, + exportingMessage: string, + showMessage: boolean + ): string { + PerformanceAPI.SetMark('Export.CustomizeExportingMessage'); + + const responseObj = { + isSuccess: true, + message: OSFramework.Enum.ErrorMessages.SuccessMessage, + code: OSFramework.Enum.ErrorCodes.GRID_SUCCESS + }; + + if (!OSFramework.Helper.IsGridReady(gridID)) { + responseObj.isSuccess = false; + responseObj.message = OSFramework.Enum.ErrorMessages.Grid_NotFound; + responseObj.code = OSFramework.Enum.ErrorCodes.CFG_GridNotFound; + return JSON.stringify(responseObj); + } + try { + const grid = GridManager.GetGridById(gridID); + + grid.features.export.customizeExportingMessage( + exportingMessage, + showMessage + ); + } catch (error) { + responseObj.isSuccess = false; + responseObj.message = error.message; + responseObj.code = + OSFramework.Enum.ErrorCodes.API_FailedCustomizeExportingMessage; + } + + PerformanceAPI.SetMark('Export.CustomizeExportingMessage-end'); + PerformanceAPI.GetMeasure( + '@datagrid-Export.CustomizeExportingMessage', + 'Export.CustomizeExportingMessage', + 'Export.CustomizeExportingMessage-end' + ); + + return JSON.stringify(responseObj); + } +} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI { + /** + * API used to Configure exporting behavior + */ + export namespace Export { + /** + * Customize the exporting message of grid + * @param gridID Grid ID + * @param exportingMessage The message that will be shown in the grid when data is being exported. + * @param showMessage Set to True to show a custom message when data is being exported. By default, the message shown in “Your data is being exported.” + * @returns A JSON representing whether the operation was succesfull or not + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + export function CustomizeExportingMessage( + gridID: string, + exportingMessage: string, + showMessage: boolean + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Export.CustomizeExportingMessage()'` + ); + return OutSystems.GridAPI.Export.CustomizeExportingMessage( + gridID, + exportingMessage, + showMessage + ); + } + } +} diff --git a/code/src/GridAPI/Filter.ts b/code/src/OutSystems/GridAPI/Filter.ts similarity index 69% rename from code/src/GridAPI/Filter.ts rename to code/src/OutSystems/GridAPI/Filter.ts index 54202690..23791b4d 100644 --- a/code/src/GridAPI/Filter.ts +++ b/code/src/OutSystems/GridAPI/Filter.ts @@ -1,8 +1,4 @@ -/** - * - */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.Filter { +namespace OutSystems.GridAPI.Filter { /** * Function that returns a boolean if the grid has data visible * @@ -356,3 +352,149 @@ namespace GridAPI.Filter { return JSON.stringify(responseObj); } } + +/** + * + */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.Filter { + /** + * Function that returns a boolean if the grid has data visible + * + * @export + * @param {string} gridID ID of the Grid that is to be to check from results. + * @returns {*} {boolean} true if there are visible results. + */ + export function HasResults(gridID: string): boolean { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Filter.HasResults()'` + ); + return OutSystems.GridAPI.Filter.HasResults(gridID); + } + + /** + * Funtion that perform a Search at a given GridID by a given value + * + * @export + * @param {string} gridID + * @param {string} searchedValue + * @returns {*} {string} Return Message Success or message of error info if it's the case. + */ + export function Search(gridID: string, searchedValue: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Filter.Search()'` + ); + return OutSystems.GridAPI.Filter.Search(gridID, searchedValue); + } + + /** + * Function that activates filter of a given column + * + * @export + * @param {string} gridID ID of the Grid that is to be to check from results. + * @param {string} columnID ID of the column that will have filter activated. + * @returns {*} {string} Return Message Success or message of error info if it's the case. + */ + export function Activate(gridID: string, columnID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Filter.Activate()'` + ); + return OutSystems.GridAPI.Filter.Activate(gridID, columnID); + } + + /** + * Function that clears filter of a given column + * + * @export + * @param {string} gridID ID of the Grid that is to be to check from results. + * @param {string} columnID ID of the column that will have filter cleared. + * @returns {*} {string} Return Message Success or message of error info if it's the case. + */ + export function Clear(gridID: string, columnID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Filter.Clear()'` + ); + return OutSystems.GridAPI.Filter.Clear(gridID, columnID); + } + /** + * Function that deactivates filter of a given column + * + * @export + * @param {string} gridID ID of the Grid that is to be to check from results. + * @param {string} columnID ID of the column that will have filter deactivated. + * @returns {*} {string} Return Message Success or message of error info if it's the case. + */ + export function Deactivate(gridID: string, columnID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Filter.Deactivate()'` + ); + return OutSystems.GridAPI.Filter.Deactivate(gridID, columnID); + } + + /** + * Function that filters a column by condition + * + * @export + * @param {string} gridID ID of the Grid that is to be to check from results. + * @param {string} columnID ID of the column that will be filtered. + * @param {string} values Values on which the column will be filtered by. + * @returns {*} {string} Return Message Success or message of error info if it's the case. + */ + export function ByCondition( + gridID: string, + columnID: string, + values: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Filter.ByCondition()'` + ); + return OutSystems.GridAPI.Filter.ByCondition(gridID, columnID, values); + } + + /** + * Function that filters a column by value + * + * @export + * @param {string} gridID ID of the Grid that is to be to check from results. + * @param {string} columnID ID of the column that will be filtered. + * @param {string} values Values on which the column will be filtered by. + * @returns {*} {string} Return Message Success or message of error info if it's the case. + */ + export function ByValue( + gridID: string, + columnID: string, + values: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Filter.ByValue()'` + ); + return OutSystems.GridAPI.Filter.ByValue(gridID, columnID, values); + } + + /** + * Function that sets column filter options only used when Grid is on ServerSidePagination Mode! + * + * @export + * @param {string} gridID ID of the Grid block. + * @param {string} columnID ID of the column block where the filter options will be set. + * @param {string} options Values that will be used on filter by value list. + * @param {number} maxVisibleOptions Maximum number of elements on the filter list of display values. + * @returns {*} {string} Return Message Success or message of error info if it's the case. + */ + export function SetColumnFilterOptions( + gridID: string, + columnID: string, + options: string, + maxVisibleOptions?: number + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Filter.SetColumnFilterOptions()'` + ); + return OutSystems.GridAPI.Filter.SetColumnFilterOptions( + gridID, + columnID, + options, + maxVisibleOptions + ); + } +} diff --git a/code/src/GridAPI/GridManager.Events.ts b/code/src/OutSystems/GridAPI/GridManager.Events.ts similarity index 61% rename from code/src/GridAPI/GridManager.Events.ts rename to code/src/OutSystems/GridAPI/GridManager.Events.ts index c8a004b5..7e18c62d 100644 --- a/code/src/GridAPI/GridManager.Events.ts +++ b/code/src/OutSystems/GridAPI/GridManager.Events.ts @@ -1,5 +1,4 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.GridManager.Events { +namespace OutSystems.GridAPI.GridManager.Events { // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any const _pendingEvents: Map< string, @@ -87,3 +86,59 @@ namespace GridAPI.GridManager.Events { } } } + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.GridManager.Events { + /** + * API method to subscribe to events of a specific grid. + * + * @export + * @param {string} gridID grid in which to attach to an event. + * @param {OSFramework.Event.Grid.GridEventType} eventName event to which attach to. + * @param {GridAPI.Callbacks.OSGrid.Event} callback to be invoked qhen the event occurs. + */ + export function Subscribe( + gridID: string, + eventName: OSFramework.Event.Grid.GridEventType, + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any + callback: OSFramework.Callbacks.OSGrid.Event + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.Events.Subscribe()'` + ); + return OutSystems.GridAPI.GridManager.Events.Subscribe( + gridID, + eventName, + callback + ); + } + + /** + * API method to check if there are pending events to a specific grid. + * + * @export + * @param {string} gridID grid that is ready for events to be attached to. + */ + export function CheckPendingEvents(gridID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.Events.CheckPendingEvents()'` + ); + return OutSystems.GridAPI.GridManager.Events.CheckPendingEvents(gridID); + } + + export function Unsubscribe( + gridID: string, + eventName: OSFramework.Event.Grid.GridEventType, + // eslint-disable-next-line + callback: OSFramework.Callbacks.OSGrid.Event + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.Events.Unsubscribe()'` + ); + return OutSystems.GridAPI.GridManager.Events.Unsubscribe( + gridID, + eventName, + callback + ); + } +} diff --git a/code/src/GridAPI/GridManager.ts b/code/src/OutSystems/GridAPI/GridManager.ts similarity index 64% rename from code/src/GridAPI/GridManager.ts rename to code/src/OutSystems/GridAPI/GridManager.ts index c1d7a615..aca7b428 100644 --- a/code/src/GridAPI/GridManager.ts +++ b/code/src/OutSystems/GridAPI/GridManager.ts @@ -1,8 +1,4 @@ -/** - * Namespace that contains functions responsible for interactions with the grid. - */ -// eslint-disable-next-line -namespace GridAPI.GridManager { +namespace OutSystems.GridAPI.GridManager { const gridMap = new Map(); //grid.uniqueId -> Grid obj let activeGrid: OSFramework.Grid.IGrid = undefined; @@ -452,9 +448,240 @@ namespace GridAPI.GridManager { */ export function SetDateSample(date: string): void { // eslint-disable-next-line @typescript-eslint/no-unused-vars - GridAPI.dateFormat = date + OutSystems.GridAPI.dateFormat = date .replace('13', 'dd') .replace('10', 'MM') .replace('1900', 'yyyy'); } } + +/** + * Namespace that contains functions responsible for interactions with the grid. + */ +// eslint-disable-next-line +namespace GridAPI.GridManager { + /** + * Function that creates an instance of grid object with the configurations passed. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {string} configs configurations for the grid in JSON format. + * @returns {*} {Grid.IGrid} instance of the grid. + */ + export function CreateGrid( + gridID: string, + configs: string + ): OSFramework.Grid.IGrid { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.CreateGrid()'` + ); + return OutSystems.GridAPI.GridManager.CreateGrid(gridID, configs); + } + + /** + * Function that gets the instance of grid, by a given ID. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {boolean} raiseError Will raise errors when there is no object with this uniqueId + * @returns {*} {Grid.IGrid} instance of the grid. + */ + export function GetGridById( + gridID: string, + raiseError = true + ): OSFramework.Grid.IGrid { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.GetGridById()'` + ); + return OutSystems.GridAPI.GridManager.GetGridById(gridID, raiseError); + } + + /** + * Function that returns all Ids of the grids in the page. + * + * @export + * @returns {*} {Map} + */ + export function GetAllGridIdsInPage(): Array { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.GetAllGridIdsInPage()'` + ); + return OutSystems.GridAPI.GridManager.GetAllGridIdsInPage(); + } + + /** + * Function that gets the instance of the current active grid. The active grid, is always the last (existing) grid that was created in the page. + * + * @export + * @returns {*} {Grid.IGrid} instance of the active grid. + */ + export function GetActiveGrid(): OSFramework.Grid.IGrid { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.GetActiveGrid()'` + ); + return OutSystems.GridAPI.GridManager.GetActiveGrid(); + } + + /** + * Function that obtains all the changed lines (added, edited, removed) by the user. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @returns {*} {string} Changed lines in JSON format. + */ + export function GetChangesInGrid(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.GetChangesInGrid()'` + ); + return OutSystems.GridAPI.GridManager.GetChangesInGrid(gridID); + } + + /** + * Function that initializes the provider grid in the page. + * The current provider grid is wijmo. + * @export + * @param {string} gridID ID of the Grid that is to be initialized. + * @param {string} [data='{}'] Data to be set in the data grid in JSON format. If the action ArrangeData is used, metadata will also be present and used to generate the columns of the grid. + * @returns {*} {boolean} true if the grid was initialized. + */ + export function InitializeGrid(gridID: string, data = '{}'): boolean { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.InitializeGrid()'` + ); + return OutSystems.GridAPI.GridManager.InitializeGrid(gridID, data); + } + + /** + * Function that will mark all changes as saved. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {boolean} [forceCleanInvalids=false] determines whether or not we should clean the validation marks. + */ + export function MarkChangesAsSaved( + gridID: string, + forceCleanInvalids = false + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.MarkChangesAsSaved()'` + ); + return OutSystems.GridAPI.GridManager.MarkChangesAsSaved( + gridID, + forceCleanInvalids + ); + } + /** + * Mark a group of Data Grid lines with given keys (from the KeyBinding field) as saved in the database. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {string} rowKeys List of row identifiers on the KeyBinding field. + * @param {boolean} [forceCleanInvalids=false] determines whether or not we should clean the validation marks. + * @return {*} {string} + */ + export function MarkChangesAsSavedByKey( + gridID: string, + rowKeys: string, + forceCleanInvalids = false + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.MarkChangesAsSavedByKey()'` + ); + return OutSystems.GridAPI.GridManager.MarkChangesAsSavedByKey( + gridID, + rowKeys, + forceCleanInvalids + ); + } + + /** + * Function that will change the data source in the respective grid. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {string} data Data to be set in the data grid in JSON format. If the action ArrangeData is used, metadata will also be present and used to generate the columns of the grid. + * @returns {*} {boolean} true if the data was changed in the grid. + */ + export function SetGridData(gridID: string, data: string): boolean { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.SetGridData()'` + ); + return OutSystems.GridAPI.GridManager.SetGridData(gridID, data); + } + + /** + * Function that will destroy the grid from the page. + * + * @export + * @param {string} gridID ID of the Grid to be destroyed. + */ + export function RemoveGrid(gridID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.RemoveGrid()'` + ); + return OutSystems.GridAPI.GridManager.RemoveGrid(gridID); + } + + /** + * Function that will change the property of a given grid. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {string} propertyName name of the property to be changed - some properties of the provider might not work out of be box. + * @param {*} propertyValue value to which the property should be changed to. + */ + export function ChangeProperty( + gridID: string, + propertyName: string, + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any + propertyValue: any + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.ChangeProperty()'` + ); + return OutSystems.GridAPI.GridManager.ChangeProperty( + gridID, + propertyName, + propertyValue + ); + } + + /** + * Function that clear all changes in grid + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + */ + export function ClearChanges(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.ClearChanges()'` + ); + return OutSystems.GridAPI.GridManager.ClearChanges(gridID); + } + + /** + * + * + * @export + * @param {string} gridID + */ + export function DestroyGrid(gridID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.DestroyGrid()'` + ); + return OutSystems.GridAPI.GridManager.DestroyGrid(gridID); + } + + /** + * Function responsible for setting up the the date format to be used in all grids. + * + * @export + * @param {string} date example of date. + */ + export function SetDateSample(date: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.GridManager.SetDateSample()'` + ); + return OutSystems.GridAPI.GridManager.SetDateSample(date); + } +} diff --git a/code/src/OutSystems/GridAPI/Language.ts b/code/src/OutSystems/GridAPI/Language.ts new file mode 100644 index 00000000..d4d448cc --- /dev/null +++ b/code/src/OutSystems/GridAPI/Language.ts @@ -0,0 +1,42 @@ +namespace OutSystems.GridAPI.Language { + /** + * + * + * @export + * @param {string} language + * @param {string} url + */ + export function SetLanguage(language: string, url: string): void { + PerformanceAPI.SetMark('Language.SetLanguage'); + + if (language !== '') { + WijmoProvider.Helper.Translation.SetLanguage(language, url); + } + + PerformanceAPI.SetMark('Language.SetLanguage-end'); + PerformanceAPI.GetMeasure( + '@datagrid-Language.SetLanguage', + 'Language.SetLanguage', + 'Language.SetLanguage-end' + ); + } +} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI { + export namespace Language { + /** + * + * + * @export + * @param {string} language + * @param {string} url + */ + export function SetLanguage(language: string, url: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Language.SetLanguage()'` + ); + return OutSystems.GridAPI.Language.SetLanguage(language, url); + } + } +} diff --git a/code/src/GridAPI/Pagination.ts b/code/src/OutSystems/GridAPI/Pagination.ts similarity index 65% rename from code/src/GridAPI/Pagination.ts rename to code/src/OutSystems/GridAPI/Pagination.ts index 848ade72..4d0affb9 100644 --- a/code/src/GridAPI/Pagination.ts +++ b/code/src/OutSystems/GridAPI/Pagination.ts @@ -1,8 +1,4 @@ -/** - * - */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.Pagination { +namespace OutSystems.GridAPI.Pagination { /** * * @@ -43,7 +39,7 @@ namespace GridAPI.Pagination { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { PerformanceAPI.SetMark('Pagination.CreatePageButtons'); gridObj.features.pagination.createPageButtons( phID, @@ -274,7 +270,7 @@ namespace GridAPI.Pagination { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { PerformanceAPI.SetMark('Pagination.RegisterCurrentPageLabel'); gridObj.features.pagination.registerLabel( OSFramework.Enum.PageLabel.PageIndex, @@ -304,7 +300,7 @@ namespace GridAPI.Pagination { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { PerformanceAPI.SetMark('Pagination.RegisterPageCountLabel'); gridObj.features.pagination.registerLabel( OSFramework.Enum.PageLabel.PageCount, @@ -332,7 +328,7 @@ namespace GridAPI.Pagination { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { PerformanceAPI.SetMark('Pagination.RegisterPageSizeLabel'); gridObj.features.pagination.registerLabel( OSFramework.Enum.PageLabel.PageSize, @@ -360,7 +356,7 @@ namespace GridAPI.Pagination { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { PerformanceAPI.SetMark('Pagination.RegisterRowEndLabel'); gridObj.features.pagination.registerLabel( OSFramework.Enum.PageLabel.RowEnd, @@ -388,7 +384,7 @@ namespace GridAPI.Pagination { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { PerformanceAPI.SetMark('Pagination.RegisterRowStartLabel'); gridObj.features.pagination.registerLabel( OSFramework.Enum.PageLabel.RowStart, @@ -416,7 +412,7 @@ namespace GridAPI.Pagination { GridManager.Events.Subscribe( gridID, OSFramework.Event.Grid.GridEventType.Initialized, - (gridId: string, gridObj: OSFramework.Grid.IGrid) => { + (_gridId: string, gridObj: OSFramework.Grid.IGrid) => { PerformanceAPI.SetMark('Pagination.RegisterRowTotalLabel'); gridObj.features.pagination.registerLabel( OSFramework.Enum.PageLabel.RowTotal, @@ -433,3 +429,233 @@ namespace GridAPI.Pagination { ); } } +/** + * + */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.Pagination { + /** + * + * + * @export + * @param {string} gridID + * @param {number} n + * @returns {*} {void} + */ + export function ChangePageSize(gridID: string, n: number): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.ChangePageSize()'` + ); + return OutSystems.GridAPI.Pagination.ChangePageSize(gridID, n); + } + + /** + * + * + * @export + * @param {string} gridID + * @param {string} phID + * @param {number} buttonQuantity + */ + export function CreatePageButtons( + gridID: string, + phID: string, + buttonQuantity: number + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.CreatePageButtons()'` + ); + return OutSystems.GridAPI.Pagination.CreatePageButtons( + gridID, + phID, + buttonQuantity + ); + } + + /** + * Gets the current page Index of the DataGrid. + * + * @export + * @param {string} gridID Id of the Grid from which to obtain the pagination Index + * @return {*} {string} Stringified JSON structure containing Index of the current page, error message and code, and success boolean + */ + export function GetCurrentPage(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.GetCurrentPage()'` + ); + return OutSystems.GridAPI.Pagination.GetCurrentPage(gridID); + } + + /** + * + * + * @export + * @param {string} gridID + * @returns {*} {void} + */ + export function MoveToFirstPage(gridID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.MoveToFirstPage()'` + ); + return OutSystems.GridAPI.Pagination.MoveToFirstPage(gridID); + } + + /** + * + * + * @export + * @param {string} gridID + * @returns {*} {void} + */ + export function MoveToLastPage(gridID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.MoveToLastPage()'` + ); + return OutSystems.GridAPI.Pagination.MoveToLastPage(gridID); + } + + /** + * + * + * @export + * @param {string} gridID + * @returns {*} {void} + */ + export function MoveToNextPage(gridID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.MoveToNextPage()'` + ); + return OutSystems.GridAPI.Pagination.MoveToNextPage(gridID); + } + + /** + * + * + * @export + * @param {string} gridID + * @param {number} n + * @returns {*} {string} Stringified JSON structure containing error message and code, and success boolean + */ + export function MoveToPage(gridID: string, n: number): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.MoveToPage()'` + ); + return OutSystems.GridAPI.Pagination.MoveToPage(gridID, n); + } + + /** + * + * + * @export + * @param {string} gridID + * @returns {*} {void} + */ + export function MoveToPreviousPage(gridID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.MoveToPreviousPage()'` + ); + return OutSystems.GridAPI.Pagination.MoveToPreviousPage(gridID); + } + + /** + * + * + * @export + * @param {string} gridID + * @param {string} phID + */ + export function RegisterCurrentPageLabel( + gridID: string, + phID: string + ): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.RegisterCurrentPageLabel()'` + ); + return OutSystems.GridAPI.Pagination.RegisterCurrentPageLabel( + gridID, + phID + ); + } + + /** + * + * + * @export + * @param {string} gridID + * @param {string} phID + */ + export function RegisterPageCountLabel(gridID: string, phID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.RegisterPageCountLabel()'` + ); + return OutSystems.GridAPI.Pagination.RegisterPageCountLabel( + gridID, + phID + ); + } + + /** + * + * + * @export + * @param {string} gridID + * @param {string} phID + */ + export function RegisterPageSizeLabel(gridID: string, phID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.RegisterPageSizeLabel()'` + ); + return OutSystems.GridAPI.Pagination.RegisterPageSizeLabel( + gridID, + phID + ); + } + + /** + * + * + * @export + * @param {string} gridID + * @param {string} phID + */ + export function RegisterRowEndLabel(gridID: string, phID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.RegisterRowEndLabel()'` + ); + return OutSystems.GridAPI.Pagination.RegisterRowEndLabel(gridID, phID); + } + + /** + * + * + * @export + * @param {string} gridID + * @param {string} phID + */ + export function RegisterRowStartLabel(gridID: string, phID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.RegisterRowStartLabel()'` + ); + return OutSystems.GridAPI.Pagination.RegisterRowStartLabel( + gridID, + phID + ); + } + + /** + * + * + * @export + * @param {string} gridID + * @param {string} phID + */ + export function RegisterRowTotalLabel(gridID: string, phID: string): void { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Pagination.RegisterRowTotalLabel()'` + ); + return OutSystems.GridAPI.Pagination.RegisterRowTotalLabel( + gridID, + phID + ); + } +} diff --git a/code/src/GridAPI/README.md b/code/src/OutSystems/GridAPI/README.md similarity index 100% rename from code/src/GridAPI/README.md rename to code/src/OutSystems/GridAPI/README.md diff --git a/code/src/GridAPI/Rows.ts b/code/src/OutSystems/GridAPI/Rows.ts similarity index 69% rename from code/src/GridAPI/Rows.ts rename to code/src/OutSystems/GridAPI/Rows.ts index d5200253..7f02a0c1 100644 --- a/code/src/GridAPI/Rows.ts +++ b/code/src/OutSystems/GridAPI/Rows.ts @@ -1,8 +1,4 @@ -/** - * Namespace responsible for all API methods associated to the rows of the Data Grid. - */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.Rows { +namespace OutSystems.GridAPI.Rows { /** * Functon that will add a CSS class to a specific row from the grid. * @@ -486,3 +482,217 @@ namespace GridAPI.Rows { return result; } } + +/** + * Namespace responsible for all API methods associated to the rows of the Data Grid. + */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.Rows { + /** + * Functon that will add a CSS class to a specific row from the grid. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {number} rowNumber Number of the row in which the class is going to be added. + * @param {string} className CSS class to add to the row. + */ + export function AddClass( + gridID: string, + rowNumber: number, + className: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.AddClass()'` + ); + return OutSystems.GridAPI.Rows.AddClass(gridID, rowNumber, className); + } + + /** + * Function that will add new rows to the grid + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @returns {*} {string} Resulting code and message in JSON format + */ + export function AddRows(gridID: string, numberOfRows = 1): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.AddRows()'` + ); + return OutSystems.GridAPI.Rows.AddRows(gridID, numberOfRows); + } + + /** + * Function that will get data from a specific row + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {number} rowNumber Number of the row in data will be retrieved. + * @returns {*} {string} Resulting code and message in JSON format + */ + export function GetRowData(gridID: string, rowNumber: number): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.GetRowData()'` + ); + return OutSystems.GridAPI.Rows.GetRowData(gridID, rowNumber); + } + + /** + * Function that will get row number + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {string} key Text set on keyBinding. + * @returns {*} {string} Resulting code and message in JSON format + */ + export function GetRowNumberByKey(gridID: string, key: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.GetRowNumberByKey()'` + ); + return OutSystems.GridAPI.Rows.GetRowNumberByKey(gridID, key); + } + + /** + * Remove all CSS classes from a specific row on the grid. + * + * @param {string} gridID ID of the Grid where the change will occur. + * @param {number} rowNumber Number of the row in which all CSS classes are going to be removed. + */ + export function RemoveAllClasses( + gridID: string, + rowNumber: number + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.RemoveAllClasses()'` + ); + return OutSystems.GridAPI.Rows.RemoveAllClasses(gridID, rowNumber); + } + + /** + * Remove a CSS class from a specific row on the grid. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {number} rowNumber Number of the row in which the class is going to be removed. + * @param {string} className CSS class to remove from the row. + */ + export function RemoveClass( + gridID: string, + rowNumber: number, + className: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.RemoveClass()'` + ); + return OutSystems.GridAPI.Rows.RemoveClass( + gridID, + rowNumber, + className + ); + } + + /** + * Function that will remove the selected rows from the grid. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @returns {*} {string} Resulting code and message in JSON format + */ + export function RemoveRows(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.RemoveRows()'` + ); + return OutSystems.GridAPI.Rows.RemoveRows(gridID); + } + + /** + * Function that will ipdate the key binding of an added line on a given grid. The id of the row with the CurrentRowId will be updated with the NewKey value. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {number} startIndex New row start index. + */ + export function UpdateAddedRowKey( + gridID: string, + currentRowId: string, + newKey: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.UpdateAddedRowKey()'` + ); + return OutSystems.GridAPI.Rows.UpdateAddedRowKey( + gridID, + currentRowId, + newKey + ); + } + + /** + * Function that will set start index of row. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {number} startIndex New row start index. + */ + export function UpdateStartingRowHeader( + gridID: string, + startIndex: number + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.UpdateStartingRowHeader()'` + ); + return OutSystems.GridAPI.Rows.UpdateStartingRowHeader( + gridID, + startIndex + ); + } + + /** + * Function that will set the row validation using the key + * + * @export + * + * @param {string} gridID ID of the Grid. + * @param {string} rowKey Key of the row that contains the cell to be validated. + * @param {string} columnID ID of the Column block in which the action of validation should be triggered. + * @param {boolean} isValid State to which the cell should get validated (valid/invalid). + * @param {string} errorMessage Message that the cell should show on a tooltip in case of an invalid state. + */ + export function SetValidationStatusByKey( + gridID: string, + rowKey: string, + columnID: string, + isValid: boolean, + errorMessage: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.SetValidationStatusByKey()'` + ); + return OutSystems.GridAPI.Rows.SetValidationStatusByKey( + gridID, + rowKey, + columnID, + isValid, + errorMessage + ); + } + + /** + * Function that toggle row dragging. + * + * @export + * @param {string} gridID ID of the Grid where the change will occur. + * @param {boolean} allowRowDragging Allow the rows to be dragged. + */ + export function ToggleRowDragging( + gridID: string, + allowRowDragging: boolean + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Rows.ToggleRowDragging()'` + ); + return OutSystems.GridAPI.Rows.ToggleRowDragging( + gridID, + allowRowDragging + ); + } +} diff --git a/code/src/GridAPI/Selection.ts b/code/src/OutSystems/GridAPI/Selection.ts similarity index 66% rename from code/src/GridAPI/Selection.ts rename to code/src/OutSystems/GridAPI/Selection.ts index 64ce2e3a..947443aa 100644 --- a/code/src/GridAPI/Selection.ts +++ b/code/src/OutSystems/GridAPI/Selection.ts @@ -1,5 +1,4 @@ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.Selection { +namespace OutSystems.GridAPI.Selection { export function GetAllSelections(gridID: string): string { PerformanceAPI.SetMark('Selection.GetAllSelections'); @@ -90,3 +89,48 @@ namespace GridAPI.Selection { return JSON.stringify(grid.features.selection.hasSelectedRows()); } } + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.Selection { + export function GetAllSelections(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Selection.GetAllSelections()'` + ); + return OutSystems.GridAPI.Selection.GetAllSelections(gridID); + } + + export function GetAllSelectionsData(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Selection.GetAllSelectionsData()'` + ); + return OutSystems.GridAPI.Selection.GetAllSelectionsData(gridID); + } + + export function GetCheckedRowsData(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Selection.GetCheckedRowsData()'` + ); + return OutSystems.GridAPI.Selection.GetCheckedRowsData(gridID); + } + + export function GetSelectedRowsCount(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Selection.GetSelectedRowsCount()'` + ); + return OutSystems.GridAPI.Selection.GetSelectedRowsCount(gridID); + } + + export function GetSelectedRowsData(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Selection.GetSelectedRowsData()'` + ); + return OutSystems.GridAPI.Selection.GetSelectedRowsData(gridID); + } + + export function HasSelectedRows(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Selection.HasSelectedRows()'` + ); + return OutSystems.GridAPI.Selection.HasSelectedRows(gridID); + } +} diff --git a/code/src/GridAPI/Sort.ts b/code/src/OutSystems/GridAPI/Sort.ts similarity index 83% rename from code/src/GridAPI/Sort.ts rename to code/src/OutSystems/GridAPI/Sort.ts index 2e4e3a12..6dd3963f 100644 --- a/code/src/GridAPI/Sort.ts +++ b/code/src/OutSystems/GridAPI/Sort.ts @@ -1,8 +1,4 @@ -/** - * - */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.Sort { +namespace OutSystems.GridAPI.Sort { /** * Function that clears sort of grid * @@ -138,3 +134,37 @@ namespace GridAPI.Sort { return JSON.stringify(responseObj); } } + +/** + * + */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.Sort { + export function Clear(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Sort.Clear()'` + ); + return OutSystems.GridAPI.Sort.Clear(gridID); + } + + export function ColumnSort( + gridID: string, + columnID: string, + sorting: OSFramework.OSStructure.Sorting + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Sort.ColumnSort()'` + ); + return OutSystems.GridAPI.Sort.ColumnSort(gridID, columnID, sorting); + } + + export function SetUnsortState( + gridID: string, + hasUnsortState: boolean + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Sort.SetUnsortState()'` + ); + return OutSystems.GridAPI.Sort.SetUnsortState(gridID, hasUnsortState); + } +} diff --git a/code/src/GridAPI/Styling.ts b/code/src/OutSystems/GridAPI/Styling.ts similarity index 78% rename from code/src/GridAPI/Styling.ts rename to code/src/OutSystems/GridAPI/Styling.ts index da5f3b9c..5db61eaf 100644 --- a/code/src/GridAPI/Styling.ts +++ b/code/src/OutSystems/GridAPI/Styling.ts @@ -1,8 +1,4 @@ -/** - * Namespace responsible for all API methods associated to the styling of cells in the Data Grid. - */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars -namespace GridAPI.Styling { +namespace OutSystems.GridAPI.Styling { /** * Function that will add a specific CSS class to a cell * @@ -278,3 +274,99 @@ namespace GridAPI.Styling { return JSON.stringify(responseObj); } } + +/** + * Namespace responsible for all API methods associated to the styling of cells in the Data Grid. + */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI.Styling { + /** + * Function that will add a specific CSS class to a cell + * + * @export + * @param {string} gridID + * @param {string} columnID + * @param {number} rowIndex + * @param {string} className + */ + export function SetCellCssClass( + gridID: string, + columnID: string, + rowIndex: number, + className: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Styling.SetCellCssClass()'` + ); + return OutSystems.GridAPI.Styling.SetCellCssClass( + gridID, + columnID, + rowIndex, + className + ); + } + + export function SetColumnCssClass( + gridID: string, + columnID: string, + cssClass: string, + applyToHeader: boolean + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Styling.SetColumnCssClass()'` + ); + return OutSystems.GridAPI.Styling.SetColumnCssClass( + gridID, + columnID, + cssClass, + applyToHeader + ); + } + + export function RemoveAllCssClassesFromCell( + gridID: string, + columnID: string, + rowIndex: number + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Styling.RemoveAllCssClassesFromCell()'` + ); + return OutSystems.GridAPI.Styling.RemoveAllCssClassesFromCell( + gridID, + columnID, + rowIndex + ); + } + + export function RemoveColumnCssClass( + gridID: string, + columnID: string, + cssClass: string + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Styling.RemoveColumnCssClass()'` + ); + return OutSystems.GridAPI.Styling.RemoveColumnCssClass( + gridID, + columnID, + cssClass + ); + } + + export function SetColumnWordWrap( + gridID: string, + columnID: string, + wordWrapValue: boolean, + dynamicHeight: boolean + ): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.Styling.SetColumnWordWrap()'` + ); + return OutSystems.GridAPI.Styling.SetColumnWordWrap( + gridID, + columnID, + wordWrapValue, + dynamicHeight + ); + } +} diff --git a/code/src/OutSystems/GridAPI/View.ts b/code/src/OutSystems/GridAPI/View.ts new file mode 100644 index 00000000..4875ceac --- /dev/null +++ b/code/src/OutSystems/GridAPI/View.ts @@ -0,0 +1,77 @@ +namespace OutSystems.GridAPI.View { + /** + * Get the current layout of a given grid + * @param gridID Grid ID + * @returns A JSON representing the current grid configuration + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + export function GetViewLayout(gridID: string): string { + if (!OSFramework.Helper.IsGridReady(gridID)) return; + const grid = GridManager.GetGridById(gridID); + + PerformanceAPI.SetMark('View.GetViewLayout'); + + let output = ''; + + output = JSON.stringify(grid.getViewLayout()); + + PerformanceAPI.SetMark('View.GetViewLayout-end'); + PerformanceAPI.GetMeasure( + '@datagrid-View.GetViewLayout', + 'View.GetViewLayout', + 'View.GetViewLayout-end' + ); + + return output; + } + + /** + * Load a predefined layout on a given grid + * @param gridID Grid ID + * @param config A JSON representing a previous saved visualization + */ + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any + export function SetViewLayout(gridID: string, config: any): any { + if (!OSFramework.Helper.IsGridReady(gridID)) return; + const grid = GridManager.GetGridById(gridID); + + PerformanceAPI.SetMark('View.SetViewLayout'); + + let output = ''; + + output = JSON.stringify(grid.setViewLayout(config)); + + PerformanceAPI.SetMark('View.SetViewLayout-end'); + PerformanceAPI.GetMeasure( + '@datagrid-View.SetViewLayout', + 'View.SetViewLayout', + 'View.SetViewLayout-end' + ); + + return output; + } +} + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +namespace GridAPI { + /** + * API used for saving and load View definitions + */ + export namespace View { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + export function GetViewLayout(gridID: string): string { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.View.GetViewLayout()'` + ); + return OutSystems.GridAPI.View.GetViewLayout(gridID); + } + + // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any + export function SetViewLayout(gridID: string, config: any): any { + OSFramework.Helper.LogWarningMessage( + `${OSFramework.Helper.warningMessage} 'OutSystems.GridAPI.View.SetViewLayout()'` + ); + return OutSystems.GridAPI.View.SetViewLayout(gridID, config); + } + } +} diff --git a/code/src/GridAPI/index.ts b/code/src/OutSystems/GridAPI/index.ts similarity index 60% rename from code/src/GridAPI/index.ts rename to code/src/OutSystems/GridAPI/index.ts index 85d22bfa..f4e719a2 100644 --- a/code/src/GridAPI/index.ts +++ b/code/src/OutSystems/GridAPI/index.ts @@ -1,3 +1,11 @@ +namespace OutSystems.GridAPI { + /** + * Format of data as set in service center. + */ + // eslint-disable-next-line prefer-const + export let dateFormat = ''; +} + /** * Namespace for all public methods to access and use the Data Grid component. */ @@ -7,5 +15,5 @@ namespace GridAPI { * Format of data as set in service center. */ // eslint-disable-next-line prefer-const - export let dateFormat = ''; + export let dateFormat = OutSystems.GridAPI.dateFormat; } diff --git a/code/src/WijmoProvider/Features/ValidationMark.ts b/code/src/WijmoProvider/Features/ValidationMark.ts index ccf346cd..c1116d97 100644 --- a/code/src/WijmoProvider/Features/ValidationMark.ts +++ b/code/src/WijmoProvider/Features/ValidationMark.ts @@ -280,8 +280,7 @@ namespace WijmoProvider.Feature { isValid = false; } // Sets cell as valid or invalid depending on the newValue - GridAPI.Cells.SetValidationStatus( - this._grid.uniqueId, + this.setCellStatus( rowNumber, column.widgetId, isValid, @@ -593,8 +592,7 @@ namespace WijmoProvider.Feature { isValid: boolean, errorMessage: string ): void { - const column = - GridAPI.ColumnManager.GetColumnById(columnWidgetID).provider; + const column = this._grid.getColumn(columnWidgetID).provider; // Sets the validation map by matching the binding of the columns with the boolean that indicates whether theres is an invalid cell in the row or not. this.getMetadataByRowNumber(rowNumber).validation.set( @@ -635,8 +633,7 @@ namespace WijmoProvider.Feature { isValid: boolean, errorMessage: string ): void { - const column = - GridAPI.ColumnManager.GetColumnById(columnWidgetID).provider; + const column = this._grid.getColumn(columnWidgetID).provider; // Sets the validation map by matching the binding of the columns with the boolean that indicates whether theres is an invalid cell in the row or not. this.getMetadataByRowKey(rowKey).validation.set(