Compare commits
4 Commits
04836ea6ce
...
v1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
| e93de750fc | |||
| 5f41c4a943 | |||
| 1d364a2351 | |||
| 88b95a7651 |
@@ -18,7 +18,7 @@ module.exports = {
|
|||||||
/* use https://admin.bro-js.ru/ to create config, navigations and features */
|
/* use https://admin.bro-js.ru/ to create config, navigations and features */
|
||||||
navigations: {
|
navigations: {
|
||||||
'challenge-admin.main': '/challenge-admin',
|
'challenge-admin.main': '/challenge-admin',
|
||||||
'link.challenge': '/challenge',
|
'link.challenge.main': '/challenge',
|
||||||
},
|
},
|
||||||
features: {
|
features: {
|
||||||
'challenge-admin': {
|
'challenge-admin': {
|
||||||
|
|||||||
@@ -112,6 +112,21 @@
|
|||||||
"challenge.admin.chains.delete.confirm.title": "Delete chain",
|
"challenge.admin.chains.delete.confirm.title": "Delete chain",
|
||||||
"challenge.admin.chains.delete.confirm.message": "Are you sure you want to delete chain \"{name}\"? This action cannot be undone.",
|
"challenge.admin.chains.delete.confirm.message": "Are you sure you want to delete chain \"{name}\"? This action cannot be undone.",
|
||||||
"challenge.admin.chains.delete.confirm.button": "Delete",
|
"challenge.admin.chains.delete.confirm.button": "Delete",
|
||||||
|
"challenge.admin.chains.duplicate.button": "Duplicate",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.title": "Duplicate chain",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.description": "Create a copy of chain \"{name}\" with the same tasks. The new chain will be created as inactive.",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name": "New chain name",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name.placeholder": "Copy - {name}",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name.helper": "Leave empty for auto-generated name",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.button.confirm": "Create copy",
|
||||||
|
"challenge.admin.chains.duplicate.success": "Chain successfully duplicated",
|
||||||
|
"challenge.admin.chains.duplicate.error": "Failed to duplicate chain",
|
||||||
|
"challenge.admin.chains.clear.submissions.button": "Clear submissions",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.title": "Clear chain submissions",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.message": "Are you sure you want to delete all submissions for chain \"{name}\"? This action is irreversible. All deleted submissions cannot be restored.",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.button.confirm": "Delete all submissions",
|
||||||
|
"challenge.admin.chains.clear.submissions.success": "Submissions successfully deleted",
|
||||||
|
"challenge.admin.chains.clear.submissions.error": "Failed to delete submissions",
|
||||||
"challenge.admin.dashboard.title": "Dashboard",
|
"challenge.admin.dashboard.title": "Dashboard",
|
||||||
"challenge.admin.dashboard.loading": "Loading statistics...",
|
"challenge.admin.dashboard.loading": "Loading statistics...",
|
||||||
"challenge.admin.dashboard.load.error": "Failed to load system statistics",
|
"challenge.admin.dashboard.load.error": "Failed to load system statistics",
|
||||||
|
|||||||
@@ -111,6 +111,21 @@
|
|||||||
"challenge.admin.chains.delete.confirm.title": "Удалить цепочку",
|
"challenge.admin.chains.delete.confirm.title": "Удалить цепочку",
|
||||||
"challenge.admin.chains.delete.confirm.message": "Вы уверены, что хотите удалить цепочку \"{name}\"? Это действие нельзя отменить.",
|
"challenge.admin.chains.delete.confirm.message": "Вы уверены, что хотите удалить цепочку \"{name}\"? Это действие нельзя отменить.",
|
||||||
"challenge.admin.chains.delete.confirm.button": "Удалить",
|
"challenge.admin.chains.delete.confirm.button": "Удалить",
|
||||||
|
"challenge.admin.chains.duplicate.button": "Дублировать",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.title": "Дублировать цепочку",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.description": "Создать копию цепочки \"{name}\" с теми же заданиями. Новая цепочка будет создана неактивной.",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name": "Название новой цепочки",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name.placeholder": "Копия - {name}",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.field.name.helper": "Оставьте пустым для автоматического названия",
|
||||||
|
"challenge.admin.chains.duplicate.dialog.button.confirm": "Создать копию",
|
||||||
|
"challenge.admin.chains.duplicate.success": "Цепочка успешно скопирована",
|
||||||
|
"challenge.admin.chains.duplicate.error": "Не удалось скопировать цепочку",
|
||||||
|
"challenge.admin.chains.clear.submissions.button": "Очистить попытки",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.title": "Очистить попытки по цепочке",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.message": "Вы уверены, что хотите удалить все попытки по цепочке \"{name}\"? Это действие необратимо. Все удаленные попытки невозможно восстановить.",
|
||||||
|
"challenge.admin.chains.clear.submissions.dialog.button.confirm": "Удалить все попытки",
|
||||||
|
"challenge.admin.chains.clear.submissions.success": "Попытки успешно удалены",
|
||||||
|
"challenge.admin.chains.clear.submissions.error": "Не удалось удалить попытки",
|
||||||
"challenge.admin.dashboard.title": "Dashboard",
|
"challenge.admin.dashboard.title": "Dashboard",
|
||||||
"challenge.admin.dashboard.loading": "Загрузка статистики...",
|
"challenge.admin.dashboard.loading": "Загрузка статистики...",
|
||||||
"challenge.admin.dashboard.load.error": "Не удалось загрузить статистику системы",
|
"challenge.admin.dashboard.load.error": "Не удалось загрузить статистику системы",
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "challenge-admin-pl",
|
"name": "challenge-admin-pl",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "challenge-admin-pl",
|
"name": "challenge-admin-pl",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@brojs/cli": "^1.9.4",
|
"@brojs/cli": "^1.9.4",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "challenge-admin",
|
"name": "challenge-admin",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "./src/index.tsx",
|
"main": "./src/index.tsx",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import type {
|
|||||||
UpdateTaskRequest,
|
UpdateTaskRequest,
|
||||||
CreateChainRequest,
|
CreateChainRequest,
|
||||||
UpdateChainRequest,
|
UpdateChainRequest,
|
||||||
|
DuplicateChainRequest,
|
||||||
|
ClearSubmissionsResponse,
|
||||||
SubmitRequest,
|
SubmitRequest,
|
||||||
TestSubmissionResult,
|
TestSubmissionResult,
|
||||||
ChainSubmissionsResponse,
|
ChainSubmissionsResponse,
|
||||||
@@ -115,6 +117,23 @@ export const api = createApi({
|
|||||||
}),
|
}),
|
||||||
invalidatesTags: ['Chain'],
|
invalidatesTags: ['Chain'],
|
||||||
}),
|
}),
|
||||||
|
duplicateChain: builder.mutation<ChallengeChain, { chainId: string; name?: string }>({
|
||||||
|
query: ({ chainId, name }) => ({
|
||||||
|
url: `/challenge/chain/${chainId}/duplicate`,
|
||||||
|
method: 'POST',
|
||||||
|
body: name ? { name } : {},
|
||||||
|
}),
|
||||||
|
transformResponse: (response: { body: ChallengeChain }) => response.body,
|
||||||
|
invalidatesTags: ['Chain'],
|
||||||
|
}),
|
||||||
|
clearChainSubmissions: builder.mutation<ClearSubmissionsResponse, string>({
|
||||||
|
query: (chainId) => ({
|
||||||
|
url: `/challenge/chain/${chainId}/submissions`,
|
||||||
|
method: 'DELETE',
|
||||||
|
}),
|
||||||
|
transformResponse: (response: { body: ClearSubmissionsResponse }) => response.body,
|
||||||
|
invalidatesTags: ['Chain', 'Submission'],
|
||||||
|
}),
|
||||||
|
|
||||||
// Statistics
|
// Statistics
|
||||||
getSystemStats: builder.query<SystemStats, void>({
|
getSystemStats: builder.query<SystemStats, void>({
|
||||||
@@ -187,6 +206,8 @@ export const {
|
|||||||
useCreateChainMutation,
|
useCreateChainMutation,
|
||||||
useUpdateChainMutation,
|
useUpdateChainMutation,
|
||||||
useDeleteChainMutation,
|
useDeleteChainMutation,
|
||||||
|
useDuplicateChainMutation,
|
||||||
|
useClearChainSubmissionsMutation,
|
||||||
useGetSystemStatsQuery,
|
useGetSystemStatsQuery,
|
||||||
useGetSystemStatsV2Query,
|
useGetSystemStatsV2Query,
|
||||||
useGetUserStatsQuery,
|
useGetUserStatsQuery,
|
||||||
|
|||||||
87
src/components/ClearSubmissionsDialog.tsx
Normal file
87
src/components/ClearSubmissionsDialog.tsx
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import React, { useEffect } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
DialogRoot,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogBody,
|
||||||
|
DialogFooter,
|
||||||
|
DialogActionTrigger,
|
||||||
|
Button,
|
||||||
|
Text,
|
||||||
|
} from '@chakra-ui/react'
|
||||||
|
import { useClearChainSubmissionsMutation } from '../__data__/api/api'
|
||||||
|
import { toaster } from './ui/toaster'
|
||||||
|
import type { ChallengeChain } from '../types/challenge'
|
||||||
|
|
||||||
|
interface ClearSubmissionsDialogProps {
|
||||||
|
isOpen: boolean
|
||||||
|
onClose: () => void
|
||||||
|
chain: ChallengeChain | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ClearSubmissionsDialog: React.FC<ClearSubmissionsDialogProps> = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
chain,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const [clearSubmissions, { isLoading }] = useClearChainSubmissionsMutation()
|
||||||
|
|
||||||
|
// Прокручиваем страницу к началу при открытии диалога
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||||
|
}
|
||||||
|
}, [isOpen])
|
||||||
|
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
if (!chain) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await clearSubmissions(chain.id).unwrap()
|
||||||
|
toaster.create({
|
||||||
|
title: t('challenge.admin.common.success'),
|
||||||
|
description: t('challenge.admin.chains.clear.submissions.success'),
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
onClose()
|
||||||
|
} catch (err) {
|
||||||
|
toaster.create({
|
||||||
|
title: t('challenge.admin.common.error'),
|
||||||
|
description: t('challenge.admin.chains.clear.submissions.error'),
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chain) return null
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogRoot open={isOpen} onOpenChange={(e) => !e.open && onClose()} scrollBehavior="inside">
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{t('challenge.admin.chains.clear.submissions.dialog.title')}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogBody>
|
||||||
|
<Text>{t('challenge.admin.chains.clear.submissions.dialog.message', { name: chain.name })}</Text>
|
||||||
|
</DialogBody>
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogActionTrigger asChild>
|
||||||
|
<Button variant="outline" onClick={onClose} disabled={isLoading}>
|
||||||
|
{t('challenge.admin.common.cancel')}
|
||||||
|
</Button>
|
||||||
|
</DialogActionTrigger>
|
||||||
|
<Button colorPalette="red" onClick={handleConfirm} disabled={isLoading}>
|
||||||
|
{t('challenge.admin.chains.clear.submissions.dialog.button.confirm')}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</DialogRoot>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import {
|
import {
|
||||||
DialogRoot,
|
DialogRoot,
|
||||||
@@ -36,8 +36,16 @@ export const ConfirmDialog: React.FC<ConfirmDialogProps> = ({
|
|||||||
|
|
||||||
const confirm = confirmLabel || t('challenge.admin.common.confirm')
|
const confirm = confirmLabel || t('challenge.admin.common.confirm')
|
||||||
const cancel = cancelLabel || t('challenge.admin.common.cancel')
|
const cancel = cancelLabel || t('challenge.admin.common.cancel')
|
||||||
|
|
||||||
|
// Прокручиваем страницу к началу при открытии диалога
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||||
|
}
|
||||||
|
}, [isOpen])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogRoot open={isOpen} onOpenChange={(e) => !e.open && onClose()}>
|
<DialogRoot open={isOpen} onOpenChange={(e) => !e.open && onClose()} scrollBehavior="inside">
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>{title}</DialogTitle>
|
<DialogTitle>{title}</DialogTitle>
|
||||||
|
|||||||
116
src/components/DuplicateChainDialog.tsx
Normal file
116
src/components/DuplicateChainDialog.tsx
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
import React, { useState, useEffect } from 'react'
|
||||||
|
import { useTranslation } from 'react-i18next'
|
||||||
|
import {
|
||||||
|
DialogRoot,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
DialogBody,
|
||||||
|
DialogFooter,
|
||||||
|
DialogActionTrigger,
|
||||||
|
Button,
|
||||||
|
Field,
|
||||||
|
Input,
|
||||||
|
Text,
|
||||||
|
VStack,
|
||||||
|
} from '@chakra-ui/react'
|
||||||
|
import { useDuplicateChainMutation } from '../__data__/api/api'
|
||||||
|
import { toaster } from './ui/toaster'
|
||||||
|
import type { ChallengeChain } from '../types/challenge'
|
||||||
|
|
||||||
|
interface DuplicateChainDialogProps {
|
||||||
|
isOpen: boolean
|
||||||
|
onClose: () => void
|
||||||
|
chain: ChallengeChain | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DuplicateChainDialog: React.FC<DuplicateChainDialogProps> = ({
|
||||||
|
isOpen,
|
||||||
|
onClose,
|
||||||
|
chain,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const [name, setName] = useState('')
|
||||||
|
const [duplicateChain, { isLoading }] = useDuplicateChainMutation()
|
||||||
|
|
||||||
|
// Прокручиваем страницу к началу при открытии диалога
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||||
|
}
|
||||||
|
}, [isOpen])
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setName('')
|
||||||
|
onClose()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleConfirm = async () => {
|
||||||
|
if (!chain) return
|
||||||
|
|
||||||
|
try {
|
||||||
|
await duplicateChain({
|
||||||
|
chainId: chain.id,
|
||||||
|
name: name.trim() || undefined,
|
||||||
|
}).unwrap()
|
||||||
|
toaster.create({
|
||||||
|
title: t('challenge.admin.common.success'),
|
||||||
|
description: t('challenge.admin.chains.duplicate.success'),
|
||||||
|
type: 'success',
|
||||||
|
})
|
||||||
|
handleClose()
|
||||||
|
} catch (err) {
|
||||||
|
toaster.create({
|
||||||
|
title: t('challenge.admin.common.error'),
|
||||||
|
description: t('challenge.admin.chains.duplicate.error'),
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!chain) return null
|
||||||
|
|
||||||
|
const defaultPlaceholder = t('challenge.admin.chains.duplicate.dialog.field.name.placeholder', {
|
||||||
|
name: chain.name,
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogRoot open={isOpen} onOpenChange={(e) => !e.open && handleClose()} scrollBehavior="inside">
|
||||||
|
<DialogContent>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{t('challenge.admin.chains.duplicate.dialog.title')}</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogBody>
|
||||||
|
<VStack gap={4} align="stretch">
|
||||||
|
<Text>{t('challenge.admin.chains.duplicate.dialog.description', { name: chain.name })}</Text>
|
||||||
|
<Field.Root>
|
||||||
|
<Field.Label>{t('challenge.admin.chains.duplicate.dialog.field.name')}</Field.Label>
|
||||||
|
<Input
|
||||||
|
value={name}
|
||||||
|
onChange={(e) => setName(e.target.value)}
|
||||||
|
placeholder={defaultPlaceholder}
|
||||||
|
/>
|
||||||
|
<Field.HelperText>
|
||||||
|
{t('challenge.admin.chains.duplicate.dialog.field.name.helper')}
|
||||||
|
</Field.HelperText>
|
||||||
|
</Field.Root>
|
||||||
|
</VStack>
|
||||||
|
</DialogBody>
|
||||||
|
<DialogFooter>
|
||||||
|
<DialogActionTrigger asChild>
|
||||||
|
<Button variant="outline" onClick={handleClose} disabled={isLoading}>
|
||||||
|
{t('challenge.admin.common.cancel')}
|
||||||
|
</Button>
|
||||||
|
</DialogActionTrigger>
|
||||||
|
<Button colorPalette="teal" onClick={handleConfirm} disabled={isLoading}>
|
||||||
|
{t('challenge.admin.chains.duplicate.dialog.button.confirm')}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</DialogRoot>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -17,7 +17,8 @@ import { URLs } from '../../__data__/urls'
|
|||||||
import { LoadingSpinner } from '../../components/LoadingSpinner'
|
import { LoadingSpinner } from '../../components/LoadingSpinner'
|
||||||
import { ErrorAlert } from '../../components/ErrorAlert'
|
import { ErrorAlert } from '../../components/ErrorAlert'
|
||||||
import { EmptyState } from '../../components/EmptyState'
|
import { EmptyState } from '../../components/EmptyState'
|
||||||
import { ConfirmDialog } from '../../components/ConfirmDialog'
|
import { DuplicateChainDialog } from '../../components/DuplicateChainDialog'
|
||||||
|
import { ClearSubmissionsDialog } from '../../components/ClearSubmissionsDialog'
|
||||||
import type { ChallengeChain } from '../../types/challenge'
|
import type { ChallengeChain } from '../../types/challenge'
|
||||||
import { toaster } from '../../components/ui/toaster'
|
import { toaster } from '../../components/ui/toaster'
|
||||||
|
|
||||||
@@ -25,24 +26,28 @@ export const ChainsListPage: React.FC = () => {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { data: chains, isLoading, error, refetch } = useGetChainsQuery()
|
const { data: chains, isLoading, error, refetch } = useGetChainsQuery()
|
||||||
const [deleteChain, { isLoading: isDeleting }] = useDeleteChainMutation()
|
const [deleteChain] = useDeleteChainMutation()
|
||||||
|
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const [chainToDelete, setChainToDelete] = useState<ChallengeChain | null>(null)
|
const [chainToDuplicate, setChainToDuplicate] = useState<ChallengeChain | null>(null)
|
||||||
|
const [chainToClearSubmissions, setChainToClearSubmissions] = useState<ChallengeChain | null>(null)
|
||||||
const [updatingChainId, setUpdatingChainId] = useState<string | null>(null)
|
const [updatingChainId, setUpdatingChainId] = useState<string | null>(null)
|
||||||
const [updateChain] = useUpdateChainMutation()
|
const [updateChain] = useUpdateChainMutation()
|
||||||
|
|
||||||
const handleDeleteChain = async () => {
|
const handleDeleteChain = async (chain: ChallengeChain) => {
|
||||||
if (!chainToDelete) return
|
const confirmed = window.confirm(
|
||||||
|
t('challenge.admin.chains.delete.confirm.message', { name: chain.name })
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!confirmed) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await deleteChain(chainToDelete.id).unwrap()
|
await deleteChain(chain.id).unwrap()
|
||||||
toaster.create({
|
toaster.create({
|
||||||
title: t('challenge.admin.common.success'),
|
title: t('challenge.admin.common.success'),
|
||||||
description: t('challenge.admin.chains.deleted'),
|
description: t('challenge.admin.chains.deleted'),
|
||||||
type: 'success',
|
type: 'success',
|
||||||
})
|
})
|
||||||
setChainToDelete(null)
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toaster.create({
|
toaster.create({
|
||||||
title: t('challenge.admin.common.error'),
|
title: t('challenge.admin.common.error'),
|
||||||
@@ -182,11 +187,26 @@ export const ChainsListPage: React.FC = () => {
|
|||||||
>
|
>
|
||||||
{t('challenge.admin.chains.list.button.edit')}
|
{t('challenge.admin.chains.list.button.edit')}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
onClick={() => setChainToDuplicate(chain)}
|
||||||
|
>
|
||||||
|
{t('challenge.admin.chains.duplicate.button')}
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
colorPalette="red"
|
colorPalette="red"
|
||||||
onClick={() => setChainToDelete(chain)}
|
onClick={() => setChainToClearSubmissions(chain)}
|
||||||
|
>
|
||||||
|
{t('challenge.admin.chains.clear.submissions.button')}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="ghost"
|
||||||
|
colorPalette="red"
|
||||||
|
onClick={() => handleDeleteChain(chain)}
|
||||||
>
|
>
|
||||||
{t('challenge.admin.chains.list.button.delete')}
|
{t('challenge.admin.chains.list.button.delete')}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -199,14 +219,16 @@ export const ChainsListPage: React.FC = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<ConfirmDialog
|
<DuplicateChainDialog
|
||||||
isOpen={!!chainToDelete}
|
isOpen={!!chainToDuplicate}
|
||||||
onClose={() => setChainToDelete(null)}
|
onClose={() => setChainToDuplicate(null)}
|
||||||
onConfirm={handleDeleteChain}
|
chain={chainToDuplicate}
|
||||||
title={t('challenge.admin.chains.delete.confirm.title')}
|
/>
|
||||||
message={t('challenge.admin.chains.delete.confirm.message', { name: chainToDelete?.name })}
|
|
||||||
confirmLabel={t('challenge.admin.chains.delete.confirm.button')}
|
<ClearSubmissionsDialog
|
||||||
isLoading={isDeleting}
|
isOpen={!!chainToClearSubmissions}
|
||||||
|
onClose={() => setChainToClearSubmissions(null)}
|
||||||
|
chain={chainToClearSubmissions}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import { URLs } from '../../__data__/urls'
|
|||||||
import { LoadingSpinner } from '../../components/LoadingSpinner'
|
import { LoadingSpinner } from '../../components/LoadingSpinner'
|
||||||
import { ErrorAlert } from '../../components/ErrorAlert'
|
import { ErrorAlert } from '../../components/ErrorAlert'
|
||||||
import { EmptyState } from '../../components/EmptyState'
|
import { EmptyState } from '../../components/EmptyState'
|
||||||
import { ConfirmDialog } from '../../components/ConfirmDialog'
|
|
||||||
import type { ChallengeTask } from '../../types/challenge'
|
import type { ChallengeTask } from '../../types/challenge'
|
||||||
import { toaster } from '../../components/ui/toaster'
|
import { toaster } from '../../components/ui/toaster'
|
||||||
|
|
||||||
@@ -25,22 +24,24 @@ export const TasksListPage: React.FC = () => {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { data: tasks, isLoading, error, refetch } = useGetTasksQuery()
|
const { data: tasks, isLoading, error, refetch } = useGetTasksQuery()
|
||||||
const [deleteTask, { isLoading: isDeleting }] = useDeleteTaskMutation()
|
const [deleteTask] = useDeleteTaskMutation()
|
||||||
|
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const [taskToDelete, setTaskToDelete] = useState<ChallengeTask | null>(null)
|
|
||||||
|
|
||||||
const handleDeleteTask = async () => {
|
const handleDeleteTask = async (task: ChallengeTask) => {
|
||||||
if (!taskToDelete) return
|
const confirmed = window.confirm(
|
||||||
|
t('challenge.admin.tasks.delete.confirm.message', { title: task.title })
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!confirmed) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await deleteTask(taskToDelete.id).unwrap()
|
await deleteTask(task.id).unwrap()
|
||||||
toaster.create({
|
toaster.create({
|
||||||
title: t('challenge.admin.common.success'),
|
title: t('challenge.admin.common.success'),
|
||||||
description: t('challenge.admin.tasks.deleted'),
|
description: t('challenge.admin.tasks.deleted'),
|
||||||
type: 'success',
|
type: 'success',
|
||||||
})
|
})
|
||||||
setTaskToDelete(null)
|
|
||||||
} catch (_err) {
|
} catch (_err) {
|
||||||
toaster.create({
|
toaster.create({
|
||||||
title: t('challenge.admin.common.error'),
|
title: t('challenge.admin.common.error'),
|
||||||
@@ -152,7 +153,7 @@ export const TasksListPage: React.FC = () => {
|
|||||||
size="sm"
|
size="sm"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
colorPalette="red"
|
colorPalette="red"
|
||||||
onClick={() => setTaskToDelete(task)}
|
onClick={() => handleDeleteTask(task)}
|
||||||
>
|
>
|
||||||
{t('challenge.admin.tasks.list.button.delete')}
|
{t('challenge.admin.tasks.list.button.delete')}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -164,16 +165,6 @@ export const TasksListPage: React.FC = () => {
|
|||||||
</Table.Root>
|
</Table.Root>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<ConfirmDialog
|
|
||||||
isOpen={!!taskToDelete}
|
|
||||||
onClose={() => setTaskToDelete(null)}
|
|
||||||
onConfirm={handleDeleteTask}
|
|
||||||
title={t('challenge.admin.tasks.delete.confirm.title')}
|
|
||||||
message={t('challenge.admin.tasks.delete.confirm.message', { title: taskToDelete?.title })}
|
|
||||||
confirmLabel={t('challenge.admin.tasks.delete.confirm.button')}
|
|
||||||
isLoading={isDeleting}
|
|
||||||
/>
|
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,6 +142,16 @@ export interface UpdateChainRequest {
|
|||||||
isActive?: boolean
|
isActive?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DuplicateChainRequest {
|
||||||
|
name?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ClearSubmissionsResponse {
|
||||||
|
deletedCount: number
|
||||||
|
chainId: string
|
||||||
|
userId?: string
|
||||||
|
}
|
||||||
|
|
||||||
// ========== Stats v2 Types ==========
|
// ========== Stats v2 Types ==========
|
||||||
|
|
||||||
export type TaskProgressStatus = 'not_started' | 'pending' | 'in_progress' | 'needs_revision' | 'completed'
|
export type TaskProgressStatus = 'not_started' | 'pending' | 'in_progress' | 'needs_revision' | 'completed'
|
||||||
|
|||||||
@@ -312,6 +312,84 @@ router.delete('/challenge/chain/:id', (req, res) => {
|
|||||||
respond(res, { success: true });
|
respond(res, { success: true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// POST /api/challenge/chain/:chainId/duplicate
|
||||||
|
router.post('/challenge/chain/:chainId/duplicate', (req, res) => {
|
||||||
|
const chains = getChains();
|
||||||
|
const chainIndex = chains.findIndex(c => c.id === req.params.chainId);
|
||||||
|
|
||||||
|
if (chainIndex === -1) {
|
||||||
|
return respondError(res, 'Chain not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
const originalChain = chains[chainIndex];
|
||||||
|
const { name } = req.body;
|
||||||
|
|
||||||
|
// Generate new name if not provided
|
||||||
|
const newName = name || `Копия - ${originalChain.name}`;
|
||||||
|
|
||||||
|
// Create duplicate with same tasks but inactive
|
||||||
|
const duplicatedChain = {
|
||||||
|
_id: `chain_${Date.now()}`,
|
||||||
|
id: `chain_${Date.now()}`,
|
||||||
|
name: newName,
|
||||||
|
tasks: originalChain.tasks.map(task => ({
|
||||||
|
_id: task._id,
|
||||||
|
id: task.id,
|
||||||
|
title: task.title,
|
||||||
|
description: task.description,
|
||||||
|
createdAt: task.createdAt,
|
||||||
|
updatedAt: task.updatedAt
|
||||||
|
})),
|
||||||
|
isActive: false,
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
updatedAt: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
chains.push(duplicatedChain);
|
||||||
|
|
||||||
|
// Update stats
|
||||||
|
const stats = getStats();
|
||||||
|
stats.chains = chains.length;
|
||||||
|
|
||||||
|
respond(res, duplicatedChain);
|
||||||
|
});
|
||||||
|
|
||||||
|
// DELETE /api/challenge/chain/:chainId/submissions
|
||||||
|
router.delete('/challenge/chain/:chainId/submissions', (req, res) => {
|
||||||
|
const chains = getChains();
|
||||||
|
const submissions = getSubmissions();
|
||||||
|
|
||||||
|
const chain = chains.find(c => c.id === req.params.chainId);
|
||||||
|
|
||||||
|
if (!chain) {
|
||||||
|
return respondError(res, 'Chain not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get task IDs from chain
|
||||||
|
const taskIds = new Set(chain.tasks.map(t => t.id));
|
||||||
|
|
||||||
|
// Count and remove submissions for tasks in this chain
|
||||||
|
let deletedCount = 0;
|
||||||
|
for (let i = submissions.length - 1; i >= 0; i--) {
|
||||||
|
const sub = submissions[i];
|
||||||
|
const taskId = typeof sub.task === 'object' ? sub.task.id : sub.task;
|
||||||
|
|
||||||
|
if (taskIds.has(taskId)) {
|
||||||
|
submissions.splice(i, 1);
|
||||||
|
deletedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update stats
|
||||||
|
const stats = getStats();
|
||||||
|
stats.submissions.total = Math.max(0, stats.submissions.total - deletedCount);
|
||||||
|
|
||||||
|
respond(res, {
|
||||||
|
deletedCount: deletedCount,
|
||||||
|
chainId: chain.id
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// ============= STATS =============
|
// ============= STATS =============
|
||||||
|
|
||||||
// GET /api/challenge/stats
|
// GET /api/challenge/stats
|
||||||
@@ -331,13 +409,32 @@ router.get('/challenge/stats/v2', (req, res) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Фильтруем данные по выбранной цепочке
|
// Сначала проверяем наличие цепочки в chains.json
|
||||||
const filteredChain = statsV2.chainsDetailed.find(c => c.chainId === chainId);
|
const chains = getChains();
|
||||||
|
const chain = chains.find(c => c.id === chainId);
|
||||||
|
|
||||||
if (!filteredChain) {
|
if (!chain) {
|
||||||
return respondError(res, 'Chain not found', 404);
|
return respondError(res, 'Chain not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ищем данные цепочки в stats-v2.json
|
||||||
|
let filteredChain = statsV2.chainsDetailed.find(c => c.chainId === chainId);
|
||||||
|
|
||||||
|
// Если цепочка не найдена в stats-v2.json, создаем пустую структуру на основе chains.json
|
||||||
|
if (!filteredChain) {
|
||||||
|
filteredChain = {
|
||||||
|
chainId: chain.id,
|
||||||
|
name: chain.name,
|
||||||
|
totalTasks: chain.tasks.length,
|
||||||
|
tasks: chain.tasks.map(t => ({
|
||||||
|
taskId: t.id,
|
||||||
|
title: t.title,
|
||||||
|
description: t.description || ''
|
||||||
|
})),
|
||||||
|
participantProgress: []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// Фильтруем tasksTable - только задания из этой цепочки
|
// Фильтруем tasksTable - только задания из этой цепочки
|
||||||
const chainTaskIds = new Set(filteredChain.tasks.map(t => t.taskId));
|
const chainTaskIds = new Set(filteredChain.tasks.map(t => t.taskId));
|
||||||
const filteredTasksTable = statsV2.tasksTable.filter(t => chainTaskIds.has(t.taskId));
|
const filteredTasksTable = statsV2.tasksTable.filter(t => chainTaskIds.has(t.taskId));
|
||||||
|
|||||||
Reference in New Issue
Block a user