sozsoft-platform/ui/src/services/UiEvalService.tsx
2026-09-05 12:06:14 +03:00

135 lines
4.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Notification, toast } from '@/components/ui'
import { generateBackgroundWorkers } from '@/services/background-worker.service'
import { getLocalization } from '@/services/localization.service'
import { store } from '@/store'
import { clearRedisCache } from './languageText.service'
import { kickUser } from './identity.service'
import { dynamicServiceService } from './dynamicService.service'
import { streamSetupMigrate } from './setup.service'
import { openDbMigrateLogPanel, dispatchMigrateLog, dispatchMigrateDone } from '@/components/shared/DbMigrateLogPanel'
export abstract class UiEvalService {
static Init = () => {
//console.log('init')
}
private static translate = (
localizationKey: string,
params?: Record<string, string | number>,
defaultResourceName?: string,
): string => {
const { texts, config } = store.getState().abpConfig
if (!texts) return localizationKey
return getLocalization(
texts,
defaultResourceName ?? config?.localization?.defaultResourceName,
localizationKey,
params,
)
}
private static runWithToast = (asyncFn: () => Promise<void>, toastKey: string) => {
asyncFn()
toast.push(
<Notification type="success" duration={2000}>
{UiEvalService.translate(toastKey)}
</Notification>,
{ placement: 'bottom-end' },
)
}
static ApiGenerateBackgroundWorkers = () => {
UiEvalService.runWithToast(() => generateBackgroundWorkers(), '::App.BackgroundWorkers.BackgroundWorkersMessage')
}
static ApiClearRedisCache = () => {
UiEvalService.runWithToast(() => clearRedisCache(), '::App.ClearRedisCache.ClearRedisCacheMessage')
}
static ApiKickUser = (userId: string, gridRef?: any) => {
UiEvalService.runWithToast(async () => {
await kickUser(userId)
if (gridRef?.current) {
gridRef.current.instance().refresh()
}
}, '::App.KickUser.KickUserMessage')
}
/**
* Dynamic Service kaydını siler. Ham SQL yerine servisten geçer; yalnızca böyle
* yüklenmiş assembly ve Swagger kaydı da runtime'dan düşer.
*/
static ApiDeleteDynamicService = (id: string, gridRef?: any) => {
if (!id) return
if (!window.confirm(UiEvalService.translate('::App.DeveloperKitDynamicServices.DeleteConfirm'))) {
return
}
void dynamicServiceService
.delete(id)
.then(() => {
if (gridRef?.current) {
gridRef.current.instance().refresh()
}
toast.push(
<Notification type="success" duration={2000}>
{UiEvalService.translate('::App.Platform.ObjectDeletedSuccessfully')}
</Notification>,
{ placement: 'bottom-end' },
)
})
.catch(() => {
toast.push(
<Notification type="danger" duration={5000}>
{UiEvalService.translate('::App.DeveloperKitDynamicServices.DeleteError')}
</Notification>,
{ placement: 'bottom-end' },
)
})
}
/**
* Canlı sistemde migration tetikler (SQL Query Manager ve Wizard dosya yöneticisi ortak kullanır).
* Yetki sunucu tarafında `App.Setup.Migrate` izniyle doğrulanır.
*/
static ApiDbMigrate = () => {
toast.push(
<Notification type="info" duration={3000}>
{UiEvalService.translate('::App.Platform.StartMessage')}
</Notification>,
{ placement: 'bottom-end' },
)
openDbMigrateLogPanel()
let failed = false
streamSetupMigrate({
onLog: dispatchMigrateLog,
onError: (err) => {
failed = true
toast.push(
<Notification type="danger" duration={6000}>
{UiEvalService.translate('::App.DbMigrate.ErrorMessage')}
{`: ${err.message}`}
</Notification>,
{ placement: 'bottom-end' },
)
},
onFinished: () => {
dispatchMigrateDone()
if (failed) return
toast.push(
<Notification type="success" duration={5000}>
{UiEvalService.translate('::App.DbMigrate.EndMessage')}
</Notification>,
{ placement: 'bottom-end' },
)
},
})
}
}
const _global = (window || global) as any
_global.UiEvalService = UiEvalService