93 lines
2.8 KiB
TypeScript
93 lines
2.8 KiB
TypeScript
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 { 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: 'top-end' },
|
|
)
|
|
}
|
|
|
|
static ApiGenerateBackgroundWorkers = () => {
|
|
UiEvalService.runWithToast(() => generateBackgroundWorkers(), '::App.BackgroundWorkers.Message')
|
|
}
|
|
|
|
static ApiClearRedisCache = () => {
|
|
UiEvalService.runWithToast(() => clearRedisCache(), '::App.ClearRedisCache.Message')
|
|
}
|
|
|
|
static ApiKickUser = (userId: string, gridRef?: any) => {
|
|
UiEvalService.runWithToast(async () => {
|
|
await kickUser(userId)
|
|
if (gridRef?.current) {
|
|
gridRef.current.instance().refresh()
|
|
}
|
|
}, '::App.KickUser.Message')
|
|
}
|
|
|
|
static ApiDbMigrate = () => {
|
|
toast.push(
|
|
<Notification type="info" duration={3000}>
|
|
{UiEvalService.translate('::App.DbMigrate.StartMessage')}
|
|
</Notification>,
|
|
{ placement: 'top-end' },
|
|
)
|
|
openDbMigrateLogPanel()
|
|
streamSetupMigrate(
|
|
(entry) => {
|
|
dispatchMigrateLog(entry)
|
|
},
|
|
() => {
|
|
dispatchMigrateDone()
|
|
toast.push(
|
|
<Notification type="success" duration={5000}>
|
|
{UiEvalService.translate('::App.DbMigrate.EndMessage')}
|
|
</Notification>,
|
|
{ placement: 'top-end' },
|
|
)
|
|
},
|
|
(err) => {
|
|
dispatchMigrateDone()
|
|
toast.push(
|
|
<Notification type="danger" duration={6000}>
|
|
{UiEvalService.translate('::App.DbMigrate.ErrorMessage')}
|
|
{err instanceof Error ? `: ${err.message}` : ''}
|
|
</Notification>,
|
|
{ placement: 'top-end' },
|
|
)
|
|
},
|
|
)
|
|
}
|
|
}
|
|
|
|
const _global = (window || global) as any
|
|
_global.UiEvalService = UiEvalService
|