diff --git a/api/modules/Sozsoft.SqlQueryManager/Sozsoft.SqlQueryManager.Application.Contracts/ISqlObjectManagerAppService.cs b/api/modules/Sozsoft.SqlQueryManager/Sozsoft.SqlQueryManager.Application.Contracts/ISqlObjectManagerAppService.cs index 98bb408..ba46a90 100644 --- a/api/modules/Sozsoft.SqlQueryManager/Sozsoft.SqlQueryManager.Application.Contracts/ISqlObjectManagerAppService.cs +++ b/api/modules/Sozsoft.SqlQueryManager/Sozsoft.SqlQueryManager.Application.Contracts/ISqlObjectManagerAppService.cs @@ -46,6 +46,11 @@ public interface ISqlObjectManagerAppService : IApplicationService /// Task> GetSqlDataFilesAsync(string dataDirectoryName = "SqlData", string relativePath = ""); + /// + /// Reads a .sql seed file content from the selected data directory. + /// + Task GetSqlDataFileContentAsync(string dataDirectoryName = "SqlData", string relativePath = ""); + /// /// Moves a SQL seed file between the selected data directory root and HostData. /// diff --git a/api/modules/Sozsoft.SqlQueryManager/Sozsoft.SqlQueryManager.Application/SqlObjectManagerAppService.cs b/api/modules/Sozsoft.SqlQueryManager/Sozsoft.SqlQueryManager.Application/SqlObjectManagerAppService.cs index f59868c..e4c46cb 100644 --- a/api/modules/Sozsoft.SqlQueryManager/Sozsoft.SqlQueryManager.Application/SqlObjectManagerAppService.cs +++ b/api/modules/Sozsoft.SqlQueryManager/Sozsoft.SqlQueryManager.Application/SqlObjectManagerAppService.cs @@ -1005,6 +1005,25 @@ FROM ( } } + [HttpGet("api/app/sql-object-manager/sql-data-file-content")] + public async Task GetSqlDataFileContentAsync( + [FromQuery] string dataDirectoryName = "SqlData", + [FromQuery] string relativePath = "") + { + ValidateTenantAccess(); + + var rootPath = ResolveSqlDataOutputPath(dataDirectoryName); + var filePath = ResolveSqlDataChildPath(rootPath, relativePath); + + if (!File.Exists(filePath)) + throw new Volo.Abp.UserFriendlyException("SQL seed file was not found."); + + if (!string.Equals(Path.GetExtension(filePath), ".sql", StringComparison.OrdinalIgnoreCase)) + throw new Volo.Abp.UserFriendlyException("Only .sql files can be previewed."); + + return await File.ReadAllTextAsync(filePath); + } + [HttpPost("api/app/sql-object-manager/move-sql-data-file")] public Task MoveSqlDataFileAsync(MoveSqlDataFileDto input) { diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json b/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json index a2fc82d..a5175dc 100644 --- a/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json +++ b/api/src/Sozsoft.Platform.DbMigrator/Seeds/LanguagesData.json @@ -17774,6 +17774,12 @@ "en": "Select key column", "tr": "Anahtar sütunu seç" }, + { + "resourceName": "Platform", + "key": "App.SqlQueryManager.ScriptLoadedToEditor", + "en": "Script loaded to editor", + "tr": "Komut dosyası düzenleyiciye yüklendi" + }, { "resourceName": "Platform", "key": "App.SqlQueryManager.IndexKeys", diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/PostgresData/Adm_T_DatabaseBackupAll.sql b/api/src/Sozsoft.Platform.DbMigrator/Seeds/PostgresData/HostData/Adm_T_DatabaseBackupAll.sql similarity index 100% rename from api/src/Sozsoft.Platform.DbMigrator/Seeds/PostgresData/Adm_T_DatabaseBackupAll.sql rename to api/src/Sozsoft.Platform.DbMigrator/Seeds/PostgresData/HostData/Adm_T_DatabaseBackupAll.sql diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/PostgresData/Adm_T_DatabaseBackupFilesDeleteAll.sql b/api/src/Sozsoft.Platform.DbMigrator/Seeds/PostgresData/HostData/Adm_T_DatabaseBackupFilesDeleteAll.sql similarity index 100% rename from api/src/Sozsoft.Platform.DbMigrator/Seeds/PostgresData/Adm_T_DatabaseBackupFilesDeleteAll.sql rename to api/src/Sozsoft.Platform.DbMigrator/Seeds/PostgresData/HostData/Adm_T_DatabaseBackupFilesDeleteAll.sql diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackupAll.sql b/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/HostData/Adm_T_DatabaseBackupAll.sql similarity index 100% rename from api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackupAll.sql rename to api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/HostData/Adm_T_DatabaseBackupAll.sql diff --git a/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackupFilesDeleteAll.sql b/api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/HostData/Adm_T_DatabaseBackupFilesDeleteAll.sql similarity index 100% rename from api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/Adm_T_DatabaseBackupFilesDeleteAll.sql rename to api/src/Sozsoft.Platform.DbMigrator/Seeds/SqlData/HostData/Adm_T_DatabaseBackupFilesDeleteAll.sql diff --git a/ui/src/services/sql-query-manager.service.ts b/ui/src/services/sql-query-manager.service.ts index e0c6c37..c961af9 100644 --- a/ui/src/services/sql-query-manager.service.ts +++ b/ui/src/services/sql-query-manager.service.ts @@ -92,6 +92,16 @@ export class SqlObjectManagerService { { apiName: this.apiName, ...config }, ) + getSqlDataFileContent = (dataDirectoryName = 'SqlData', relativePath: string, config?: Partial) => + apiService.fetchData( + { + method: 'GET', + url: '/api/app/sql-object-manager/sql-data-file-content', + params: { dataDirectoryName, relativePath }, + }, + { apiName: this.apiName, ...config }, + ) + moveSqlDataFile = ( input: { dataDirectoryName: string; sourceRelativePath: string; targetRelativePath: string }, config?: Partial, diff --git a/ui/src/views/developerKit/SqlQueryManager.tsx b/ui/src/views/developerKit/SqlQueryManager.tsx index 955bbb9..7555508 100644 --- a/ui/src/views/developerKit/SqlQueryManager.tsx +++ b/ui/src/views/developerKit/SqlQueryManager.tsx @@ -16,6 +16,7 @@ import { FaExclamationTriangle, FaArrowLeft, FaArrowRight, + FaEye, } from 'react-icons/fa' import { FaCheckCircle } from 'react-icons/fa' import { useLocalization } from '@/utils/hooks/useLocalization' @@ -100,6 +101,7 @@ const SqlQueryManager = () => { const [showSqlDataFilesDialog, setShowSqlDataFilesDialog] = useState(false) const [isLoadingSqlDataFiles, setIsLoadingSqlDataFiles] = useState(false) const [isMovingSqlDataFile, setIsMovingSqlDataFile] = useState(false) + const [isPreviewingSqlDataFile, setIsPreviewingSqlDataFile] = useState(false) const [sqlDataRootFiles, setSqlDataRootFiles] = useState([]) const [sqlDataHostFiles, setSqlDataHostFiles] = useState([]) const [selectedRootSqlDataFiles, setSelectedRootSqlDataFiles] = useState([]) @@ -1118,6 +1120,47 @@ GO`, } } + const handlePreviewSqlDataFile = async (file: SqlDataExplorerEntry) => { + if (!file.relativePath || isPreviewingSqlDataFile) { + return + } + + setIsPreviewingSqlDataFile(true) + + try { + const response = await sqlObjectManagerService.getSqlDataFileContent( + sqlDataDirectoryName, + file.relativePath, + ) + + setState((prev) => ({ + ...prev, + editorContent: response.data || '', + executionResult: null, + tableColumns: null, + isDirty: false, + })) + setShowSqlDataFilesDialog(false) + + toast.push( + + {translate('::App.SqlQueryManager.ScriptLoadedToEditor') || + 'SQL dosyasi Query Editor icine yuklendi.'} + , + { placement: 'top-center' }, + ) + } catch (error: any) { + toast.push( + + {error.response?.data?.error?.message || 'SQL dosyasi okunamadi.'} + , + { placement: 'top-center' }, + ) + } finally { + setIsPreviewingSqlDataFile(false) + } + } + const renderSqlDataPane = ( title: string, files: SqlDataExplorerEntry[], @@ -1154,28 +1197,39 @@ GO`, return (
  • - +
  • ) })}