sozsoft-platform/ui/src/services/UiEvalService.tsx

144 lines
4.6 KiB
TypeScript
Raw Normal View History

2026-02-24 20:44:16 +00:00
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'
2026-04-28 12:43:19 +00:00
import { kickUser } from './identity.service'
import { dynamicServiceService } from './dynamicService.service'
2026-04-28 17:12:14 +00:00
import { streamSetupMigrate } from './setup.service'
import { openDbMigrateLogPanel, dispatchMigrateLog, dispatchMigrateDone } from '@/components/shared/DbMigrateLogPanel'
2026-02-24 20:44:16 +00:00
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,
2026-02-24 20:44:16 +00:00
)
}
private static runWithToast = (asyncFn: () => Promise<void>, toastKey: string) => {
asyncFn()
2026-02-24 20:44:16 +00:00
toast.push(
<Notification type="success" duration={2000}>
{UiEvalService.translate(toastKey)}
2026-02-24 20:44:16 +00:00
</Notification>,
2026-07-08 06:14:40 +00:00
{ placement: 'bottom-end' },
2026-02-24 20:44:16 +00:00
)
}
2026-04-28 12:43:19 +00:00
static ApiGenerateBackgroundWorkers = () => {
UiEvalService.runWithToast(() => generateBackgroundWorkers(), '::App.BackgroundWorkers.BackgroundWorkersMessage')
}
2026-04-28 12:43:19 +00:00
static ApiClearRedisCache = () => {
UiEvalService.runWithToast(() => clearRedisCache(), '::App.ClearRedisCache.ClearRedisCacheMessage')
}
2026-04-28 12:43:19 +00:00
static ApiKickUser = (userId: string, gridRef?: any) => {
UiEvalService.runWithToast(async () => {
2026-04-28 12:43:19 +00:00
await kickUser(userId)
if (gridRef?.current) {
gridRef.current.instance().refresh()
}
}, '::App.KickUser.KickUserMessage')
}
2026-04-28 12:43:19 +00:00
/**
* 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. `onSuccess`, migrate hatasız
* bittiğinde çağrılır; migrate'in kurduğu kayıtları gösteren ekran kendini yeniler.
2026-10-04 08:14:38 +00:00
* Migrate seed'leri canlı veritabanına uygular; buton script'inden (`OnClick`) çağrıldığında da
* onay sorulur. Kendi onay diyaloğunu açan `DbMigrateButton` `confirmed: true` geçer.
*/
2026-10-04 08:14:38 +00:00
static ApiDbMigrate = (onSuccess?: () => void, confirmed = false) => {
if (!confirmed && !window.confirm(UiEvalService.translate('::App.DbMigrate.ConfirmMessage'))) {
return
}
2026-04-28 17:12:14 +00:00
toast.push(
<Notification type="info" duration={3000}>
{UiEvalService.translate('::App.Platform.StartMessage')}
2026-04-28 17:12:14 +00:00
</Notification>,
2026-07-08 06:14:40 +00:00
{ placement: 'bottom-end' },
2026-04-28 17:12:14 +00:00
)
2026-04-28 17:12:14 +00:00
openDbMigrateLogPanel()
let failed = false
streamSetupMigrate({
onLog: dispatchMigrateLog,
onError: (err) => {
failed = true
2026-04-28 17:12:14 +00:00
toast.push(
<Notification type="danger" duration={6000}>
{UiEvalService.translate('::App.DbMigrate.ErrorMessage')}
{`: ${err.message}`}
2026-04-28 17:12:14 +00:00
</Notification>,
2026-07-08 06:14:40 +00:00
{ placement: 'bottom-end' },
2026-04-28 17:12:14 +00:00
)
},
onFinished: () => {
2026-04-28 17:12:14 +00:00
dispatchMigrateDone()
if (failed) return
2026-04-28 17:12:14 +00:00
toast.push(
<Notification type="success" duration={5000}>
{UiEvalService.translate('::App.DbMigrate.EndMessage')}
2026-04-28 17:12:14 +00:00
</Notification>,
2026-07-08 06:14:40 +00:00
{ placement: 'bottom-end' },
2026-04-28 17:12:14 +00:00
)
onSuccess?.()
2026-04-28 17:12:14 +00:00
},
})
2026-04-28 12:43:19 +00:00
}
2026-02-24 20:44:16 +00:00
}
const _global = (window || global) as any
_global.UiEvalService = UiEvalService