Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e93de750fc | |||
| 5f41c4a943 | |||
| 1d364a2351 | |||
| 88b95a7651 | |||
| 04836ea6ce | |||
| 18e2ccb6bc | |||
| 9104280325 | |||
| d1bddcf972 | |||
| 86dffc802b | |||
| 7b9cb044fa |
@@ -18,11 +18,11 @@ 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': {
|
||||||
// add your features here in the format [featureName]: { value: string }
|
'use-chain-submissions-api': { value: 'true' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
config: {
|
config: {
|
||||||
|
|||||||
236
docs/API_CHAIN_SUBMISSIONS.md
Normal file
236
docs/API_CHAIN_SUBMISSIONS.md
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
# Техническое задание: Эндпоинт получения попыток по цепочке
|
||||||
|
|
||||||
|
## Цель
|
||||||
|
|
||||||
|
Создать новый API эндпоинт для получения списка попыток (submissions) участников в рамках конкретной цепочки заданий. Это упростит работу админ-панели и уменьшит объём передаваемых данных.
|
||||||
|
|
||||||
|
## Текущая проблема
|
||||||
|
|
||||||
|
Сейчас для отображения попыток по цепочке фронтенд должен:
|
||||||
|
1. Загрузить список цепочек (`GET /challenge/chains/admin`)
|
||||||
|
2. Загрузить общую статистику (`GET /challenge/stats/v2`)
|
||||||
|
3. Для каждого участника отдельно загрузить его submissions (`GET /challenge/user/:userId/submissions`)
|
||||||
|
4. На клиенте фильтровать submissions по taskIds из выбранной цепочки
|
||||||
|
|
||||||
|
Это создаёт избыточные запросы и усложняет логику на фронтенде.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Новый эндпоинт
|
||||||
|
|
||||||
|
### `GET /challenge/chain/:chainId/submissions`
|
||||||
|
|
||||||
|
Возвращает все попытки всех участников для заданий из указанной цепочки.
|
||||||
|
|
||||||
|
### Параметры URL
|
||||||
|
|
||||||
|
| Параметр | Тип | Обязательный | Описание |
|
||||||
|
|----------|-----|--------------|----------|
|
||||||
|
| `chainId` | string | Да | ID цепочки заданий |
|
||||||
|
|
||||||
|
### Query параметры (опциональные)
|
||||||
|
|
||||||
|
| Параметр | Тип | По умолчанию | Описание |
|
||||||
|
|----------|-----|--------------|----------|
|
||||||
|
| `userId` | string | - | Фильтр по конкретному пользователю |
|
||||||
|
| `status` | string | - | Фильтр по статусу: `pending`, `in_progress`, `accepted`, `needs_revision` |
|
||||||
|
| `limit` | number | 100 | Лимит записей |
|
||||||
|
| `offset` | number | 0 | Смещение для пагинации |
|
||||||
|
|
||||||
|
### Формат ответа
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
interface ChainSubmissionsResponse {
|
||||||
|
success: boolean;
|
||||||
|
body: {
|
||||||
|
chain: {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
tasks: Array<{
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
}>;
|
||||||
|
};
|
||||||
|
participants: Array<{
|
||||||
|
userId: string;
|
||||||
|
nickname: string;
|
||||||
|
completedTasks: number;
|
||||||
|
totalTasks: number;
|
||||||
|
progressPercent: number;
|
||||||
|
}>;
|
||||||
|
submissions: Array<{
|
||||||
|
id: string;
|
||||||
|
user: {
|
||||||
|
id: string;
|
||||||
|
nickname: string;
|
||||||
|
};
|
||||||
|
task: {
|
||||||
|
id: string;
|
||||||
|
title: string;
|
||||||
|
};
|
||||||
|
status: 'pending' | 'in_progress' | 'accepted' | 'needs_revision';
|
||||||
|
attemptNumber: number;
|
||||||
|
submittedAt: string; // ISO date
|
||||||
|
checkedAt?: string; // ISO date
|
||||||
|
feedback?: string;
|
||||||
|
}>;
|
||||||
|
pagination: {
|
||||||
|
total: number;
|
||||||
|
limit: number;
|
||||||
|
offset: number;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Пример запроса
|
||||||
|
|
||||||
|
```bash
|
||||||
|
GET /api/challenge/chain/607f1f77bcf86cd799439021/submissions?status=needs_revision&limit=50
|
||||||
|
```
|
||||||
|
|
||||||
|
### Пример ответа
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"body": {
|
||||||
|
"chain": {
|
||||||
|
"id": "607f1f77bcf86cd799439021",
|
||||||
|
"name": "Основы JavaScript",
|
||||||
|
"tasks": [
|
||||||
|
{ "id": "507f1f77bcf86cd799439011", "title": "Реализовать сортировку массива" },
|
||||||
|
{ "id": "507f1f77bcf86cd799439015", "title": "Валидация формы" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"participants": [
|
||||||
|
{
|
||||||
|
"userId": "user_123",
|
||||||
|
"nickname": "alex_dev",
|
||||||
|
"completedTasks": 1,
|
||||||
|
"totalTasks": 2,
|
||||||
|
"progressPercent": 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"userId": "user_456",
|
||||||
|
"nickname": "maria_coder",
|
||||||
|
"completedTasks": 2,
|
||||||
|
"totalTasks": 2,
|
||||||
|
"progressPercent": 100
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"submissions": [
|
||||||
|
{
|
||||||
|
"id": "sub_001",
|
||||||
|
"user": {
|
||||||
|
"id": "user_123",
|
||||||
|
"nickname": "alex_dev"
|
||||||
|
},
|
||||||
|
"task": {
|
||||||
|
"id": "507f1f77bcf86cd799439011",
|
||||||
|
"title": "Реализовать сортировку массива"
|
||||||
|
},
|
||||||
|
"status": "needs_revision",
|
||||||
|
"attemptNumber": 2,
|
||||||
|
"submittedAt": "2024-12-10T14:30:00.000Z",
|
||||||
|
"checkedAt": "2024-12-10T14:30:45.000Z",
|
||||||
|
"feedback": "Алгоритм работает неверно для отрицательных чисел"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"pagination": {
|
||||||
|
"total": 15,
|
||||||
|
"limit": 50,
|
||||||
|
"offset": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Логика на бэкенде
|
||||||
|
|
||||||
|
### Алгоритм
|
||||||
|
|
||||||
|
1. Получить цепочку по `chainId`
|
||||||
|
2. Если цепочка не найдена — вернуть 404
|
||||||
|
3. Получить список `taskIds` из цепочки
|
||||||
|
4. Найти все submissions где `task._id` входит в `taskIds`
|
||||||
|
5. Применить фильтры (`userId`, `status`) если указаны
|
||||||
|
6. Вычислить прогресс по каждому участнику:
|
||||||
|
- Найти уникальных пользователей из submissions
|
||||||
|
- Для каждого посчитать `completedTasks` (количество уникальных tasks со статусом `accepted`)
|
||||||
|
- Рассчитать `progressPercent = (completedTasks / totalTasks) * 100`
|
||||||
|
7. Применить пагинацию к submissions
|
||||||
|
8. Вернуть результат
|
||||||
|
|
||||||
|
### Индексы MongoDB (рекомендуется)
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Для быстрой выборки submissions по task
|
||||||
|
db.submissions.createIndex({ "task": 1, "submittedAt": -1 })
|
||||||
|
|
||||||
|
// Составной индекс для фильтрации
|
||||||
|
db.submissions.createIndex({ "task": 1, "status": 1, "submittedAt": -1 })
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Права доступа
|
||||||
|
|
||||||
|
Эндпоинт должен быть доступен только пользователям с ролями:
|
||||||
|
- `challenge-admin`
|
||||||
|
- `challenge-teacher`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Коды ошибок
|
||||||
|
|
||||||
|
| Код | Описание |
|
||||||
|
|-----|----------|
|
||||||
|
| 200 | Успешный ответ |
|
||||||
|
| 400 | Некорректные параметры запроса |
|
||||||
|
| 401 | Не авторизован |
|
||||||
|
| 403 | Недостаточно прав |
|
||||||
|
| 404 | Цепочка не найдена |
|
||||||
|
| 500 | Внутренняя ошибка сервера |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Изменения на фронтенде после реализации
|
||||||
|
|
||||||
|
После добавления эндпоинта в `src/__data__/api/api.ts` нужно добавить:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// В endpoints builder
|
||||||
|
getChainSubmissions: builder.query<ChainSubmissionsResponse, {
|
||||||
|
chainId: string;
|
||||||
|
userId?: string;
|
||||||
|
status?: SubmissionStatus;
|
||||||
|
limit?: number;
|
||||||
|
offset?: number;
|
||||||
|
}>({
|
||||||
|
query: ({ chainId, userId, status, limit, offset }) => ({
|
||||||
|
url: `/challenge/chain/${chainId}/submissions`,
|
||||||
|
params: { userId, status, limit, offset },
|
||||||
|
}),
|
||||||
|
transformResponse: (response: { body: ChainSubmissionsResponse }) => response.body,
|
||||||
|
providesTags: ['Submission'],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
Это позволит упростить `SubmissionsPage.tsx`:
|
||||||
|
- Один запрос вместо нескольких
|
||||||
|
- Убрать клиентскую фильтрацию по taskIds
|
||||||
|
- Получать готовый прогресс участников
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Приоритет
|
||||||
|
|
||||||
|
**Средний** — текущая реализация работает, но создаёт избыточную нагрузку при большом количестве участников.
|
||||||
|
|
||||||
|
## Оценка трудозатрат
|
||||||
|
|
||||||
|
~4-6 часов (включая тесты)
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
Содержит два блока изменений:
|
Содержит два блока изменений:
|
||||||
- **Управление видимостью цепочек заданий** (поле `isActive` и новый админский эндпоинт).
|
- **Управление видимостью цепочек заданий** (поле `isActive` и новый админский эндпоинт).
|
||||||
- **Тестовая проверка решения задания админом** (флаг `isTest` в `/submit`).
|
- **Тестовая проверка решения задания админом** (флаг `isTest` и опциональные `hiddenInstructions` в `/submit`).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -158,14 +158,15 @@
|
|||||||
|
|
||||||
#### `POST /api/challenge/submit`
|
#### `POST /api/challenge/submit`
|
||||||
|
|
||||||
К существующему API добавлен новый опциональный флаг в теле запроса:
|
К существующему API добавлены новые опциональные поля в теле запроса:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"userId": "...",
|
"userId": "...",
|
||||||
"taskId": "...",
|
"taskId": "...",
|
||||||
"result": "...",
|
"result": "...",
|
||||||
"isTest": true // НОВОЕ: опциональный флаг
|
"isTest": true, // НОВОЕ: флаг тестового режима
|
||||||
|
"hiddenInstructions": "..." // НОВОЕ: опциональные инструкции для проверки
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -183,8 +184,9 @@
|
|||||||
- Доступен только для ролей `teacher` / `challenge-author` (проверка через `isTeacher(req, true)`).
|
- Доступен только для ролей `teacher` / `challenge-author` (проверка через `isTeacher(req, true)`).
|
||||||
- **Не создаётся** запись `ChallengeSubmission`.
|
- **Не создаётся** запись `ChallengeSubmission`.
|
||||||
- **Не используется** очередь проверки.
|
- **Не используется** очередь проверки.
|
||||||
- Проверяется только существование задания (`taskId`), пользователь по `userId` в этом режиме **не ищется и не нужен**.
|
- Проверяется только существование задания (`taskId`), пользователь по `userId` в этом режиме **не ищется и не нужен** (но поле всё ещё формально обязательно по схеме).
|
||||||
- Сразу вызывается LLM и возвращается результат проверки.
|
- Если переданы `hiddenInstructions`, они используются **вместо** `task.hiddenInstructions` при формировании промпта для LLM.
|
||||||
|
- Никакие изменения инструкций, переданные через `hiddenInstructions`, **не сохраняются** в базу — это чисто временная инструкция для одной тестовой проверки.
|
||||||
|
|
||||||
**Пример запроса (тестовый режим):**
|
**Пример запроса (тестовый режим):**
|
||||||
|
|
||||||
@@ -197,12 +199,11 @@ Authorization: Bearer <keycloak_token_teacher_or_author>
|
|||||||
"userId": "any-or-dummy-id",
|
"userId": "any-or-dummy-id",
|
||||||
"taskId": "507f1f77bcf86cd799439012",
|
"taskId": "507f1f77bcf86cd799439012",
|
||||||
"result": "function solve() { ... }",
|
"result": "function solve() { ... }",
|
||||||
"isTest": true
|
"isTest": true,
|
||||||
|
"hiddenInstructions": "ВРЕМЕННЫЕ инструкции для проверки, не сохраняются"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
> `userId` формально обязателен по схеме, но в тестовом режиме не используется на бэке. Можно передавать любой корректный ObjectId.
|
|
||||||
|
|
||||||
**Пример ответа (тестовый режим):**
|
**Пример ответа (тестовый режим):**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@@ -222,12 +223,13 @@ Authorization: Bearer <keycloak_token_teacher_or_author>
|
|||||||
|
|
||||||
- **Где использовать тестовый режим**:
|
- **Где использовать тестовый режим**:
|
||||||
- только в админских/преподавательских интерфейсах (например, экран настройки задания или предпросмотр проверки);
|
- только в админских/преподавательских интерфейсах (например, экран настройки задания или предпросмотр проверки);
|
||||||
- использовать флаг `isTest: true`, когда нужно получить мгновенный ответ от LLM без записи в историю.
|
- использовать флаг `isTest: true`, когда нужно получить мгновенный ответ от LLM без записи в историю;
|
||||||
|
- при наличии UI-редактора скрытых инструкций использовать `hiddenInstructions` для передачи временного варианта, не сохраняя его.
|
||||||
- **Где НЕ использовать**:
|
- **Где НЕ использовать**:
|
||||||
- в пользовательском флоу сдачи заданий студентами — там должен использоваться обычный режим **без** `isTest`.
|
- в пользовательском флоу сдачи заданий студентами — там должен использоваться обычный режим **без** `isTest`.
|
||||||
- **UI-ожидания**:
|
- **UI-ожидания**:
|
||||||
- показывать администратору статус (`accepted` / `needs_revision`) и `feedback`;
|
- показывать администратору статус (`accepted` / `needs_revision`) и `feedback`;
|
||||||
- явно обозначить в интерфейсе, что это «тестовая проверка» и она **не попадает в статистику / попытки**.
|
- явно обозначить в интерфейсе, что это «тестовая проверка» и она **не попадает в статистику / попытки**, а переданные `hiddenInstructions` не сохраняются.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -238,4 +240,4 @@ Authorization: Bearer <keycloak_token_teacher_or_author>
|
|||||||
- админский список: `GET /api/challenge/chains/admin` → все цепочки + управление `isActive` через `POST/PUT /chain`.
|
- админский список: `GET /api/challenge/chains/admin` → все цепочки + управление `isActive` через `POST/PUT /chain`.
|
||||||
- Для отправки решений:
|
- Для отправки решений:
|
||||||
- обычный режим без `isTest` — всё как раньше (очередь, попытки, статистика);
|
- обычный режим без `isTest` — всё как раньше (очередь, попытки, статистика);
|
||||||
- тестовый режим с `isTest: true` — только для `teacher/challenge-author`, без записи прогресса, сразу возвращает результат проверки.
|
- тестовый режим с `isTest: true` + опциональные `hiddenInstructions` — только для `teacher/challenge-author`, без записи прогресса, сразу возвращает результат проверки с учётом временных инструкций.
|
||||||
@@ -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",
|
||||||
@@ -166,8 +181,21 @@
|
|||||||
"challenge.admin.submissions.title": "Solution attempts",
|
"challenge.admin.submissions.title": "Solution attempts",
|
||||||
"challenge.admin.submissions.loading": "Loading attempts...",
|
"challenge.admin.submissions.loading": "Loading attempts...",
|
||||||
"challenge.admin.submissions.load.error": "Failed to load attempts list",
|
"challenge.admin.submissions.load.error": "Failed to load attempts list",
|
||||||
|
"challenge.admin.submissions.select.chain": "Select a chain to view participant attempts",
|
||||||
|
"challenge.admin.submissions.chain.tasks": "tasks",
|
||||||
|
"challenge.admin.submissions.chain.click": "Click to view attempts",
|
||||||
|
"challenge.admin.submissions.no.chains.title": "No chains",
|
||||||
|
"challenge.admin.submissions.no.chains.description": "Create a task chain to get started",
|
||||||
|
"challenge.admin.submissions.back.to.chains": "Back to chain selection",
|
||||||
|
"challenge.admin.submissions.chain.description": "Total tasks in chain: {{count}}",
|
||||||
|
"challenge.admin.submissions.participants.title": "Chain participants",
|
||||||
|
"challenge.admin.submissions.participants.description": "Select a participant to view their attempts in this chain",
|
||||||
|
"challenge.admin.submissions.participants.empty.title": "No participants",
|
||||||
|
"challenge.admin.submissions.participants.empty.description": "No one has submitted solutions in this chain yet",
|
||||||
|
"challenge.admin.submissions.participants.click.to.view": "→ view",
|
||||||
"challenge.admin.submissions.search.placeholder": "Search by user or task...",
|
"challenge.admin.submissions.search.placeholder": "Search by user or task...",
|
||||||
"challenge.admin.submissions.filter.user": "Select user",
|
"challenge.admin.submissions.filter.user": "Select user",
|
||||||
|
"challenge.admin.submissions.filter.user.clear": "← All participants",
|
||||||
"challenge.admin.submissions.filter.status": "Status",
|
"challenge.admin.submissions.filter.status": "Status",
|
||||||
"challenge.admin.submissions.status.all": "All statuses",
|
"challenge.admin.submissions.status.all": "All statuses",
|
||||||
"challenge.admin.submissions.status.accepted": "Accepted",
|
"challenge.admin.submissions.status.accepted": "Accepted",
|
||||||
|
|||||||
@@ -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": "Не удалось загрузить статистику системы",
|
||||||
@@ -165,9 +180,21 @@
|
|||||||
"challenge.admin.submissions.title": "Попытки решений",
|
"challenge.admin.submissions.title": "Попытки решений",
|
||||||
"challenge.admin.submissions.loading": "Загрузка попыток...",
|
"challenge.admin.submissions.loading": "Загрузка попыток...",
|
||||||
"challenge.admin.submissions.load.error": "Не удалось загрузить список попыток",
|
"challenge.admin.submissions.load.error": "Не удалось загрузить список попыток",
|
||||||
|
"challenge.admin.submissions.select.chain": "Выберите цепочку для просмотра попыток участников",
|
||||||
|
"challenge.admin.submissions.chain.tasks": "заданий",
|
||||||
|
"challenge.admin.submissions.chain.click": "Нажмите для просмотра попыток",
|
||||||
|
"challenge.admin.submissions.no.chains.title": "Нет цепочек",
|
||||||
|
"challenge.admin.submissions.no.chains.description": "Создайте цепочку заданий для начала работы",
|
||||||
|
"challenge.admin.submissions.back.to.chains": "Назад к выбору цепочки",
|
||||||
|
"challenge.admin.submissions.chain.description": "Всего заданий в цепочке: {{count}}",
|
||||||
|
"challenge.admin.submissions.participants.title": "Участники цепочки",
|
||||||
|
"challenge.admin.submissions.participants.description": "Выберите участника для просмотра его попыток в этой цепочке",
|
||||||
|
"challenge.admin.submissions.participants.empty.title": "Нет участников",
|
||||||
|
"challenge.admin.submissions.participants.empty.description": "Пока никто не отправил решения в этой цепочке",
|
||||||
|
"challenge.admin.submissions.participants.click.to.view": "→ посмотреть",
|
||||||
"challenge.admin.submissions.search.placeholder": "Поиск по пользователю или заданию...",
|
"challenge.admin.submissions.search.placeholder": "Поиск по пользователю или заданию...",
|
||||||
"challenge.admin.submissions.filter.user": "Выберите пользователя",
|
"challenge.admin.submissions.filter.user": "Выберите пользователя",
|
||||||
"challenge.admin.submissions.filter.user.clear": "Показать всех",
|
"challenge.admin.submissions.filter.user.clear": "← Все участники",
|
||||||
"challenge.admin.submissions.filter.status": "Статус",
|
"challenge.admin.submissions.filter.status": "Статус",
|
||||||
"challenge.admin.submissions.status.all": "Все статусы",
|
"challenge.admin.submissions.status.all": "Все статусы",
|
||||||
"challenge.admin.submissions.status.accepted": "Принято",
|
"challenge.admin.submissions.status.accepted": "Принято",
|
||||||
|
|||||||
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,9 +13,12 @@ import type {
|
|||||||
UpdateTaskRequest,
|
UpdateTaskRequest,
|
||||||
CreateChainRequest,
|
CreateChainRequest,
|
||||||
UpdateChainRequest,
|
UpdateChainRequest,
|
||||||
|
DuplicateChainRequest,
|
||||||
|
ClearSubmissionsResponse,
|
||||||
SubmitRequest,
|
SubmitRequest,
|
||||||
TestSubmissionResult,
|
TestSubmissionResult,
|
||||||
APIResponse,
|
ChainSubmissionsResponse,
|
||||||
|
SubmissionStatus,
|
||||||
} from '../../types/challenge'
|
} from '../../types/challenge'
|
||||||
|
|
||||||
export const api = createApi({
|
export const api = createApi({
|
||||||
@@ -114,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>({
|
||||||
@@ -144,10 +164,21 @@ export const api = createApi({
|
|||||||
transformResponse: (response: { body: ChallengeSubmission[] }) => response.body,
|
transformResponse: (response: { body: ChallengeSubmission[] }) => response.body,
|
||||||
providesTags: ['Submission'],
|
providesTags: ['Submission'],
|
||||||
}),
|
}),
|
||||||
|
getChainSubmissions: builder.query<
|
||||||
|
ChainSubmissionsResponse,
|
||||||
|
{ chainId: string; userId?: string; status?: SubmissionStatus }
|
||||||
|
>({
|
||||||
|
query: ({ chainId, userId, status }) => ({
|
||||||
|
url: `/challenge/chain/${chainId}/submissions`,
|
||||||
|
params: userId || status ? { userId, status } : undefined,
|
||||||
|
}),
|
||||||
|
transformResponse: (response: { body: ChainSubmissionsResponse }) => response.body,
|
||||||
|
providesTags: ['Submission'],
|
||||||
|
}),
|
||||||
|
|
||||||
// Test submission (LLM check without creating a real submission)
|
// Test submission (LLM check without creating a real submission)
|
||||||
testSubmission: builder.mutation<TestSubmissionResult, SubmitRequest>({
|
testSubmission: builder.mutation<TestSubmissionResult, SubmitRequest>({
|
||||||
query: ({ userId, taskId, result, isTest = true }) => ({
|
query: ({ userId, taskId, result, isTest = true, hiddenInstructions }) => ({
|
||||||
url: '/challenge/submit',
|
url: '/challenge/submit',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
@@ -155,9 +186,11 @@ export const api = createApi({
|
|||||||
taskId,
|
taskId,
|
||||||
result,
|
result,
|
||||||
isTest,
|
isTest,
|
||||||
|
hiddenInstructions,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
transformResponse: (response: APIResponse<TestSubmissionResult>) => response.data,
|
// Сервер возвращает { success: boolean; body: TestSubmissionResult }
|
||||||
|
transformResponse: (response: { success: boolean; body: TestSubmissionResult }) => response.body,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
@@ -173,10 +206,13 @@ export const {
|
|||||||
useCreateChainMutation,
|
useCreateChainMutation,
|
||||||
useUpdateChainMutation,
|
useUpdateChainMutation,
|
||||||
useDeleteChainMutation,
|
useDeleteChainMutation,
|
||||||
|
useDuplicateChainMutation,
|
||||||
|
useClearChainSubmissionsMutation,
|
||||||
useGetSystemStatsQuery,
|
useGetSystemStatsQuery,
|
||||||
useGetSystemStatsV2Query,
|
useGetSystemStatsV2Query,
|
||||||
useGetUserStatsQuery,
|
useGetUserStatsQuery,
|
||||||
useGetUserSubmissionsQuery,
|
useGetUserSubmissionsQuery,
|
||||||
|
useGetChainSubmissionsQuery,
|
||||||
useTestSubmissionMutation,
|
useTestSubmissionMutation,
|
||||||
} = api
|
} = api
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,12 @@ export const URLs = {
|
|||||||
|
|
||||||
// Submissions
|
// Submissions
|
||||||
submissions: makeUrl('/submissions'),
|
submissions: makeUrl('/submissions'),
|
||||||
submissionDetails: (userId: string, submissionId: string) => makeUrl(`/submissions/${userId}/${submissionId}`),
|
submissionsChain: (chainId: string) => makeUrl(`/submissions/${chainId}`),
|
||||||
submissionDetailsPath: makeUrl('/submissions/:userId/:submissionId'),
|
submissionsChainPath: makeUrl('/submissions/:chainId'),
|
||||||
|
submissionDetails: (chainId: string, userId: string, submissionId: string) => makeUrl(`/submissions/${chainId}/${userId}/${submissionId}`),
|
||||||
|
submissionDetailsPath: makeUrl('/submissions/:chainId/:userId/:submissionId'),
|
||||||
|
|
||||||
// External links
|
// External links
|
||||||
challengePlayer: navs['link.challenge'] || '/challenge',
|
challengePlayer: navs['link.challenge.main'] || '/challenge',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -130,6 +130,14 @@ export const Dashboard = () => {
|
|||||||
</PageWrapper>
|
</PageWrapper>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path={URLs.submissionsChainPath}
|
||||||
|
element={
|
||||||
|
<PageWrapper>
|
||||||
|
<SubmissionsPage />
|
||||||
|
</PageWrapper>
|
||||||
|
}
|
||||||
|
/>
|
||||||
<Route
|
<Route
|
||||||
path={URLs.submissionDetailsPath}
|
path={URLs.submissionDetailsPath}
|
||||||
element={
|
element={
|
||||||
|
|||||||
@@ -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'),
|
||||||
@@ -165,7 +170,7 @@ export const ChainsListPage: React.FC = () => {
|
|||||||
size="xs"
|
size="xs"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => handleToggleActive(chain, !chain.isActive)}
|
onClick={() => handleToggleActive(chain, !chain.isActive)}
|
||||||
isDisabled={updatingChainId === chain.id}
|
disabled={updatingChainId === chain.id}
|
||||||
>
|
>
|
||||||
{chain.isActive
|
{chain.isActive
|
||||||
? t('challenge.admin.chains.list.status.inactive')
|
? t('challenge.admin.chains.list.status.inactive')
|
||||||
@@ -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>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import { URLs } from '../../__data__/urls'
|
|||||||
|
|
||||||
export const SubmissionDetailsPage: React.FC = () => {
|
export const SubmissionDetailsPage: React.FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { userId, submissionId } = useParams<{ userId: string; submissionId: string }>()
|
const { chainId, userId, submissionId } = useParams<{ chainId: string; userId: string; submissionId: string }>()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
// Получаем submissions для конкретного пользователя
|
// Получаем submissions для конкретного пользователя
|
||||||
@@ -24,8 +24,8 @@ export const SubmissionDetailsPage: React.FC = () => {
|
|||||||
const submission = submissions?.find((s) => s.id === submissionId)
|
const submission = submissions?.find((s) => s.id === submissionId)
|
||||||
|
|
||||||
const handleBack = () => {
|
const handleBack = () => {
|
||||||
if (userId) {
|
if (chainId) {
|
||||||
navigate(`${URLs.submissions}?userId=${encodeURIComponent(userId)}`)
|
navigate(URLs.submissionsChain(chainId))
|
||||||
} else {
|
} else {
|
||||||
navigate(URLs.submissions)
|
navigate(URLs.submissions)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState } from 'react'
|
import React, { useState, useMemo } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useNavigate, useSearchParams } from 'react-router-dom'
|
import { useNavigate, useParams, Link } from 'react-router-dom'
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Heading,
|
Heading,
|
||||||
@@ -10,19 +10,26 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
HStack,
|
HStack,
|
||||||
VStack,
|
VStack,
|
||||||
Select,
|
Badge,
|
||||||
Progress,
|
Progress,
|
||||||
Grid,
|
Grid,
|
||||||
|
SimpleGrid,
|
||||||
|
Select,
|
||||||
createListCollection,
|
createListCollection,
|
||||||
} from '@chakra-ui/react'
|
} from '@chakra-ui/react'
|
||||||
import { useGetSystemStatsV2Query, useGetUserSubmissionsQuery } from '../../__data__/api/api'
|
import { getFeatureValue } from '@brojs/cli'
|
||||||
|
import {
|
||||||
|
useGetChainsQuery,
|
||||||
|
useGetChainSubmissionsQuery,
|
||||||
|
useGetSystemStatsV2Query,
|
||||||
|
useGetUserSubmissionsQuery,
|
||||||
|
} from '../../__data__/api/api'
|
||||||
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 { StatusBadge } from '../../components/StatusBadge'
|
import { StatusBadge } from '../../components/StatusBadge'
|
||||||
import { URLs } from '../../__data__/urls'
|
import { URLs } from '../../__data__/urls'
|
||||||
import type {
|
import type {
|
||||||
ActiveParticipant,
|
|
||||||
ChallengeSubmission,
|
ChallengeSubmission,
|
||||||
SubmissionStatus,
|
SubmissionStatus,
|
||||||
ChallengeTask,
|
ChallengeTask,
|
||||||
@@ -32,14 +39,49 @@ import type {
|
|||||||
export const SubmissionsPage: React.FC = () => {
|
export const SubmissionsPage: React.FC = () => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const [searchParams] = useSearchParams()
|
const { chainId } = useParams<{ chainId?: string }>()
|
||||||
const initialUserId = searchParams.get('userId')
|
|
||||||
const { data: stats, isLoading: isStatsLoading, error: statsError, refetch: refetchStats } =
|
|
||||||
useGetSystemStatsV2Query(undefined)
|
|
||||||
|
|
||||||
|
// Проверяем feature flag
|
||||||
|
const featureValue = getFeatureValue('challenge-admin', 'use-chain-submissions-api')
|
||||||
|
const useNewApi = featureValue?.value === 'true'
|
||||||
|
|
||||||
|
// Состояние для выбранного пользователя и фильтров
|
||||||
|
const [selectedUserId, setSelectedUserId] = useState<string | null>(null)
|
||||||
const [searchQuery, setSearchQuery] = useState('')
|
const [searchQuery, setSearchQuery] = useState('')
|
||||||
const [statusFilter, setStatusFilter] = useState<SubmissionStatus | 'all'>('all')
|
const [statusFilter, setStatusFilter] = useState<SubmissionStatus | 'all'>('all')
|
||||||
const [selectedUserId, setSelectedUserId] = useState<string | null>(initialUserId)
|
|
||||||
|
// Получаем список цепочек
|
||||||
|
const {
|
||||||
|
data: chains,
|
||||||
|
isLoading: isChainsLoading,
|
||||||
|
error: chainsError,
|
||||||
|
refetch: refetchChains,
|
||||||
|
} = useGetChainsQuery()
|
||||||
|
|
||||||
|
// Новый API: получаем данные по цепочке через новый эндпоинт
|
||||||
|
const {
|
||||||
|
data: chainData,
|
||||||
|
isLoading: isChainDataLoading,
|
||||||
|
error: chainDataError,
|
||||||
|
refetch: refetchChainData,
|
||||||
|
} = useGetChainSubmissionsQuery(
|
||||||
|
{
|
||||||
|
chainId: chainId!,
|
||||||
|
userId: selectedUserId || undefined,
|
||||||
|
status: statusFilter !== 'all' ? statusFilter : undefined,
|
||||||
|
},
|
||||||
|
{ skip: !chainId || !useNewApi }
|
||||||
|
)
|
||||||
|
|
||||||
|
// Старый API: получаем общую статистику и submissions отдельно
|
||||||
|
const {
|
||||||
|
data: stats,
|
||||||
|
isLoading: isStatsLoading,
|
||||||
|
error: statsError,
|
||||||
|
refetch: refetchStats,
|
||||||
|
} = useGetSystemStatsV2Query(undefined, {
|
||||||
|
skip: !chainId || useNewApi,
|
||||||
|
})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: submissions,
|
data: submissions,
|
||||||
@@ -48,36 +90,78 @@ export const SubmissionsPage: React.FC = () => {
|
|||||||
refetch: refetchSubmissions,
|
refetch: refetchSubmissions,
|
||||||
} = useGetUserSubmissionsQuery(
|
} = useGetUserSubmissionsQuery(
|
||||||
{ userId: selectedUserId!, taskId: undefined },
|
{ userId: selectedUserId!, taskId: undefined },
|
||||||
{ skip: !selectedUserId }
|
{ skip: !selectedUserId || useNewApi }
|
||||||
)
|
)
|
||||||
|
|
||||||
const isLoading = isStatsLoading || (selectedUserId && isSubmissionsLoading)
|
const isLoading =
|
||||||
const error = statsError || submissionsError
|
isChainsLoading ||
|
||||||
|
(chainId && useNewApi && isChainDataLoading) ||
|
||||||
|
(chainId && !useNewApi && isStatsLoading) ||
|
||||||
|
(selectedUserId && !useNewApi && isSubmissionsLoading)
|
||||||
|
|
||||||
|
const error = chainsError || (useNewApi ? chainDataError : statsError || submissionsError)
|
||||||
|
|
||||||
const handleRetry = () => {
|
const handleRetry = () => {
|
||||||
|
refetchChains()
|
||||||
|
if (chainId) {
|
||||||
|
if (useNewApi) {
|
||||||
|
refetchChainData()
|
||||||
|
} else {
|
||||||
refetchStats()
|
refetchStats()
|
||||||
if (selectedUserId) {
|
if (selectedUserId) {
|
||||||
refetchSubmissions()
|
refetchSubmissions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (isLoading) {
|
|
||||||
return <LoadingSpinner message={t('challenge.admin.submissions.loading')} />
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error || !stats) {
|
// Получаем данные выбранной цепочки из списка chains (для старого API)
|
||||||
return <ErrorAlert message={t('challenge.admin.submissions.load.error')} onRetry={handleRetry} />
|
const selectedChain = useMemo(() => {
|
||||||
}
|
if (!chainId || !chains) return null
|
||||||
|
return chains.find((c) => c.id === chainId) || null
|
||||||
|
}, [chainId, chains])
|
||||||
|
|
||||||
const participants: ActiveParticipant[] = stats.activeParticipants || []
|
// Получаем taskIds из текущей цепочки (для старого API)
|
||||||
const submissionsList: ChallengeSubmission[] = submissions || []
|
const chainTaskIds = useMemo(() => {
|
||||||
|
if (!selectedChain) return new Set<string>()
|
||||||
|
return new Set(selectedChain.tasks.map((t) => t.id))
|
||||||
|
}, [selectedChain])
|
||||||
|
|
||||||
|
// Старый API: фильтруем участников - только те, кто имеет прогресс в этой цепочке
|
||||||
|
const chainParticipantsOld = useMemo(() => {
|
||||||
|
if (!stats?.activeParticipants || !chainId || useNewApi) return []
|
||||||
|
|
||||||
|
return stats.activeParticipants
|
||||||
|
.map((participant) => {
|
||||||
|
const chainProgress = participant.chainProgress?.find((cp) => cp.chainId === chainId)
|
||||||
|
return {
|
||||||
|
...participant,
|
||||||
|
progressPercent: chainProgress?.progressPercent ?? 0,
|
||||||
|
completedTasks: chainProgress?.completedTasks ?? 0,
|
||||||
|
totalTasks: selectedChain?.tasks.length ?? 0,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.sort((a, b) => a.progressPercent - b.progressPercent)
|
||||||
|
}, [stats?.activeParticipants, chainId, selectedChain, useNewApi])
|
||||||
|
|
||||||
|
// Старый API: фильтруем submissions только по заданиям из текущей цепочки
|
||||||
|
const filteredSubmissionsOld = useMemo(() => {
|
||||||
|
if (!submissions || chainTaskIds.size === 0 || useNewApi) return []
|
||||||
|
|
||||||
const normalizedSearchQuery = (searchQuery ?? '').toLowerCase()
|
const normalizedSearchQuery = (searchQuery ?? '').toLowerCase()
|
||||||
|
|
||||||
const filteredSubmissions = submissionsList.filter((submission) => {
|
return submissions.filter((submission) => {
|
||||||
const rawUser = submission.user as ChallengeUser | string | undefined
|
|
||||||
const rawTask = submission.task as ChallengeTask | string | undefined
|
const rawTask = submission.task as ChallengeTask | string | undefined
|
||||||
|
const taskId =
|
||||||
|
rawTask && typeof rawTask === 'object' && 'id' in rawTask
|
||||||
|
? rawTask.id
|
||||||
|
: typeof rawTask === 'string'
|
||||||
|
? rawTask
|
||||||
|
: ''
|
||||||
|
|
||||||
|
if (!chainTaskIds.has(taskId)) return false
|
||||||
|
|
||||||
|
const rawUser = submission.user as ChallengeUser | string | undefined
|
||||||
const nickname =
|
const nickname =
|
||||||
rawUser && typeof rawUser === 'object' && 'nickname' in rawUser
|
rawUser && typeof rawUser === 'object' && 'nickname' in rawUser
|
||||||
? (rawUser.nickname ?? '')
|
? (rawUser.nickname ?? '')
|
||||||
@@ -96,6 +180,52 @@ export const SubmissionsPage: React.FC = () => {
|
|||||||
|
|
||||||
return matchesSearch && matchesStatus
|
return matchesSearch && matchesStatus
|
||||||
})
|
})
|
||||||
|
}, [submissions, chainTaskIds, searchQuery, statusFilter, useNewApi])
|
||||||
|
|
||||||
|
// Новый API: фильтруем submissions по поисковому запросу (статус уже отфильтрован на сервере)
|
||||||
|
const filteredSubmissionsNew = useMemo(() => {
|
||||||
|
if (!chainData?.submissions || !useNewApi) return []
|
||||||
|
|
||||||
|
const normalizedSearchQuery = (searchQuery ?? '').toLowerCase()
|
||||||
|
if (!normalizedSearchQuery) return chainData.submissions
|
||||||
|
|
||||||
|
return chainData.submissions.filter((submission) => {
|
||||||
|
const rawUser = submission.user as ChallengeUser | string | undefined
|
||||||
|
const rawTask = submission.task as ChallengeTask | string | undefined
|
||||||
|
|
||||||
|
const nickname =
|
||||||
|
rawUser && typeof rawUser === 'object' && 'nickname' in rawUser
|
||||||
|
? (rawUser.nickname ?? '')
|
||||||
|
: typeof rawUser === 'string'
|
||||||
|
? rawUser
|
||||||
|
: ''
|
||||||
|
|
||||||
|
const title =
|
||||||
|
rawTask && typeof rawTask === 'object' && 'title' in rawTask
|
||||||
|
? (rawTask.title ?? '')
|
||||||
|
: typeof rawTask === 'string'
|
||||||
|
? rawTask
|
||||||
|
: ''
|
||||||
|
|
||||||
|
return (
|
||||||
|
nickname.toLowerCase().includes(normalizedSearchQuery) ||
|
||||||
|
title.toLowerCase().includes(normalizedSearchQuery)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}, [chainData?.submissions, searchQuery, useNewApi])
|
||||||
|
|
||||||
|
// Выбираем данные в зависимости от фичи
|
||||||
|
const filteredSubmissions = useNewApi ? filteredSubmissionsNew : filteredSubmissionsOld
|
||||||
|
|
||||||
|
// Сортируем участников по прогрессу
|
||||||
|
const sortedParticipants = useMemo(() => {
|
||||||
|
if (useNewApi) {
|
||||||
|
if (!chainData?.participants) return []
|
||||||
|
return [...chainData.participants].sort((a, b) => a.progressPercent - b.progressPercent)
|
||||||
|
} else {
|
||||||
|
return chainParticipantsOld
|
||||||
|
}
|
||||||
|
}, [chainData?.participants, chainParticipantsOld, useNewApi])
|
||||||
|
|
||||||
const formatDate = (dateStr: string) => {
|
const formatDate = (dateStr: string) => {
|
||||||
return new Date(dateStr).toLocaleString('ru-RU', {
|
return new Date(dateStr).toLocaleString('ru-RU', {
|
||||||
@@ -125,70 +255,133 @@ export const SubmissionsPage: React.FC = () => {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
const userOptions = createListCollection({
|
if (isLoading) {
|
||||||
items: participants.map((participant) => ({
|
return <LoadingSpinner message={t('challenge.admin.submissions.loading')} />
|
||||||
label: `${participant.nickname} (${participant.userId})`,
|
|
||||||
value: participant.userId,
|
|
||||||
})),
|
|
||||||
})
|
|
||||||
|
|
||||||
const hasParticipants = participants.length > 0
|
|
||||||
const hasSelectedUser = !!selectedUserId
|
|
||||||
|
|
||||||
const participantOverviewRows = participants
|
|
||||||
.map((participant) => {
|
|
||||||
const chains = participant.chainProgress || []
|
|
||||||
|
|
||||||
const totalTasks = chains.reduce((sum, chain) => sum + (chain.totalTasks ?? 0), 0)
|
|
||||||
const completedTasks = chains.reduce(
|
|
||||||
(sum, chain) => sum + (chain.completedTasks ?? 0),
|
|
||||||
0
|
|
||||||
)
|
|
||||||
|
|
||||||
const overallPercent =
|
|
||||||
totalTasks > 0 ? Math.round((completedTasks / totalTasks) * 100) : 0
|
|
||||||
|
|
||||||
return {
|
|
||||||
userId: participant.userId,
|
|
||||||
nickname: participant.nickname,
|
|
||||||
totalSubmissions: participant.totalSubmissions,
|
|
||||||
completedTasks,
|
|
||||||
totalTasks,
|
|
||||||
overallPercent,
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.sort((a, b) => a.overallPercent - b.overallPercent)
|
if (error) {
|
||||||
|
return <ErrorAlert message={t('challenge.admin.submissions.load.error')} onRetry={handleRetry} />
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если chainId не указан - показываем выбор цепочки
|
||||||
|
if (!chainId) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Box mb={6}>
|
||||||
|
<Heading mb={2}>{t('challenge.admin.submissions.title')}</Heading>
|
||||||
|
<Text color="gray.600" fontSize="sm">
|
||||||
|
{t('challenge.admin.submissions.select.chain')}
|
||||||
|
</Text>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{chains && chains.length > 0 ? (
|
||||||
|
<SimpleGrid columns={{ base: 1, md: 2, lg: 3 }} gap={6}>
|
||||||
|
{chains.map((chain) => (
|
||||||
|
<Link key={chain.id} to={URLs.submissionsChain(chain.id)} style={{ textDecoration: 'none' }}>
|
||||||
|
<Box
|
||||||
|
p={6}
|
||||||
|
bg="white"
|
||||||
|
borderRadius="lg"
|
||||||
|
boxShadow="sm"
|
||||||
|
borderWidth="1px"
|
||||||
|
borderColor="gray.200"
|
||||||
|
_hover={{
|
||||||
|
boxShadow: 'md',
|
||||||
|
borderColor: 'teal.400',
|
||||||
|
transform: 'translateY(-2px)',
|
||||||
|
}}
|
||||||
|
transition="all 0.2s"
|
||||||
|
cursor="pointer"
|
||||||
|
height="100%"
|
||||||
|
>
|
||||||
|
<VStack align="start" gap={3}>
|
||||||
|
<Heading size="md" color="teal.600">
|
||||||
|
{chain.name}
|
||||||
|
</Heading>
|
||||||
|
<HStack>
|
||||||
|
<Badge colorPalette="teal" size="lg">
|
||||||
|
{chain.tasks.length} {t('challenge.admin.submissions.chain.tasks')}
|
||||||
|
</Badge>
|
||||||
|
{!chain.isActive && (
|
||||||
|
<Badge colorPalette="gray" size="lg">
|
||||||
|
{t('challenge.admin.chains.list.status.inactive')}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</HStack>
|
||||||
|
<Text fontSize="sm" color="gray.600" mt={2}>
|
||||||
|
{t('challenge.admin.submissions.chain.click')}
|
||||||
|
</Text>
|
||||||
|
</VStack>
|
||||||
|
</Box>
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</SimpleGrid>
|
||||||
|
) : (
|
||||||
|
<EmptyState
|
||||||
|
title={t('challenge.admin.submissions.no.chains.title')}
|
||||||
|
description={t('challenge.admin.submissions.no.chains.description')}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если цепочка выбрана но данных нет
|
||||||
|
if (useNewApi && !chainData) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Link to={URLs.submissions} style={{ textDecoration: 'none', color: '#319795' }}>
|
||||||
|
<Text fontSize="sm" _hover={{ textDecoration: 'underline' }} mb={4}>
|
||||||
|
← {t('challenge.admin.submissions.back.to.chains')}
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
<ErrorAlert message={t('challenge.admin.common.not.found')} onRetry={handleRetry} />
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!useNewApi && !selectedChain) {
|
||||||
|
return (
|
||||||
|
<Box>
|
||||||
|
<Link to={URLs.submissions} style={{ textDecoration: 'none', color: '#319795' }}>
|
||||||
|
<Text fontSize="sm" _hover={{ textDecoration: 'underline' }} mb={4}>
|
||||||
|
← {t('challenge.admin.submissions.back.to.chains')}
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
<ErrorAlert message={t('challenge.admin.common.not.found')} onRetry={handleRetry} />
|
||||||
|
</Box>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const chainName = useNewApi ? chainData?.chain.name : selectedChain?.name
|
||||||
|
const chainTasksCount = useNewApi ? chainData?.chain.tasks.length : selectedChain?.tasks.length
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Heading mb={6}>{t('challenge.admin.submissions.title')}</Heading>
|
{/* Header с навигацией */}
|
||||||
|
<Box mb={6}>
|
||||||
|
<HStack gap={2} mb={2}>
|
||||||
|
<Link to={URLs.submissions} style={{ textDecoration: 'none', color: '#319795' }}>
|
||||||
|
<Text fontSize="sm" _hover={{ textDecoration: 'underline' }}>
|
||||||
|
← {t('challenge.admin.submissions.back.to.chains')}
|
||||||
|
</Text>
|
||||||
|
</Link>
|
||||||
|
</HStack>
|
||||||
|
<Heading mb={2}>{chainName}</Heading>
|
||||||
|
<Text color="gray.600" fontSize="sm">
|
||||||
|
{t('challenge.admin.submissions.chain.description', { count: chainTasksCount ?? 0 })}
|
||||||
|
</Text>
|
||||||
|
</Box>
|
||||||
|
|
||||||
{/* Filters */}
|
{/* Выбор участника и фильтры */}
|
||||||
{hasParticipants && (
|
{sortedParticipants.length > 0 && (
|
||||||
<VStack mb={4} gap={3} align="stretch">
|
<VStack mb={4} gap={3} align="stretch">
|
||||||
<HStack gap={4} align="center">
|
<HStack gap={4} align="center" wrap="wrap">
|
||||||
<Select.Root
|
{selectedUserId && (
|
||||||
collection={userOptions}
|
|
||||||
value={selectedUserId ? [selectedUserId] : []}
|
|
||||||
onValueChange={(e) => setSelectedUserId(e.value[0] ?? null)}
|
|
||||||
maxW="300px"
|
|
||||||
>
|
|
||||||
<Select.Trigger>
|
|
||||||
<Select.ValueText placeholder={t('challenge.admin.submissions.filter.user')} />
|
|
||||||
</Select.Trigger>
|
|
||||||
<Select.Content>
|
|
||||||
{userOptions.items.map((option) => (
|
|
||||||
<Select.Item key={option.value} item={option}>
|
|
||||||
{option.label}
|
|
||||||
</Select.Item>
|
|
||||||
))}
|
|
||||||
</Select.Content>
|
|
||||||
</Select.Root>
|
|
||||||
|
|
||||||
{hasSelectedUser && (
|
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="ghost"
|
variant="outline"
|
||||||
|
colorPalette="teal"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedUserId(null)
|
setSelectedUserId(null)
|
||||||
setSearchQuery('')
|
setSearchQuery('')
|
||||||
@@ -199,13 +392,13 @@ export const SubmissionsPage: React.FC = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{submissionsList.length > 0 && (
|
{selectedUserId && filteredSubmissions.length > 0 && (
|
||||||
<>
|
<>
|
||||||
<Input
|
<Input
|
||||||
placeholder={t('challenge.admin.submissions.search.placeholder')}
|
placeholder={t('challenge.admin.submissions.search.placeholder')}
|
||||||
value={searchQuery}
|
value={searchQuery}
|
||||||
onChange={(e) => setSearchQuery(e.target.value)}
|
onChange={(e) => setSearchQuery(e.target.value)}
|
||||||
maxW="400px"
|
maxW="300px"
|
||||||
/>
|
/>
|
||||||
<Select.Root
|
<Select.Root
|
||||||
collection={statusOptions}
|
collection={statusOptions}
|
||||||
@@ -230,24 +423,20 @@ export const SubmissionsPage: React.FC = () => {
|
|||||||
</VStack>
|
</VStack>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!hasParticipants ? (
|
{/* Если не выбран пользователь - показываем обзор участников */}
|
||||||
<EmptyState
|
{!selectedUserId ? (
|
||||||
title={t('challenge.admin.submissions.empty.title')}
|
|
||||||
description={t('challenge.admin.submissions.empty.description')}
|
|
||||||
/>
|
|
||||||
) : !hasSelectedUser ? (
|
|
||||||
<Box>
|
<Box>
|
||||||
<Heading size="md" mb={4}>
|
<Heading size="md" mb={4}>
|
||||||
{t('challenge.admin.submissions.overview.title')}
|
{t('challenge.admin.submissions.participants.title')}
|
||||||
</Heading>
|
</Heading>
|
||||||
<Text mb={4} color="gray.600">
|
<Text mb={4} color="gray.600">
|
||||||
{t('challenge.admin.submissions.overview.description')}
|
{t('challenge.admin.submissions.participants.description')}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
{participantOverviewRows.length === 0 ? (
|
{sortedParticipants.length === 0 ? (
|
||||||
<EmptyState
|
<EmptyState
|
||||||
title={t('challenge.admin.detailed.stats.participants.empty')}
|
title={t('challenge.admin.submissions.participants.empty.title')}
|
||||||
description={t('challenge.admin.detailed.stats.chains.empty')}
|
description={t('challenge.admin.submissions.participants.empty.description')}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Grid
|
<Grid
|
||||||
@@ -257,43 +446,50 @@ export const SubmissionsPage: React.FC = () => {
|
|||||||
lg: 'repeat(3, minmax(0, 1fr))',
|
lg: 'repeat(3, minmax(0, 1fr))',
|
||||||
xl: 'repeat(4, minmax(0, 1fr))',
|
xl: 'repeat(4, minmax(0, 1fr))',
|
||||||
}}
|
}}
|
||||||
gap={2}
|
gap={3}
|
||||||
>
|
>
|
||||||
{participantOverviewRows.map((row) => {
|
{sortedParticipants.map((participant) => {
|
||||||
const colorPalette =
|
const colorPalette =
|
||||||
row.overallPercent >= 70
|
participant.progressPercent >= 70
|
||||||
? 'green'
|
? 'green'
|
||||||
: row.overallPercent >= 40
|
: participant.progressPercent >= 40
|
||||||
? 'orange'
|
? 'orange'
|
||||||
: 'red'
|
: 'red'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
key={row.userId}
|
key={participant.userId}
|
||||||
p={2}
|
p={3}
|
||||||
borderWidth="1px"
|
borderWidth="1px"
|
||||||
borderRadius="md"
|
borderRadius="md"
|
||||||
borderColor="gray.200"
|
borderColor="gray.200"
|
||||||
_hover={{ bg: 'gray.50' }}
|
bg="white"
|
||||||
|
_hover={{ bg: 'gray.50', borderColor: 'teal.300' }}
|
||||||
cursor="pointer"
|
cursor="pointer"
|
||||||
onClick={() => setSelectedUserId(row.userId)}
|
onClick={() => setSelectedUserId(participant.userId)}
|
||||||
|
transition="all 0.2s"
|
||||||
>
|
>
|
||||||
<HStack justify="space-between" mb={1} gap={2}>
|
<HStack justify="space-between" mb={2} gap={2}>
|
||||||
<Text fontSize="xs" fontWeight="medium" truncate maxW="150px">
|
<Text fontSize="sm" fontWeight="medium" truncate maxW="180px">
|
||||||
{row.nickname}
|
{participant.nickname}
|
||||||
</Text>
|
|
||||||
<Text fontSize="xs" color="gray.500">
|
|
||||||
{row.overallPercent}%
|
|
||||||
</Text>
|
</Text>
|
||||||
|
<Badge colorPalette={colorPalette} size="sm">
|
||||||
|
{participant.progressPercent}%
|
||||||
|
</Badge>
|
||||||
</HStack>
|
</HStack>
|
||||||
<Progress.Root value={row.overallPercent} size="xs" colorPalette={colorPalette}>
|
<Progress.Root value={participant.progressPercent} size="sm" colorPalette={colorPalette}>
|
||||||
<Progress.Track>
|
<Progress.Track>
|
||||||
<Progress.Range />
|
<Progress.Range />
|
||||||
</Progress.Track>
|
</Progress.Track>
|
||||||
</Progress.Root>
|
</Progress.Root>
|
||||||
<Text fontSize="xs" color="gray.500" mt={1}>
|
<HStack justify="space-between" mt={2}>
|
||||||
{row.completedTasks} / {row.totalTasks}
|
<Text fontSize="xs" color="gray.500">
|
||||||
|
{participant.completedTasks} / {participant.totalTasks}
|
||||||
</Text>
|
</Text>
|
||||||
|
<Text fontSize="xs" color="gray.400">
|
||||||
|
{t('challenge.admin.submissions.participants.click.to.view')}
|
||||||
|
</Text>
|
||||||
|
</HStack>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
@@ -306,6 +502,7 @@ export const SubmissionsPage: React.FC = () => {
|
|||||||
description={t('challenge.admin.submissions.search.empty.description')}
|
description={t('challenge.admin.submissions.search.empty.description')}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
/* Таблица попыток выбранного пользователя */
|
||||||
<Box bg="white" borderRadius="lg" boxShadow="sm" borderWidth="1px" borderColor="gray.200" overflowX="auto">
|
<Box bg="white" borderRadius="lg" boxShadow="sm" borderWidth="1px" borderColor="gray.200" overflowX="auto">
|
||||||
<Table.Root size="sm">
|
<Table.Root size="sm">
|
||||||
<Table.Header>
|
<Table.Header>
|
||||||
@@ -316,7 +513,9 @@ export const SubmissionsPage: React.FC = () => {
|
|||||||
<Table.ColumnHeader>{t('challenge.admin.submissions.table.attempt')}</Table.ColumnHeader>
|
<Table.ColumnHeader>{t('challenge.admin.submissions.table.attempt')}</Table.ColumnHeader>
|
||||||
<Table.ColumnHeader>{t('challenge.admin.submissions.table.submitted')}</Table.ColumnHeader>
|
<Table.ColumnHeader>{t('challenge.admin.submissions.table.submitted')}</Table.ColumnHeader>
|
||||||
<Table.ColumnHeader>{t('challenge.admin.submissions.table.check.time')}</Table.ColumnHeader>
|
<Table.ColumnHeader>{t('challenge.admin.submissions.table.check.time')}</Table.ColumnHeader>
|
||||||
<Table.ColumnHeader textAlign="right">{t('challenge.admin.submissions.table.actions')}</Table.ColumnHeader>
|
<Table.ColumnHeader textAlign="right">
|
||||||
|
{t('challenge.admin.submissions.table.actions')}
|
||||||
|
</Table.ColumnHeader>
|
||||||
</Table.Row>
|
</Table.Row>
|
||||||
</Table.Header>
|
</Table.Header>
|
||||||
<Table.Body>
|
<Table.Body>
|
||||||
@@ -365,7 +564,7 @@ export const SubmissionsPage: React.FC = () => {
|
|||||||
size="sm"
|
size="sm"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
colorPalette="teal"
|
colorPalette="teal"
|
||||||
onClick={() => navigate(URLs.submissionDetails(selectedUserId!, submission.id))}
|
onClick={() => navigate(URLs.submissionDetails(chainId!, selectedUserId, submission.id))}
|
||||||
>
|
>
|
||||||
{t('challenge.admin.submissions.button.details')}
|
{t('challenge.admin.submissions.button.details')}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -380,4 +579,3 @@ export const SubmissionsPage: React.FC = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,39 @@ export const TaskFormPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
}, [task])
|
}, [task])
|
||||||
|
|
||||||
|
// Восстановление сохранённого тестового ответа для конкретной задачи
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isEdit || !id) return
|
||||||
|
if (typeof window === 'undefined') return
|
||||||
|
|
||||||
|
const key = `challenge-admin.task-test-answer.${id}`
|
||||||
|
try {
|
||||||
|
const saved = window.localStorage.getItem(key)
|
||||||
|
if (saved) {
|
||||||
|
setTestAnswer(saved)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore localStorage errors
|
||||||
|
}
|
||||||
|
}, [isEdit, id])
|
||||||
|
|
||||||
|
// Сохранение тестового ответа в localStorage
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isEdit || !id) return
|
||||||
|
if (typeof window === 'undefined') return
|
||||||
|
|
||||||
|
const key = `challenge-admin.task-test-answer.${id}`
|
||||||
|
try {
|
||||||
|
if (testAnswer.trim()) {
|
||||||
|
window.localStorage.setItem(key, testAnswer)
|
||||||
|
} else {
|
||||||
|
window.localStorage.removeItem(key)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore localStorage errors
|
||||||
|
}
|
||||||
|
}, [isEdit, id, testAnswer])
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
@@ -136,6 +169,7 @@ export const TaskFormPage: React.FC = () => {
|
|||||||
taskId: task.id,
|
taskId: task.id,
|
||||||
result: testAnswer.trim(),
|
result: testAnswer.trim(),
|
||||||
isTest: true,
|
isTest: true,
|
||||||
|
hiddenInstructions: hiddenInstructions.trim() || undefined,
|
||||||
}).unwrap()
|
}).unwrap()
|
||||||
|
|
||||||
setTestStatus(result.status)
|
setTestStatus(result.status)
|
||||||
|
|||||||
@@ -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'
|
||||||
@@ -234,6 +244,8 @@ export interface SubmitRequest {
|
|||||||
result: string
|
result: string
|
||||||
// Флаг тестового режима: проверка без создания Submission и очереди
|
// Флаг тестового режима: проверка без создания Submission и очереди
|
||||||
isTest?: boolean
|
isTest?: boolean
|
||||||
|
// Временные скрытые инструкции для тестовой проверки (не сохраняются в задачу)
|
||||||
|
hiddenInstructions?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TestSubmissionResult {
|
export interface TestSubmissionResult {
|
||||||
@@ -242,3 +254,28 @@ export interface TestSubmissionResult {
|
|||||||
feedback?: string
|
feedback?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========== Chain Submissions API ==========
|
||||||
|
|
||||||
|
export interface ChainSubmissionsParticipant {
|
||||||
|
userId: string
|
||||||
|
nickname: string
|
||||||
|
completedTasks: number
|
||||||
|
totalTasks: number
|
||||||
|
progressPercent: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChainSubmissionsResponse {
|
||||||
|
chain: {
|
||||||
|
id: string
|
||||||
|
name: string
|
||||||
|
tasks: Array<{ id: string; title: string }>
|
||||||
|
}
|
||||||
|
participants: ChainSubmissionsParticipant[]
|
||||||
|
submissions: ChallengeSubmission[]
|
||||||
|
pagination: {
|
||||||
|
total: number
|
||||||
|
limit: number
|
||||||
|
offset: number
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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));
|
||||||
@@ -461,4 +558,116 @@ router.get('/challenge/user/:userId/submissions', (req, res) => {
|
|||||||
respond(res, filtered);
|
respond(res, filtered);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// GET /api/challenge/chain/:chainId/submissions
|
||||||
|
router.get('/challenge/chain/:chainId/submissions', (req, res) => {
|
||||||
|
const chains = getChains();
|
||||||
|
const submissions = getSubmissions();
|
||||||
|
const users = getUsers();
|
||||||
|
|
||||||
|
const chainId = req.params.chainId;
|
||||||
|
const userId = req.query.userId;
|
||||||
|
const status = req.query.status;
|
||||||
|
const limit = parseInt(req.query.limit) || 100;
|
||||||
|
const offset = parseInt(req.query.offset) || 0;
|
||||||
|
|
||||||
|
// Найти цепочку
|
||||||
|
const chain = chains.find(c => c.id === chainId);
|
||||||
|
if (!chain) {
|
||||||
|
return respondError(res, 'Chain not found', 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получить taskIds из цепочки
|
||||||
|
const taskIds = new Set(chain.tasks.map(t => t.id));
|
||||||
|
|
||||||
|
// Фильтровать submissions по taskIds цепочки
|
||||||
|
let filteredSubmissions = submissions.filter(s => {
|
||||||
|
const taskId = typeof s.task === 'object' ? s.task.id : s.task;
|
||||||
|
return taskIds.has(taskId);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Применить фильтр по userId если указан
|
||||||
|
if (userId) {
|
||||||
|
filteredSubmissions = filteredSubmissions.filter(s => {
|
||||||
|
const subUserId = typeof s.user === 'object' ? s.user.id : s.user;
|
||||||
|
return subUserId === userId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Применить фильтр по status если указан
|
||||||
|
if (status) {
|
||||||
|
filteredSubmissions = filteredSubmissions.filter(s => s.status === status);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получить уникальных участников
|
||||||
|
const participantMap = new Map();
|
||||||
|
|
||||||
|
filteredSubmissions.forEach(sub => {
|
||||||
|
const subUserId = typeof sub.user === 'object' ? sub.user.id : sub.user;
|
||||||
|
const subUserNickname = typeof sub.user === 'object' ? sub.user.nickname : '';
|
||||||
|
|
||||||
|
// Найти nickname если не заполнен
|
||||||
|
let nickname = subUserNickname;
|
||||||
|
if (!nickname) {
|
||||||
|
const user = users.find(u => u.id === subUserId);
|
||||||
|
nickname = user ? user.nickname : subUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!participantMap.has(subUserId)) {
|
||||||
|
participantMap.set(subUserId, {
|
||||||
|
userId: subUserId,
|
||||||
|
nickname: nickname,
|
||||||
|
completedTasks: new Set(),
|
||||||
|
totalTasks: chain.tasks.length,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если статус accepted, добавляем taskId в completedTasks
|
||||||
|
if (sub.status === 'accepted') {
|
||||||
|
const taskId = typeof sub.task === 'object' ? sub.task.id : sub.task;
|
||||||
|
participantMap.get(subUserId).completedTasks.add(taskId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Преобразовать в массив и рассчитать прогресс
|
||||||
|
const participants = Array.from(participantMap.values()).map(p => ({
|
||||||
|
userId: p.userId,
|
||||||
|
nickname: p.nickname,
|
||||||
|
completedTasks: p.completedTasks.size,
|
||||||
|
totalTasks: p.totalTasks,
|
||||||
|
progressPercent: p.totalTasks > 0
|
||||||
|
? Math.round((p.completedTasks.size / p.totalTasks) * 100)
|
||||||
|
: 0,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Сортировать submissions по дате (новые сначала)
|
||||||
|
filteredSubmissions.sort((a, b) =>
|
||||||
|
new Date(b.submittedAt) - new Date(a.submittedAt)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Применить пагинацию
|
||||||
|
const total = filteredSubmissions.length;
|
||||||
|
const paginatedSubmissions = filteredSubmissions.slice(offset, offset + limit);
|
||||||
|
|
||||||
|
// Формируем ответ
|
||||||
|
const response = {
|
||||||
|
chain: {
|
||||||
|
id: chain.id,
|
||||||
|
name: chain.name,
|
||||||
|
tasks: chain.tasks.map(t => ({
|
||||||
|
id: t.id,
|
||||||
|
title: t.title,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
participants: participants,
|
||||||
|
submissions: paginatedSubmissions,
|
||||||
|
pagination: {
|
||||||
|
total: total,
|
||||||
|
limit: limit,
|
||||||
|
offset: offset,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
respond(res, response);
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
Reference in New Issue
Block a user